diff --git a/bookingbug-angular-services.min.js b/bookingbug-angular-services.min.js index 5c09b83..ba78704 100644 --- a/bookingbug-angular-services.min.js +++ b/bookingbug-angular-services.min.js @@ -1,2 +1,2 @@ -(function(){"use strict";angular.module("BBAdminServices",["BB","BBAdmin.Services","BBAdmin.Filters","BBAdmin.Controllers","trNgGrid","ui.calendar"]),angular.module("BBAdminServices").config(function($logProvider){return $logProvider.debugEnabled(!0)}),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)))&&((!this.params.end_time||(this.end_time||(this.end_time=moment(this.params.end_time)),!this.end_time.isBefore(item.end_time)))&&((!this.params.start_date||(this.start_date||(this.start_date=moment(this.params.start_date)),!this.start_date.isAfter(item.start_date)))&&(!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",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",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",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;if(event.start.hasTime())return 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)},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(){if(uiCalendarConfig&&uiCalendarConfig.calendars.scheduleCal)return uiCalendarConfig.calendars.scheduleCal.fullCalendar("refetchEvents"),uiCalendarConfig.calendars.scheduleCal.fullCalendar("unselect")}},{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){if(null!=value)return ngModel.$setViewValue(value)})},{link:link,templateUrl:"schedule_edit_main.html",require:"ngModel",scope:{options:"="}}}),angular.module("schemaForm").config(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",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",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;if(event.start.hasTime())return 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)},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(){if(uiCalendarConfig&&uiCalendarConfig.calendars.scheduleWeekdays)return uiCalendarConfig.calendars.scheduleWeekdays.fullCalendar("refetchEvents"),uiCalendarConfig.calendars.scheduleWeekdays.fullCalendar("unselect")}},{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",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("Admin.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("Admin.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){if(present)return person_id})),this.resource_ids=_.compact(_.map(this.resources,function(present,resource_id){if(present)return resource_id})),this.service_ids=_.compact(_.map(this.services,function(present,service_id){if(present)return service_id})),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("Admin.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){var defer;return defer=$q.defer(),this.$put("attendance",{},{status:status}).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){if(_this.availability[str]="No",sched&&sched.dates&&sched.dates[start.format("YYYY-MM-DD")]&&"None"!==sched.dates[start.format("YYYY-MM-DD")])return _this.availability[str]="Yes"}}(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;i=days;1<=days?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("Admin.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",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;i-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",function($q,UriTemplate,halClient,SlotCollections,BBModel,BookingCollections){return{query:function(params){var company,defer;return company=params.company,defer=$q.defer(),company.$get("resources").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;i-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",function($q,BBModel,ScheduleRules,BBAssets){return{query:function(params){var company,defer;return company=params.company,defer=$q.defer(),company.$get("schedules").then(function(collection){return collection.$get("schedules").then(function(schedules){var models,s;return models=function(){var i,len,results;for(results=[],i=0,len=schedules.length;i0?$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;if(event.start.hasTime())return 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)},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(){if(uiCalendarConfig&&uiCalendarConfig.calendars.scheduleCal)return uiCalendarConfig.calendars.scheduleCal.fullCalendar("refetchEvents"),uiCalendarConfig.calendars.scheduleCal.fullCalendar("unselect")}},{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){if(null!=value)return ngModel.$setViewValue(value)})},{link:link,templateUrl:"schedule_edit_main.html",require:"ngModel",scope:{options:"="}}}),angular.module("schemaForm").config(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",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",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;if(event.start.hasTime())return 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)},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(){if(uiCalendarConfig&&uiCalendarConfig.calendars.scheduleWeekdays)return uiCalendarConfig.calendars.scheduleWeekdays.fullCalendar("refetchEvents"),uiCalendarConfig.calendars.scheduleWeekdays.fullCalendar("unselect")}},{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",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",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",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){if(present)return person_id})),this.resource_ids=_.compact(_.map(this.resources,function(present,resource_id){if(present)return resource_id})),this.service_ids=_.compact(_.map(this.services,function(present,service_id){if(present)return service_id})),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",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){var defer;return defer=$q.defer(),this.$put("attendance",{},{status:status}).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){if(_this.availability[str]="No",sched&&sched.dates&&sched.dates[start.format("YYYY-MM-DD")]&&"None"!==sched.dates[start.format("YYYY-MM-DD")])return _this.availability[str]="Yes"}}(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;i=days;1<=days?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",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",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;i-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",function($q,UriTemplate,halClient,SlotCollections,BBModel,BookingCollections){return{query:function(params){var company,defer;return company=params.company,defer=$q.defer(),company.$get("resources").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;i-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",function($q,BBModel,ScheduleRules,BBAssets){return{query:function(params){var company,defer;return company=params.company,defer=$q.defer(),company.$get("schedules").then(function(collection){return collection.$get("schedules").then(function(schedules){var models,s;return models=function(){var i,len,results;for(results=[],i=0,len=schedules.length;i