-
Notifications
You must be signed in to change notification settings - Fork 1
/
bookingbug-angular-services.min.js
2 lines (2 loc) · 41.1 KB
/
bookingbug-angular-services.min.js
1
2
(function(){"use strict";angular.module("BBAdminServices").config(["$logProvider",function($logProvider){"ngInject";$logProvider.debugEnabled(!0)}])}).call(this),function(){"use strict";angular.module("BBAdminServices",["BB","BBAdmin.Services","BBAdmin.Filters","BBAdmin.Controllers","trNgGrid","ui.calendar"]),angular.module("BBAdminServicesMockE2E",["BBAdminServices","BBAdminMockE2E"])}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;window.Collection.Clinic=function(superClass){function Clinic(){return Clinic.__super__.constructor.apply(this,arguments)}return extend(Clinic,superClass),Clinic.prototype.checkItem=function(item){return Clinic.__super__.checkItem.apply(this,arguments)},Clinic.prototype.matchesParams=function(item){return this.params.start_time&&(this.start_time||(this.start_time=moment(this.params.start_time)),this.start_time.isAfter(item.start_time))?!1:this.params.end_time&&(this.end_time||(this.end_time=moment(this.params.end_time)),this.end_time.isBefore(item.end_time))?!1:this.params.start_date&&(this.start_date||(this.start_date=moment(this.params.start_date)),this.start_date.isAfter(item.start_date))?!1:!this.params.end_date||(this.end_date||(this.end_date=moment(this.params.end_date)),!this.end_date.isBefore(item.end_date))},Clinic}(window.Collection.Base),angular.module("BBAdmin.Services").provider("ClinicCollections",function(){return{$get:function(){return new window.BaseCollections}}})}.call(this),function(){"use strict";angular.module("BBAdminServices").directive("personTable",["$log","ModalForm","BBModel",function($log,ModalForm,BBModel){var controller,link;return controller=function($scope){return $scope.fields=["id","name","mobile"],$scope.getPeople=function(){return BBModel.Admin.Person.$query({company:$scope.company}).then(function(people){return $scope.people=people})},$scope.newPerson=function(){return ModalForm["new"]({company:$scope.company,title:"New Person",new_rel:"new_person",post_rel:"people",success:function(person){return $scope.people.push(person)}})},$scope["delete"]=function(person){return person.$del("self").then(function(){return $scope.people=_.reject($scope.people,person)},function(err){return $log.error("Failed to delete person")})},$scope.edit=function(person){return ModalForm.edit({model:person,title:"Edit Person"})},$scope.schedule=function(person){return person.$get("schedule").then(function(schedule){return ModalForm.edit({model:schedule,title:"Edit Schedule"})})}},link=function(scope,element,attrs){return scope.company?scope.getPeople():BBModel.Admin.Company.$query(attrs).then(function(company){return scope.company=company,scope.getPeople()})},{controller:controller,link:link,templateUrl:"person_table_main.html"}}])}.call(this),function(){"use strict";angular.module("BBAdminServices").directive("resourceTable",["BBModel","$log","ModalForm",function(BBModel,$log,ModalForm){var controller,link;return controller=function($scope){return $scope.fields=["id","name"],$scope.getResources=function(){var params;return params={company:$scope.company},BBModel.Admin.Resource.$query(params).then(function(resources){return $scope.resources=resources})},$scope.newResource=function(){return ModalForm["new"]({company:$scope.company,title:"New Resource",new_rel:"new_resource",post_rel:"resources",size:"lg",success:function(resource){return $scope.resources.push(resource)}})},$scope["delete"]=function(resource){return resource.$del("self").then(function(){return $scope.resources=_.reject($scope.resources,function(p){return p.id===id})},function(err){return $log.error("Failed to delete resource")})},$scope.edit=function(resource){return ModalForm.edit({model:resource,title:"Edit Resource"})},$scope.schedule=function(resource){return resource.$get("schedule").then(function(schedule){return ModalForm.edit({model:schedule,title:"Edit Schedule"})})}},link=function(scope,element,attrs){return scope.company?scope.getResources():BBModel.Admin.Company.$query(attrs).then(function(company){return scope.company=company,scope.getResources()})},{controller:controller,link:link,templateUrl:"resource_table_main.html"}}])}.call(this),function(){"use strict";angular.module("BBAdminServices").directive("scheduleCalendar",["uiCalendarConfig","ScheduleRules",function(uiCalendarConfig,ScheduleRules){var controller,link;return controller=function($scope,$attrs){var options;return $scope.calendarName="scheduleCal",$scope.eventSources=[{events:function(start,end,timezone,callback){return callback($scope.getEvents())}}],$scope.getCalendarEvents=function(start,end){var events;return events=uiCalendarConfig.calendars.scheduleCal.fullCalendar("clientEvents",function(e){return(start.isAfter(e.start)||start.isSame(e.start))&&(end.isBefore(e.end)||end.isSame(e.end))})},options=$scope.setOptions,options||(options={}),$scope.options={calendar:{schedulerLicenseKey:"0598149132-fcs-1443104297",height:options.height||"auto",editable:!1,selectable:!0,defaultView:"agendaWeek",header:{left:"today,prev,next",center:"title",right:"month,agendaWeek"},selectHelper:!1,eventOverlap:!1,lazyFetching:!1,views:{agendaWeek:{duration:{weeks:1},allDaySlot:!1,slotEventOverlap:!1,minTime:options.min_time||"00:00:00",maxTime:options.max_time||"24:00:00"}},select:function(start,end,jsEvent,view){var events;return events=$scope.getCalendarEvents(start,end),events.length>0?$scope.removeRange(start,end):$scope.addRange(start,end)},eventResizeStop:function(event,jsEvent,ui,view){return $scope.addRange(event.start,event.end)},eventDrop:function(event,delta,revertFunc,jsEvent,ui,view){var orig;return event.start.hasTime()?(orig={start:moment(event.start).subtract(delta),end:moment(event.end).subtract(delta)},$scope.removeRange(orig.start,orig.end),$scope.addRange(event.start,event.end)):void 0},eventClick:function(event,jsEvent,view){return $scope.removeRange(event.start,event.end)}}},$scope.render=function(){return uiCalendarConfig.calendars.scheduleCal.fullCalendar("render")}},link=function(scope,element,attrs,ngModel){var scheduleRules;return scheduleRules=function(){return new ScheduleRules(ngModel.$viewValue)},scope.getEvents=function(){return scheduleRules().toEvents()},scope.addRange=function(start,end){return ngModel.$setViewValue(scheduleRules().addRange(start,end)),ngModel.$render()},scope.removeRange=function(start,end){return ngModel.$setViewValue(scheduleRules().removeRange(start,end)),ngModel.$render()},scope.toggleRange=function(start,end){return ngModel.$setViewValue(scheduleRules().toggleRange(start,end)),ngModel.$render()},ngModel.$render=function(){return uiCalendarConfig&&uiCalendarConfig.calendars.scheduleCal?(uiCalendarConfig.calendars.scheduleCal.fullCalendar("refetchEvents"),uiCalendarConfig.calendars.scheduleCal.fullCalendar("unselect")):void 0}},{controller:controller,link:link,templateUrl:"schedule_cal_main.html",require:"ngModel",scope:{render:"=?",setOptions:"=options"}}}])}.call(this),function(){"use strict";angular.module("BBAdminServices").directive("scheduleEdit",function(){var link;return link=function(scope,element,attrs,ngModel){return ngModel.$render=function(){return scope.$$value$$=ngModel.$viewValue},scope.$watch("$$value$$",function(value){return null!=value?ngModel.$setViewValue(value):void 0})},{link:link,templateUrl:"schedule_edit_main.html",require:"ngModel",scope:{options:"="}}}),angular.module("schemaForm").config(["schemaFormProvider","schemaFormDecoratorsProvider","sfPathProvider",function(schemaFormProvider,schemaFormDecoratorsProvider,sfPathProvider){return schemaFormDecoratorsProvider.addMapping("bootstrapDecorator","schedule","schedule_edit_form.html"),schemaFormDecoratorsProvider.createDirective("schedule","schedule_edit_form.html")}])}.call(this),function(){"use strict";angular.module("BBAdminServices").directive("scheduleTable",["BBModel","$log","ModalForm",function(BBModel,$log,ModalForm){var controller,link;return controller=function($scope){return $scope.fields=["id","name","mobile"],$scope.getSchedules=function(){var params;return params={company:$scope.company},BBModel.Admin.Schedule.query(params).then(function(schedules){return $scope.schedules=schedules})},$scope.newSchedule=function(){return ModalForm["new"]({company:$scope.company,title:"New Schedule",new_rel:"new_schedule",post_rel:"schedules",size:"lg",success:function(schedule){return $scope.schedules.push(schedule)}})},$scope["delete"]=function(schedule){return schedule.$del("self").then(function(){return $scope.schedules=_.reject($scope.schedules,schedule)},function(err){return $log.error("Failed to delete schedule")})},$scope.edit=function(schedule){return ModalForm.edit({model:schedule,title:"Edit Schedule",size:"lg"})}},link=function(scope,element,attrs){return scope.company?scope.getSchedules():BBModel.Admin.Company.query(attrs).then(function(company){return scope.company=company,scope.getSchedules()})},{controller:controller,link:link,templateUrl:"schedule_table_main.html"}}])}.call(this),function(){"use strict";angular.module("BBAdminServices").directive("scheduleWeekdays",["uiCalendarConfig","ScheduleRules",function(uiCalendarConfig,ScheduleRules){var controller,link;return controller=function($scope,$attrs){var options;return $scope.calendarName="scheduleWeekdays",$scope.eventSources=[{events:function(start,end,timezone,callback){return callback($scope.getEvents())}}],$scope.getCalendarEvents=function(start,end){var events;return events=uiCalendarConfig.calendars.scheduleWeekdays.fullCalendar("clientEvents",function(e){return(start.isAfter(e.start)||start.isSame(e.start))&&(end.isBefore(e.end)||end.isSame(e.end))})},options=$scope.setOptions,options||(options={}),$scope.options={calendar:{schedulerLicenseKey:"0598149132-fcs-1443104297",height:options.height||"auto",editable:!1,selectable:!0,defaultView:"agendaWeek",header:{left:"",center:"title",right:""},selectHelper:!1,eventOverlap:!1,views:{agendaWeek:{duration:{weeks:1},titleFormat:"[]",allDaySlot:!1,columnFormat:"ddd",slotEventOverlap:!1,minTime:options.min_time||"00:00:00",maxTime:options.max_time||"24:00:00"}},select:function(start,end,jsEvent,view){var events;return events=$scope.getCalendarEvents(start,end),events.length>0?$scope.removeRange(start,end):$scope.addRange(start,end)},eventResizeStop:function(event,jsEvent,ui,view){return $scope.addRange(event.start,event.end)},eventDrop:function(event,delta,revertFunc,jsEvent,ui,view){var orig;return event.start.hasTime()?(orig={start:moment(event.start).subtract(delta),end:moment(event.end).subtract(delta)},$scope.removeRange(orig.start,orig.end),$scope.addRange(event.start,event.end)):void 0},eventClick:function(event,jsEvent,view){return $scope.removeRange(event.start,event.end)}}},$scope.render=function(){return uiCalendarConfig.calendars.scheduleWeekdays.fullCalendar("render")}},link=function(scope,element,attrs,ngModel){var scheduleRules;return scheduleRules=function(){return new ScheduleRules(ngModel.$viewValue)},scope.getEvents=function(){return scheduleRules().toWeekdayEvents()},scope.addRange=function(start,end){return ngModel.$setViewValue(scheduleRules().addWeekdayRange(start,end)),ngModel.$render()},scope.removeRange=function(start,end){return ngModel.$setViewValue(scheduleRules().removeWeekdayRange(start,end)),ngModel.$render()},ngModel.$render=function(){return uiCalendarConfig&&uiCalendarConfig.calendars.scheduleWeekdays?(uiCalendarConfig.calendars.scheduleWeekdays.fullCalendar("refetchEvents"),uiCalendarConfig.calendars.scheduleWeekdays.fullCalendar("unselect")):void 0}},{controller:controller,link:link,templateUrl:"schedule_cal_main.html",require:"ngModel",scope:{render:"=?",setOptions:"=options"}}}])}.call(this),function(){"use strict";angular.module("BBAdminServices").directive("serviceTable",["$uibModal","$log","ModalForm","BBModel",function($uibModal,$log,ModalForm,BBModel){var controller,link;return controller=function($scope){return $scope.fields=["id","name"],$scope.getServices=function(){var params;return params={company:$scope.company},BBModel.Admin.Service.$query(params).then(function(services){return $scope.services=services})},$scope.newService=function(){return ModalForm["new"]({company:$scope.company,title:"New Service",new_rel:"new_service",post_rel:"services",success:function(service){return $scope.services.push(service)}})},$scope["delete"]=function(service){return service.$del("self").then(function(){return $scope.services=_.reject($scope.services,service)},function(err){return $log.error("Failed to delete service")})},$scope.edit=function(service){return ModalForm.edit({model:service,title:"Edit Service"})},$scope.newBooking=function(service){return ModalForm.book({model:service,company:$scope.company,title:"New Booking",success:function(booking){return $log.info("Created new booking ",booking)}})}},link=function(scope,element,attrs){return scope.company?scope.getServices():BBModel.Admin.Company.query(attrs).then(function(company){return scope.company=company,scope.getServices()})},{controller:controller,link:link,templateUrl:"service_table_main.html"}}])}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;angular.module("BB.Models").factory("AdminAddressModel",["$q","BBModel","BaseModel","AddressModel",function($q,BBModel,BaseModel,AddressModel){var Admin_Address;return Admin_Address=function(superClass){function Admin_Address(){return Admin_Address.__super__.constructor.apply(this,arguments)}return extend(Admin_Address,superClass),Admin_Address.prototype.distanceFrom=function(address,options){var base;return this.dists||(this.dists=[]),(base=this.dists)[address]||(base[address]=Math.round(50*Math.random(),0)),this.dists[address]},Admin_Address}(AddressModel)}])}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;angular.module("BB.Models").factory("AdminClinicModel",["$q","BBModel","BaseModel","ClinicModel",function($q,BBModel,BaseModel,ClinicModel){var Admin_Clinic;return Admin_Clinic=function(superClass){function Admin_Clinic(data){var base;Admin_Clinic.__super__.constructor.call(this,data),this.repeat_rule||(this.repeat_rule={}),(base=this.repeat_rule).rules||(base.rules={})}return extend(Admin_Clinic,superClass),Admin_Clinic.prototype.calcRepeatRule=function(){var en,id,ref,ref1,ref2,vals;vals={},vals.name=this.name,vals.start_time=this.start_time.format("HH:mm"),vals.end_time=this.end_time.format("HH:mm"),vals.address_id=this.address_id,vals.resource_ids=[],ref=this.resources;for(id in ref)en=ref[id],en&&vals.resource_ids.push(id);vals.person_ids=[],ref1=this.people;for(id in ref1)en=ref1[id],en&&vals.person_ids.push(id);vals.service_ids=[],ref2=this.services;for(id in ref2)en=ref2[id],en&&vals.service_ids.push(id);return this.repeat_rule.properties=vals,this.repeat_rule},Admin_Clinic.prototype.getPostData=function(){var data,en,id,ref,ref1,ref2;data={},data.name=this.name,data.repeat_rule=this.repeat_rule,data.start_time=this.start_time,data.end_time=this.end_time,data.resource_ids=[],data.update_for_repeat=this.update_for_repeat,ref=this.resources;for(id in ref)en=ref[id],en&&data.resource_ids.push(id);data.person_ids=[],ref1=this.people;for(id in ref1)en=ref1[id],en&&data.person_ids.push(id);data.service_ids=[],ref2=this.services;for(id in ref2)en=ref2[id],en&&data.service_ids.push(id);return this.address&&(data.address_id=this.address.id),this.settings&&(data.settings=this.settings),this.repeat_rule&&this.repeat_rule.rules&&this.repeat_rule.rules.frequency&&(data.repeat_rule=this.calcRepeatRule()),data},Admin_Clinic.prototype.save=function(){return this.person_ids=_.compact(_.map(this.people,function(present,person_id){return present?person_id:void 0})),this.resource_ids=_.compact(_.map(this.resources,function(present,resource_id){return present?resource_id:void 0})),this.service_ids=_.compact(_.map(this.services,function(present,service_id){return present?service_id:void 0})),this.$put("self",{},this).then(function(_this){return function(clinic){return _this.updateModel(clinic),_this.setTimes(),_this.setResourcesAndPeople()}}(this))},Admin_Clinic.prototype.$update=function(data){return data||(data=this),this.$put("self",{},data).then(function(_this){return function(res){return _this.constructor(res)}}(this))},Admin_Clinic}(ClinicModel)}])}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;angular.module("BB.Models").factory("AdminPersonModel",["$q","AdminPersonService","BBModel","BaseModel","PersonModel",function($q,AdminPersonService,BBModel,BaseModel,PersonModel){var Admin_Person;return Admin_Person=function(superClass){function Admin_Person(data){Admin_Person.__super__.constructor.call(this,data)}return extend(Admin_Person,superClass),Admin_Person.prototype.setAttendance=function(status,duration){var defer;return defer=$q.defer(),this.$put("attendance",{},{status:status,estimated_duration:duration}).then(function(_this){return function(p){return _this.updateModel(p),defer.resolve(_this)}}(this),function(_this){return function(err){return defer.reject(err)}}(this)),defer.promise},Admin_Person.prototype.finishServing=function(){var defer;return defer=$q.defer(),this.$has("finish_serving")?(this.$flush("self"),this.$post("finish_serving").then(function(_this){return function(q){return _this.$get("self").then(function(p){return _this.updateModel(p)}),_this.serving=null,defer.resolve(q)}}(this),function(_this){return function(err){return defer.reject(err)}}(this))):defer.reject("finish_serving link not available"),defer.promise},Admin_Person.prototype.isAvailable=function(start,end){var str;return str=start.format("YYYY-MM-DD")+"-"+end.format("YYYY-MM-DD"),this.availability||(this.availability={}),this.availability[str]?"Yes"===this.availability[str]:(this.availability[str]="-",this.$has("schedule")?this.$get("schedule",{start_date:start.format("YYYY-MM-DD"),end_date:end.format("YYYY-MM-DD")}).then(function(_this){return function(sched){return _this.availability[str]="No",sched&&sched.dates&&sched.dates[start.format("YYYY-MM-DD")]&&"None"!==sched.dates[start.format("YYYY-MM-DD")]?_this.availability[str]="Yes":void 0}}(this)):this.availability[str]="Yes","Yes"===this.availability[str])},Admin_Person.prototype.startServing=function(queuer){var defer,params;return defer=$q.defer(),this.$has("start_serving")?(this.$flush("self"),params={queuer_id:queuer?queuer.id:null},this.$post("start_serving",params).then(function(_this){return function(q){return _this.$get("self").then(function(p){return _this.updateModel(p)}),_this.serving=q,defer.resolve(q)}}(this),function(_this){return function(err){return defer.reject(err)}}(this))):defer.reject("start_serving link not available"),defer.promise},Admin_Person.prototype.getQueuers=function(){var defer;return defer=$q.defer(),this.$has("queuers")?(this.$flush("queuers"),this.$get("queuers").then(function(_this){return function(collection){return collection.$get("queuers").then(function(queuers){var models,q;return models=function(){var i,len,results;for(results=[],i=0,len=queuers.length;len>i;i++)q=queuers[i],results.push(new BBModel.Admin.Queuer(q));return results}(),_this.queuers=models,defer.resolve(models)},function(err){return defer.reject(err)})}}(this),function(_this){return function(err){return defer.reject(err)}}(this))):defer.reject("queuers link not available"),defer.promise},Admin_Person.prototype.getPostData=function(){var data;return data={},data.id=this.id,data.name=this.name,data.extra=this.extra,data.description=this.description,data},Admin_Person.prototype.$update=function(data){return data||(data=this.getPostData()),this.$put("self",{},data).then(function(_this){return function(res){return _this.constructor(res)}}(this))},Admin_Person.$query=function(params){return AdminPersonService.query(params)},Admin_Person.$block=function(company,person,data){return AdminPersonService.block(company,person,data)},Admin_Person.$signup=function(user,data){return AdminPersonService.signup(user,data)},Admin_Person.prototype.$refetch=function(){var defer;return defer=$q.defer(),this.$flush("self"),this.$get("self").then(function(_this){return function(res){return _this.constructor(res),defer.resolve(_this)}}(this),function(err){return defer.reject(err)}),defer.promise},Admin_Person}(PersonModel)}])}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;angular.module("BB.Models").factory("AdminResourceModel",["$q","AdminResourceService","BBModel","BaseModel","ResourceModel",function($q,AdminResourceService,BBModel,BaseModel,ResourceModel){var Admin_Resource;return Admin_Resource=function(superClass){function Admin_Resource(){return Admin_Resource.__super__.constructor.apply(this,arguments)}return extend(Admin_Resource,superClass),Admin_Resource.prototype.isAvailable=function(start,end){var str;return str=start.format("YYYY-MM-DD")+"-"+end.format("YYYY-MM-DD"),this.availability||(this.availability={}),this.availability[str]?"Yes"===this.availability[str]:(this.availability[str]="-",this.$has("schedule")?this.$get("schedule",{start_date:start.format("YYYY-MM-DD"),end_date:end.format("YYYY-MM-DD")}).then(function(_this){return function(sched){return _this.availability[str]="No",sched&&sched.dates&&sched.dates[start.format("YYYY-MM-DD")]&&"None"!==sched.dates[start.format("YYYY-MM-DD")]?_this.availability[str]="Yes":void 0}}(this)):this.availability[str]="Yes","Yes"===this.availability[str])},Admin_Resource.$query=function(params){return AdminResourceService.query(params)},Admin_Resource.$block=function(company,resource,data){return AdminResourceService.block(company,resource,data)},Admin_Resource}(ResourceModel)}])}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;angular.module("BB.Models").factory("AdminScheduleModel",["$q","AdminScheduleService","BBModel","BaseModel","ScheduleRules",function($q,AdminScheduleService,BBModel,BaseModel,ScheduleRules){var Admin_Schedule;return Admin_Schedule=function(superClass){function Admin_Schedule(data){Admin_Schedule.__super__.constructor.call(this,data)}return extend(Admin_Schedule,superClass),Admin_Schedule.prototype.getPostData=function(){var data;return data={},data.id=this.id,data.rules=this.rules,data.name=this.name,data.company_id=this.company_id,data.duration=this.duration,data},Admin_Schedule.$query=function(params){return AdminScheduleService.query(params)},Admin_Schedule.$delete=function(schedule){return AdminScheduleService["delete"](schedule)},Admin_Schedule.$update=function(schedule){return AdminScheduleService.update(schedule)},Admin_Schedule}(BaseModel)}])}.call(this),function(){"use strict";var bind=function(fn,me){return function(){return fn.apply(me,arguments)}};angular.module("BB.Models").factory("ScheduleRules",function(){var ScheduleRules;return ScheduleRules=function(){function ScheduleRules(rules){null==rules&&(rules={}),this.removeRangeFromDate=bind(this.removeRangeFromDate,this),this.addRangeToDate=bind(this.addRangeToDate,this),this.rules=rules}return ScheduleRules.prototype.addRange=function(start,end){return this.applyFunctionToDateRange(start,end,"YYYY-MM-DD",this.addRangeToDate)},ScheduleRules.prototype.removeRange=function(start,end){return this.applyFunctionToDateRange(start,end,"YYYY-MM-DD",this.removeRangeFromDate)},ScheduleRules.prototype.addWeekdayRange=function(start,end){return this.applyFunctionToDateRange(start,end,"d",this.addRangeToDate)},ScheduleRules.prototype.removeWeekdayRange=function(start,end){return this.applyFunctionToDateRange(start,end,"d",this.removeRangeFromDate)},ScheduleRules.prototype.addRangeToDate=function(date,range){var ranges;return ranges=this.rules[date]?this.rules[date]:[],this.rules[date]=this.joinRanges(this.insertRange(ranges,range))},ScheduleRules.prototype.removeRangeFromDate=function(date,range){var ranges;return ranges=this.rules[date]?this.rules[date]:[],this.rules[date]=this.joinRanges(this.subtractRange(ranges,range)),""===this.rules[date]?delete this.rules[date]:void 0},ScheduleRules.prototype.applyFunctionToDateRange=function(start,end,format,func){var date,days,end_time,range,results;return days=this.diffInDays(start,end),0===days?(date=start.format(format),range=[start.format("HHmm"),end.format("HHmm")].join("-"),func(date,range)):(end_time=moment(start).endOf("day"),this.applyFunctionToDateRange(start,end_time,format,func),_.each(function(){results=[];for(var j=1;days>=1?days>=j:j>=days;days>=1?j++:j--)results.push(j);return results}.apply(this),function(_this){return function(i){var start_time;return date=moment(start).add(i,"days"),i!==days?(start_time=moment(date).startOf("day"),end_time=moment(date).endOf("day"),_this.applyFunctionToDateRange(start_time,end_time,format,func)):0!==end.hour()||0!==end.minute()?(start_time=moment(end).startOf("day"),_this.applyFunctionToDateRange(start_time,end,format,func)):void 0}}(this))),this.rules},ScheduleRules.prototype.diffInDays=function(start,end){return moment.duration(end.diff(start)).days()},ScheduleRules.prototype.insertRange=function(ranges,range){return ranges.splice(_.sortedIndex(ranges,range),0,range),ranges},ScheduleRules.prototype.subtractRange=function(ranges,range){return _.indexOf(ranges,range,!0)>-1?_.without(ranges,range):_.flatten(_.map(ranges,function(r){return range.slice(0,4)>=r.slice(0,4)&&range.slice(5,9)<=r.slice(5,9)?range.slice(0,4)===r.slice(0,4)?[range.slice(5,9),r.slice(5,9)].join("-"):range.slice(5,9)===r.slice(5,9)?[r.slice(0,4),range.slice(0,4)].join("-"):[[r.slice(0,4),range.slice(0,4)].join("-"),[range.slice(5,9),r.slice(5,9)].join("-")]:r}))},ScheduleRules.prototype.joinRanges=function(ranges){return _.reduce(ranges,function(m,range){return""===m?range:range.slice(0,4)<=m.slice(m.length-4,m.length)?range.slice(5,9)>=m.slice(m.length-4,m.length)?m.slice(0,m.length-4)+range.slice(5,9):m:[m,range].join()},"").split(",")},ScheduleRules.prototype.filterRulesByDates=function(){return _.pick(this.rules,function(value,key){return key.match(/^\d{4}-\d{2}-\d{2}$/)&&"None"!==value})},ScheduleRules.prototype.filterRulesByWeekdays=function(){return _.pick(this.rules,function(value,key){return key.match(/^\d$/)})},ScheduleRules.prototype.formatTime=function(time){return[time.slice(0,2),time.slice(2,4)].join(":")},ScheduleRules.prototype.toEvents=function(d){return d&&"None"!==this.rules[d]?_.map(this.rules[d],function(_this){return function(range){return{start:[d,_this.formatTime(range.split("-")[0])].join("T"),end:[d,_this.formatTime(range.split("-")[1])].join("T")}}}(this)):_.reduce(this.filterRulesByDates(),function(_this){return function(memo,ranges,date){return memo.concat(_.map(ranges,function(range){return{start:[date,_this.formatTime(range.split("-")[0])].join("T"),end:[date,_this.formatTime(range.split("-")[1])].join("T")}}))}}(this),[])},ScheduleRules.prototype.toWeekdayEvents=function(){return _.reduce(this.filterRulesByWeekdays(),function(_this){return function(memo,ranges,day){var date;return date=moment().set("day",day).format("YYYY-MM-DD"),memo.concat(_.map(ranges,function(range){return{start:[date,_this.formatTime(range.split("-")[0])].join("T"),end:[date,_this.formatTime(range.split("-")[1])].join("T")}}))}}(this),[])},ScheduleRules}()})}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;angular.module("BB.Models").factory("AdminServiceModel",["$q","AdminServiceService","BBModel","ServiceModel",function($q,AdminServiceService,BBModel,ServiceModel){var Admin_Service;return Admin_Service=function(superClass){function Admin_Service(){return Admin_Service.__super__.constructor.apply(this,arguments)}return extend(Admin_Service,superClass),Admin_Service.$query=function(params){return AdminServiceService.query(params)},Admin_Service}(ServiceModel)}])}.call(this),function(){"use strict";angular.module("BBAdmin.Services").factory("AdminAddressService",["$q","BBModel",function($q,BBModel){return{query:function(params){var company,defer;return company=params.company,defer=$q.defer(),company.$get("addresses").then(function(collection){return collection.$get("addresses").then(function(addresss){var models,s;return models=function(){var i,len,results;for(results=[],i=0,len=addresss.length;len>i;i++)s=addresss[i],results.push(new BBModel.Admin.Address(s));return results}(),defer.resolve(models)},function(err){return defer.reject(err)})},function(err){return defer.reject(err)}),defer.promise}}}])}.call(this),function(){"use strict";angular.module("BBAdmin.Services").factory("AdminClinicService",["$q","BBModel","ClinicCollections","$window",function($q,BBModel,ClinicCollections,$window){return{query:function(params){var company,defer,existing;return company=params.company,defer=$q.defer(),params.id?company.$get("clinics",params).then(function(clinic){return clinic=new BBModel.Admin.Clinic(clinic),defer.resolve(clinic)},function(err){return defer.reject(err)}):(existing=ClinicCollections.find(params),existing&&!params.skip_cache?defer.resolve(existing):(params.skip_cache&&(existing&&ClinicCollections["delete"](existing),company.$flush("clinics",params)),company.$get("clinics",params).then(function(collection){return collection.$get("clinics").then(function(clinics){var models,s;return models=function(){var i,len,results;for(results=[],i=0,len=clinics.length;len>i;i++)s=clinics[i],results.push(new BBModel.Admin.Clinic(s));return results}(),clinics=new $window.Collection.Clinic(collection,models,params),ClinicCollections.add(clinics),defer.resolve(clinics)},function(err){return defer.reject(err)})},function(err){return defer.reject(err)}))),defer.promise},create:function(prms,clinic){var company,deferred;return company=prms.company,deferred=$q.defer(),company.$post("clinics",{},clinic.getPostData()).then(function(_this){return function(clinic){return clinic=new BBModel.Admin.Clinic(clinic),ClinicCollections.checkItems(clinic),deferred.resolve(clinic)}}(this),function(_this){return function(err){return deferred.reject(err)}}(this)),deferred.promise},cancel:function(clinic){var deferred;return deferred=$q.defer(),clinic.$post("cancel",clinic).then(function(_this){return function(clinic){return clinic=new BBModel.Admin.Clinic(clinic),ClinicCollections.deleteItems(clinic),deferred.resolve(clinic)}}(this),function(_this){return function(err){return deferred.reject(err)}}(this)),deferred.promise},update:function(clinic){var deferred;return deferred=$q.defer(),
clinic.$put("self",{},clinic.getPostData()).then(function(_this){return function(c){return clinic=new BBModel.Admin.Clinic(c),ClinicCollections.checkItems(clinic),deferred.resolve(clinic)}}(this),function(_this){return function(err){return deferred.reject(err)}}(this)),deferred.promise}}}])}.call(this),function(){"use strict";angular.module("BBAdminServices").factory("AdminPersonService",["$q","$window","$rootScope","halClient","SlotCollections","BookingCollections","BBModel","LoginService","$log",function($q,$window,$rootScope,halClient,SlotCollections,BookingCollections,BBModel,LoginService,$log){return{query:function(params){var company,defer;return company=params.company,defer=$q.defer(),company.$has("people")?company.$get("people",params).then(function(collection){var obj;return collection.$has("people")?collection.$get("people").then(function(people){var models,p;return models=function(){var i,len,results;for(results=[],i=0,len=people.length;len>i;i++)p=people[i],results.push(new BBModel.Admin.Person(p));return results}(),defer.resolve(models)},function(err){return defer.reject(err)}):(obj=new BBModel.Admin.Person(collection),defer.resolve(obj))},function(err){return defer.reject(err)}):($log.warn("company has no people link"),defer.reject("company has no people link")),defer.promise},block:function(company,person,data){var deferred;return deferred=$q.defer(),person.$put("block",{},data).then(function(_this){return function(response){var booking,slot;return response.$href("self").indexOf("bookings")>-1?(booking=new BBModel.Admin.Booking(response),BookingCollections.checkItems(booking),deferred.resolve(booking)):(slot=new BBModel.Admin.Slot(response),SlotCollections.checkItems(slot),deferred.resolve(slot))}}(this),function(_this){return function(err){return deferred.reject(err)}}(this)),deferred.promise},signup:function(user,data){var defer;return defer=$q.defer(),user.$get("company").then(function(company){var params;return params={},company.$post("people",params,data).then(function(person){return person.$has("administrator")?person.$get("administrator").then(function(user){return LoginService.setLogin(user),defer.resolve(person)}):defer.resolve(person)},function(err){return defer.reject(err)}),defer.promise})}}}])}.call(this),function(){"use strict";angular.module("BBAdmin.Services").factory("AdminResourceService",["$q","UriTemplate","halClient","SlotCollections","BBModel","BookingCollections",function($q,UriTemplate,halClient,SlotCollections,BBModel,BookingCollections){return{query:function(params){var company,defer;return company=params.company,defer=$q.defer(),company.$get("resources",params).then(function(collection){return collection.$get("resources").then(function(resources){var models,r;return models=function(){var i,len,results;for(results=[],i=0,len=resources.length;len>i;i++)r=resources[i],results.push(new BBModel.Admin.Resource(r));return results}(),defer.resolve(models)},function(err){return defer.reject(err)})},function(err){return defer.reject(err)}),defer.promise},block:function(company,resource,data){var deferred;return deferred=$q.defer(),resource.$put("block",{},data).then(function(_this){return function(response){var booking,slot;return response.$href("self").indexOf("bookings")>-1?(booking=new BBModel.Admin.Booking(response),BookingCollections.checkItems(booking),deferred.resolve(booking)):(slot=new BBModel.Admin.Slot(response),SlotCollections.checkItems(slot),deferred.resolve(slot))}}(this),function(_this){return function(err){return deferred.reject(err)}}(this)),deferred.promise}}}])}.call(this),function(){"use strict";angular.module("BBAdmin.Services").factory("AdminScheduleService",["$q","BBModel","ScheduleRules","BBAssets",function($q,BBModel,ScheduleRules,BBAssets){var cacheDates,getCacheDates,loadScheduleCaches,schedule_cache;return schedule_cache={},cacheDates=function(asset,dates){var k,name,results,v;schedule_cache[name=asset.self]||(schedule_cache[name]={}),results=[];for(k in dates)v=dates[k],results.push(schedule_cache[asset.self][k]=v);return results},getCacheDates=function(asset,start,end){var asset_cache,curr,dates,en,st,test;if(!schedule_cache[asset.self])return!1;for(st=moment(start),en=moment(end),curr=moment(start),dates=[],asset_cache=schedule_cache[asset.self];curr.unix()<end.unix();){if(test=curr.format("YYYY-MM-DD"),!asset_cache[test])return!1;dates[test]=asset_cache[test],curr=curr.add(1,"day")}return dates},loadScheduleCaches=function(assets){var asset,fin,i,len,proms;for(proms=[],i=0,len=assets.length;len>i;i++)asset=assets[i],asset.$has("immediate_schedule")&&!function(_this){return function(asset){var prom;return prom=asset.$get("immediate_schedule"),proms.push(prom),prom.then(function(schedules){return cacheDates(asset,schedules.dates)})}}(this)(asset);return fin=$q.defer(),proms.length>0?$q.all(proms).then(function(){return fin.resolve()}):fin.resolve(),fin.promise},{mapAssetsToScheduleEvents:function(start,end,assets){var assets_with_schedule;return assets_with_schedule=_.filter(assets,function(asset){return asset.$has("schedule")}),_.map(assets_with_schedule,function(asset){var events,found,params,prom,rules;return found=getCacheDates(asset,start,end),found?(rules=new ScheduleRules(found),events=rules.toEvents(),_.each(events,function(e){return e.resourceId=parseInt(asset.id)+"_"+asset.type[0],e.title=asset.name,e.start=moment(e.start),e.end=moment(e.end),e.rendering="background"}),prom=$q.defer(),prom.resolve(events),prom.promise):(params={start_date:start.format("YYYY-MM-DD"),end_date:end.format("YYYY-MM-DD")},asset.$get("schedule",params).then(function(schedules){return rules=new ScheduleRules(schedules.dates),events=rules.toEvents(),_.each(events,function(e){return e.resourceId=parseInt(asset.id)+"_"+asset.type[0],e.title=asset.name,e.start=moment(e.start),e.end=moment(e.end),e.rendering="background"}),events}))})},getAssetsScheduleEvents:function(company,start,end,filtered,requested){var localMethod;return null==filtered&&(filtered=!1),null==requested&&(requested=[]),filtered?loadScheduleCaches(requested).then(function(_this){return function(){return $q.all(_this.mapAssetsToScheduleEvents(start,end,requested)).then(function(schedules){return _.flatten(schedules)})}}(this)):(localMethod=this.mapAssetsToScheduleEvents,BBAssets.getAssets(company).then(function(assets){return loadScheduleCaches(assets).then(function(){return $q.all(localMethod(start,end,assets)).then(function(schedules){return _.flatten(schedules)})})}))}}}])}.call(this),function(){"use strict";angular.module("BBAdmin.Services").factory("AdminServiceService",["$q","BBModel","$log",function($q,BBModel,$log){return{query:function(params){var company,defer;return company=params.company,defer=$q.defer(),company.$get("services").then(function(collection){return collection.$get("services").then(function(services){var models,s;return models=function(){var i,len,results;for(results=[],i=0,len=services.length;len>i;i++)s=services[i],results.push(new BBModel.Admin.Service(s));return results}(),defer.resolve(models)},function(err){return defer.reject(err)})},function(err){return defer.reject(err)}),defer.promise}}}])}.call(this),function(){"use strict";angular.module("BBAdminServices").factory("BB.Service.schedule",["$q","BBModel",function($q,BBModel){return{unwrap:function(resource){return new BBModel.Admin.Schedule(resource)}}}]),angular.module("BBAdminServices").factory("BB.Service.person",["$q","BBModel",function($q,BBModel){return{unwrap:function(resource){return new BBModel.Admin.Person(resource)}}}]),angular.module("BBAdminServices").factory("BB.Service.people",["$q","BBModel",function($q,BBModel){return{promise:!0,unwrap:function(resource){var deferred;return deferred=$q.defer(),resource.$get("people").then(function(_this){return function(items){var i,j,len,models;for(models=[],j=0,len=items.length;len>j;j++)i=items[j],models.push(new BBModel.Admin.Person(i));return deferred.resolve(models)}}(this),function(_this){return function(err){return deferred.reject(err)}}(this)),deferred.promise}}}]),angular.module("BBAdminServices").factory("BB.Service.resource",["$q","BBModel",function($q,BBModel){return{unwrap:function(resource){return new BBModel.Admin.Resource(resource)}}}]),angular.module("BBAdminServices").factory("BB.Service.resources",["$q","BBModel",function($q,BBModel){return{promise:!0,unwrap:function(resource){var deferred;return deferred=$q.defer(),resource.$get("resources").then(function(_this){return function(items){var i,j,len,models;for(models=[],j=0,len=items.length;len>j;j++)i=items[j],models.push(new BBModel.Admin.Resource(i));return deferred.resolve(models)}}(this),function(_this){return function(err){return deferred.reject(err)}}(this)),deferred.promise}}}]),angular.module("BBAdminServices").factory("BB.Service.service",["$q","BBModel",function($q,BBModel){return{unwrap:function(resource){return new BBModel.Admin.Service(resource)}}}]),angular.module("BBAdminServices").factory("BB.Service.services",["$q","BBModel",function($q,BBModel){return{promise:!0,unwrap:function(resource){var deferred;return deferred=$q.defer(),resource.$get("services").then(function(_this){return function(items){var i,j,len,models;for(models=[],j=0,len=items.length;len>j;j++)i=items[j],models.push(new BBModel.Admin.Service(i));return deferred.resolve(models)}}(this),function(_this){return function(err){return deferred.reject(err)}}(this)),deferred.promise}}}])}.call(this),function(){"use strict";angular.module("BBAdminServices").config(["$translateProvider",function($translateProvider){"ngInject";var translations;translations={SERVICES:{PERSON_TABLE:{NEW_PERSON:"New Person",DELETE:"@:COMMON.BTN.DELETE",EDIT:"@:COMMON.BTN.EDIT",SCHEDULE:"@:COMMON.TERMINOLOGY.SCHEDULE"},RESOURCE_TABLE:{NEW_RESOURCE:"New Resource",DELETE:"@:COMMON.BTN.DELETE",EDIT:"@:COMMON.BTN.EDIT",SCHEDULE:"@:COMMON.TERMINOLOGY.SCHEDULE"},SERVICE_TABLE:{NEW_SERVICE:"New Service",EDIT:"@:COMMON.BTN.EDIT",BOOK_BTN:"@:COMMON.BTN.BOOK"}}},$translateProvider.translations("en",translations)}])}.call(this);