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

3 lines
46 KiB
JavaScript
Raw Normal View History

!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","Preferences","Mailbox","Message",function($q,$timeout,$log,Settings,Resource,Preferences,Mailbox,Message){return angular.extend(Account,{$q:$q,$timeout:$timeout,$log:$log,$$resource:new Resource(Settings.activeUser("folderURL")+"Mail",Settings.activeUser()),$Preferences:Preferences,$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,Account.$Preferences.ready().then(function(){var expandedFolders,_visit=function(mailboxes){_.forEach(mailboxes,function(o){o.$expanded=expandedFolders.indexOf("/"+o.id)>=0,o.children&&o.children.length>0&&_visit(o.children)})};Account.$Preferences.settings.Mail.ExpandedFolders&&(expandedFolders=angular.isString(Account.$Preferences.settings.Mail.ExpandedFolders)?angular.fromJson(Account.$Preferences.settings.Mail.ExpandedFolders):Account.$Preferences.settings.Mail.ExpandedFolders,expandedFolders.length>0&&_visit(_this.$mailboxes)),_this.$flattenMailboxes({reload:!0})}),_this.$mailboxes}):Account.$q.when(this.$mailboxes)},Account.prototype.$flattenMailboxes=function(options){var _this=this,allMailboxes=[],expandedMailboxes=[],_visit=function(mailboxes){_.each(mailboxes,function(o){allMailboxes.push(o),(options&&options.all||o.$expanded)&&o.children&&o.children.length>0&&_visit(o.children)})};return!this.$$flattenMailboxes||options&&(options.reload||options.all)?(_visit(this.$mailboxes),_this.$$flattenMailboxes=allMailboxes,options&&options.saveState&&(_.reduce(allMailboxes,function(expandedFolders,mailbox){return mailbox.$expanded&&expandedFolders.push("/"+mailbox.id),expandedFolders},expandedMailboxes),Account.$$resource.post(null,"saveFoldersState",expandedMailboxes))):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.$absolute
var root,mailboxes=[],_visit=function(folders){_.each(folders,function(o){mailboxes.push(o),o.children&&o.children.length>0&&_visit(o.children)})};vm.virtualMailbox=new VirtualMailbox(vm.accounts[0]),Mailbox.$virtualMode||(vm.searchPreviousMailbox=Mailbox.selectedFolder),Mailbox.selectedFolder=vm.virtualMailbox,Mailbox.$virtualMode=!0,angular.isDefined(vm.search.mailbox)?(root=vm.accounts[0].$getMailboxByPath(vm.search.mailbox),mailboxes.push(root),vm.search.subfolders&&root.children.length&&_visit(root.children)):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){return vm.currentSearchParam=v,focus("advancedSearch"),!1}function newSearchParam(pattern){if(pattern.length&&vm.currentSearchParam.length){var n=0,searchParam=vm.currentSearchParam;return pattern.startsWith("!")&&(n=1,pattern=pattern.substring(1).trim()),vm.currentSearchParam="",{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('An error occured while creating the mailbox "%{0}".',name),l(data.error))})})}function delegate(account){function MailboxDelegationController($scope,$mdDialog,User,account){function userFilter($query){return User.$filter($query,account.delegates)}function closeModal(){$mdDialog.hide()}function removeUser(user){account.$removeDelegate(user.uid)["catch"](function(data,status){Dialog.alert(l("Warning"),l("An error occured please try again."))})}function addUser(data){data&&account.$addDelegate(data).then(function(){vm.userToAdd="",vm.searchText=""},function(error){Dialog.alert(l("Warning"),error)})}var vm=this;vm.users=account.delegates,vm.account=account,vm.userToAdd="",vm.searchText="",vm.userFilter=userFilter,vm.closeModal=closeModal,vm.removeUser=removeUser,vm.addUser=addUser}$mdDialog.show({templateUrl:account.id+"/delegation",controller:MailboxDelegationController,controllerAs:"delegate",clickOutsideToClose:!0,escapeToClose:!0,locals:{User:User,account:account}}),MailboxDelegationController.$inject=["$scope","$mdDialog","User","account"]}function editFolder(folder){vm.editMode=folder.path,focus("mailboxName_"+folder.path)}function revertEditing(folder){folder.$reset(),vm.editMode=!1}function selectFolder(account,folder){vm.editMode!=folder.path&&(vm.editMode=!1,vm.showingAdvancedSearch=!1,vm.service.$virtualMode=!1,$state.go("mail.account.mailbox",{accountId:account.id,mailboxId:encodeUriFilter(folder.path)}))}function saveFolder(folder){folder.$rename().then(function(data){vm.editMode=!1},function(data,status){Dialog.alert(l("Warning"),data)})}function compactFolder(folder){folder.$compact().then(function(){},function(error){Dialog.alert(l("Warning"),error)})}function emptyTrashFolder(folder){folder.$emptyTrash().then(function(){},function(error){Dialog.alert(l("Warning"),error)})}function exportMails(folder){window.location.href=ApplicationBaseURL+"/"+folder.id+"/exportFolder"}function confirmDelete(folder){Dialog.confirm(l("Confirmation"),l("Do you really want to move this folder into the trash ?")).then(function(){folder.$delete().then(function(){$state.go("mail")},function(data,status){Dialog.alert(l('An error occured while deleting the mailbox "%{0}".',folder.name),l(data.error))})})}function markFolderRead(folder){folder.$markAsRead()}function share(folder){folder.$acl.$users().then(function(){$mdDialog.show({templateUrl:folder.id+"/UIxAclEditor",controller:"AclController",controllerAs:"acl",clickOutsideToClose:!0,escapeToClose:!0,locals:{usersWithACL:folder.$acl.users,User:User,folder:folder}})})}function metadataForFolder(folder){return"inbox"==folder.type?{name:folder.name,icon:"inbox"}:"draft"==folder.type?{name:l("DraftsFolderName"),icon:"drafts"}:"sent"==folder.type?{name:l("SentFolderName"),icon
//# sourceMappingURL=Mailer.services.js.map