Ext.namespace("Zarafa.plugins.desktopnotifications");Zarafa.plugins.desktopnotifications.ABOUT='<p>Copyright (C) 2013  Saket Patel &lt;silentsakky@gmail.com&gt;<br>Copyright (C) 2016 Kopano and its licensors</p><p>This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</p><p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.</p><p>You should have received a copy of the GNU Affero General Public License along with this program. If not, see <a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>.</p>';
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(a){if(this.supports()){var b=Ext.isFunction(a)?function(b){var c="granted";b&&(c=b);a.apply(this,[c])}:Ext.emptyFn;Ext.isFunction(Notification.requestPermission)&&Notification.requestPermission(b)}else console.log("Browser doesn't support notifications")},notify:function(a,c,d){if(this.supports())if(this.hasPermission()){var b=new Notification(a,{icon:c.icon,body:c.body,requireInteraction:!0});if(container.getSettingsModel().get("zarafa/v1/plugins/desktopnotifications/autohide_enable")){var f=
1E3*container.getSettingsModel().get("zarafa/v1/plugins/desktopnotifications/autohide_time");b.addEventListener("show",function(){setTimeout(function(){b.close()},f)})}if(d)for(var e in d)b["on"+e]=d[e];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}}});
if(!Ext.isIE)Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"desktopnotifications",displayName:dgettext("plugin_desktopnotifications","Desktop Notifications Plugin"),about:Zarafa.plugins.desktopnotifications.ABOUT,pluginConstructor:Zarafa.plugins.desktopnotifications.DesktopNotificationsPlugin}))});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:"plugins/desktopnotifications/resources/Kopano.ico"},{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.settings");
Zarafa.plugins.desktopnotifications.js.settings.SettingsNotificationsCategory=Ext.extend(Zarafa.settings.ui.SettingsCategory,{constructor:function(a){a=a||{};Ext.applyIf(a,{title:dgettext("plugin_desktopnotifications","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:dgettext("plugin_desktopnotifications","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:dgettext("plugin_desktopnotifications","We need permissions to enable desktop notifications.")},{xtype:"button",width:200,text:dgettext("plugin_desktopnotifications","Request Permissions"),handler:this.requestPermission,scope:this,hideLabel:!0,ref:"../requestPermissionBtn",style:"margin-bottom: 6px;"},{xtype:"checkbox",boxLabel:dgettext("plugin_desktopnotifications","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:dgettext("plugin_desktopnotifications","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",defaultMargins:"0 0 0 0",plugins:["zarafa.splitfieldlabeler"],fieldLabel:dgettext("plugin_desktopnotifications","{A} Autohide 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,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
