2016-01-13 15:18:14 +01:00
|
|
|
(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","Preferences","Component","Acl",function($q,$timeout,$log,Settings,Resource,Preferences,Component,Acl){angular.extend(Calendar,{$q:$q,$timeout:$timeout,$log:$log,$$resource:new Resource(Settings.activeUser("folderURL")+"Calendar",Settings.activeUser()),$Preferences:Preferences,$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.$defaultCalendar=function(){var defaultCalendar=Calendar.$Preferences.defaults.SOGoDefaultCalendar,calendar;if(defaultCalendar=="first"){calendar=_.find(Calendar.$findAll(null,true),function(calendar){return calendar.active});if(calendar)return calendar.id}return"personal"};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,writable){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)})}if(writable){return _.union(this.$calendars,_.filter(this.$subscriptions,function(calendar){return calendar.acls.objectCreator}))}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.$Compon
|