2018-02-07 08:19:11 +01:00
|
|
|
!function(){"use strict";function e(t){if(this.init(t),this.name&&!this.id){var n=e.$$resource.create("createFolder",this.name);this.$unwrap(n)}}e.$factory=["$q","$timeout","$log","sgSettings","Resource","Preferences","Component","Acl",function(t,n,a,o,i,r,s,c){return angular.extend(e,{$q:t,$timeout:n,$log:a,$$resource:new i(o.activeUser("folderURL")+"Calendar",o.activeUser()),$Preferences:r,$Component:s,$$Acl:c,activeUser:o.activeUser(),$view:null}),e}];try{angular.module("SOGo.SchedulerUI")}catch(e){angular.module("SOGo.SchedulerUI",["SOGo.Common"])}angular.module("SOGo.SchedulerUI").value("CalendarSettings",{EventDragDayLength:96,EventDragHorizontalOffset:3,ConflictHTTPErrorCode:409}).factory("Calendar",e.$factory),e.$defaultCalendar=function(){var t;return"first"==e.$Preferences.defaults.SOGoDefaultCalendar&&(t=_.find(e.$findAll(null,!0),function(e){return e.active}))?t.id:"personal"},e.$add=function(t){var n,a;n=t.isWebCalendar?this.$webcalendars:t.isSubscription?this.$subscriptions:this.$calendars,(a=_.findIndex(n,function(e,n){return"personal"==t.id||"personal"!=e.id&&e.name.localeCompare(t.name)>0}))<0?n.push(t):n.splice(a,0,t),e.$Preferences.settings.Calendar.FoldersOrder&&e.saveFoldersOrder(_.flatMap(e.$findAll(),"id")),e.$reloadAll()},e.$findAll=function(t,n){var a=this;if(t)this.$calendars=[],this.$subscriptions=[],this.$webcalendars=[],angular.forEach(t,function(t,n){var o=new e(t);o.isWebCalendar?a.$webcalendars.push(o):o.isSubscription?a.$subscriptions.push(o):a.$calendars.push(o)});else if(angular.isUndefined(this.$calendars))return this.$calendars=[],this.$subscriptions=[],this.$webcalendars=[],e.$$resource.fetch("calendarslist").then(function(t){return e.$findAll(t.calendars,n)});return n?_.union(this.$calendars,_.filter(this.$subscriptions,function(e){return e.isOwned||e.acls.objectCreator})):_.union(this.$calendars,this.$subscriptions,this.$webcalendars)},e.$reloadAll=function(){var t=this;e.$$resource.fetch("calendarslist").then(function(n){_.forEach(n.calendars,function(n){var a,o;a=n.isWebCalendar?t.$webcalendars:n.owner!=e.activeUser.login?t.$subscriptions:t.$calendars,(o=_.find(a,function(e){return e.id==n.id}))&&o.init(n)})})},e.$get=function(t){var n;return(n=_.find(e.$calendars,function(e){return e.id==t}))||(n=_.find(e.$subscriptions,function(e){return e.id==t})),n||(n=_.find(e.$webcalendars,function(e){return e.id==t})),n},e.$getIndex=function(t){var n;return(n=_.indexOf(_.map(e.$calendars,"id"),t))<0&&(n=_.indexOf(_.map(e.$subscriptions,"id"),t)),n<0&&(n=_.indexOf(_.map(e.$webcalendars,"id"),t)),n},e.$subscribe=function(t,n){var a=this;return e.$$resource.userResource(t).fetch(n,"subscribe").then(function(t){var n=new e(angular.extend({active:1},t));return _.find(a.$subscriptions,function(e){return e.id==t.id})||e.$add(n),n})},e.$addWebCalendar=function(t){var n=e.$q.defer();return _.find(this.$webcalendars,function(e){return e.urls.webCalendarURL==t})?n.reject():e.$$resource.post(null,"addWebCalendar",{url:t}).then(function(a){angular.extend(a,{isWebCalendar:!0,isEditable:!0,isRemote:!1,owner:e.activeUser.login,urls:{webCalendarURL:t}});var o=new e(a);e.$$resource.fetch(o.id,"reload").then(function(t){e.$log.debug(JSON.stringify(t,void 0,2)),e.$add(o),n.resolve()},function(e){401==e.status?n.resolve(o):n.reject()})},n.reject),n.promise},e.reloadWebCalendars=function(){var t=[];return _.forEach(this.$webcalendars,function(n){var a=e.$$resource.fetch(n.id,"reload");a.then(function(e){n.$error=!1},function(e){n.$error=l(e.statusText)}),t.push(a)}),e.$q.all(t)},e.$deleteComponents=function(t){var n={},a=[];return _.forEach(t,function(e){angular.isDefined(n[e.pid])||(n[e.pid]=[]),n[e.pid].push(e.id)}),_.forEach(n,function(t,n){a.push(e.$$resource.post(n,"batchDelete",{uids:t}))}),e.$q.all(a)},e.saveFoldersActivation=function(t){var n={};return _.forEach(t,function(t){var a=e.$get(t);n[a.id]=a.active}),e.$$resource.post(null,"saveFoldersActivation",n)},e.saveFoldersOrder=function(t){return this.$$resource.post(null,"saveFoldersOrder",{folders:t}).then(function(){if(e.$Preferences.settings.Calen
|