2017-06-02 08:16:11 +02:00
|
|
|
!function(){"use strict";function e(t){"function"!=typeof t.then&&(angular.extend(this,t),_.forEach(this.identities,function(e){e.fullName?e.full=e.fullName+" <"+e.email+">":e.full="<"+e.email+">"}),e.$log.debug("Account: "+JSON.stringify(t,void 0,2)))}e.$factory=["$q","$timeout","$log","sgSettings","Resource","Preferences","Mailbox","Message",function(t,n,s,o,a,i,r,l){return angular.extend(e,{$q:t,$timeout:n,$log:s,$$resource:new a(o.activeUser("folderURL")+"Mail",o.activeUser()),$Preferences:i,$Mailbox:r,$Message:l}),e}];try{angular.module("SOGo.MailerUI")}catch(e){angular.module("SOGo.MailerUI",["SOGo.Common"])}angular.module("SOGo.MailerUI").factory("Account",e.$factory),e.$findAll=function(t){return t?e.$unwrapCollection(t):e.$$resource.fetch("","mailAccounts").then(function(t){return e.$unwrapCollection(t)})},e.$unwrapCollection=function(t){var n=[];return angular.forEach(t,function(t,s){t.id=s,n[s]=new e(t)}),e.$accounts=n,n},e.prototype.getLength=function(){return this.$flattenMailboxes().length},e.prototype.getItemAtIndex=function(e){var t;return t=this.$flattenMailboxes(),e>=0&&e<t.length?t[e]:null},e.prototype.$getMailboxes=function(t){var n=this;return!this.$mailboxes||t&&t.reload?e.$Mailbox.$find(this,t).then(function(t){n.$mailboxes=t,n.$expanded=!1;var s,o=function(e){_.forEach(e,function(e){e.$expanded=s.indexOf("/"+e.id)>=0,e.children&&e.children.length>0&&o(e.children)})};return e.$Preferences.settings.Mail.ExpandedFolders&&(s=angular.isString(e.$Preferences.settings.Mail.ExpandedFolders)?angular.fromJson(e.$Preferences.settings.Mail.ExpandedFolders):e.$Preferences.settings.Mail.ExpandedFolders,n.$expanded=s.indexOf("/"+n.id)>=0,s.length>0&&o(n.$mailboxes)),e.$accounts&&(n.$expanded|=1==e.$accounts.length),n.$flattenMailboxes({reload:!0}),n.$mailboxes}):e.$q.when(this.$mailboxes)},e.prototype.$flattenMailboxes=function(t){var n=this,s=[],o=[],a=function(e){_.forEach(e,function(e){s.push(e),(t&&t.all||e.$expanded)&&e.children&&e.children.length>0&&a(e.children)})};return!this.$$flattenMailboxes||t&&(t.reload||t.all)?(a(this.$mailboxes),t&&t.all||(n.$$flattenMailboxes=s,t&&t.saveState&&(_.forEach(e.$accounts,function(e){e.$expanded&&o.push("/"+e.id),_.reduce(e.$$flattenMailboxes,function(e,t){return t.$expanded&&e.push("/"+t.id),e},o)}),e.$$resource.post(null,"saveFoldersState",o)))):s=this.$$flattenMailboxes,s},e.prototype.$getMailboxByType=function(e){var t=function(n){var s=_.find(n,function(t){return t.type==e});return s||angular.forEach(n,function(e){!s&&e.children&&e.children.length>0&&(s=t(e.children))}),s};return t(this.$mailboxes)},e.prototype.$getMailboxByPath=function(e){var t=function(n){var s=_.find(n,function(t){return t.path==e});return s||angular.forEach(n,function(e){!s&&e.children&&e.children.length>0&&(s=t(e.children))}),s};return t(this.$mailboxes)},e.prototype.$newMailbox=function(t,n){var s=this;return e.$$resource.post(t.toString(),"createFolder",{name:n}).then(function(){s.$getMailboxes({reload:!0})})},e.prototype.updateQuota=function(e){var t,n;t=Math.round(1e4*e.usedSpace/e.maxQuota)/100,n=l("quotasFormat").formatted(t,Math.round(e.maxQuota/10.24)/100),this.$quota={percent:t,description:n}},e.prototype.$newMessage=function(){var t=this;return e.$$resource.fetch(this.id.toString(),"compose").then(function(n){return e.$log.debug("New message (compose): "+JSON.stringify(n,void 0,2)),new e.$Message(n.accountId,t.$getMailboxByPath(n.mailboxPath),n)}).then(function(t){return e.$$resource.fetch(t.$absolutePath({asDraft:!0}),"edit").then(function(n){return e.$log.debug("New message (edit): "+JSON.stringify(n,void 0,2)),angular.extend(t.editable,n),t.isNew=!0,t})})},e.prototype.$addDelegate=function(t){var n=this,s=e.$q.defer(),o={uid:t.uid};return!t.uid||_.indexOf(_.map(this.delegates,"uid"),t.uid)>-1?s.resolve():e.$$resource.fetch(this.id.toString(),"addDelegate",o).then(function(){n.delegates.push(t),s.resolve(n.users)},function(e,t){s.reject(l("An error occured please try again."))}),s.promise},e.prototype.$removeDelegate=function(t){var n=this,s={uid:t};return e.$$resource.fetch(thi
|