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

3 lines
48 KiB
JavaScript
Raw Normal View History

2015-12-08 18:23:54 +01:00
(function(){"use strict";function Account(futureAccountData){if(typeof futureAccountData.then!=="function"){angular.extend(this,futureAccountData);_.each(this.identities,function(identity){if(identity.fullName)identity.full=identity.fullName+" <"+identity.email+">";else identity.full="<"+identity.email+">"});Account.$log.debug("Account: "+JSON.stringify(futureAccountData,undefined,2))}else{}}Account.$factory=["$q","$timeout","$log","sgSettings","Resource","Preferences","Mailbox","Message",function($q,$timeout,$log,Settings,Resource,Preferences,Mailbox,Message){angular.extend(Account,{$q:$q,$timeout:$timeout,$log:$log,$$resource:new Resource(Settings.activeUser("folderURL")+"Mail",Settings.activeUser()),$Preferences:Preferences,$Mailbox:Mailbox,$Message:Message});return 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){if(!data){return Account.$$resource.fetch("","mailAccounts").then(function(o){return Account.$unwrapCollection(o)})}return Account.$unwrapCollection(data)};Account.$unwrapCollection=function(data){var collection=[];angular.forEach(data,function(o,i){o.id=i;collection[i]=new Account(o)});return collection};Account.prototype.$getMailboxes=function(options){var _this=this;if(this.$mailboxes&&!(options&&options.reload)){return Account.$q.when(this.$mailboxes)}else{return Account.$Mailbox.$find(this).then(function(data){_this.$mailboxes=data;Account.$Preferences.ready().then(function(){var expandedFolders,_visit=function(mailboxes){_.forEach(mailboxes,function(o){o.$expanded=expandedFolders.indexOf("/"+o.id)>=0;if(o.children&&o.children.length>0){_visit(o.children)}})};if(Account.$Preferences.settings.Mail.ExpandedFolders){if(angular.isString(Account.$Preferences.settings.Mail.ExpandedFolders))expandedFolders=angular.fromJson(Account.$Preferences.settings.Mail.ExpandedFolders);else expandedFolders=Account.$Preferences.settings.Mail.ExpandedFolders;if(expandedFolders.length>0){_visit(_this.$mailboxes)}}_this.$flattenMailboxes({reload:true})});return _this.$mailboxes})}};Account.prototype.$flattenMailboxes=function(options){var _this=this,allMailboxes=[],expandedMailboxes=[],_visit=function(mailboxes){_.each(mailboxes,function(o){allMailboxes.push(o);if((options&&options.all||o.$expanded)&&o.children&&o.children.length>0){_visit(o.children)}})};if(this.$$flattenMailboxes&&!(options&&(options.reload||options.all))){allMailboxes=this.$$flattenMailboxes}else{_visit(this.$mailboxes);_this.$$flattenMailboxes=allMailboxes;if(options&&options.saveState){_.reduce(allMailboxes,function(expandedFolders,mailbox){if(mailbox.$expanded){expandedFolders.push("/"+mailbox.id)}return expandedFolders},expandedMailboxes);Account.$$resource.post(null,"saveFoldersState",expandedMailboxes)}}return allMailboxes};Account.prototype.$getMailboxByType=function(type){var mailbox,_find=function(mailboxes){var mailbox=_.find(mailboxes,function(o){return o.type==type});if(!mailbox){angular.forEach(mailboxes,function(o){if(!mailbox&&o.children&&o.children.length>0){mailbox=_find(o.children)}})}return 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});if(!mailbox){angular.forEach(mailboxes,function(o){if(!mailbox&&o.children&&o.children.length>0){mailbox=_find(o.children)}})}return mailbox};mailbox=_find(this.$mailboxes);return mailbox};Account.prototype.$newMailbox=function(path,name){var _this=this;return Account.$$resource.post(path.toString(),"createFolder",{name:name}).then(function(){_this.$getMailboxes({reload:true})})};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,undefined,2));var message=new Account.$Message(data.accountId,_this.
2015-12-09 15:48:09 +01:00
vm.selectedFolder.$filter({sort:field})}function sortedBy(field){return Mailbox.$query.sort==field}function cancelSearch(){vm.mode.search=false;vm.selectedFolder.$filter()}function newMessage($event){var message;if(messageDialog===null){message=vm.account.$newMessage();messageDialog=$mdDialog.show({parent:angular.element(document.body),targetEvent:$event,clickOutsideToClose:false,escapeToClose:false,templateUrl:"UIxMailEditor",controller:"MessageEditorController",controllerAs:"editor",locals:{stateAccounts:vm.accounts,stateMessage:message,stateRecipients:[]}}).finally(function(){messageDialog=null})}}}angular.module("SOGo.MailerUI").controller("MailboxController",MailboxController)})();(function(){"use strict";MailboxesController.$inject=["$state","$timeout","$mdDialog","$mdMedia","$mdSidenav","sgFocus","encodeUriFilter","Dialog","sgSettings","Account","Mailbox","VirtualMailbox","User","Preferences","stateAccounts"];function MailboxesController($state,$timeout,$mdDialog,$mdMedia,$mdSidenav,focus,encodeUriFilter,Dialog,Settings,Account,Mailbox,VirtualMailbox,User,Preferences,stateAccounts){var vm=this,account,mailbox;vm.service=Mailbox;vm.accounts=stateAccounts;vm.newFolder=newFolder;vm.delegate=delegate;vm.editFolder=editFolder;vm.revertEditing=revertEditing;vm.selectFolder=selectFolder;vm.saveFolder=saveFolder;vm.compactFolder=compactFolder;vm.emptyTrashFolder=emptyTrashFolder;vm.exportMails=exportMails;vm.confirmDelete=confirmDelete;vm.markFolderRead=markFolderRead;vm.share=share;vm.metadataForFolder=metadataForFolder;vm.setFolderAs=setFolderAs;vm.refreshUnseenCount=refreshUnseenCount;vm.showingAdvancedSearch=false;vm.currentSearchParam="";vm.addSearchParam=addSearchParam;vm.newSearchParam=newSearchParam;vm.showAdvancedSearch=showAdvancedSearch;vm.hideAdvancedSearch=hideAdvancedSearch;vm.toggleAdvancedSearch=toggleAdvancedSearch;vm.search={options:{"":l("Select a criteria"),subject:l("Enter Subject"),from:l("Enter From"),to:l("Enter To"),cc:l("Enter Cc"),body:l("Enter Body")},mailbox:"INBOX",subfolders:1,match:"AND",params:[]};if($state.current.name=="mail"&&vm.accounts.length>0&&vm.accounts[0].$mailboxes.length>0){account=vm.accounts[0];mailbox=account.$mailboxes[0];$state.go("mail.account.mailbox",{accountId:account.id,mailboxId:encodeUriFilter(mailbox.path)})}function showAdvancedSearch(path){vm.showingAdvancedSearch=true;vm.search.mailbox=path}function hideAdvancedSearch(){vm.showingAdvancedSearch=false;vm.service.$virtualMode=false;account=vm.accounts[0];mailbox=vm.searchPreviousMailbox;$state.go("mail.account.mailbox",{accountId:account.id,mailboxId:encodeUriFilter(mailbox.path)})}function toggleAdvancedSearch(){if(Mailbox.selectedFolder.$isLoading){vm.virtualMailbox.stopSearch()}else{var root,mailboxes=[],_visit=function(folders){_.each(folders,function(o){mailboxes.push(o);if(o.children&&o.children.length>0){_visit(o.children)}})};vm.virtualMailbox=new VirtualMailbox(vm.accounts[0]);if(!Mailbox.$virtualMode)vm.searchPreviousMailbox=Mailbox.selectedFolder;Mailbox.selectedFolder=vm.virtualMailbox;Mailbox.$virtualMode=true;if(angular.isDefined(vm.search.mailbox)){root=vm.accounts[0].$getMailboxByPath(vm.search.mailbox);mailboxes.push(root);if(vm.search.subfolders&&root.children.length)_visit(root.children)}else{mailboxes=vm.accounts[0].$flattenMailboxes()}vm.virtualMailbox.setMailboxes(mailboxes);vm.virtualMailbox.startSearch(vm.search.match,vm.search.params);$state.go("mail.account.virtualMailbox",{accountId:vm.accounts[0].id})}}function addSearchParam(v){vm.currentSearchParam=v;focus("advancedSearch");return false}function newSearchParam(pattern){if(pattern.length&&vm.currentSearchParam.length){var n=0,searchParam=vm.currentSearchParam;if(pattern.startsWith("!")){n=1;pattern=pattern.substring(1).trim()}vm.currentSearchParam="";return{searchBy:searchParam,searchInput:pattern,negative:n}}}function newFolder(parentFolder){Dialog.prompt(l("New folder"),l("Enter the new name of your folder :")).then(function(name){parentFolder.$newMailbox(parentFolder.id,name).then(function(){},function(data,status){Dialog.alert(l('
//# sourceMappingURL=Mailer.services.js.map