Ext.namespace("Zarafa.plugins.desktopnotifications.js");
Zarafa.plugins.desktopnotifications.js.DesktopNotifier=Ext.extend(Zarafa.core.ui.notifier.NotifyPlugin,{constructor:function(a){a=a||{};Zarafa.plugins.desktopnotifications.js.DesktopNotifier.superclass.constructor.call(this,a)},notify:function(a,b,c,d){Zarafa.plugins.desktopnotifications.js.DesktopNotification.notify(b,{tag:a,body:c,icon:"client/resources/images/favicon.ico?kv2.2.0"},{click:function(){window.focus()}});Zarafa.plugins.desktopnotifications.js.DesktopNotifier.superclass.notify.apply(this,arguments)}});
Zarafa.onReady(function(){container.getNotifier().registerPlugin("desktopnotifier",new Zarafa.plugins.desktopnotifications.js.DesktopNotifier)});Ext.namespace("Zarafa.plugins.desktopnotifications.js");
Zarafa.plugins.desktopnotifications.js.DesktopNotification=function(){var a=["granted","default","denied"];return{supports:function(){return window.Notification?!0:!1},hasPermission:function(){if(this.supports()){var b="default";Ext.isFunction(Notification.checkPermission)?b=a[Notification.checkPermission()]:Ext.isFunction(Notification.permissionLevel)?b=Notification.permissionLevel():Notification.permission&&(b=Notification.permission);return"granted"===b?!0:!1}console.log("Browser doesn't support notifications")},
authorize:function(b){if(this.supports()){var c=Ext.isFunction(b)?function(d){var e="granted";d&&(e=d);b.apply(this,[e])}:Ext.emptyFn;Ext.isFunction(Notification.requestPermission)&&Notification.requestPermission(c)}else console.log("Browser doesn't support notifications")},notify:function(b,c,d){if(this.supports())if(this.hasPermission()){var e=new Notification(b,{icon:c.icon,body:c.body,requireInteraction:!0});if(container.getSettingsModel().get("zarafa/v1/plugins/desktopnotifications/autohide_enable")){var g=
1E3*container.getSettingsModel().get("zarafa/v1/plugins/desktopnotifications/autohide_time");e.addEventListener("show",function(){setTimeout(function(){e.close()},g)})}if(d)for(var f in d)e["on"+f]=d[f];this.audioTag=Ext.getBody().createChild({tag:"audio",type:"audio/ogg",src:"plugins/desktopnotifications/resources/audio.ogg",autoplay:!0});this.audioTag.on("ended",function(){Ext.destroy(this.audioTag);delete this.audioTag},this)}else console.log("Permission is denied to show desktop notifications");
else console.log("Browser doesn't support notifications")}}}();Ext.namespace("Zarafa.plugins.desktopnotifications");
Zarafa.plugins.desktopnotifications.DesktopNotificationsPlugin=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){Zarafa.plugins.desktopnotifications.DesktopNotificationsPlugin.superclass.initPlugin.apply(this,arguments);this.registerInsertionPoint("context.settings.categories",this.createSettingsCategory,this)},createSettingsCategory:function(){return{xtype:"zarafa.settingsdesktopnotificationscategory",plugin:this}}});
Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"desktopnotifications",displayName:_("Desktop Notifications Plugin"),about:Zarafa.plugins.desktopnotifications.ABOUT,pluginConstructor:Zarafa.plugins.desktopnotifications.DesktopNotificationsPlugin}))});Ext.namespace("Zarafa.plugins.desktopnotifications.js.settings");
Zarafa.plugins.desktopnotifications.js.settings.SettingsNotificationsCategory=Ext.extend(Zarafa.settings.ui.SettingsCategory,{constructor:function(a){a=a||{};Ext.applyIf(a,{title:_("Desktop Notifications"),categoryIndex:9996,xtype:"zarafa.settingsdesktopnotificationscategory",iconCls:"icon_desktopnotifications_settings",items:[{xtype:"zarafa.settingsdesktopnotificationswidget",settingsContext:a.settingsContext}]});Zarafa.plugins.desktopnotifications.js.settings.SettingsNotificationsCategory.superclass.constructor.call(this,
a)}});Ext.reg("zarafa.settingsdesktopnotificationscategory",Zarafa.plugins.desktopnotifications.js.settings.SettingsNotificationsCategory);Ext.namespace("Zarafa.plugins.desktopnotifications.js.settings");
Zarafa.plugins.desktopnotifications.js.settings.SettingsNotificationsWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{plugin:void 0,model:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{title:_("Desktop Notifications Settings"),xtype:"zarafa.settingsdesktopnotificationswidget",layout:{type:"fit"},items:this.createPanelItems()});Zarafa.plugins.desktopnotifications.js.settings.SettingsNotificationsWidget.superclass.constructor.call(this,a)},createPanelItems:function(){return[{xtype:"form",
border:!1,autoHeight:!0,items:[{xtype:"displayfield",hideLabel:!0,value:_("We need permissions to enable desktop notifications.")},{xtype:"button",width:200,text:_("Request Permissions"),handler:this.requestPermission,scope:this,hideLabel:!0,ref:"../requestPermissionBtn",style:"margin-bottom: 6px;"},{xtype:"checkbox",boxLabel:_("Enable desktop notifications for new mail"),name:"zarafa/v1/main/notifier/info/newmail/value",handler:this.onChangeCheckbox,scope:this,hideLabel:!0,ref:"../newMailNotificationsCheck"},
{xtype:"checkbox",boxLabel:_("Enable desktop notifications for reminders"),name:"zarafa/v1/main/notifier/info/reminder/value",handler:this.onChangeCheckbox,scope:this,hideLabel:!0,ref:"../reminderNotificationsCheck"},{xtype:"zarafa.compositefield",plugins:["zarafa.splitfieldlabeler"],fieldLabel:_("{A} Auto-hide desktop notification after second(s) {B}"),labelWidth:300,combineErrors:!1,items:[{xtype:"checkbox",labelSplitter:"{A}",name:"zarafa/v1/plugins/desktopnotifications/autohide_enable",ref:"../../autoHideBox",
boxLabel:"",hideLabel:!0,checked:!0,style:"margin-top: 4px",listeners:{change:this.onFieldChange,scope:this}},{xtype:"zarafa.spinnerfield",labelSplitter:"{B}",vtype:"naturalInteger",name:"zarafa/v1/plugins/desktopnotifications/autohide_time",ref:"../../autoHideTimeSpinner",incrementValue:1,defaultValue:1,minValue:1,width:55,allowBlank:!1,allowDecimals:!1,allowNegative:!1,listeners:{change:this.onFieldChange,scope:this},plugins:["zarafa.numberspinner"]}]}]}]},requestPermission:function(){Zarafa.plugins.desktopnotifications.js.DesktopNotification.authorize(function(a){"granted"===
a&&this.update(this.model)}.createDelegate(this))},onChangeCheckbox:function(a,b){if(this.model){var c=container.getSettingsModel().get(a.name,!1,!0)||"popup";b&&(c="desktopnotifier");this.model.get(a.name)!==c&&this.model.set(a.name,c);this.update(this.model)}},update:function(a){this.model=a;var b=Zarafa.plugins.desktopnotifications.js.DesktopNotification.hasPermission();this.requestPermissionBtn.setDisabled(b);this.newMailNotificationsCheck.setDisabled(!b);this.reminderNotificationsCheck.setDisabled(!b);
b="desktopnotifier"===this.model.get(this.newMailNotificationsCheck.name);this.newMailNotificationsCheck.setValue(b);b="desktopnotifier"===this.model.get(this.reminderNotificationsCheck.name);this.reminderNotificationsCheck.setValue(b);a=a.get(this.autoHideBox.name);this.autoHideBox.setValue(a);a=this.model.get(this.autoHideTimeSpinner.name);0!==a&&Ext.isDefined(a)?this.autoHideTimeSpinner.setValue(a):this.autoHideTimeSpinner.setValue(5)},updateSettings:function(a){var b=this.autoHideTimeSpinner.getValue();
0!==b&&Ext.isDefined(b)||(b=1);a.beginEdit();a.set(this.autoHideTimeSpinner.name,b);a.endEdit()},onFieldChange:function(a,b){this.model&&this.model.get(a.name)!==b&&this.model.set(a.name,b)}});Ext.reg("zarafa.settingsdesktopnotificationswidget",Zarafa.plugins.desktopnotifications.js.settings.SettingsNotificationsWidget);//# sourceMappingURL=desktopnotifications.js.map
