sogo/UI/WebServerResources/js/Scheduler.services.js
2015-12-04 15:38:30 -05:00

2 lines
26 KiB
JavaScript

(function(){"use strict";function Calendar(futureCalendarData){this.init(futureCalendarData);if(this.name&&!this.id){var newCalendarData=Calendar.$$resource.create("createFolder",this.name);this.$unwrap(newCalendarData)}if(this.id){this.$acl=new Calendar.$$Acl("Calendar/"+this.id)}}Calendar.$factory=["$q","$timeout","$log","sgSettings","Resource","Component","Acl",function($q,$timeout,$log,Settings,Resource,Component,Acl){angular.extend(Calendar,{$q:$q,$timeout:$timeout,$log:$log,$$resource:new Resource(Settings.activeUser("folderURL")+"Calendar",Settings.activeUser()),$Component:Component,$$Acl:Acl,activeUser:Settings.activeUser(),$view:null});return Calendar}];try{angular.module("SOGo.SchedulerUI")}catch(e){angular.module("SOGo.SchedulerUI",["SOGo.Common"])}angular.module("SOGo.SchedulerUI").value("CalendarSettings",{EventDragDayLength:24*4,EventDragHorizontalOffset:3}).factory("Calendar",Calendar.$factory);Calendar.$add=function(calendar){var list,sibling,i;if(calendar.isWebCalendar)list=this.$webcalendars;else if(calendar.isSubscription)list=this.$subscriptions;else list=this.$calendars;sibling=_.find(list,function(o){return o.id!="personal"&&o.name.localeCompare(calendar.name)===1});i=sibling?_.indexOf(_.pluck(list,"id"),sibling.id):1;list.splice(i,0,calendar)};Calendar.$findAll=function(data){var _this=this;if(data){this.$calendars=[];this.$subscriptions=[];this.$webcalendars=[];angular.forEach(data,function(o,i){var calendar=new Calendar(o);if(calendar.isWebCalendar)_this.$webcalendars.push(calendar);else if(calendar.isSubscription)_this.$subscriptions.push(calendar);else _this.$calendars.push(calendar)})}return _.union(this.$calendars,this.$subscriptions,this.$webcalendars)};Calendar.$get=function(id){var calendar;calendar=_.find(Calendar.$calendars,function(o){return o.id==id});if(!calendar)calendar=_.find(Calendar.$subscriptions,function(o){return o.id==id});if(!calendar)calendar=_.find(Calendar.$webcalendars,function(o){return o.id==id});return calendar};Calendar.$getIndex=function(id){var i;i=_.indexOf(_.pluck(Calendar.$calendars,"id"),id);if(i<0)i=_.indexOf(_.pluck(Calendar.$subscriptions,"id"),id);if(i<0)i=_.indexOf(_.pluck(Calendar.$webcalendars,"id"),id);return i};Calendar.$subscribe=function(uid,path){var _this=this;return Calendar.$$resource.userResource(uid).fetch(path,"subscribe").then(function(calendarData){var calendar=new Calendar(calendarData);if(!_.find(_this.$subscriptions,function(o){return o.id==calendarData.id})){Calendar.$add(calendar)}return calendar})};Calendar.$addWebCalendar=function(url){var _this=this,d=Calendar.$q.defer();if(_.find(_this.$webcalendars,function(o){return o.urls.webCalendarURL==url})){d.reject()}else{Calendar.$$resource.post(null,"addWebCalendar",{url:url}).then(function(calendarData){angular.extend(calendarData,{isWebCalendar:true,isEditable:true,isRemote:false,owner:Calendar.activeUser.login,urls:{webCalendarURL:url}});var calendar=new Calendar(calendarData);Calendar.$add(calendar);Calendar.$$resource.fetch(calendar.id,"reload").then(function(data){Calendar.$log.debug(JSON.stringify(data,undefined,2))});d.resolve()},function(){d.reject()})}return d.promise};Calendar.$deleteComponents=function(components){var calendars={},_this=this;_.forEach(components,function(component){if(!angular.isDefined(calendars[component.c_folder]))calendars[component.c_folder]=[];calendars[component.c_folder].push(component.c_name)});_.forEach(calendars,function(uids,c_folder){Calendar.$$resource.post(c_folder,"batchDelete",{uids:uids})});_this.$Component.$events=_.difference(_this.$Component.$events,components);_this.$Component.$tasks=_.difference(_this.$Component.$tasks,components)};Calendar.prototype.init=function(data){this.color=this.color||"#AAAAAA";angular.extend(this,data);this.isOwned=Calendar.activeUser.isSuperUser||this.owner==Calendar.activeUser.login;this.isSubscription=!this.isRemote&&this.owner!=Calendar.activeUser.login;if(angular.isUndefined(this.$shadowData)){this.$shadowData=this.$omit()}};Calendar.prototype.$id=function(){if(this.id){return Calendar.$q.when(this.id)}else{return this.$futureCalendarData.then(function(calendar){return calendar.id})}};Calendar.prototype.getClassName=function(base){if(angular.isUndefined(base))base="fg";return base+"-folder"+this.id};Calendar.prototype.$rename=function(){var _this=this,i,calendars;if(this.name==this.$shadowData.name){return Calendar.$q.when()}if(this.isWebCalendar)calendars=Calendar.$webcalendars;else if(this.isSubscription)calendars=Calendar.$subscriptions;else calendars=Calendar.$calendars;i=_.indexOf(_.pluck(calendars,"id"),this.id);if(i>-1){return this.$save().then(function(){calendars.splice(i,1);Calendar.$add(_this)})}else{return Calendar.$q.reject()}};Calendar.prototype.$delete=function(){var _this=this,list,promise;if(this.isSubscription){promise=Calendar.$$resource.fetch(this.id,"unsubscribe");list=Calendar.$subscriptions}else{promise=Calendar.$$resource.remove(this.id);if(this.isWebCalendar)list=Calendar.$webcalendars;else list=Calendar.$calendars}return promise.then(function(){var i=_.indexOf(_.pluck(list,"id"),_this.id);list.splice(i,1)})};Calendar.prototype.$reset=function(){var _this=this;angular.forEach(this,function(value,key){if(key!="constructor"&&key[0]!="$"){delete _this[key]}});angular.extend(this,this.$shadowData);this.$shadowData=this.$omit()};Calendar.prototype.$save=function(){var _this=this;return Calendar.$$resource.save(this.id,this.$omit()).then(function(data){_this.$shadowData=_this.$omit();return data},function(data){Calendar.$log.error(JSON.stringify(data,undefined,2));_this.$reset();return data})};Calendar.prototype.$setActivation=function(){return Calendar.$$resource.fetch(this.id,(this.active?"":"de")+"activateFolder")};Calendar.prototype.$getComponent=function(componentId,recurrenceId){return Calendar.$Component.$find(this.id,componentId,recurrenceId)};Calendar.prototype.$unwrap=function(futureCalendarData){var _this=this;this.$futureCalendarData=futureCalendarData.then(function(data){return Calendar.$timeout(function(){_this.init(data);return _this})},function(data){_this.isError=true;if(angular.isObject(data)){Calendar.$timeout(function(){angular.extend(_this,data)})}})};Calendar.prototype.$omit=function(){var calendar={};angular.forEach(this,function(value,key){if(key!="constructor"&&key[0]!="$"){calendar[key]=value}});return calendar}})();(function(){"use strict";function Component(futureComponentData){if(typeof futureComponentData.then!=="function"){this.init(futureComponentData);if(this.pid&&!this.id){var newComponentData=Component.$$resource.newguid(this.pid);this.$unwrap(newComponentData);this.isNew=true}}else{this.$unwrap(futureComponentData)}}Component.$factory=["$q","$timeout","$log","sgSettings","Preferences","Gravatar","Resource",function($q,$timeout,$log,Settings,Preferences,Gravatar,Resource){angular.extend(Component,{$q:$q,$timeout:$timeout,$log:$log,$Preferences:Preferences,$gravatar:Gravatar,$$resource:new Resource(Settings.baseURL(),Settings.activeUser()),timeFormat:"%H:%M",$query:{value:"",search:"title_Category_Location"},$queryEvents:{sort:"start",asc:1,filterpopup:"view_next7"},$queryTasks:{sort:"status",asc:1,filterpopup:"view_incomplete"},$refreshTimeout:null,$ghost:{}});Preferences.ready().then(function(){if(Preferences.settings.Calendar.EventsFilterState)Component.$queryEvents.filterpopup=Preferences.settings.Calendar.EventsFilterState;if(Preferences.settings.Calendar.TasksFilterState)Component.$queryTasks.filterpopup=Preferences.settings.Calendar.TasksFilterState;if(Preferences.settings.Calendar.EventsSortingState){Component.$queryEvents.sort=Preferences.settings.Calendar.EventsSortingState[0];Component.$queryEvents.asc=parseInt(Preferences.settings.Calendar.EventsSortingState[1])}if(Preferences.settings.Calendar.TasksSortingState){Component.$queryTasks.sort=Preferences.settings.Calendar.TasksSortingState[0];Component.$queryTasks.asc=parseInt(Preferences.settings.Calendar.TasksSortingState[1])}Component.$queryTasks.show_completed=parseInt(Preferences.settings.ShowCompletedTasks);Component.$categories=Preferences.defaults.SOGoCalendarCategoriesColors;if(Preferences.defaults.SOGoTimeFormat){Component.timeFormat=Preferences.defaults.SOGoTimeFormat}});return Component}];try{angular.module("SOGo.SchedulerUI")}catch(e){angular.module("SOGo.SchedulerUI",["SOGo.Common"])}angular.module("SOGo.SchedulerUI").factory("Component",Component.$factory);Component.$selectedCount=function(){var count;count=0;if(Component.$events){count+=_.filter(Component.$events,function(event){return event.selected}).length}if(Component.$tasks){count+=_.filter(Component.$tasks,function(task){return task.selected}).length}return count};Component.$startRefreshTimeout=function(type){var _this=this;if(Component.$refreshTimeout)Component.$timeout.cancel(Component.$refreshTimeout);Component.$Preferences.ready().then(function(){var refreshViewCheck=Component.$Preferences.defaults.SOGoRefreshViewCheck;if(refreshViewCheck&&refreshViewCheck!="manually"){var f=angular.bind(_this,Component.$filter,type);Component.$refreshTimeout=Component.$timeout(f,refreshViewCheck.timeInterval()*1e3)}})};Component.$filter=function(type,options){var _this=this,now=new Date,day=now.getDate(),month=now.getMonth()+1,year=now.getFullYear(),queryKey="$query"+type.capitalize(),params={day:""+year+(month<10?"0":"")+month+(day<10?"0":"")+day};Component.$startRefreshTimeout(type);return this.$Preferences.ready().then(function(){var futureComponentData,dirty=false,otherType;angular.extend(_this.$query,params);if(options){_.each(_.keys(options),function(key){dirty|=_this.$query[key]&&options[key]!=Component.$query[key];if(key=="reload"&&options[key])dirty=true;else if(angular.isDefined(_this.$query[key]))_this.$query[key]=options[key];else _this[queryKey][key]=options[key]})}futureComponentData=_this.$$resource.fetch(null,type+"list",angular.extend(_this[queryKey],_this.$query));otherType=type=="tasks"?"$events":"$tasks";if(dirty){delete Component[otherType];Component.$log.debug("force reload of "+otherType)}return _this.$unwrapCollection(type,futureComponentData)})};Component.$find=function(calendarId,componentId,occurrenceId){var futureComponentData,path=[calendarId,componentId];if(occurrenceId)path.push(occurrenceId);futureComponentData=this.$$resource.fetch(path.join("/"),"view");return new Component(futureComponentData)};Component.filterCategories=function(query){var re=new RegExp(query,"i");return _.filter(_.keys(Component.$categories),function(category){return category.search(re)!=-1})};Component.saveSelectedList=function(componentType){return this.$$resource.post(null,"saveSelectedList",{list:componentType+"ListView"})};Component.$eventsBlocksForView=function(view,date){var viewAction,startDate,endDate,params;if(view=="day"){viewAction="dayView";startDate=endDate=date}else if(view=="multicolumnday"){viewAction="multicolumndayView";startDate=endDate=date}else if(view=="week"){viewAction="weekView";startDate=date.beginOfWeek();endDate=new Date;endDate.setTime(startDate.getTime());endDate.addDays(6)}else if(view=="month"){viewAction="monthView";startDate=date;startDate.setDate(1);startDate=startDate.beginOfWeek();endDate=new Date;endDate.setTime(startDate.getTime());endDate.setMonth(endDate.getMonth()+1);endDate.addDays(-1);endDate=endDate.endOfWeek()}return this.$eventsBlocks(viewAction,startDate,endDate)};Component.$eventsBlocks=function(view,startDate,endDate){var params,futureComponentData,i,j,dates=[],deferred=Component.$q.defer();params={view:view.toLowerCase(),sd:startDate.getDayString(),ed:endDate.getDayString()};Component.$log.debug("eventsblocks "+JSON.stringify(params,undefined,2));futureComponentData=this.$$resource.fetch(null,"eventsblocks",params);futureComponentData.then(function(views){var reduceComponent,associateComponent;reduceComponent=function(objects,eventData,i){var componentData=_.object(this.eventsFields,eventData),start=new Date(componentData.c_startdate*1e3);componentData.hour=start.getHourString();componentData.blocks=[];objects.push(new Component(componentData));return objects};associateComponent=function(block){this[block.nbr].blocks.push(block);block.component=this[block.nbr]};Component.$views=[];Component.$timeout(function(){_.forEach(views,function(data){var components=[],blocks={},allDayBlocks={},viewData;data.eventsFields.splice(_.indexOf(data.eventsFields,"c_folder"),1,"pid");data.eventsFields.splice(_.indexOf(data.eventsFields,"c_name"),1,"id");data.eventsFields.splice(_.indexOf(data.eventsFields,"c_recurrence_id"),1,"occurrenceId");data.eventsFields.splice(_.indexOf(data.eventsFields,"c_title"),1,"summary");_.reduce(data.events,reduceComponent,components,data);_.forEach(_.flatten(data.blocks),associateComponent,components);_.each(_.flatten(data.allDayBlocks),associateComponent,components);if(dates.length===0)for(i=0;i<data.blocks.length;i++){dates.push(startDate.getDayString());startDate.addDays(1)}for(i=0;i<data.blocks.length;i++){for(j=0;j<data.blocks[i].length;j++)data.blocks[i][j].dayNumber=i;blocks[dates[i]]=data.blocks[i]}for(i=0;i<data.allDayBlocks.length;i++){for(j=0;j<data.allDayBlocks[i].length;j++)data.allDayBlocks[i][j].dayNumber=i;allDayBlocks[dates[i]]=data.allDayBlocks[i]}Component.$log.debug("blocks ready ("+_.flatten(data.blocks).length+")");Component.$log.debug("all day blocks ready ("+_.flatten(data.allDayBlocks).length+")");viewData={blocks:blocks,allDayBlocks:allDayBlocks};if(data.id&&data.calendarName){viewData.id=data.id;viewData.calendarName=data.calendarName}Component.$views.push(viewData)});deferred.resolve(Component.$views)})},deferred.reject);return deferred.promise};Component.$unwrapCollection=function(type,futureComponentData){var _this=this,components=[];return futureComponentData.then(function(data){return Component.$timeout(function(){var fields=_.invoke(data.fields,"toLowerCase");fields.splice(_.indexOf(fields,"c_folder"),1,"pid");fields.splice(_.indexOf(fields,"c_name"),1,"id");fields.splice(_.indexOf(fields,"c_recurrence_id"),1,"occurrenceId");_.reduce(data[type],function(components,componentData,i){var data=_.object(fields,componentData);components.push(new Component(data));return components},components);Component.$log.debug("list of "+type+" ready ("+components.length+")");Component["$"+type]=components;return components})})};Component.prototype.init=function(data){var _this=this;this.categories=[];this.repeat={};this.alarm={action:"display",quantity:5,unit:"MINUTES",reference:"BEFORE",relation:"START"};this.status="not-specified";this.delta=60;angular.extend(this,data);Component.$Preferences.ready().then(function(){var type=_this.type=="appointment"?"Events":"Tasks";_this.classification=_this.classification||Component.$Preferences.defaults["SOGoCalendar"+type+"DefaultClassification"].toLowerCase()});if(this.component=="vevent")this.type="appointment";else if(this.component=="vtoto")this.type="task";if(this.startDate){if(angular.isString(this.startDate))this.start=new Date(this.startDate.substring(0,10)+" "+this.startDate.substring(11,16));else this.start=this.startDate}else if(this.type=="appointment"){this.start=new Date;this.start.setMinutes(Math.round(this.start.getMinutes()/15)*15)}if(this.endDate){this.end=new Date(this.endDate.substring(0,10)+" "+this.endDate.substring(11,16));this.delta=this.start.minutesTo(this.end)}else if(this.type=="appointment"){this.setDelta(this.delta)}if(this.dueDate)this.due=new Date(this.dueDate.substring(0,10)+" "+this.dueDate.substring(11,16));if(this.c_category)this.categories=_.invoke(this.c_category,"asCSSIdentifier");this.$isRecurrent=angular.isDefined(data.repeat);if(this.repeat.days){var byDayMask=_.find(this.repeat.days,function(o){return angular.isDefined(o.occurrence)});if(byDayMask)if(this.repeat.frequency=="yearly")this.repeat.year={byday:true};this.repeat.month={type:"byday",occurrence:byDayMask.occurrence.toString(),day:byDayMask.day}}else{this.repeat.days=[]}if(angular.isUndefined(this.repeat.frequency))this.repeat.frequency="never";if(angular.isUndefined(this.repeat.interval))this.repeat.interval=1;if(angular.isUndefined(this.repeat.month))this.repeat.month={occurrence:"1",day:"SU",type:"bymonthday"};if(angular.isUndefined(this.repeat.monthdays))this.repeat.monthdays=[];if(angular.isUndefined(this.repeat.months))this.repeat.months=[];if(angular.isUndefined(this.repeat.year))this.repeat.year={};if(this.repeat.count)this.repeat.end="count";else if(this.repeat.until){this.repeat.end="until";this.repeat.until=this.repeat.until.substring(0,10).asDate()}else this.repeat.end="never";this.$hasCustomRepeat=this.hasCustomRepeat();if(this.isNew){Component.$Preferences.ready().then(function(){var units={M:"MINUTES",H:"HOURS",D:"DAYS",W:"WEEKS"};var match=/-PT?([0-9]+)([MHDW])/.exec(Component.$Preferences.defaults.SOGoCalendarDefaultReminder);if(match){_this.$hasAlarm=true;_this.alarm.quantity=parseInt(match[1]);_this.alarm.unit=units[match[2]]}})}else{this.$hasAlarm=angular.isDefined(data.alarm)}this.destinationCalendar=this.pid;this.updateFreeBusy();this.selected=false};Component.prototype.hasCustomRepeat=function(){var b=angular.isDefined(this.repeat)&&(this.repeat.interval>1||this.repeat.days&&this.repeat.days.length>0||this.repeat.monthdays&&this.repeat.monthdays.length>0||this.repeat.months&&this.repeat.months.length>0);return b};Component.prototype.isEditable=function(){return!this.occurrenceId&&!this.isReadOnly};Component.prototype.isEditableOccurrence=function(){return this.occurrenceId&&!this.isReadOnly};Component.prototype.isInvitation=function(){return!this.occurrenceId&&this.userHasRSVP};Component.prototype.isInvitationOccurrence=function(){return this.occurrenceId&&this.userHasRSVP};Component.prototype.isReadOnly=function(){return this.isReadOnly&&!this.userHasRSVP};Component.prototype.enablePercentComplete=function(){return this.type=="task"&&this.status!="not-specified"&&this.status!="cancelled"};Component.prototype.coversFreeBusy=function(day,hour,quarter){var b=angular.isDefined(this.freebusy[day])&&angular.isDefined(this.freebusy[day][hour])&&this.freebusy[day][hour][quarter]==1;return b};Component.prototype.updateFreeBusyCoverage=function(){var _this=this,freebusy={};if(this.start&&this.end){var roundedStart=new Date(this.start.getTime()),roundedEnd=new Date(this.end.getTime()),startQuarter=parseInt(roundedStart.getMinutes()/15+.5),endQuarter=parseInt(roundedEnd.getMinutes()/15+.5);roundedStart.setMinutes(15*startQuarter);roundedEnd.setMinutes(15*endQuarter);_.each(roundedStart.daysUpTo(roundedEnd),function(date,index){var currentDay=date.getDate(),dayKey=date.getDayString(),hourKey;if(dayKey==_this.start.getDayString()){hourKey=date.getHours().toString();freebusy[dayKey]={};freebusy[dayKey][hourKey]=[];while(startQuarter>0){freebusy[dayKey][hourKey].push(0);startQuarter--}}else{date=date.beginOfDay();freebusy[dayKey]={}}while(date.getTime()<_this.end.getTime()&&date.getDate()==currentDay){hourKey=date.getHours().toString();if(angular.isUndefined(freebusy[dayKey][hourKey]))freebusy[dayKey][hourKey]=[];freebusy[dayKey][hourKey].push(1);date.addMinutes(15)}});return freebusy}};Component.prototype.updateFreeBusy=function(){var _this=this;this.freebusy=this.updateFreeBusyCoverage();if(this.attendees){_.each(this.attendees,function(attendee){attendee.image=Component.$gravatar(attendee.email,32);_this.updateFreeBusyAttendee(attendee)})}};Component.prototype.setDelta=function(delta){this.delta=delta;this.end=new Date(this.start.getTime());this.end.setMinutes(Math.round(this.end.getMinutes()/15)*15);this.end.addMinutes(this.delta)};Component.prototype.updateFreeBusyAttendee=function(attendee){var params,url,days;if(attendee.uid){params={sday:this.start.getDayString(),eday:this.end.getDayString()};url=["..","..",attendee.uid,"freebusy.ifb"];days=_.map(this.start.daysUpTo(this.end),function(day){return day.getDayString()});if(angular.isUndefined(attendee.freebusy))attendee.freebusy={};Component.$$resource.fetch(url.join("/"),"ajaxRead",params).then(function(data){_.each(days,function(day){var hour;if(angular.isUndefined(attendee.freebusy[day]))attendee.freebusy[day]={};if(angular.isUndefined(data[day]))data[day]={};for(var i=0;i<=23;i++){hour=i.toString();if(data[day][hour])attendee.freebusy[day][hour]=[data[day][hour]["0"],data[day][hour]["15"],data[day][hour]["30"],data[day][hour]["45"]];else attendee.freebusy[day][hour]=[0,0,0,0]}})})}};Component.prototype.getClassName=function(base){if(angular.isUndefined(base))base="fg";return base+"-folder"+(this.destinationCalendar||this.c_folder||this.pid)};Component.prototype.addAttendee=function(card){var attendee,url,params;if(card){attendee={name:card.c_cn,email:card.$preferredEmail(),role:"req-participant",status:"needs-action",uid:card.c_uid};if(!_.find(this.attendees,function(o){return o.email==attendee.email})){attendee.image=Component.$gravatar(attendee.email,32);if(this.attendees)this.attendees.push(attendee);else this.attendees=[attendee];this.updateFreeBusyAttendee(attendee)}}};Component.prototype.hasAttendee=function(card){var attendee=_.find(this.attendees,function(attendee){return _.find(card.emails,function(email){return email.value==attendee.email})});return angular.isDefined(attendee)};Component.prototype.deleteAttendee=function(attendee){var index=_.findIndex(this.attendees,function(currentAttendee){return currentAttendee.email==attendee.email});this.attendees.splice(index,1)};Component.prototype.canRemindAttendeesByEmail=function(){return this.alarm.action=="email"&&!this.isReadOnly&&this.attendees&&this.attendees.length>0};Component.prototype.addAttachUrl=function(attachUrl){if(angular.isUndefined(this.attachUrls)){this.attachUrls=[{value:attachUrl}]}else{for(var i=0;i<this.attachUrls.length;i++){if(this.attachUrls[i].value==attachUrl){break}}if(i==this.attachUrls.length)this.attachUrls.push({value:attachUrl})}return this.attachUrls.length-1};Component.prototype.deleteAttachUrl=function(index){if(index>-1&&this.attachUrls.length>index){this.attachUrls.splice(index,1)}};Component.prototype.$addDueDate=function(){this.due=new Date;this.due.setMinutes(Math.round(this.due.getMinutes()/15)*15);this.dueDate=this.due.toISOString()};Component.prototype.$deleteDueDate=function(){delete this.due;delete this.dueDate};Component.prototype.$addStartDate=function(){this.start=new Date;this.start.setMinutes(Math.round(this.start.getMinutes()/15)*15)};Component.prototype.$deleteStartDate=function(){delete this.start;delete this.startDate};Component.prototype.$reset=function(){var _this=this;angular.forEach(this,function(value,key){if(key!="constructor"&&key[0]!="$"){delete _this[key]}});this.init(this.$shadowData);this.$shadowData=this.$omit(true)};Component.prototype.$reply=function(){var _this=this,data,path=[this.pid,this.id];if(this.occurrenceId)path.push(this.occurrenceId);data={reply:this.reply,delegatedTo:this.delegatedTo,alarm:this.$hasAlarm?this.alarm:{}};return Component.$$resource.save(path.join("/"),data,{action:"rsvpAppointment"}).then(function(data){_this.$shadowData=_this.$omit(true);return data})};Component.prototype.$adjust=function(params){var path=[this.pid,this.id];if(_.every(_.values(params),function(v){return v===0}))return Component.$q.when();if(this.occurrenceId)path.push(this.occurrenceId);Component.$log.debug("adjust "+path.join("/")+" "+JSON.stringify(params));return Component.$$resource.save(path.join("/"),params,{action:"adjust"})};Component.prototype.$save=function(){var _this=this,options,path=[this.pid,this.id];if(this.isNew)options={action:"saveAs"+this.type.capitalize()};if(this.occurrenceId)path.push(this.occurrenceId);return Component.$$resource.save(path.join("/"),this.$omit(),options).then(function(data){_this.$shadowData=_this.$omit(true);return data})};Component.prototype.remove=function(occurrenceOnly){var _this=this,path=[this.pid,this.id];if(occurrenceOnly&&this.occurrenceId)path.push(this.occurrenceId);return Component.$$resource.remove(path.join("/"))};Component.prototype.$unwrap=function(futureComponentData){var _this=this;this.$futureComponentData=futureComponentData;this.$futureComponentData.then(function(data){_this.init(data);_this.$shadowData=_this.$omit()},function(data){angular.extend(_this,data);_this.isError=true;Component.$log.error(_this.error)})};Component.prototype.$omit=function(){var component={},date;angular.forEach(this,function(value,key){if(key!="constructor"&&key[0]!="$"&&key!="blocks"){component[key]=angular.copy(value)}});component.startDate=component.start?formatDate(component.start):"";component.startTime=component.start?formatTime(component.start):"";component.endDate=component.end?formatDate(component.end):"";component.endTime=component.end?formatTime(component.end):"";component.dueDate=component.due?formatDate(component.due):"";component.dueTime=component.due?formatTime(component.due):"";if(this.$hasCustomRepeat){if(this.repeat.frequency=="monthly"&&this.repeat.month.type&&this.repeat.month.type=="byday"||this.repeat.frequency=="yearly"&&this.repeat.year.byday){delete component.repeat.monthdays;component.repeat.days=[{day:this.repeat.month.day,occurrence:this.repeat.month.occurrence.toString()}]}else if(this.repeat.month.type){delete component.repeat.days}}else if(this.repeat.frequency){component.repeat={frequency:this.repeat.frequency}}if(this.repeat.frequency){if(this.repeat.end=="until"&&this.repeat.until)component.repeat.until=this.repeat.until.stringWithSeparator("-");else if(this.repeat.end=="count"&&this.repeat.count)component.repeat.count=this.repeat.count;else{delete component.repeat.until;delete component.repeat.count}}else{delete component.repeat}if(this.$hasAlarm){if(this.alarm.action&&this.alarm.action=="email"&&!(this.attendees&&this.attendees.length>0)){this.alarm.attendees=0;this.alarm.organizer=1}}else{component.alarm={}}function formatTime(date){var hours=date.getHours();if(hours<10)hours="0"+hours;var minutes=date.getMinutes();if(minutes<10)minutes="0"+minutes;return hours+":"+minutes}function formatDate(date){var year=date.getYear();if(year<1e3)year+=1900;var month=""+(date.getMonth()+1);if(month.length==1)month="0"+month;var day=""+date.getDate();if(day.length==1)day="0"+day;return year+"-"+month+"-"+day}return component};Component.prototype.repeatDescription=function(){var localizedString=null;if(this.repeat)localizedString=l("repeat_"+this.repeat.frequency.toUpperCase());return localizedString};Component.prototype.alarmDescription=function(){var key,localizedString=null;if(this.alarm){key=["reminder"+this.alarm.quantity,this.alarm.unit,this.alarm.reference].join("_");localizedString=l(key);if(key===localizedString)localizedString=[this.alarm.quantity,l("reminder_"+this.alarm.unit),l("reminder_"+this.alarm.reference)].join(" ")}return localizedString};Component.prototype.toString=function(){return"[Component "+this.id+"]"}})();
//# sourceMappingURL=Scheduler.services.js.map