!function(){"use strict";function f(){var e,a,o=this;if(this.nextAlarm=null,this.nextInboxPoll=null,this.currentToast=f.$q.when(!0),this.lastUid=null,this.notifications={},this.defaults={},this.settings={Mail:{}},e=f.$document[0].getElementById("UserDefaults")){try{a=angular.fromJson(e.textContent||e.innerHTML)}catch(e){f.$log.error("Can't parse user's defaults: "+e.message),a={}}a.SOGoMailLabelsColorsKeys=[],a.SOGoMailLabelsColorsValues=[],_.forEach(a.SOGoMailLabelsColors,function(e,t){a.SOGoMailLabelsColorsKeys.push(t),a.SOGoMailLabelsColorsValues.push(e),"$"==t.charAt(0)&&(Object.defineProperty(a.SOGoMailLabelsColors,"_"+t,Object.getOwnPropertyDescriptor(a.SOGoMailLabelsColors,t)),delete a.SOGoMailLabelsColors[t])}),_.forEach(a.SOGoSieveFilters,function(e){_.forEach(e.actions,function(e){"addflag"==e.method&&"$"==e.argument.charAt(0)&&(e.argument="_"+e.argument)})}),a.SOGoRememberLastModule&&(a.SOGoLoginModule="Last"),a.SOGoMailAutoSave=parseInt(a.SOGoMailAutoSave)||0,a.SOGoMailComposeWindowEnabled=angular.isDefined(a.SOGoMailComposeWindow),a.SOGoMailComposeFontSizeEnabled=0$/.exec(e),e=new f.$User({uid:t,cn:e[1],c_email:e[2]});return e.$$image||(e.$$image=o.avatar(e.c_email,32,{no_404:!0})),e}):a.Calendar.PreventInvitationsWhitelist=[]),angular.extend(o.settings,a)}}f.$factory=["$window","$document","$q","$timeout","$log","$state","$mdDateLocale","$mdToast","sgSettings","Gravatar","Resource","User",function(e,t,a,o,n,i,r,s,l,d,c,u){return angular.extend(f,{$window:e,$document:t,$q:a,$timeout:o,$log:n,$state:i,$mdDateLocaleProvider:r,$toast:s,$gravatar:d,$$resource:new c(l.activeUser("folderURL"),l.activeUser()),$resourcesURL:l.resourcesURL(),$User:u}),new f}];try{angular.module("SOGo.PreferencesUI")}catch(e){angular.module("SOGo.PreferencesUI",["SOGo.Common"])}angular.module("SOGo.PreferencesUI").factory("Preferences",f.$factory),f.prototype.ready=function(){return f.$log.warn("Preferences.ready is deprecated -- access settings/defaults directly."),f.$q.when(!0)},f.prototype.avatar=function(e,t,a){var o=this.defaults.SOGoAlternateAvatar,o=this.defaults.SOGoGravatarEnabled?f.$gravatar(e,t,o,a):[f.$resourcesURL,"img","ic_person_grey_24px.svg"].join("/");return a&&a.dstObject&&a.dstAttr&&(a.dstObject[a.dstAttr]=o),o},f.prototype.hasActiveExternalSieveScripts=function(e){var t=this;if(void 0!==e)this.defaults.hasActiveExternalSieveScripts=e;else{if(void 0!==this.defaults.hasActiveExternalSieveScripts)return this.defaults.hasActiveExternalSieveScripts;this.defaults.hasActiveExternalSieveScripts=!1,f.$$resource.quietFetch("activeExternalSieveScripts").then(function(){t.defaults.hasActiveExternalSieveScripts=!0},function(e){if(t.defaults.hasActiveExternalSieveScripts=!1,404===e.status)return f.$q.resolve(!0)})}},f.prototype.supportsNotifications=function(){return"undefined"!=typeof Notification||(f.$log.warn("Notifications are not available for your browser."),!1)},f.prototype.authorizeNotifications=function(){this.supportsNotifications()&&Notification.requestPermission(function(e){return e})},f.prototype.createNotification=function(e,t,a){var o=this,n=_.pick(a,["body","icon"]);this.supportsNotifications()&&(n.tag=e,n.lang="",n.dir="auto",this.notifications[e]=new Notification(t,n),this.notifications[e].onclick=function(){a.onClick(),o.notifications[e].close()})},f.prototype.viewInboxMessage=function(e){f.$state.get("mail.account")?f.$state.go("mail.account.mailbox.message",{accountId:0,mailboxId:"INBOX",messageId:e}):f.$window.location=f.$$resource.path("Mail","view#!/Mail/0/INBOX/"+e)},f.prototype.pollInbox=function(){var e,c=this;function u(e,t,a,o){e.title=a,e.body=o,e.close=function(){t.hide("ok")}}e={sortingAttributes:{sort:"arrival",asc:0,noHeaders:0,dry:1},filters:[{searchBy:"flags",searchInput:"unseen"}]},this.nextInboxPoll&&f.$timeout.cancel(this.nextInboxPoll),f.$$resource.post("Mail","0/folderINBOX/view",e).then(function(i){var e=i.uids,r=i.headers[0].indexOf("uid"),s=i.headers[0].indexOf("From"),d=i.headers[0].indexOf("Subject");i.threaded&&(i.uids.splice(0,1),e=_.map(i.uids,0)),c.lastUid?(_.find(e,function(t,e){var a,o,n;return!(t>c.lastUid)||(f.$log.debug("Show notification for message "+t),a=_.find(i.headers,function(e){return e[r]==t}),c.defaults.SOGoDesktopNotifications?(o="mail-inbox-"+t,f.$state.href("mail.account.mailbox.message",{accountId:0,mailboxId:"INBOX",messageId:t}),c.createNotification(o,a[d],{body:a[s][0].name||a[s][0].email,icon:"/SOGo.woa/WebServerResources/img/email-256px.png",onClick:function(){c.viewInboxMessage(t)}})):(n={locals:{title:a[d],body:a[s][0].name||a[s][0].email},template:['','
','
',' email','
',' ','
',"
","
",' ',l("View")," ","
","
","
"].join(""),position:"top right",hideDelay:5e3,controller:u},c.currentToast=c.currentToast.then(function(){return f.$toast.show(n).then(function(e){"ok"===e&&c.viewInboxMessage(t)})})),!1)}),e[0]>c.lastUid&&(c.lastUid=e[0])):c.lastUid=e[0]}).finally(function(){var e=c.defaults.SOGoRefreshViewCheck;e&&"manually"!=e&&(c.nextInboxPoll=f.$timeout(angular.bind(c,c.pollInbox),1e3*e.timeInterval()))}),u.$inject=["scope","$mdToast","title","body"]},f.prototype.getAlarms=function(){var n=this,e=new Date,e=Math.floor(e.getTime()/1e3);f.$$resource.fetch("Calendar","alarmslist?browserTime="+e).then(function(e){var t,a,o=e.alarms.sort(function(e,t){e=parseInt(e[2]);return parseInt(t[2])-e});0",'
','
','

{{ summary }}

','
'," ",' ',' ',' ',l("5 minutes")," ",' ',l("10 minutes")," ",' ',l("15 minutes")," ",' ',l("30 minutes")," ",' ',l("45 minutes")," ",' ',l("1 hour")," ",' ',l("1 day")," "," "," ",' ',l("Snooze")," ",' ',l("Close")," ","
","
","
",""].join(""),locals:{url:i},controller:n})}),n.$inject=["scope","url"]})},f.prototype.$save=function(){return f.$$resource.save("Preferences",this.$omit(!0)).then(function(e){return e})},f.prototype.$omit=function(a){var o={},t={};return angular.forEach(this,function(e,t){"constructor"!=t&&"$"!=t[0]&&(o[t]=a?angular.copy(e):e)}),o.defaults.SOGoMailLabelsColors={},_.forEach(o.defaults.SOGoMailLabelsColorsKeys,function(e,t){o.defaults.SOGoMailLabelsColors[e]=o.defaults.SOGoMailLabelsColorsValues[t]}),delete o.defaults.SOGoMailLabelsColorsKeys,delete o.defaults.SOGoMailLabelsColorsValues,_.forEach(o.defaults.SOGoSieveFilters,function(e){_.forEach(e.actions,function(e){"addflag"==e.method&&"_"==e.argument.charAt(0)&&"$"==e.argument.charAt(1)&&(e.argument=e.argument.substring(1))})}),_.forEach(o.defaults.AuxiliaryMailAccounts,function(e){var t=[];_.forEach(e.identities,function(e){e.isReadOnly||t.push(_.pick(e,["email","fullName","replyTo","signature","isDefault"]))}),e.identities=t}),o.defaults.SOGoMailComposeWindowEnabled||delete o.defaults.SOGoMailComposeWindow,delete o.defaults.SOGoMailComposeWindowEnabled,o.defaults.SOGoMailComposeFontSizeEnabled||(o.defaults.SOGoMailComposeFontSize=0),delete o.defaults.SOGoMailComposeFontSizeEnabled,o.defaults.Vacation&&(o.defaults.Vacation.startDateEnabled?o.defaults.Vacation.startDate=o.defaults.Vacation.startDate.getTime()/1e3:(delete o.defaults.Vacation.startDateEnabled,o.defaults.Vacation.startDate=0),o.defaults.Vacation.endDateEnabled?o.defaults.Vacation.endDate=o.defaults.Vacation.endDate.getTime()/1e3:(delete o.defaults.Vacation.endDateEnabled,o.defaults.Vacation.endDate=0),o.defaults.Vacation.autoReplyEmailAddresses?o.defaults.Vacation.autoReplyEmailAddresses=_.compact(o.defaults.Vacation.autoReplyEmailAddresses):o.defaults.Vacation.autoReplyEmailAddresses=[]),o.defaults.Forward&&o.defaults.Forward.forwardAddress&&(o.defaults.Forward.forwardAddress=_.compact(o.defaults.Forward.forwardAddress)),o.defaults.SOGoCalendarCategoriesColors={},_.forEach(o.defaults.SOGoCalendarCategories,function(e,t){o.defaults.SOGoCalendarCategoriesColors[e]=o.defaults.SOGoCalendarCategoriesColorsValues[t]}),delete o.defaults.SOGoCalendarCategoriesColorsValues,o.settings.Calendar&&o.settings.Calendar.PreventInvitationsWhitelist&&(_.forEach(o.settings.Calendar.PreventInvitationsWhitelist,function(e){t[e.uid]=e.$shortFormat()}),o.settings.Calendar.PreventInvitationsWhitelist=t),o}}(); //# sourceMappingURL=Preferences.services.js.map