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