2015-08-25 17:46:14 +02:00
|
|
|
!function(){"use strict";function Account(futureAccountData){"function"!=typeof futureAccountData.then&&(angular.extend(this,futureAccountData),_.each(this.identities,function(identity){identity.fullName?identity.full=identity.fullName+" <"+identity.email+">":identity.full="<"+identity.email+">"}),Account.$log.debug("Account: "+JSON.stringify(futureAccountData,void 0,2)))}Account.$factory=["$q","$timeout","$log","sgSettings","Resource","Mailbox","Message",function($q,$timeout,$log,Settings,Resource,Mailbox,Message){return angular.extend(Account,{$q:$q,$timeout:$timeout,$log:$log,$$resource:new Resource(Settings.baseURL(),Settings.activeUser()),$Mailbox:Mailbox,$Message:Message}),Account}];try{angular.module("SOGo.MailerUI")}catch(e){angular.module("SOGo.MailerUI",["SOGo.Common"])}angular.module("SOGo.MailerUI").factory("Account",Account.$factory),Account.$findAll=function(data){var collection=[];return data&&angular.forEach(data,function(o,i){o.id=i,collection[i]=new Account(o)}),collection},Account.prototype.$getMailboxes=function(options){var _this=this,deferred=Account.$q.defer();return!this.$mailboxes||options&&options.reload?Account.$Mailbox.$find(this).then(function(data){_this.$mailboxes=data,_this.$flattenMailboxes({reload:!0}),deferred.resolve(_this.$mailboxes)}):deferred.resolve(this.$mailboxes),deferred.promise},Account.prototype.$flattenMailboxes=function(options){var _this=this,allMailboxes=[],_visit=function(mailboxes){_.each(mailboxes,function(o){allMailboxes.push(o),o.children&&o.children.length>0&&_visit(o.children)})};return!this.$$flattenMailboxes||options&&options.reload?(_visit(this.$mailboxes),_this.$$flattenMailboxes=allMailboxes):allMailboxes=this.$$flattenMailboxes,allMailboxes},Account.prototype.$getMailboxByType=function(type){var mailbox,_find=function(mailboxes){var mailbox=_.find(mailboxes,function(o){return o.type==type});return mailbox||angular.forEach(mailboxes,function(o){!mailbox&&o.children&&o.children.length>0&&(mailbox=_find(o.children))}),mailbox};mailbox=_find(this.$mailboxes),console.debug(mailbox),console.debug(this.specialMailboxes)},Account.prototype.$getMailboxByPath=function(path){var mailbox=null,_find=function(mailboxes){var mailbox=_.find(mailboxes,function(o){return o.path==path});return mailbox||angular.forEach(mailboxes,function(o){!mailbox&&o.children&&o.children.length>0&&(mailbox=_find(o.children))}),mailbox};return mailbox=_find(this.$mailboxes)},Account.prototype.$newMailbox=function(path,name){var _this=this;return Account.$$resource.post(path.toString(),"createFolder",{name:name}).then(function(){_this.$getMailboxes({reload:!0})})},Account.prototype.$newMessage=function(){var _this=this;return Account.$$resource.fetch(this.id.toString(),"compose").then(function(data){Account.$log.debug("New message (compose): "+JSON.stringify(data,void 0,2));var message=new Account.$Message(data.accountId,_this.$getMailboxByPath(data.mailboxPath),data);return message}).then(function(message){return Account.$$resource.fetch(message.$absolutePath({asDraft:!0}),"edit").then(function(data){return Account.$log.debug("New message (edit): "+JSON.stringify(data,void 0,2)),angular.extend(message.editable,data),message})})},Account.prototype.$addDelegate=function(user){var _this=this,deferred=Account.$q.defer(),param={uid:user.uid};return!user.uid||_.indexOf(_.pluck(this.delegates,"uid"),user.uid)>-1?deferred.resolve():Account.$$resource.fetch(this.id.toString(),"addDelegate",param).then(function(){_this.delegates.push(user),deferred.resolve(_this.users)},function(data,status){deferred.reject(l("An error occured please try again."))}),deferred.promise},Account.prototype.$removeDelegate=function(uid){var _this=this,param={uid:uid};return Account.$$resource.fetch(this.id.toString(),"removeDelegate",param).then(function(){var i=_.indexOf(_.pluck(_this.delegates,"uid"),uid);i>=0&&_this.delegates.splice(i,1)})}}(),function(){"use strict";function Mailbox(account,futureMailboxData){if(this.$account=account,"function"!=typeof futureMailboxData.then){if(this.init(futureMailboxData),this.name&&!th
|