sogo/UI/WebServerResources/js/Preferences.js
2018-03-07 11:09:20 -05:00

2 lines
14 KiB
JavaScript

!function(){"use strict";function a(a,b){a.state("preferences",{abstract:!0,views:{preferences:{templateUrl:"preferences.html",controller:"PreferencesController",controllerAs:"app"}}}).state("preferences.general",{url:"/general",views:{module:{templateUrl:"generalPreferences.html"}}}).state("preferences.calendars",{url:"/calendars",views:{module:{templateUrl:"calendarsPreferences.html"}}}).state("preferences.addressbooks",{url:"/addressbooks",views:{module:{templateUrl:"addressbooksPreferences.html"}}}).state("preferences.mailer",{url:"/mailer",views:{module:{templateUrl:"mailerPreferences.html"}}}),b.otherwise("/general")}function b(a){a.$on("$routeChangeError",function(a,b,c,d){console.error(a,b,c,d)})}angular.module("SOGo.PreferencesUI",["ui.router","ck","angularFileUpload","SOGo.Common","SOGo.MailerUI","SOGo.ContactsUI","SOGo.Authentication","as.sortable"]).config(a).run(b),a.$inject=["$stateProvider","$urlRouterProvider"],b.$inject=["$rootScope"]}(),function(){"use strict";function a(a,b,c,d,e,f,g,h,i,j){function k(){t.account.security&&t.account.security.hasCertificate&&u.$certificate().then(function(a){t.certificate=a},function(){delete t.account.security.hasCertificate})}function m(a){var b=a.type.indexOf("pkcs12")>0||/\.(p12|pfx)$/.test(a.name);return t.form.certificateFilename.$setValidity("fileformat",b),b}function n(){return!(i>0)&&!j}function o(){t.uploader.queue[0].formData=[{password:t.certificatePassword}],t.uploader.uploadItem(0)}function p(a){t.form=a,t.uploader.clearQueue()}function q(){u.$removeCertificate().then(function(){delete t.account.security.hasCertificate})}function r(){b.cancel()}function s(){b.hide()}var t=this,u=new f({id:i,security:h.security});t.defaultPort=143,t.defaults=g,t.account=h,t.accountId=i,t.customFromIsReadonly=n,t.onBeforeUploadCertificate=p,t.removeCertificate=q,t.importCertificate=o,t.cancel=r,t.save=s,t.hostnameRE=i>0?/^(?!(127\.0\.0\.1|localhost(?:\.localdomain)?)$)/:/./,t.account.encryption?"ssl"==t.account.encryption&&(t.defaultPort=993):t.account.encryption="none",k(),t.uploader=new c({url:[e.activeUser("folderURL")+"Mail",i,"importCertificate"].join("/"),autoUpload:!1,queueLimit:1,filters:[{name:m,fn:m}],onAfterAddingFile:function(a){t.certificateFilename=a.file.name},onSuccessItem:function(b,c,d,e){this.clearQueue(),a(function(){_.assign(t.account,{security:{hasCertificate:!0}})}),k()},onErrorItem:function(a,b,c,e){d.alert(l("Error"),l("An error occurred while importing the certificate. Verify your password."))}})}a.$inject=["$timeout","$mdDialog","FileUploader","Dialog","sgSettings","Account","defaults","account","accountId","mailCustomFromEnabled"],angular.module("SOGo.PreferencesUI").controller("AccountDialogController",a)}(),function(){"use strict";function a(a,b,c,d,e,f){function g(){c.cancel()}function h(){var a=[o.filter.actions];return"allmessages"!=o.filter.match&&a.push(o.filter.rules),_.every(a,function(a){return a&&a.length>0})}function i(a){c.hide()}function j(a){o.filter.rules||(o.filter.rules=[]),o.filter.rules.push({field:"subject",operator:"contains"})}function k(a){o.filter.rules.splice(a,1)}function m(a){o.filter.actions||(o.filter.actions=[]),o.filter.actions.push({method:"discard"})}function n(a){o.filter.actions.splice(a,1)}var o=this,p=b.sieveCapabilities,q=b.forwardEnabled;b.vacationEnabled;o.filter=d,o.mailboxes=e,o.labels=f,o.cancel=g,o.hasRulesAndActions=h,o.save=i,o.addMailFilterRule=j,o.removeMailFilterRule=k,o.addMailFilterAction=m,o.removeMailFilterAction=n,o.fieldLabels={subject:l("Subject"),from:l("From"),to:l("To"),cc:l("Cc"),to_or_cc:l("To or Cc"),size:l("Size (Kb)"),header:l("Header")},p.indexOf("body")>-1&&(o.fieldLabels.body=l("Body")),o.methodLabels={discard:l("Discard the message"),keep:l("Keep the message"),stop:l("Stop processing filter rules")},q&&(o.methodLabels.redirect=l("Forward the message to")),p.indexOf("reject")>-1&&(o.methodLabels.reject=l("Send a reject message")),p.indexOf("fileinto")>-1&&(o.methodLabels.fileinto=l("File the message in")),(p.indexOf("imapflags")>-1||p.indexOf("imap4flags")>-1)&&(o.methodLabels.addflag=l("Flag the message with")),o.numberOperatorLabels={under:l("is under"),over:l("is over")},o.textOperatorLabels={is:l("is"),is_not:l("is not"),contains:l("contains"),contains_not:l("does not contain"),matches:l("matches"),matches_not:l("does not match")},p.indexOf("regex")>-1&&(o.textOperatorLabels.regex=l("matches regex"),o.textOperatorLabels.regex_not=l("does not match regex")),o.flagLabels={seen:l("Seen"),deleted:l("Deleted"),answered:l("Answered"),flagged:l("Flagged"),junk:l("Junk"),not_junk:l("Not Junk")}}a.$inject=["$scope","$window","$mdDialog","filter","mailboxes","labels"],angular.module("SOGo.PreferencesUI").controller("FiltersDialogController",a)}(),function(){"use strict";function a(a,b,c,d,e,f,g,h,i,j,k,m,n,o){var p,q=this,r=[],s=(new Date).beginOfDay();this.$onInit=function(){this.preferences=n,this.passwords={newPassword:null,newPasswordConfirmation:null},this.timeZonesList=b.timeZonesList,this.timeZonesSearchText="",this.sieveVariablesCapability=b.sieveCapabilities.indexOf("variables")>=0,this.mailLabelKeyRE=new RegExp('^[^(){} %*"\\\\]*$'),h.activeUser("path").mail&&(p=new m({id:0}),p.$getMailboxes().then(function(){for(var a=p.$flattenMailboxes({all:!0}),b=-1,c=a.length;++b<c;)r.push(a[b])})),n.defaults.SOGoAlternateAvatar&&(k.$alternateAvatar=n.defaults.SOGoAlternateAvatar),this.updateVacationDates()},this.go=function(a,b){b.$valid&&(d("gt-sm")||e("left").close(),c.go("preferences."+a))},this.onLanguageChange=function(a){a.$valid&&j.confirm(l("Warning"),l("Save preferences and reload page now?"),{ok:l("Yes"),cancel:l("No")}).then(function(){q.save(a,{quick:!0}).then(function(){b.location.reload(!0)})})},this.addCalendarCategory=function(a){this.preferences.defaults.SOGoCalendarCategoriesColors["New category"]="#aaa",this.preferences.defaults.SOGoCalendarCategories.push("New category"),i("calendarCategory_"+(this.preferences.defaults.SOGoCalendarCategories.length-1)),a.$setDirty()},this.removeCalendarCategory=function(a,b){var c=this.preferences.defaults.SOGoCalendarCategories[a];this.preferences.defaults.SOGoCalendarCategories.splice(a,1),delete this.preferences.defaults.SOGoCalendarCategoriesColors[c],b.$setDirty()},this.addContactCategory=function(a){var b=_.indexOf(this.preferences.defaults.SOGoContactsCategories,"");b<0&&(this.preferences.defaults.SOGoContactsCategories.push(""),b=this.preferences.defaults.SOGoContactsCategories.length-1),i("contactCategory_"+b),a.$setDirty()},this.removeContactCategory=function(a,b){this.preferences.defaults.SOGoContactsCategories.splice(a,1),b.$setDirty()},this.addMailAccount=function(a,c){var d;this.preferences.defaults.AuxiliaryMailAccounts.push({}),d=_.last(this.preferences.defaults.AuxiliaryMailAccounts),angular.extend(d,{isNew:!0,name:"",identities:[{fullName:"",email:""}],receipts:{receiptAction:"ignore",receiptNonRecipientAction:"ignore",receiptOutsideDomainAction:"ignore",receiptAnyAction:"ignore"}}),f.show({controller:"AccountDialogController",controllerAs:"$AccountDialogController",templateUrl:"editAccount?account=new",targetEvent:a,locals:{defaults:this.preferences.defaults,account:d,accountId:this.preferences.defaults.AuxiliaryMailAccounts.length-1,mailCustomFromEnabled:b.mailCustomFromEnabled}}).then(function(){c.$setDirty()}).catch(function(){q.preferences.defaults.AuxiliaryMailAccounts.pop()})},this.editMailAccount=function(a,c,d){var e=this.preferences.defaults.AuxiliaryMailAccounts[c];f.show({controller:"AccountDialogController",controllerAs:"$AccountDialogController",templateUrl:"editAccount?account="+c,targetEvent:a,locals:{defaults:this.preferences.defaults,account:e,accountId:c,mailCustomFromEnabled:b.mailCustomFromEnabled}}).then(function(){q.preferences.defaults.AuxiliaryMailAccounts[c]=e,d.$setDirty()},function(){})},this.removeMailAccount=function(a,b){this.preferences.defaults.AuxiliaryMailAccounts.splice(a,1),b.$setDirty()},this.resetMailLabelValidity=function(a,b){b["mailIMAPLabel_"+a].$setValidity("duplicate",!0)},this.addMailLabel=function(a){"_$$"+guid();this.preferences.defaults.SOGoMailLabelsColorsKeys.push("label"),this.preferences.defaults.SOGoMailLabelsColorsValues.push(["New label","#aaa"]),i("mailLabel_"+(_.size(this.preferences.defaults.SOGoMailLabelsColorsKeys)-1)),a.$setDirty()},this.removeMailLabel=function(a,b){this.preferences.defaults.SOGoMailLabelsColorsKeys.splice(a,1),this.preferences.defaults.SOGoMailLabelsColorsValues.splice(a,1),b.$setDirty()},this.addMailFilter=function(a,b){var c={match:"all",active:1};f.show({templateUrl:"editFilter?filter=new",controller:"FiltersDialogController",controllerAs:"filterEditor",targetEvent:a,locals:{filter:c,mailboxes:r,labels:this.preferences.defaults.SOGoMailLabelsColors}}).then(function(){q.preferences.defaults.SOGoSieveFilters||(q.preferences.defaults.SOGoSieveFilters=[]),q.preferences.defaults.SOGoSieveFilters.push(c),b.$setDirty()})},this.editMailFilter=function(a,b,c){var d=angular.copy(this.preferences.defaults.SOGoSieveFilters[b]);f.show({templateUrl:"editFilter?filter="+b,controller:"FiltersDialogController",controllerAs:"filterEditor",targetEvent:null,locals:{filter:d,mailboxes:r,labels:this.preferences.defaults.SOGoMailLabelsColors}}).then(function(){q.preferences.defaults.SOGoSieveFilters[b]=d,c.$setDirty()})},this.removeMailFilter=function(a,b){this.preferences.defaults.SOGoSieveFilters.splice(a,1),b.$setDirty()},this.addDefaultEmailAddresses=function(a){var c=[];angular.isDefined(this.preferences.defaults.Vacation.autoReplyEmailAddresses)&&(c=this.preferences.defaults.Vacation.autoReplyEmailAddresses.split(",")),this.preferences.defaults.Vacation.autoReplyEmailAddresses=_.union(b.defaultEmailAddresses.split(","),c).join(","),a.$setDirty()},this.userFilter=function(a,b){return a.length<h.minimumSearchLength()?[]:k.$filter(a,b).then(function(a){return _.forEach(a,function(a){a.$$image||(a.image?a.$$image=a.image:q.preferences.avatar(a.c_email,32,{no_404:!0}).then(function(b){a.$$image=b}))}),a})},this.confirmChanges=function(a,c){var d;if(c.$dirty&&c.$valid){for(a.preventDefault(),a.stopPropagation(),d=a.target;"A"!=d.tagName;)d=d.parentNode;j.confirm(l("Unsaved Changes"),l("Do you want to save your changes made to the configuration?"),{ok:l("Save"),cancel:l("Don't Save")}).then(function(){q.save(c,{quick:!0}).then(function(){b.location=d.href})},function(){b.location=d.href})}},this.save=function(c,d){var e,f,h,i,k,m;if(f=!0,k=[],b.forwardConstraints>0&&angular.isDefined(this.preferences.defaults.Forward)&&this.preferences.defaults.Forward.enabled&&angular.isDefined(this.preferences.defaults.Forward.forwardAddress))for(h=this.preferences.defaults.Forward.forwardAddress.split(","),i=b.defaultEmailAddresses.split(/, */),_.forEach(i,function(a){var b=a.split("@")[1];b&&k.push(b.toLowerCase())}),e=0;e<h.length&&f;e++)m=h[e].split("@")[1].toLowerCase(),k.indexOf(m)<0&&1==b.forwardConstraints?(j.alert(l("Error"),l("You are not allowed to forward your messages to an external email address.")),f=!1):k.indexOf(m)>=0&&2==b.forwardConstraints&&(j.alert(l("Error"),l("You are not allowed to forward your messages to an internal email address.")),f=!1);return this.preferences.defaults.SOGoMailLabelsColorsKeys.length==this.preferences.defaults.SOGoMailLabelsColorsValues.length&&this.preferences.defaults.SOGoMailLabelsColorsKeys.length==_.uniq(this.preferences.defaults.SOGoMailLabelsColorsKeys).length||(j.alert(l("Error"),l("IMAP labels must have unique names.")),_.forEach(this.preferences.defaults.SOGoMailLabelsColorsKeys,function(a,b,d){c["mailIMAPLabel_"+b].$dirty&&(d.indexOf(a)!=b||d.indexOf(a,b+1)>-1)&&(c["mailIMAPLabel_"+b].$setValidity("duplicate",!1),f=!1)})),f?this.preferences.$save().then(function(a){d&&d.quick||(g.show(g.simple().content(l("Preferences saved")).position("bottom right").hideDelay(2e3)),c.$setPristine())}):a.reject()},this.canChangePassword=function(){return!!(this.passwords.newPassword&&this.passwords.newPassword.length>0&&this.passwords.newPasswordConfirmation&&this.passwords.newPasswordConfirmation.length&&this.passwords.newPassword==this.passwords.newPasswordConfirmation)},this.changePassword=function(){o.changePassword(this.passwords.newPassword).then(function(){var a=f.alert({title:l("Password"),content:l("The password was changed successfully."),ok:l("OK")});f.show(a).finally(function(){a=void 0})},function(a){var b=f.alert({title:l("Password"),content:a,ok:l("OK")});f.show(b).finally(function(){b=void 0})})},this.timeZonesListFilter=function(a){return _.filter(this.timeZonesList,function(b){return b.toUpperCase().indexOf(a.toUpperCase())>=0})},this.updateVacationDates=function(){var a=this.preferences.defaults;a&&a.Vacation&&a.Vacation.enabled&&(this.toggleVacationStartDate(),this.toggleVacationEndDate())},this.toggleVacationStartDate=function(){var a;a=this.preferences.defaults.Vacation,a.startDateEnabled&&a.endDateEnabled&&a.startDate.getTime()>a.endDate.getTime()&&(a.startDate=new Date(a.endDate.getTime()),a.startDate.addDays(-1))},this.toggleVacationEndDate=function(){var a;a=this.preferences.defaults.Vacation,a.endDateEnabled&&a.startDateEnabled&&a.endDate.getTime()<a.startDate.getTime()&&(a.endDate=new Date(a.startDate.getTime()),a.endDate.addDays(1))},this.validateVacationStartDate=function(a){var b=q.preferences.defaults,c=!0;return b&&b.Vacation&&b.Vacation.enabled&&b.Vacation.startDateEnabled&&(c=(!b.Vacation.endDateEnabled||a.getTime()<b.Vacation.endDate.getTime())&&a.getTime()>=s.getTime()),c},this.validateVacationEndDate=function(a){var b=q.preferences.defaults,c=!0;return b&&b.Vacation&&b.Vacation.enabled&&b.Vacation.endDateEnabled&&(c=(!b.Vacation.startDateEnabled||a.getTime()>b.Vacation.startDate.getTime())&&a.getTime()>=s.getTime()),c}}a.$inject=["$q","$window","$state","$mdMedia","$mdSidenav","$mdDialog","$mdToast","sgSettings","sgFocus","Dialog","User","Account","Preferences","Authentication"],angular.module("SOGo.PreferencesUI").controller("PreferencesController",a)}();
//# sourceMappingURL=Preferences.js.map