diff --git a/bookingbug-angular-member.js b/bookingbug-angular-member.js index 5765032..82a5dae 100644 --- a/bookingbug-angular-member.js +++ b/bookingbug-angular-member.js @@ -494,1558 +494,1558 @@ angular.module("BBMember").controller("Wallet", function ($scope, $rootScope, $q }); 'use strict'; -angular.module('BBMember').directive('bbMemberBooking', function () { - return { - templateUrl: '_member_booking.html', - scope: { - booking: '=bbMemberBooking' - }, - require: ['^?bbMemberUpcomingBookings', '^?bbMemberPastBookings'], - link: function link(scope, element, attrs, controllers) { - var BOOKING_STATUS = { - ENQUIRY: 'Enquiry', - BOOKING: 'Booking', - RESERVATION: 'Reservation' - }; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - scope.actions = []; +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - var member_booking_controller = controllers[0] ? controllers[0] : controllers[1]; - var time_now = moment(); +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - if (scope.booking.on_waitlist && !scope.booking.datetime.isBefore(time_now, 'day')) { - scope.actions.push({ - action: member_booking_controller.book, - label: 'Book', - translation_key: 'MEMBER_BOOKING_WAITLIST_ACCEPT', - disabled: !scope.booking.settings.sent_waitlist - }); - } +angular.module('BB.Models').factory("Member.BookingModel", function ($q, $window, $bbug, MemberBookingService, BBModel, BaseModel) { + return function (_BaseModel) { + _inherits(Member_Booking, _BaseModel); - // The booking is an Enquiry, so the user can not pay - if (scope.booking.status === BOOKING_STATUS.ENQUIRY) { - scope.actions.push({ disabled: true, label: 'Confirmation pending' }); - } else if (scope.booking.paid < scope.booking.price && scope.booking.datetime.isAfter(time_now)) { - scope.actions.push({ action: member_booking_controller.pay, label: 'Pay' }); - } + function Member_Booking(data) { + _classCallCheck(this, Member_Booking); - scope.actions.push({ - action: member_booking_controller.edit, - label: 'Details', - translation_key: 'MEMBER_BOOKING_EDIT' - }); + var _this = _possibleConstructorReturn(this, _BaseModel.call(this, data)); - if (!scope.booking.datetime.isBefore(time_now, 'day')) { - return scope.actions.push({ - action: member_booking_controller.cancel, - label: 'Cancel', - translation_key: 'MEMBER_BOOKING_CANCEL' - }); + _this.datetime = moment.parseZone(_this.datetime); + if (_this.time_zone) { + _this.datetime.tz(_this.time_zone); + } + + _this.end_datetime = moment.parseZone(_this.end_datetime); + if (_this.time_zone) { + _this.end_datetime.tz(_this.time_zone); } + + _this.min_cancellation_time = moment(_this.min_cancellation_time); + _this.min_cancellation_hours = _this.datetime.diff(_this.min_cancellation_time, 'hours'); + return _this; } - }; -}); -'use strict'; -angular.module('BBMember').directive('memberBookings', function ($rootScope) { - return { - templateUrl: 'member_bookings_tabs.html', - scope: { - member: '=' - }, - link: function link(scope, element, attrs) {} - }; -}); -// methods -'use strict'; + Member_Booking.prototype.icalLink = function icalLink() { + return this._data.$href('ical'); + }; -angular.module('BBMember').directive('memberBookingsTable', function ($uibModal, $log, ModalForm, BBModel) { + Member_Booking.prototype.webcalLink = function webcalLink() { + return this._data.$href('ical'); + }; - var controller = function controller($scope, $uibModal, $document) { + Member_Booking.prototype.gcalLink = function gcalLink() { + return this._data.$href('gcal'); + }; - $scope.loading = true; + Member_Booking.prototype.getGroup = function getGroup() { + var _this2 = this; - if (!$scope.fields) { - $scope.fields = ['date_order', 'details']; - } + if (this.group) { + return this.group; + } + if (this._data.$has('event_groups')) { + return this._data.$get('event_groups').then(function (group) { + _this2.group = group; + return _this2.group; + }); + } + }; - $scope.$watch('member', function (member) { - if (member != null) { - return getBookings($scope, member); + Member_Booking.prototype.getColour = function getColour() { + if (this.getGroup()) { + return this.getGroup().colour; + } else { + return "#FFFFFF"; } - }); + }; - $scope.edit = function (id) { - var booking = _.find($scope.booking_models, function (b) { - return b.id === id; - }); - return booking.$getAnswers().then(function (answers) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + Member_Booking.prototype.getCompany = function getCompany() { + var _this3 = this; - try { - for (var _iterator = Array.from(answers.answers)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var answer = _step.value; + if (this.company) { + return this.company; + } + if (this.$has('company')) { + return this._data.$get('company').then(function (company) { + _this3.company = new BBModel.Company(company); + return _this3.company; + }); + } + }; - booking['question' + answer.question_id] = answer.value; - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } + Member_Booking.prototype.getAnswers = function getAnswers() { + var _this4 = this; - return ModalForm.edit({ - model: booking, - title: 'Booking Details', - templateUrl: 'edit_booking_modal_form.html', - success: function success(b) { - b = new BBModel.Member.Booking(b); - var i = _.indexOf($scope.booking_models, function (b) { - return b.id === id; - }); - $scope.booking_models[i] = b; - return $scope.setRows(); - } + var defer = $q.defer(); + if (this.answers) { + defer.resolve(this.answers); + } + if (this._data.$has('answers')) { + this._data.$get('answers').then(function (answers) { + _this4.answers = Array.from(answers).map(function (a) { + return new BBModel.Answer(a); + }); + return defer.resolve(_this4.answers); }); - }); + } else { + defer.resolve([]); + } + return defer.promise; }; - $scope.cancel = function (id) { - var _booking = _.find($scope.booking_models, function (b) { - return b.id === id; - }); - - var modalInstance = $uibModal.open({ - templateUrl: 'member_bookings_table_cancel_booking.html', - controller: function controller($scope, $uibModalInstance, booking) { - $scope.booking = booking; - $scope.booking.notify = true; - $scope.ok = function () { - return $uibModalInstance.close($scope.booking); - }; - return $scope.close = function () { - return $uibModalInstance.dismiss(); - }; - }, + Member_Booking.prototype.printed_price = function printed_price() { + if (parseFloat(this.price) % 1 === 0) { + return '\xA3' + this.price; + } + return $window.sprintf("£%.2f", parseFloat(this.price)); + }; - scope: $scope, - resolve: { - booking: function booking() { - return _booking; - } - } - }); + Member_Booking.prototype.$getMember = function $getMember() { + var _this5 = this; - return modalInstance.result.then(function (booking) { - $scope.loading = true; - var params = { notify: booking.notify }; - return booking.$post('cancel', params).then(function () { - var i = _.findIndex($scope.booking_models, function (b) { - return b.id === booking.id; - }); - $scope.booking_models.splice(i, 1); - $scope.setRows(); - return $scope.loading = false; + var defer = $q.defer(); + if (this.member) { + defer.resolve(this.member); + } + if (this._data.$has('member')) { + this._data.$get('member').then(function (member) { + _this5.member = new BBModel.Member.Member(member); + return defer.resolve(_this5.member); }); - }); + } + return defer.promise; }; - $scope.setRows = function () { - return $scope.bookings = _.map($scope.booking_models, function (booking) { - return { - id: booking.id, - date: moment(booking.datetime).format('YYYY-MM-DD'), - date_order: moment(booking.datetime).format('x'), - datetime: moment(booking.datetime), - details: booking.full_describe - }; - }); + Member_Booking.prototype.canCancel = function canCancel() { + return moment(this.min_cancellation_time).isAfter(moment()); }; - var getBookings = function getBookings($scope, member) { - var params = { - src: member, - start_date: $scope.startDate.format('YYYY-MM-DD'), - start_time: $scope.startTime ? $scope.startTime.format('HH:mm') : undefined, - end_date: $scope.endDate ? $scope.endDate.format('YYYY-MM-DD') : undefined, - end_time: $scope.endTime ? $scope.endTime.format('HH:mm') : undefined - }; - return BBModel.Member.Booking.$query(member, params).then(function (bookings) { - var now = moment.unix(); - if ($scope.period && $scope.period === "past") { - $scope.booking_models = _.filter(bookings.items, function (x) { - return x.datetime.unix() < now; - }); - } - if ($scope.period && $scope.period === "future") { - $scope.booking_models = _.filter(bookings.items, function (x) { - return x.datetime.unix() > now; - }); - } else { - $scope.booking_models = bookings.items; - } + Member_Booking.prototype.canMove = function canMove() { + return this.canCancel(); + }; - $scope.setRows(); - return $scope.loading = false; - }, function (err) { - $log.error(err.data); - return $scope.loading = false; - }); + Member_Booking.prototype.$update = function $update() { + return MemberBookingService.update(this); }; - if (!$scope.startDate) { - $scope.startDate = moment(); - } + Member_Booking.$query = function $query(member, params) { + return MemberBookingService.query(member, params); + }; - $scope.orderBy = $scope.defaultOrder; - if ($scope.orderBy == null) { - $scope.orderBy = 'date_order'; - } + Member_Booking.$cancel = function $cancel(member, booking) { + return MemberBookingService.cancel(member, booking); + }; - $scope.now = moment(); + Member_Booking.$update = function $update(booking) { + return MemberBookingService.update(booking); + }; - if ($scope.member) { - return getBookings($scope, $scope.member); - } - }; + Member_Booking.$flush = function $flush(member, params) { + return MemberBookingService.flush(member, params); + }; - return { - controller: controller, - templateUrl: 'member_bookings_table.html', - scope: { - apiUrl: '@', - fields: '=?', - member: '=', - startDate: '=?', - startTime: '=?', - endDate: '=?', - endTime: '=?', - defaultOrder: '=?', - period: '=?' - } - }; + return Member_Booking; + }(BaseModel); }); -'use strict'; +"use strict"; -/** - * @ngdoc directive - * @name BBMember.directive:memberForm - * @scope - * @restrict E - * - * @description - * Member form, validates & submits a form that represents a member/client - * - * @param {string} apiUrl Expexts to be bled through the scope (MUST FIX) - * @param {object} member Member object - * @param {function} onSuccessSave On save success callback - * @param {function} onFailSave On save fail callback - * @param {function} onValidationError On validation fail callback - * - */ -angular.module('BBMember').directive('memberForm', function ($rootScope, AlertService, PathSvc) { +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - return { - templateUrl: function templateUrl(el, attrs) { - if (attrs.bbCustomMemberForm != null) { - return PathSvc.directivePartial("_member_form"); - } else { - return PathSvc.directivePartial("_member_schema_form"); - } - }, +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - scope: { - apiUrl: '@', - member: '=', - onSuccessSave: '=', - onFailSave: '=', - onValidationError: '=' - }, - link: function link(scope, element, attrs) { +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - if (!$rootScope.bb) { - $rootScope.bb = {}; - } - if (!$rootScope.bb.api_url) { - $rootScope.bb.api_url = attrs.apiUrl; - } - if (!$rootScope.bb.api_url) { - $rootScope.bb.api_url = "http://www.bookingbug.com"; - } +angular.module('BB.Models').factory("Member.MemberModel", function ($q, MemberService, BBModel, BaseModel, ClientModel) { + return function (_ClientModel) { + _inherits(Member_Member, _ClientModel); - if (attrs.bbCustomMemberForm != null) { - return scope.custom_member_form = true; - } - }, - controller: function controller($scope, FormTransform) { + function Member_Member() { + _classCallCheck(this, Member_Member); - $scope.loading = true; + return _possibleConstructorReturn(this, _ClientModel.apply(this, arguments)); + } - // THIS IS CRUFTY AND SHOULD BE REMOVE WITH AN API UPDATE THAT TIDIES UP THE SCEMA RESPONE - // fix the issues we have with the the sub client and question blocks being in doted notation, and not in child objects - var checkSchema = function checkSchema(schema) { - for (var k in schema.properties) { - var v = schema.properties[k]; - var vals = k.split("."); - var identifier = vals[0]; + Member_Member.$refresh = function $refresh(member) { + return MemberService.refresh(member); + }; - if ((identifier === 'q' || identifier === 'questions') && vals.length > 1) { - if (!schema.properties[identifier]) { - schema.properties[identifier] = { type: 'object', properties: {} }; - } - if (!schema.properties[identifier].properties[vals[1]]) { - schema.properties[identifier].properties[vals[1]] = { type: 'object', properties: { answer: v } }; - } - } - if (identifier === "client" && vals.length > 2) { - if (!schema.properties.client) { - schema.properties.client = { - type: "object", - properties: { q: { type: "object", properties: {} } } - }; - } - if (schema.properties.client.properties) { - if (!schema.properties.client.properties.q.properties[vals[2]]) { - schema.properties.client.properties.q.properties[vals[2]] = { - type: "object", - properties: { answer: v } - }; - } - } - } - } - return schema; - }; + Member_Member.$current = function $current() { + return MemberService.current(); + }; - $scope.$watch('member', function (member) { - if (member != null) { - if (member.$has('edit_member')) { - return member.$get('edit_member').then(function (member_schema) { - $scope.form = member_schema.form; - var model_type = functionName(member.constructor); - if (FormTransform['edit'][model_type]) { - $scope.form = FormTransform['edit'][model_type]($scope.form, member_schema.schema, member); - } - $scope.schema = checkSchema(member_schema.schema); - return $scope.loading = false; - }); - } else if (member.$has('edit')) { - return member.$get('edit').then(function (member_schema) { - $scope.form = member_schema.form; - var model_type = functionName(member.constructor); - if (FormTransform['edit'][model_type]) { - $scope.form = FormTransform['edit'][model_type]($scope.form, member_schema.schema, member); - } - $scope.schema = checkSchema(member_schema.schema); - return $scope.loading = false; - }); - } - } - }); + Member_Member.$updateMember = function $updateMember(member, params) { + return MemberService.updateMember(member, params); + }; - var functionName = function functionName(func) { - var result = /^function\s+([\w\$]+)\s*\(/.exec(func.toString()); - if (result) { - return result[1]; - } else { - return ''; - } - }; + Member_Member.$sendWelcomeEmail = function $sendWelcomeEmail(member, params) { + return MemberService.sendWelcomeEmail(member, params); + }; - return $scope.submit = function (form, data) { - // Required for the fields to validate themselves - $scope.$broadcast('schemaFormValidate'); + Member_Member.prototype.getBookings = function getBookings(params) { + return BBModel.Member.Booking.$query(this, params); + }; - if (form.$valid) { - $scope.loading = true; - // -------------------------------------------------------------------- - // member_schema form does not bind the question answers in - // custom form elements to the Client.questions array of objects - // but rather to the Client.q array of objects, so for example: - // Client.q.1.answer <= INSTEAD OF => Client.questions[0].answer - // So in that case we need to update answers in questions to match - // the answers in q, so that if a user changes a custom form field - // the new answer and not the old one will be sent to the api - // -------------------------------------------------------------------- - if (!$scope.custom_member_form) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + return Member_Member; + }(ClientModel); +}); +"use strict"; - try { - for (var _iterator = Array.from(data.questions)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var item = _step.value; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - if (data.q[item.id]) item.answer = data.q[item.id].answer; - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - } +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - return $scope.member.$put('self', {}, data).then(function (member) { - $scope.loading = false; - AlertService.raise('UPDATE_SUCCESS'); +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - if (typeof $scope.onSuccessSave === 'function') { - return $scope.onSuccessSave(); - } - }, function (err) { - $scope.loading = false; - AlertService.raise('UPDATE_FAILED'); +angular.module("BB.Models").factory("Member.PaymentItemModel", function (BBModel, BaseModel) { + return function (_BaseModel) { + _inherits(Member_PaymentItem, _BaseModel); - if (typeof $scope.onFailSave === 'function') { - return $scope.onFailSave(); - } - }); - } else { - if (typeof $scope.onValidationError === 'function') { - return $scope.onValidationError(); - } - } - }; + function Member_PaymentItem(data) { + _classCallCheck(this, Member_PaymentItem); + + return _possibleConstructorReturn(this, _BaseModel.call(this, data)); } - }; + + return Member_PaymentItem; + }(BaseModel); }); -'use strict'; +"use strict"; -angular.module('BBMember').directive('loginMember', function ($uibModal, $document, $log, $rootScope, MemberLoginService, $templateCache, $q, $sessionStorage, halClient) { +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - var loginMemberController = function loginMemberController($scope, $uibModalInstance, company_id) { - $scope.title = 'Login'; - $scope.schema = { - type: 'object', - properties: { - email: { type: 'string', title: 'Email' }, - password: { type: 'string', title: 'Password' } - } - }; - $scope.form = [{ - key: 'email', - type: 'email', - feedback: false, - autofocus: true - }, { - key: 'password', - type: 'password', - feedback: false - }]; - $scope.login_form = {}; +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - $scope.submit = function (form) { - var options = { company_id: company_id }; - return MemberLoginService.login(form, options).then(function (member) { - member.email = form.email; - member.password = form.password; - return $uibModalInstance.close(member); - }, function (err) { - return $uibModalInstance.dismiss(err); - }); - }; +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - return $scope.cancel = function () { - return $uibModalInstance.dismiss('cancel'); - }; - }; +angular.module('BB.Models').factory("Member.PrePaidBookingModel", function (BaseModel) { + return function (_BaseModel) { + _inherits(Member_PrePaidBooking, _BaseModel); - var pickCompanyController = function pickCompanyController($scope, $uibModalInstance, companies) { - var c = void 0; - $scope.title = 'Pick Company'; - $scope.schema = { - type: 'object', - properties: { - company_id: { type: 'integer', title: 'Company' } - } - }; - $scope.schema.properties.company_id.enum = function () { - var result = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + function Member_PrePaidBooking(data) { + _classCallCheck(this, Member_PrePaidBooking); - try { - for (var _iterator = Array.from(companies)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - c = _step.value; + return _possibleConstructorReturn(this, _BaseModel.call(this, data)); + } - result.push(c.id); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } + return Member_PrePaidBooking; + }(BaseModel); +}); +"use strict"; - return result; - }(); - $scope.form = [{ - key: 'company_id', - type: 'select', - titleMap: function () { - var result1 = []; - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - try { - for (var _iterator2 = Array.from(companies)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - c = _step2.value; +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - result1.push({ value: c.id, name: c.name }); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - return result1; - }(), - autofocus: true - }]; - $scope.pick_company_form = {}; +angular.module("BB.Models").factory("Member.PurchaseModel", function ($q, MemberPurchaseService, BBModel, BaseModel) { + return function (_BaseModel) { + _inherits(Member_Purchase, _BaseModel); - $scope.submit = function (form) { - return $uibModalInstance.close(form.company_id); - }; + function Member_Purchase(data) { + _classCallCheck(this, Member_Purchase); - return $scope.cancel = function () { - return $uibModalInstance.dismiss('cancel'); - }; - }; + var _this = _possibleConstructorReturn(this, _BaseModel.call(this, data)); - var link = function link(scope, element, attrs) { - if (!$rootScope.bb) { - $rootScope.bb = {}; - } - if (!$rootScope.bb.api_url) { - $rootScope.bb.api_url = scope.apiUrl; - } - if (!$rootScope.bb.api_url) { - $rootScope.bb.api_url = "http://www.bookingbug.com"; + _this.created_at = moment.parseZone(_this.created_at); + if (_this.time_zone) { + _this.created_at.tz(_this.time_zone); + } + return _this; } - var loginModal = function loginModal() { - var modalInstance = $uibModal.open({ - templateUrl: 'login_modal_form.html', - controller: loginMemberController, - resolve: { - company_id: function company_id() { - return scope.companyId; - } - } - }); - return modalInstance.result.then(function (result) { - scope.memberEmail = result.email; - scope.memberPassword = result.password; - if (result.$has('members')) { - return result.$get('members').then(function (members) { - scope.members = members; - return $q.all(Array.from(members).map(function (m) { - return m.$get('company'); - })).then(function (companies) { - return pickCompanyModal(companies); - }); - }); - } else { - return scope.member = result; - } - }, function () { - return loginModal(); + Member_Purchase.prototype.getItems = function getItems() { + var deferred = $q.defer(); + this._data.$get('purchase_items').then(function (items) { + this.items = Array.from(items).map(function (item) { + return new BBModel.Member.PurchaseItem(item); + }); + return deferred.resolve(this.items); }); + return deferred.promise; }; - var pickCompanyModal = function pickCompanyModal(_companies) { - var modalInstance = $uibModal.open({ - templateUrl: 'pick_company_modal_form.html', - controller: pickCompanyController, - resolve: { - companies: function companies() { - return _companies; - } - } - }); - return modalInstance.result.then(function (company_id) { - scope.companyId = company_id; - return tryLogin(); - }, function () { - return pickCompanyModal(); - }); + Member_Purchase.$query = function $query(member, params) { + return MemberPurchaseService.query(member, params); }; - var tryLogin = function tryLogin() { - var login_form = { - email: scope.memberEmail, - password: scope.memberPassword - }; - var options = { company_id: scope.companyId }; - return MemberLoginService.login(login_form, options).then(function (result) { - if (result.$has('members')) { - return result.$get('members').then(function (members) { - scope.members = members; - return $q.all(Array.from(members).map(function (m) { - return m.$get('company'); - })).then(function (companies) { - return pickCompanyModal(companies); - }); - }); - } else { - return scope.member = result; - } - }, function (err) { - return loginModal(); - }); - }; + return Member_Purchase; + }(BaseModel); +}); +"use strict"; - if (scope.memberEmail && scope.memberPassword) { - return tryLogin(); - } else if ($sessionStorage.getItem("login")) { - var session_member = $sessionStorage.getItem("login"); - session_member = halClient.createResource(session_member); - return scope.member = session_member; - } else { - return loginModal(); +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +angular.module("BB.Models").factory("Member.PurchaseItemModel", function (BBModel, BaseModel) { + return function (_BaseModel) { + _inherits(Member_PurchaseItem, _BaseModel); + + function Member_PurchaseItem(data) { + _classCallCheck(this, Member_PurchaseItem); + + return _possibleConstructorReturn(this, _BaseModel.call(this, data)); } - }; - return { - link: link, - scope: { - memberEmail: '@', - memberPassword: '@', - companyId: '@', - apiUrl: '@', - member: '=' - }, - transclude: true, - template: '
' - }; + return Member_PurchaseItem; + }(BaseModel); }); -'use strict'; +"use strict"; -angular.module('BBMember').directive('bbMemberPastBookings', function ($rootScope, PaginationService) { +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - return { - templateUrl: 'member_past_bookings.html', - scope: { - member: '=', - notLoaded: '=', - setLoaded: '=' - }, - controller: 'MemberBookings', - link: function link(scope, element, attrs) { +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - var getBookings = function getBookings() { - return scope.getPastBookings().then(function (past_bookings) { - if (past_bookings) { - return PaginationService.update(scope.pagination, past_bookings.length); - } - }); - }; +angular.module("BB.Models").factory("Member.WalletModel", function (WalletService, BBModel, BaseModel) { + return function (_BaseModel) { + _inherits(Member_Wallet, _BaseModel); - scope.$watch('member', function () { - if (scope.member && !scope.past_bookings) { - return getBookings(); - } - }); + function Member_Wallet(data) { + _classCallCheck(this, Member_Wallet); - if (scope.member) { - return getBookings(); - } + return _possibleConstructorReturn(this, _BaseModel.call(this, data)); } - }; -}); -'use strict'; - -angular.module('BBMember').directive('bbMemberPrePaidBookings', function ($rootScope, PaginationService) { - return { - templateUrl: 'member_pre_paid_bookings.html', - scope: { - member: '=' - }, - controller: 'MemberBookings', - link: function link(scope, element, attrs) { + Member_Wallet.$getWalletForMember = function $getWalletForMember(member, params) { + return WalletService.getWalletForMember(member, params); + }; - scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); + Member_Wallet.$getWalletLogs = function $getWalletLogs(wallet) { + return WalletService.getWalletLogs(wallet); + }; - var getBookings = function getBookings() { - return scope.getPrePaidBookings({}).then(function (pre_paid_bookings) { - return PaginationService.update(scope.pagination, pre_paid_bookings.length); - }); - }; + Member_Wallet.$getWalletPurchaseBandsForWallet = function $getWalletPurchaseBandsForWallet(wallet) { + return WalletService.getWalletPurchaseBandsForWallet(wallet); + }; - scope.$watch('member', function () { - if (!scope.pre_paid_bookings) { - return getBookings(); - } - }); + Member_Wallet.$updateWalletForMember = function $updateWalletForMember(member, params) { + return WalletService.updateWalletForMember(member, params); + }; - scope.$on("booking:cancelled", function (event) { - return scope.getPrePaidBookings({}).then(function (pre_paid_bookings) { - return PaginationService.update(scope.pagination, pre_paid_bookings.length); - }); - }); + Member_Wallet.$createWalletForMember = function $createWalletForMember(member) { + return WalletService.createWalletForMember(member); + }; - if (scope.member) { - return getBookings(); - } - } - }; + return Member_Wallet; + }(BaseModel); }); -'use strict'; +"use strict"; -angular.module('BBMember').directive('bbMemberPurchases', function ($rootScope, PaginationService) { +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - return { - templateUrl: 'member_purchases.html', - scope: true, - controller: 'MemberPurchases', - link: function link(scope, element, attrs) { +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - scope.member = scope.$eval(attrs.member); - if ($rootScope.member) { - if (!scope.member) { - scope.member = $rootScope.member; - } - } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); +angular.module("BB.Models").factory("Member.WalletLogModel", function ($q, BBModel, BaseModel) { + return function (_BaseModel) { + _inherits(Member_WalletLog, _BaseModel); - return $rootScope.connection_started.then(function () { - if (scope.member) { - return scope.getPurchases().then(function (purchases) { - return PaginationService.update(scope.pagination, purchases.length); - }); - } - }); - } - }; -}); -'use strict'; + function Member_WalletLog(data) { + _classCallCheck(this, Member_WalletLog); -/** - * @ngdoc directive - * @module BBMember - * @name memberSsoLogin - * - * @description - * Initialises member login with SSO - */ + var _this = _possibleConstructorReturn(this, _BaseModel.call(this, data)); -(function () { - angular.module('BBMember').directive('memberSsoLogin', memberSsoLogin); + _this.created_at = moment(_this.created_at); - function memberSsoLogin($rootScope, $sniffer, $window, $log, LoginService, QueryStringService, MemberOptions, bbConfig) { - return { - scope: { - token: '@memberSsoLogin', - company_id: '@companyId' - }, - transclude: true, - template: '
', - link: link - }; + // HACK - if payment amount is less than zero, API returns it as zero! + _this.payment_amount = parseFloat(_this.amount) * 100; - function link(scope) { - var handleSso = function handleSso() { - var options = { - root: $rootScope.bb.api_url, - company_id: scope.company_id - }; + // HACK - new wallet amount should be returned as a integer + _this.new_wallet_amount = parseFloat(_this.new_wallet_amount) * 100; + return _this; + } - var data = { - token: scope.token ? scope.token : QueryStringService('sso_token') - }; + return Member_WalletLog; + }(BaseModel); +}); +"use strict"; - if ($sniffer.msie && $sniffer.msie < 10 && $rootScope.iframe_proxy_ready === false) { - $timeout(function () { - loginSso(options, data); - }, 2000); - } else { - loginSso(options, data); - } - }; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - var redirectToErrorPage = function redirectToErrorPage(page) { - if (!page.includes('.html')) { - $log.info('configured sso redirect page is not a valid html file'); - } else { - $window.location.pathname = page; - } - }; +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - var loginSso = function loginSso(options, data) { - LoginService.ssoLogin(options, data).then(function (member) { - scope.member = member; - }, function (err) { - $log.info('Could not complete member sso login', err); - if (MemberOptions.ssoErrorRedirectPage) { - var redirectPath = bbConfig.BUILD.DEPLOY_PATH + MemberOptions.ssoErrorRedirectPage; - redirectToErrorPage(redirectPath); - } - }); - }; +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - handleSso(); +angular.module("BB.Models").factory('Member.WalletPurchaseBandModel', function (BBModel, BaseModel) { + return function (_BaseModel) { + _inherits(Member_WalletPurchaseBand, _BaseModel); + + function Member_WalletPurchaseBand(data) { + _classCallCheck(this, Member_WalletPurchaseBand); + + return _possibleConstructorReturn(this, _BaseModel.call(this, data)); } - } -})(); -'use strict'; -angular.module('BBMember').directive('bbMemberUpcomingBookings', function ($rootScope, PaginationService, PurchaseService) { + return Member_WalletPurchaseBand; + }(BaseModel); +}); +'use strict'; +angular.module('BBMember').directive('bbMemberBooking', function () { return { - templateUrl: 'member_upcoming_bookings.html', + templateUrl: '_member_booking.html', scope: { - member: '=', - notLoaded: '=', - setLoaded: '=' + booking: '=bbMemberBooking' }, - controller: 'MemberBookings', - link: function link(scope, element, attrs) { - - scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); - - var getBookings = function getBookings() { - return scope.getUpcomingBookings().then(function (upcoming_bookings) { - return PaginationService.update(scope.pagination, upcoming_bookings.length); - }); + require: ['^?bbMemberUpcomingBookings', '^?bbMemberPastBookings'], + link: function link(scope, element, attrs, controllers) { + var BOOKING_STATUS = { + ENQUIRY: 'Enquiry', + BOOKING: 'Booking', + RESERVATION: 'Reservation' }; - scope.$on('updateBookings', function () { - scope.flushBookings(); - return getBookings(); - }); + scope.actions = []; - scope.$watch('member', function () { - if (!scope.upcoming_bookings) { - return getBookings(); - } - }); + var member_booking_controller = controllers[0] ? controllers[0] : controllers[1]; + var time_now = moment(); - return $rootScope.connection_started.then(function () { - return getBookings(); + if (scope.booking.on_waitlist && !scope.booking.datetime.isBefore(time_now, 'day')) { + scope.actions.push({ + action: member_booking_controller.book, + label: 'Book', + translation_key: 'MEMBER_BOOKING_WAITLIST_ACCEPT', + disabled: !scope.booking.settings.sent_waitlist + }); + } + + // The booking is an Enquiry, so the user can not pay + if (scope.booking.status === BOOKING_STATUS.ENQUIRY) { + scope.actions.push({ disabled: true, label: 'Confirmation pending' }); + } else if (scope.booking.paid < scope.booking.price && scope.booking.datetime.isAfter(time_now)) { + scope.actions.push({ action: member_booking_controller.pay, label: 'Pay' }); + } + + scope.actions.push({ + action: member_booking_controller.edit, + label: 'Details', + translation_key: 'MEMBER_BOOKING_EDIT' }); + + if (!scope.booking.datetime.isBefore(time_now, 'day')) { + return scope.actions.push({ + action: member_booking_controller.cancel, + label: 'Cancel', + translation_key: 'MEMBER_BOOKING_CANCEL' + }); + } } }; }); 'use strict'; -angular.module('BBMember').directive('bbWallet', function ($rootScope) { - +angular.module('BBMember').directive('memberBookings', function ($rootScope) { return { - scope: true, - controller: 'Wallet', - templateUrl: 'wallet.html', - link: function link(scope, element, attrs) { + templateUrl: 'member_bookings_tabs.html', + scope: { + member: '=' + }, + link: function link(scope, element, attrs) {} + }; +}); +// methods +'use strict'; - scope.member = scope.$eval(attrs.member); - if ($rootScope.member) { - if (!scope.member) { - scope.member = $rootScope.member; - } - } +angular.module('BBMember').directive('memberBookingsTable', function ($uibModal, $log, ModalForm, BBModel) { - scope.show_wallet_logs = true; - scope.show_topup_box = false; + var controller = function controller($scope, $uibModal, $document) { - $rootScope.connection_started.then(function () { - if (scope.member) { - return scope.getWalletForMember(scope.member); - } - }); + $scope.loading = true; - scope.$on('wallet:topped_up', function (event, wallet) { - scope.wallet = wallet; - scope.show_topup_box = false; - return scope.show_wallet_logs = true; + if (!$scope.fields) { + $scope.fields = ['date_order', 'details']; + } + + $scope.$watch('member', function (member) { + if (member != null) { + return getBookings($scope, member); + } + }); + + $scope.edit = function (id) { + var booking = _.find($scope.booking_models, function (b) { + return b.id === id; }); + return booking.$getAnswers().then(function (answers) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; - return scope.$on("booking:cancelled", function (event) { - if (scope.member) { - return scope.getWalletForMember(scope.member); + try { + for (var _iterator = Array.from(answers.answers)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var answer = _step.value; + + booking['question' + answer.question_id] = answer.value; + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } } + + return ModalForm.edit({ + model: booking, + title: 'Booking Details', + templateUrl: 'edit_booking_modal_form.html', + success: function success(b) { + b = new BBModel.Member.Booking(b); + var i = _.indexOf($scope.booking_models, function (b) { + return b.id === id; + }); + $scope.booking_models[i] = b; + return $scope.setRows(); + } + }); }); - } - }; -}); -'use strict'; + }; -angular.module('BBMember').directive('bbWalletLogs', function ($rootScope, PaginationService) { + $scope.cancel = function (id) { + var _booking = _.find($scope.booking_models, function (b) { + return b.id === id; + }); - return { - templateUrl: 'wallet_logs.html', - scope: true, - controller: 'Wallet', - require: '^?bbWallet', - link: function link(scope, element, attrs, ctrl) { + var modalInstance = $uibModal.open({ + templateUrl: 'member_bookings_table_cancel_booking.html', + controller: function controller($scope, $uibModalInstance, booking) { + $scope.booking = booking; + $scope.booking.notify = true; + $scope.ok = function () { + return $uibModalInstance.close($scope.booking); + }; + return $scope.close = function () { + return $uibModalInstance.dismiss(); + }; + }, - scope.member = scope.$eval(attrs.member); - if ($rootScope.member) { - if (!scope.member) { - scope.member = $rootScope.member; + scope: $scope, + resolve: { + booking: function booking() { + return _booking; + } } - } - - scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); + }); - var getWalletLogs = function getWalletLogs() { - return scope.getWalletLogs().then(function (logs) { - return PaginationService.update(scope.pagination, logs.length); + return modalInstance.result.then(function (booking) { + $scope.loading = true; + var params = { notify: booking.notify }; + return booking.$post('cancel', params).then(function () { + var i = _.findIndex($scope.booking_models, function (b) { + return b.id === booking.id; + }); + $scope.booking_models.splice(i, 1); + $scope.setRows(); + return $scope.loading = false; }); - }; + }); + }; - // listen to when the wallet is topped up - scope.$on('wallet:topped_up', function (event) { - return getWalletLogs(); + $scope.setRows = function () { + return $scope.bookings = _.map($scope.booking_models, function (booking) { + return { + id: booking.id, + date: moment(booking.datetime).format('YYYY-MM-DD'), + date_order: moment(booking.datetime).format('x'), + datetime: moment(booking.datetime), + details: booking.full_describe + }; }); + }; - // wait for wallet to be loaded by bbWallet or by self - return $rootScope.connection_started.then(function () { - if (ctrl) { - var deregisterWatch = void 0; - return deregisterWatch = scope.$watch('wallet', function () { - if (scope.wallet) { - getWalletLogs(); - return deregisterWatch(); - } + var getBookings = function getBookings($scope, member) { + var params = { + src: member, + start_date: $scope.startDate.format('YYYY-MM-DD'), + start_time: $scope.startTime ? $scope.startTime.format('HH:mm') : undefined, + end_date: $scope.endDate ? $scope.endDate.format('YYYY-MM-DD') : undefined, + end_time: $scope.endTime ? $scope.endTime.format('HH:mm') : undefined + }; + return BBModel.Member.Booking.$query(member, params).then(function (bookings) { + var now = moment.unix(); + if ($scope.period && $scope.period === "past") { + $scope.booking_models = _.filter(bookings.items, function (x) { + return x.datetime.unix() < now; }); - } else { - return scope.getWalletForMember(scope.member).then(function () { - return getWalletLogs(); + } + if ($scope.period && $scope.period === "future") { + $scope.booking_models = _.filter(bookings.items, function (x) { + return x.datetime.unix() > now; }); + } else { + $scope.booking_models = bookings.items; } + + $scope.setRows(); + return $scope.loading = false; + }, function (err) { + $log.error(err.data); + return $scope.loading = false; }); + }; + + if (!$scope.startDate) { + $scope.startDate = moment(); + } + + $scope.orderBy = $scope.defaultOrder; + if ($scope.orderBy == null) { + $scope.orderBy = 'date_order'; + } + + $scope.now = moment(); + + if ($scope.member) { + return getBookings($scope, $scope.member); + } + }; + + return { + controller: controller, + templateUrl: 'member_bookings_table.html', + scope: { + apiUrl: '@', + fields: '=?', + member: '=', + startDate: '=?', + startTime: '=?', + endDate: '=?', + endTime: '=?', + defaultOrder: '=?', + period: '=?' } }; }); -"use strict"; +'use strict'; -angular.module("BB.Directives").directive("bbWalletPayment", function ($sce, $rootScope, $window, $location, GeneralOptions, AlertService) { +/** + * @ngdoc directive + * @name BBMember.directive:memberForm + * @scope + * @restrict E + * + * @description + * Member form, validates & submits a form that represents a member/client + * + * @param {string} apiUrl Expexts to be bled through the scope (MUST FIX) + * @param {object} member Member object + * @param {function} onSuccessSave On save success callback + * @param {function} onFailSave On save fail callback + * @param {function} onValidationError On validation fail callback + * + */ +angular.module('BBMember').directive('memberForm', function ($rootScope, AlertService, PathSvc) { return { - restrict: 'A', - controller: 'Wallet', - scope: true, - replace: true, - require: '^?bbWallet', - link: function link(scope, element, attrs, ctrl) { - - var one_pound = 100; - scope.wallet_payment_options = scope.$eval(attrs.bbWalletPayment) || {}; - scope.member = scope.$eval(attrs.member); - if ($rootScope.member) { - if (!scope.member) { - scope.member = $rootScope.member; - } - } - if (scope.wallet_payment_options.member) { - if (!scope.member) { - scope.member = scope.wallet_payment_options.member; - } + templateUrl: function templateUrl(el, attrs) { + if (attrs.bbCustomMemberForm != null) { + return PathSvc.directivePartial("_member_form"); + } else { + return PathSvc.directivePartial("_member_schema_form"); } - scope.amount_increment = scope.wallet_payment_options.amount_increment || one_pound; - - var getHost = function getHost(url) { - var a = document.createElement('a'); - a.href = url; - return a['protocol'] + '//' + a['host']; - }; - - var sendLoadEvent = function sendLoadEvent(element, origin, scope) { - var referrer = $location.protocol() + "://" + $location.host(); - if ($location.port()) { - referrer += ":" + $location.port(); - } + }, - var custom_stylesheet = scope.wallet_payment_options.custom_stylesheet ? scope.wallet_payment_options.custom_stylesheet : null; - var custom_partial_url = scope.bb && scope.bb.custom_partial_url ? scope.bb.custom_partial_url : null; + scope: { + apiUrl: '@', + member: '=', + onSuccessSave: '=', + onFailSave: '=', + onValidationError: '=' + }, + link: function link(scope, element, attrs) { - var payload = JSON.stringify({ - 'type': 'load', - 'message': referrer, - 'custom_partial_url': custom_partial_url, - 'custom_stylesheet': custom_stylesheet, - 'scroll_offset': GeneralOptions.scroll_offset - }); - return element.find('iframe')[0].contentWindow.postMessage(payload, origin); - }; + if (!$rootScope.bb) { + $rootScope.bb = {}; + } + if (!$rootScope.bb.api_url) { + $rootScope.bb.api_url = attrs.apiUrl; + } + if (!$rootScope.bb.api_url) { + $rootScope.bb.api_url = "http://www.bookingbug.com"; + } - var calculateAmount = function calculateAmount() { - // if this is a basket topup, use either the amount due or the min topup amount, whichever is greatest + if (attrs.bbCustomMemberForm != null) { + return scope.custom_member_form = true; + } + }, + controller: function controller($scope, FormTransform) { - if (scope.wallet_payment_options.basket_topup) { + $scope.loading = true; - var amount_due = scope.bb.basket.dueTotal() - scope.wallet.amount; + // THIS IS CRUFTY AND SHOULD BE REMOVE WITH AN API UPDATE THAT TIDIES UP THE SCEMA RESPONE + // fix the issues we have with the the sub client and question blocks being in doted notation, and not in child objects + var checkSchema = function checkSchema(schema) { + for (var k in schema.properties) { + var v = schema.properties[k]; + var vals = k.split("."); + var identifier = vals[0]; - if (amount_due > scope.wallet.min_amount) { - scope.amount = Math.ceil(amount_due / scope.amount_increment) * scope.amount_increment; - } else { - scope.amount = scope.wallet.min_amount; + if ((identifier === 'q' || identifier === 'questions') && vals.length > 1) { + if (!schema.properties[identifier]) { + schema.properties[identifier] = { type: 'object', properties: {} }; + } + if (!schema.properties[identifier].properties[vals[1]]) { + schema.properties[identifier].properties[vals[1]] = { type: 'object', properties: { answer: v } }; + } } - - return scope.min_amount = scope.amount; - } else if (scope.wallet.min_amount) { - scope.amount = scope.wallet_payment_options.amount && scope.wallet_payment_options.amount > scope.wallet.min_amount ? scope.wallet_payment_options.amount : scope.wallet.min_amount; - return scope.min_amount = scope.wallet.min_amount; - } else { - scope.min_amount = 0; - if (scope.wallet_payment_options.amount) { - return scope.amount = scope.wallet_payment_options.amount; + if (identifier === "client" && vals.length > 2) { + if (!schema.properties.client) { + schema.properties.client = { + type: "object", + properties: { q: { type: "object", properties: {} } } + }; + } + if (schema.properties.client.properties) { + if (!schema.properties.client.properties.q.properties[vals[2]]) { + schema.properties.client.properties.q.properties[vals[2]] = { + type: "object", + properties: { answer: v } + }; + } + } } } + return schema; }; - // wait for wallet to be loaded by bbWallet or by self - $rootScope.connection_started.then(function () { - if (ctrl) { - var deregisterWatch = void 0; - return deregisterWatch = scope.$watch('wallet', function () { - if (scope.wallet) { - calculateAmount(); - return deregisterWatch(); - } - }); - } else { - return scope.getWalletForMember(scope.member).then(function () { - return calculateAmount(); - }); - } - }); - - // listen to when the wallet is updated - scope.$on('wallet:updated', function (event, wallet, band) { - - // load iframe using payment link - if (band == null) { - band = null; - } - if (wallet.$has('new_payment')) { - scope.notLoaded(scope); - if (band) { - scope.amount = band.actual_amount; - } - scope.wallet_payment_url = $sce.trustAsResourceUrl(wallet.$href("new_payment")); - scope.show_payment_iframe = true; - return element.find('iframe').bind('load', function (event) { - var url = void 0; - if (scope.wallet_payment_url) { - url = scope.wallet_payment_url; - } - var origin = getHost(url); - sendLoadEvent(element, origin, scope); - return scope.$apply(function () { - return scope.setLoaded(scope); + $scope.$watch('member', function (member) { + if (member != null) { + if (member.$has('edit_member')) { + return member.$get('edit_member').then(function (member_schema) { + $scope.form = member_schema.form; + var model_type = functionName(member.constructor); + if (FormTransform['edit'][model_type]) { + $scope.form = FormTransform['edit'][model_type]($scope.form, member_schema.schema, member); + } + $scope.schema = checkSchema(member_schema.schema); + return $scope.loading = false; + }); + } else if (member.$has('edit')) { + return member.$get('edit').then(function (member_schema) { + $scope.form = member_schema.form; + var model_type = functionName(member.constructor); + if (FormTransform['edit'][model_type]) { + $scope.form = FormTransform['edit'][model_type]($scope.form, member_schema.schema, member); + } + $scope.schema = checkSchema(member_schema.schema); + return $scope.loading = false; }); - }); + } } }); - // register iframe message listener - return $window.addEventListener('message', function (event) { - var data = void 0; - if (angular.isObject(event.data)) { - data = event.data; - } else if (!event.data.match(/iFrameSizer/)) { - data = JSON.parse(event.data); + var functionName = function functionName(func) { + var result = /^function\s+([\w\$]+)\s*\(/.exec(func.toString()); + if (result) { + return result[1]; + } else { + return ''; } - return scope.$apply(function () { - if (data) { - switch (data.type) { - case "submitting": - return scope.notLoaded(scope); - case "error": - $rootScope.$broadcast("wallet:topup_failed"); - scope.notLoaded(scope); - // reload the payment iframe - document.getElementsByTagName("iframe")[0].src += ''; - return AlertService.raise('PAYMENT_FAILED'); - case "payment_complete": - case "wallet_payment_complete": - case "basket_wallet_payment_complete": - scope.show_payment_iframe = false; - if (scope.wallet_payment_options.basket_topup) { - return scope.basketWalletPaymentDone(); - } else { - return scope.walletPaymentDone(); + }; + + return $scope.submit = function (form, data) { + // Required for the fields to validate themselves + $scope.$broadcast('schemaFormValidate'); + + if (form.$valid) { + $scope.loading = true; + // -------------------------------------------------------------------- + // member_schema form does not bind the question answers in + // custom form elements to the Client.questions array of objects + // but rather to the Client.q array of objects, so for example: + // Client.q.1.answer <= INSTEAD OF => Client.questions[0].answer + // So in that case we need to update answers in questions to match + // the answers in q, so that if a user changes a custom form field + // the new answer and not the old one will be sent to the api + // -------------------------------------------------------------------- + if (!$scope.custom_member_form) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = Array.from(data.questions)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var item = _step.value; + + if (data.q[item.id]) item.answer = data.q[item.id].answer; + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; } + } } } - }); - }, false); - } - }; -}); -"use strict"; - -angular.module("BB.Directives").directive("bbWalletPurchaseBands", function ($rootScope) { - return { - scope: true, - restrict: "AE", - templateUrl: "wallet_purchase_bands.html", - controller: "Wallet", - require: '^?bbWallet', - link: function link(scope, attr, elem, ctrl) { + return $scope.member.$put('self', {}, data).then(function (member) { + $scope.loading = false; + AlertService.raise('UPDATE_SUCCESS'); - scope.member = scope.$eval(attr.member); - if ($rootScope.member) { - if (!scope.member) { - scope.member = $rootScope.member; - } - } + if (typeof $scope.onSuccessSave === 'function') { + return $scope.onSuccessSave(); + } + }, function (err) { + $scope.loading = false; + AlertService.raise('UPDATE_FAILED'); - return $rootScope.connection_started.then(function () { - if (ctrl) { - var deregisterWatch = void 0; - return deregisterWatch = scope.$watch('wallet', function () { - if (scope.wallet) { - scope.getWalletPurchaseBandsForWallet(scope.wallet); - return deregisterWatch(); + if (typeof $scope.onFailSave === 'function') { + return $scope.onFailSave(); } }); } else { - return scope.getWalletForMember(scope.member).then(function () { - return scope.getWalletPurchaseBandsForWallet(scope.wallet); - }); + if (typeof $scope.onValidationError === 'function') { + return $scope.onValidationError(); + } } - }); + }; } }; }); 'use strict'; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -angular.module('BB.Models').factory("Member.BookingModel", function ($q, $window, $bbug, MemberBookingService, BBModel, BaseModel) { - return function (_BaseModel) { - _inherits(Member_Booking, _BaseModel); - - function Member_Booking(data) { - _classCallCheck(this, Member_Booking); - - var _this = _possibleConstructorReturn(this, _BaseModel.call(this, data)); - - _this.datetime = moment.parseZone(_this.datetime); - if (_this.time_zone) { - _this.datetime.tz(_this.time_zone); - } +angular.module('BBMember').directive('loginMember', function ($uibModal, $document, $log, $rootScope, MemberLoginService, $templateCache, $q, $sessionStorage, halClient) { - _this.end_datetime = moment.parseZone(_this.end_datetime); - if (_this.time_zone) { - _this.end_datetime.tz(_this.time_zone); + var loginMemberController = function loginMemberController($scope, $uibModalInstance, company_id) { + $scope.title = 'Login'; + $scope.schema = { + type: 'object', + properties: { + email: { type: 'string', title: 'Email' }, + password: { type: 'string', title: 'Password' } } - - _this.min_cancellation_time = moment(_this.min_cancellation_time); - _this.min_cancellation_hours = _this.datetime.diff(_this.min_cancellation_time, 'hours'); - return _this; - } - - Member_Booking.prototype.icalLink = function icalLink() { - return this._data.$href('ical'); }; + $scope.form = [{ + key: 'email', + type: 'email', + feedback: false, + autofocus: true + }, { + key: 'password', + type: 'password', + feedback: false + }]; + $scope.login_form = {}; - Member_Booking.prototype.webcalLink = function webcalLink() { - return this._data.$href('ical'); - }; - - Member_Booking.prototype.gcalLink = function gcalLink() { - return this._data.$href('gcal'); - }; - - Member_Booking.prototype.getGroup = function getGroup() { - var _this2 = this; - - if (this.group) { - return this.group; - } - if (this._data.$has('event_groups')) { - return this._data.$get('event_groups').then(function (group) { - _this2.group = group; - return _this2.group; - }); - } + $scope.submit = function (form) { + var options = { company_id: company_id }; + return MemberLoginService.login(form, options).then(function (member) { + member.email = form.email; + member.password = form.password; + return $uibModalInstance.close(member); + }, function (err) { + return $uibModalInstance.dismiss(err); + }); }; - Member_Booking.prototype.getColour = function getColour() { - if (this.getGroup()) { - return this.getGroup().colour; - } else { - return "#FFFFFF"; - } + return $scope.cancel = function () { + return $uibModalInstance.dismiss('cancel'); }; + }; - Member_Booking.prototype.getCompany = function getCompany() { - var _this3 = this; - - if (this.company) { - return this.company; - } - if (this.$has('company')) { - return this._data.$get('company').then(function (company) { - _this3.company = new BBModel.Company(company); - return _this3.company; - }); + var pickCompanyController = function pickCompanyController($scope, $uibModalInstance, companies) { + var c = void 0; + $scope.title = 'Pick Company'; + $scope.schema = { + type: 'object', + properties: { + company_id: { type: 'integer', title: 'Company' } } }; + $scope.schema.properties.company_id.enum = function () { + var result = []; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; - Member_Booking.prototype.getAnswers = function getAnswers() { - var _this4 = this; + try { + for (var _iterator = Array.from(companies)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + c = _step.value; - var defer = $q.defer(); - if (this.answers) { - defer.resolve(this.answers); - } - if (this._data.$has('answers')) { - this._data.$get('answers').then(function (answers) { - _this4.answers = Array.from(answers).map(function (a) { - return new BBModel.Answer(a); - }); - return defer.resolve(_this4.answers); - }); - } else { - defer.resolve([]); + result.push(c.id); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } } - return defer.promise; - }; - Member_Booking.prototype.printed_price = function printed_price() { - if (parseFloat(this.price) % 1 === 0) { - return '\xA3' + this.price; - } - return $window.sprintf("£%.2f", parseFloat(this.price)); - }; + return result; + }(); + $scope.form = [{ + key: 'company_id', + type: 'select', + titleMap: function () { + var result1 = []; + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; - Member_Booking.prototype.$getMember = function $getMember() { - var _this5 = this; + try { + for (var _iterator2 = Array.from(companies)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + c = _step2.value; - var defer = $q.defer(); - if (this.member) { - defer.resolve(this.member); - } - if (this._data.$has('member')) { - this._data.$get('member').then(function (member) { - _this5.member = new BBModel.Member.Member(member); - return defer.resolve(_this5.member); - }); - } - return defer.promise; - }; + result1.push({ value: c.id, name: c.name }); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } - Member_Booking.prototype.canCancel = function canCancel() { - return moment(this.min_cancellation_time).isAfter(moment()); - }; + return result1; + }(), + autofocus: true + }]; + $scope.pick_company_form = {}; - Member_Booking.prototype.canMove = function canMove() { - return this.canCancel(); + $scope.submit = function (form) { + return $uibModalInstance.close(form.company_id); }; - Member_Booking.prototype.$update = function $update() { - return MemberBookingService.update(this); + return $scope.cancel = function () { + return $uibModalInstance.dismiss('cancel'); }; + }; - Member_Booking.$query = function $query(member, params) { - return MemberBookingService.query(member, params); - }; + var link = function link(scope, element, attrs) { + if (!$rootScope.bb) { + $rootScope.bb = {}; + } + if (!$rootScope.bb.api_url) { + $rootScope.bb.api_url = scope.apiUrl; + } + if (!$rootScope.bb.api_url) { + $rootScope.bb.api_url = "http://www.bookingbug.com"; + } - Member_Booking.$cancel = function $cancel(member, booking) { - return MemberBookingService.cancel(member, booking); + var loginModal = function loginModal() { + var modalInstance = $uibModal.open({ + templateUrl: 'login_modal_form.html', + controller: loginMemberController, + resolve: { + company_id: function company_id() { + return scope.companyId; + } + } + }); + return modalInstance.result.then(function (result) { + scope.memberEmail = result.email; + scope.memberPassword = result.password; + if (result.$has('members')) { + return result.$get('members').then(function (members) { + scope.members = members; + return $q.all(Array.from(members).map(function (m) { + return m.$get('company'); + })).then(function (companies) { + return pickCompanyModal(companies); + }); + }); + } else { + return scope.member = result; + } + }, function () { + return loginModal(); + }); }; - Member_Booking.$update = function $update(booking) { - return MemberBookingService.update(booking); + var pickCompanyModal = function pickCompanyModal(_companies) { + var modalInstance = $uibModal.open({ + templateUrl: 'pick_company_modal_form.html', + controller: pickCompanyController, + resolve: { + companies: function companies() { + return _companies; + } + } + }); + return modalInstance.result.then(function (company_id) { + scope.companyId = company_id; + return tryLogin(); + }, function () { + return pickCompanyModal(); + }); }; - Member_Booking.$flush = function $flush(member, params) { - return MemberBookingService.flush(member, params); + var tryLogin = function tryLogin() { + var login_form = { + email: scope.memberEmail, + password: scope.memberPassword + }; + var options = { company_id: scope.companyId }; + return MemberLoginService.login(login_form, options).then(function (result) { + if (result.$has('members')) { + return result.$get('members').then(function (members) { + scope.members = members; + return $q.all(Array.from(members).map(function (m) { + return m.$get('company'); + })).then(function (companies) { + return pickCompanyModal(companies); + }); + }); + } else { + return scope.member = result; + } + }, function (err) { + return loginModal(); + }); }; - return Member_Booking; - }(BaseModel); + if (scope.memberEmail && scope.memberPassword) { + return tryLogin(); + } else if ($sessionStorage.getItem("login")) { + var session_member = $sessionStorage.getItem("login"); + session_member = halClient.createResource(session_member); + return scope.member = session_member; + } else { + return loginModal(); + } + }; + + return { + link: link, + scope: { + memberEmail: '@', + memberPassword: '@', + companyId: '@', + apiUrl: '@', + member: '=' + }, + transclude: true, + template: '
' + }; }); -"use strict"; +'use strict'; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +angular.module('BBMember').directive('bbMemberPastBookings', function ($rootScope, PaginationService) { -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + return { + templateUrl: 'member_past_bookings.html', + scope: { + member: '=', + notLoaded: '=', + setLoaded: '=' + }, + controller: 'MemberBookings', + link: function link(scope, element, attrs) { -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); -angular.module('BB.Models').factory("Member.MemberModel", function ($q, MemberService, BBModel, BaseModel, ClientModel) { - return function (_ClientModel) { - _inherits(Member_Member, _ClientModel); + var getBookings = function getBookings() { + return scope.getPastBookings().then(function (past_bookings) { + if (past_bookings) { + return PaginationService.update(scope.pagination, past_bookings.length); + } + }); + }; - function Member_Member() { - _classCallCheck(this, Member_Member); + scope.$watch('member', function () { + if (scope.member && !scope.past_bookings) { + return getBookings(); + } + }); - return _possibleConstructorReturn(this, _ClientModel.apply(this, arguments)); + if (scope.member) { + return getBookings(); + } } - - Member_Member.$refresh = function $refresh(member) { - return MemberService.refresh(member); - }; - - Member_Member.$current = function $current() { - return MemberService.current(); - }; - - Member_Member.$updateMember = function $updateMember(member, params) { - return MemberService.updateMember(member, params); - }; - - Member_Member.$sendWelcomeEmail = function $sendWelcomeEmail(member, params) { - return MemberService.sendWelcomeEmail(member, params); - }; - - Member_Member.prototype.getBookings = function getBookings(params) { - return BBModel.Member.Booking.$query(this, params); - }; - - return Member_Member; - }(ClientModel); + }; }); -"use strict"; +'use strict'; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +angular.module('BBMember').directive('bbMemberPrePaidBookings', function ($rootScope, PaginationService) { + + return { + templateUrl: 'member_pre_paid_bookings.html', + scope: { + member: '=' + }, + controller: 'MemberBookings', + link: function link(scope, element, attrs) { -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + var getBookings = function getBookings() { + return scope.getPrePaidBookings({}).then(function (pre_paid_bookings) { + return PaginationService.update(scope.pagination, pre_paid_bookings.length); + }); + }; -angular.module("BB.Models").factory("Member.PaymentItemModel", function (BBModel, BaseModel) { - return function (_BaseModel) { - _inherits(Member_PaymentItem, _BaseModel); + scope.$watch('member', function () { + if (!scope.pre_paid_bookings) { + return getBookings(); + } + }); - function Member_PaymentItem(data) { - _classCallCheck(this, Member_PaymentItem); + scope.$on("booking:cancelled", function (event) { + return scope.getPrePaidBookings({}).then(function (pre_paid_bookings) { + return PaginationService.update(scope.pagination, pre_paid_bookings.length); + }); + }); - return _possibleConstructorReturn(this, _BaseModel.call(this, data)); + if (scope.member) { + return getBookings(); + } } - - return Member_PaymentItem; - }(BaseModel); + }; }); -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +'use strict'; -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } +angular.module('BBMember').directive('bbMemberPurchases', function ($rootScope, PaginationService) { -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + return { + templateUrl: 'member_purchases.html', + scope: true, + controller: 'MemberPurchases', + link: function link(scope, element, attrs) { -angular.module('BB.Models').factory("Member.PrePaidBookingModel", function (BaseModel) { - return function (_BaseModel) { - _inherits(Member_PrePaidBooking, _BaseModel); + scope.member = scope.$eval(attrs.member); + if ($rootScope.member) { + if (!scope.member) { + scope.member = $rootScope.member; + } + } - function Member_PrePaidBooking(data) { - _classCallCheck(this, Member_PrePaidBooking); + scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); - return _possibleConstructorReturn(this, _BaseModel.call(this, data)); + return $rootScope.connection_started.then(function () { + if (scope.member) { + return scope.getPurchases().then(function (purchases) { + return PaginationService.update(scope.pagination, purchases.length); + }); + } + }); } - - return Member_PrePaidBooking; - }(BaseModel); + }; }); -"use strict"; +'use strict'; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +/** + * @ngdoc directive + * @module BBMember + * @name memberSsoLogin + * + * @description + * Initialises member login with SSO + */ -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } +(function () { + angular.module('BBMember').directive('memberSsoLogin', memberSsoLogin); -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + function memberSsoLogin($rootScope, $sniffer, $window, $log, LoginService, QueryStringService, MemberOptions, bbConfig) { + return { + scope: { + token: '@memberSsoLogin', + company_id: '@companyId' + }, + transclude: true, + template: '
', + link: link + }; -angular.module("BB.Models").factory("Member.PurchaseModel", function ($q, MemberPurchaseService, BBModel, BaseModel) { - return function (_BaseModel) { - _inherits(Member_Purchase, _BaseModel); + function link(scope) { + var handleSso = function handleSso() { + var options = { + root: $rootScope.bb.api_url, + company_id: scope.company_id + }; - function Member_Purchase(data) { - _classCallCheck(this, Member_Purchase); + var data = { + token: scope.token ? scope.token : QueryStringService('sso_token') + }; - var _this = _possibleConstructorReturn(this, _BaseModel.call(this, data)); + if ($sniffer.msie && $sniffer.msie < 10 && $rootScope.iframe_proxy_ready === false) { + $timeout(function () { + loginSso(options, data); + }, 2000); + } else { + loginSso(options, data); + } + }; - _this.created_at = moment.parseZone(_this.created_at); - if (_this.time_zone) { - _this.created_at.tz(_this.time_zone); - } - return _this; + var redirectToErrorPage = function redirectToErrorPage(page) { + if (!page.includes('.html')) { + $log.info('configured sso redirect page is not a valid html file'); + } else { + $window.location.pathname = page; + } + }; + + var loginSso = function loginSso(options, data) { + LoginService.ssoLogin(options, data).then(function (member) { + scope.member = member; + }, function (err) { + $log.info('Could not complete member sso login', err); + if (MemberOptions.ssoErrorRedirectPage) { + var redirectPath = bbConfig.BUILD.DEPLOY_PATH + MemberOptions.ssoErrorRedirectPage; + redirectToErrorPage(redirectPath); + } + }); + }; + + handleSso(); } + } +})(); +'use strict'; - Member_Purchase.prototype.getItems = function getItems() { - var deferred = $q.defer(); - this._data.$get('purchase_items').then(function (items) { - this.items = Array.from(items).map(function (item) { - return new BBModel.Member.PurchaseItem(item); +angular.module('BBMember').directive('bbMemberUpcomingBookings', function ($rootScope, PaginationService, PurchaseService) { + + return { + templateUrl: 'member_upcoming_bookings.html', + scope: { + member: '=', + notLoaded: '=', + setLoaded: '=' + }, + controller: 'MemberBookings', + link: function link(scope, element, attrs) { + + scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); + + var getBookings = function getBookings() { + return scope.getUpcomingBookings().then(function (upcoming_bookings) { + return PaginationService.update(scope.pagination, upcoming_bookings.length); }); - return deferred.resolve(this.items); + }; + + scope.$on('updateBookings', function () { + scope.flushBookings(); + return getBookings(); }); - return deferred.promise; - }; - Member_Purchase.$query = function $query(member, params) { - return MemberPurchaseService.query(member, params); - }; + scope.$watch('member', function () { + if (!scope.upcoming_bookings) { + return getBookings(); + } + }); - return Member_Purchase; - }(BaseModel); + return $rootScope.connection_started.then(function () { + return getBookings(); + }); + } + }; }); -"use strict"; +'use strict'; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +angular.module('BBMember').directive('bbWallet', function ($rootScope) { -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + return { + scope: true, + controller: 'Wallet', + templateUrl: 'wallet.html', + link: function link(scope, element, attrs) { -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + scope.member = scope.$eval(attrs.member); + if ($rootScope.member) { + if (!scope.member) { + scope.member = $rootScope.member; + } + } -angular.module("BB.Models").factory("Member.PurchaseItemModel", function (BBModel, BaseModel) { - return function (_BaseModel) { - _inherits(Member_PurchaseItem, _BaseModel); + scope.show_wallet_logs = true; + scope.show_topup_box = false; - function Member_PurchaseItem(data) { - _classCallCheck(this, Member_PurchaseItem); + $rootScope.connection_started.then(function () { + if (scope.member) { + return scope.getWalletForMember(scope.member); + } + }); - return _possibleConstructorReturn(this, _BaseModel.call(this, data)); - } + scope.$on('wallet:topped_up', function (event, wallet) { + scope.wallet = wallet; + scope.show_topup_box = false; + return scope.show_wallet_logs = true; + }); - return Member_PurchaseItem; - }(BaseModel); + return scope.$on("booking:cancelled", function (event) { + if (scope.member) { + return scope.getWalletForMember(scope.member); + } + }); + } + }; }); -"use strict"; +'use strict'; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +angular.module('BBMember').directive('bbWalletLogs', function ($rootScope, PaginationService) { -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + return { + templateUrl: 'wallet_logs.html', + scope: true, + controller: 'Wallet', + require: '^?bbWallet', + link: function link(scope, element, attrs, ctrl) { + + scope.member = scope.$eval(attrs.member); + if ($rootScope.member) { + if (!scope.member) { + scope.member = $rootScope.member; + } + } -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + scope.pagination = PaginationService.initialise({ page_size: 10, max_size: 5 }); -angular.module("BB.Models").factory("Member.WalletModel", function (WalletService, BBModel, BaseModel) { - return function (_BaseModel) { - _inherits(Member_Wallet, _BaseModel); + var getWalletLogs = function getWalletLogs() { + return scope.getWalletLogs().then(function (logs) { + return PaginationService.update(scope.pagination, logs.length); + }); + }; - function Member_Wallet(data) { - _classCallCheck(this, Member_Wallet); + // listen to when the wallet is topped up + scope.$on('wallet:topped_up', function (event) { + return getWalletLogs(); + }); - return _possibleConstructorReturn(this, _BaseModel.call(this, data)); + // wait for wallet to be loaded by bbWallet or by self + return $rootScope.connection_started.then(function () { + if (ctrl) { + var deregisterWatch = void 0; + return deregisterWatch = scope.$watch('wallet', function () { + if (scope.wallet) { + getWalletLogs(); + return deregisterWatch(); + } + }); + } else { + return scope.getWalletForMember(scope.member).then(function () { + return getWalletLogs(); + }); + } + }); } + }; +}); +"use strict"; - Member_Wallet.$getWalletForMember = function $getWalletForMember(member, params) { - return WalletService.getWalletForMember(member, params); - }; +angular.module("BB.Directives").directive("bbWalletPayment", function ($sce, $rootScope, $window, $location, GeneralOptions, AlertService) { - Member_Wallet.$getWalletLogs = function $getWalletLogs(wallet) { - return WalletService.getWalletLogs(wallet); - }; + return { + restrict: 'A', + controller: 'Wallet', + scope: true, + replace: true, + require: '^?bbWallet', + link: function link(scope, element, attrs, ctrl) { - Member_Wallet.$getWalletPurchaseBandsForWallet = function $getWalletPurchaseBandsForWallet(wallet) { - return WalletService.getWalletPurchaseBandsForWallet(wallet); - }; + var one_pound = 100; + scope.wallet_payment_options = scope.$eval(attrs.bbWalletPayment) || {}; + scope.member = scope.$eval(attrs.member); + if ($rootScope.member) { + if (!scope.member) { + scope.member = $rootScope.member; + } + } + if (scope.wallet_payment_options.member) { + if (!scope.member) { + scope.member = scope.wallet_payment_options.member; + } + } + scope.amount_increment = scope.wallet_payment_options.amount_increment || one_pound; - Member_Wallet.$updateWalletForMember = function $updateWalletForMember(member, params) { - return WalletService.updateWalletForMember(member, params); - }; + var getHost = function getHost(url) { + var a = document.createElement('a'); + a.href = url; + return a['protocol'] + '//' + a['host']; + }; - Member_Wallet.$createWalletForMember = function $createWalletForMember(member) { - return WalletService.createWalletForMember(member); - }; + var sendLoadEvent = function sendLoadEvent(element, origin, scope) { + var referrer = $location.protocol() + "://" + $location.host(); + if ($location.port()) { + referrer += ":" + $location.port(); + } - return Member_Wallet; - }(BaseModel); -}); -"use strict"; + var custom_stylesheet = scope.wallet_payment_options.custom_stylesheet ? scope.wallet_payment_options.custom_stylesheet : null; + var custom_partial_url = scope.bb && scope.bb.custom_partial_url ? scope.bb.custom_partial_url : null; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + var payload = JSON.stringify({ + 'type': 'load', + 'message': referrer, + 'custom_partial_url': custom_partial_url, + 'custom_stylesheet': custom_stylesheet, + 'scroll_offset': GeneralOptions.scroll_offset + }); + return element.find('iframe')[0].contentWindow.postMessage(payload, origin); + }; -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + var calculateAmount = function calculateAmount() { + // if this is a basket topup, use either the amount due or the min topup amount, whichever is greatest -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + if (scope.wallet_payment_options.basket_topup) { -angular.module("BB.Models").factory("Member.WalletLogModel", function ($q, BBModel, BaseModel) { - return function (_BaseModel) { - _inherits(Member_WalletLog, _BaseModel); + var amount_due = scope.bb.basket.dueTotal() - scope.wallet.amount; - function Member_WalletLog(data) { - _classCallCheck(this, Member_WalletLog); + if (amount_due > scope.wallet.min_amount) { + scope.amount = Math.ceil(amount_due / scope.amount_increment) * scope.amount_increment; + } else { + scope.amount = scope.wallet.min_amount; + } - var _this = _possibleConstructorReturn(this, _BaseModel.call(this, data)); + return scope.min_amount = scope.amount; + } else if (scope.wallet.min_amount) { + scope.amount = scope.wallet_payment_options.amount && scope.wallet_payment_options.amount > scope.wallet.min_amount ? scope.wallet_payment_options.amount : scope.wallet.min_amount; + return scope.min_amount = scope.wallet.min_amount; + } else { + scope.min_amount = 0; + if (scope.wallet_payment_options.amount) { + return scope.amount = scope.wallet_payment_options.amount; + } + } + }; - _this.created_at = moment(_this.created_at); + // wait for wallet to be loaded by bbWallet or by self + $rootScope.connection_started.then(function () { + if (ctrl) { + var deregisterWatch = void 0; + return deregisterWatch = scope.$watch('wallet', function () { + if (scope.wallet) { + calculateAmount(); + return deregisterWatch(); + } + }); + } else { + return scope.getWalletForMember(scope.member).then(function () { + return calculateAmount(); + }); + } + }); - // HACK - if payment amount is less than zero, API returns it as zero! - _this.payment_amount = parseFloat(_this.amount) * 100; + // listen to when the wallet is updated + scope.$on('wallet:updated', function (event, wallet, band) { - // HACK - new wallet amount should be returned as a integer - _this.new_wallet_amount = parseFloat(_this.new_wallet_amount) * 100; - return _this; - } + // load iframe using payment link + if (band == null) { + band = null; + } + if (wallet.$has('new_payment')) { + scope.notLoaded(scope); + if (band) { + scope.amount = band.actual_amount; + } + scope.wallet_payment_url = $sce.trustAsResourceUrl(wallet.$href("new_payment")); + scope.show_payment_iframe = true; + return element.find('iframe').bind('load', function (event) { + var url = void 0; + if (scope.wallet_payment_url) { + url = scope.wallet_payment_url; + } + var origin = getHost(url); + sendLoadEvent(element, origin, scope); + return scope.$apply(function () { + return scope.setLoaded(scope); + }); + }); + } + }); - return Member_WalletLog; - }(BaseModel); + // register iframe message listener + return $window.addEventListener('message', function (event) { + var data = void 0; + if (angular.isObject(event.data)) { + data = event.data; + } else if (!event.data.match(/iFrameSizer/)) { + data = JSON.parse(event.data); + } + return scope.$apply(function () { + if (data) { + switch (data.type) { + case "submitting": + return scope.notLoaded(scope); + case "error": + $rootScope.$broadcast("wallet:topup_failed"); + scope.notLoaded(scope); + // reload the payment iframe + document.getElementsByTagName("iframe")[0].src += ''; + return AlertService.raise('PAYMENT_FAILED'); + case "payment_complete": + case "wallet_payment_complete": + case "basket_wallet_payment_complete": + scope.show_payment_iframe = false; + if (scope.wallet_payment_options.basket_topup) { + return scope.basketWalletPaymentDone(); + } else { + return scope.walletPaymentDone(); + } + } + } + }); + }, false); + } + }; }); "use strict"; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } +angular.module("BB.Directives").directive("bbWalletPurchaseBands", function ($rootScope) { -angular.module("BB.Models").factory('Member.WalletPurchaseBandModel', function (BBModel, BaseModel) { - return function (_BaseModel) { - _inherits(Member_WalletPurchaseBand, _BaseModel); + return { + scope: true, + restrict: "AE", + templateUrl: "wallet_purchase_bands.html", + controller: "Wallet", + require: '^?bbWallet', + link: function link(scope, attr, elem, ctrl) { - function Member_WalletPurchaseBand(data) { - _classCallCheck(this, Member_WalletPurchaseBand); + scope.member = scope.$eval(attr.member); + if ($rootScope.member) { + if (!scope.member) { + scope.member = $rootScope.member; + } + } - return _possibleConstructorReturn(this, _BaseModel.call(this, data)); + return $rootScope.connection_started.then(function () { + if (ctrl) { + var deregisterWatch = void 0; + return deregisterWatch = scope.$watch('wallet', function () { + if (scope.wallet) { + scope.getWalletPurchaseBandsForWallet(scope.wallet); + return deregisterWatch(); + } + }); + } else { + return scope.getWalletForMember(scope.member).then(function () { + return scope.getWalletPurchaseBandsForWallet(scope.wallet); + }); + } + }); } - - return Member_WalletPurchaseBand; - }(BaseModel); + }; }); 'use strict'; diff --git a/bower.json b/bower.json index 9e55f51..10431d2 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bookingbug-angular-member", - "version": "2.2.55", + "version": "2.2.56", "homepage": "https://github.com/BookingBug/bookingbug-angular-member-bower", "authors": [ "Glenn Shoosmith ", @@ -21,6 +21,6 @@ "tests" ], "dependencies": { - "bookingbug-angular-core": "2.2.55" + "bookingbug-angular-core": "2.2.56" } }