sogo/UI/WebServerResources/js/Mailer.services.js

3 lines
38 KiB
JavaScript
Raw Normal View History

2015-08-31 17:08:41 +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.activeUser("folderURL")+"Mail",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){return data?Account.$unwrapCollection(data):Account.$$resource.fetch("","mailAccounts").then(function(o){return Account.$unwrapCollection(o)})},Account.$unwrapCollection=function(data){var collection=[];return angular.forEach(data,function(o,i){o.id=i,collection[i]=new Account(o)}),collection},Account.prototype.$getMailboxes=function(options){var _this=this;return!this.$mailboxes||options&&options.reload?Account.$Mailbox.$find(this).then(function(data){return _this.$mailboxes=data,_this.$flattenMailboxes({reload:!0}),_this.$mailboxes}):Account.$q.when(this.$mailboxes)},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 Mailbo
2015-08-28 20:09:20 +02:00
mailbox=account.$mailboxes[0],$state.go("mail.account.mailbox",{accountId:account.id,mailboxId:encodeUriFilter(mailbox.path)})),vm.refreshUnseenCount()}MailboxesController.$inject=["$state","$timeout","$mdDialog","sgFocus","encodeUriFilter","Dialog","sgSettings","Account","Mailbox","User","Preferences","stateAccounts"],angular.module("SOGo.MailerUI").controller("MailboxesController",MailboxesController)}(),function(){"use strict";function MessageController($scope,$state,$mdDialog,stateAccounts,stateAccount,stateMailbox,stateMessage,encodeUriFilter,focus,Dialog,Account,Mailbox,Message){function doDelete(){stateMailbox.$deleteMessages([stateMessage.uid]).then(function(){var index=_.findIndex(stateMailbox.$messages,function(o){return o.uid==stateMessage.uid});-1!=index&&stateMailbox.$messages.splice(index,1),vm.message=null,$state.go("mail.account.mailbox",{accountId:stateAccount.id,mailboxId:encodeUriFilter(stateMailbox.path)})})}function showMailEditor($event,message,recipients){null===messageDialog&&(angular.isDefined(recipients)||(recipients=[]),messageDialog=$mdDialog.show({parent:angular.element(document.body),targetEvent:$event,clickOutsideToClose:!1,escapeToClose:!1,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccounts:vm.accounts,stateMessage:message,stateRecipients:recipients}})["finally"](function(){messageDialog=null}))}function close(){$state.go("mail.account.mailbox",{accountId:stateAccount.id,mailboxId:encodeUriFilter(stateMailbox.path)}).then(function(){vm.message=null,delete stateMailbox.selectedMessage})}function reply($event){var message=vm.message.$reply();showMailEditor($event,message)}function replyAll($event){var message=vm.message.$replyAll();showMailEditor($event,message)}function forward($event){var message=vm.message.$forward();showMailEditor($event,message)}function edit($event){vm.message.$editableContent().then(function(){showMailEditor($event,vm.message)})}function newMessage($event,recipient){var message=vm.account.$newMessage();showMailEditor($event,message,[recipient])}function saveMessage(){window.location.href=ApplicationBaseURL+"/"+vm.mailbox.id+"/saveMessages?uid="+vm.message.uid}function viewRawSource($event){Message.$$resource.post(vm.message.id,"viewsource").then(function(data){function MessageRawSourceDialogController(scope,$mdDialog){scope.close=function(){$mdDialog.hide()}}$mdDialog.show({parent:angular.element(document.body),targetEvent:$event,clickOutsideToClose:!0,escapeToClose:!0,template:['<md-dialog flex="80" flex-sm="100" aria-label="'+l("View Message Source")+'">'," <md-dialog-content>"," <pre>",data," </pre>"," </md-dialog-content>",' <div class="md-actions">',' <md-button ng-click="close()">'+l("Close")+"</md-button>"," </div>","</md-dialog>"].join(""),controller:MessageRawSourceDialogController}),MessageRawSourceDialogController.$inject=["scope","$mdDialog"]})}var vm=this,messageDialog=null;vm.accounts=stateAccounts,vm.account=stateAccount,vm.mailbox=stateMailbox,vm.message=stateMessage,vm.service=Message,vm.tags={searchText:"",selected:""},vm.doDelete=doDelete,vm.close=close,vm.reply=reply,vm.replyAll=replyAll,vm.forward=forward,vm.edit=edit,vm.newMessage=newMessage,vm.saveMessage=saveMessage,vm.viewRawSource=viewRawSource,$scope.$watchCollection("viewer.message.flags",function(oldTags,newTags){_.each(_.difference(newTags,oldTags),function(tag){vm.message.removeTag(tag)})})}MessageController.$inject=["$scope","$state","$mdDialog","stateAccounts","stateAccount","stateMailbox","stateMessage","encodeUriFilter","sgFocus","Dialog","Account","Mailbox","Message"],angular.module("SOGo.MailerUI").controller("MessageController",MessageController)}(),function(){"use strict";function MessageEditorController($stateParams,$state,$q,$mdDialog,FileUploader,stateAccounts,stateMessage,stateRecipients,$timeout,encodeUriFilter,focus,Dialog,Account,Mailbox,AddressBook,Preferences){function cancel(){vm.autosave&&$timeout.cancel(vm.autosave),$mdDialog.cancel()}function send(){vm.autosave&&$timeout.cancel(vm.autosave),vm.mes
//# sourceMappingURL=Mailer.services.js.map