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=window.webkitNotifications||window.Notification,b=["granted","default","denied"];return{supports:function(){return a?!0:!1},hasPermission:function(){if(this.supports()){var c="default";Ext.isFunction(a.checkPermission)?c=b[a.checkPermission()]:Ext.isFunction(a.permissionLevel)?c=a.permissionLevel():a.permission&&(c=a.permission);return"granted"===c?!0:!1}console.log("Browser doesn't support notifications")},authorize:function(b){if(this.supports()){var c=
Ext.isFunction(b)?function(a){var c="granted";a&&(c=a);b.apply(this,[c])}:Ext.emptyFn;Ext.isFunction(a.requestPermission)&&a.requestPermission(c)}else console.log("Browser doesn't support notifications")},notify:function(b,d,e){if(this.supports())if(this.hasPermission()){var c;Ext.isFunction(a.createNotification)?(c=a.createNotification(d.icon,b,d.body),c.show()):c=new a(b,{icon:d.icon,body:d.body,tag:d.tag});if(container.getSettingsModel().get("zarafa/v1/plugins/desktopnotifications/autohide_enable")){var g=
1E3*container.getSettingsModel().get("zarafa/v1/plugins/desktopnotifications/autohide_time");c.addEventListener("show",function(){setTimeout(function(){c.close()},g)})}if(e)for(var f in e)c["on"+f]=e[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");
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:_("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 Plugin"),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:_("For enabling desktop notifications we need permissions from the browser. (Only Chrome and Firefox are supported) ")},{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} 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,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="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
