Ext.namespace("Zarafa.plugins.chat");
Zarafa.plugins.chat.Chat=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){var a=container.getSettingsModel().get("zarafa/v1/plugins/chat",!0),b={url:a.url,tabOrder:9};this.registerInsertionPoint("main.maintabbar.left",this.createMainTab.createDelegate(this,[b]),this);this.registerInsertionPoint("context.settings.categories",this.createSettingCategory,this);Zarafa.core.data.SharedComponentType.addProperty("plugins.chat.panel");if(a.autostart)container.on("webapploaded",function(){this.openTab(this.createMainTab(b));
container.getMainPanel().contentPanel.activate(0)},this)},createMainTab:function(a){return{text:"Chat",url:a.url,tabOrderIndex:a.tabOrder,cls:"mainmenu-button-chat",handler:this.openTab}},openTab:function(a){var b;Ext.each(container.getTabPanel().items.items,function(c,d){"chat"===c.tabId&&(b=d)});Ext.isDefined(b)?container.getMainPanel().contentPanel.activate(b):Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["plugins.chat.panel"],null,{url:a.url,title:a.text,tabOrder:a.tabOrderIndex,
tabId:"chat"})},createSettingCategory:function(){return{xtype:"zarafa.plugins.chat.settings.category"}},bidSharedComponent:function(a,b){b=-1;switch(a){case Zarafa.core.data.SharedComponentType["plugins.chat.panel"]:b=1}return b},getSharedComponent:function(a,b){switch(a){case Zarafa.core.data.SharedComponentType["plugins.chat.panel"]:return Zarafa.plugins.chat.ui.ContentPanel}}});
Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"chat",displayName:"Chat",allowUserVisible:!0,pluginConstructor:Zarafa.plugins.chat.Chat}))});Ext.namespace("Zarafa.plugins.chat.ui");
Zarafa.plugins.chat.ui.ContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"zarafa.plugins.chat.ui.contentpanel",layout:"fit",header:!1,iconCls:"icon_chat",border:!1,items:[{xtype:"zarafa.plugins.chat.ui.panel",url:a.url,tabOrder:a.tabOrder}]});Zarafa.plugins.chat.ui.ContentPanel.superclass.constructor.call(this,a)}});Ext.reg("zarafa.plugins.chat.ui.contentpanel",Zarafa.plugins.chat.ui.ContentPanel);Ext.namespace("Zarafa.plugins.chat.ui");
Zarafa.plugins.chat.ui.Panel=Ext.extend(Ext.Panel,{iframeId:void 0,constructor:function(a){a=a||{};this.iframeId="chat-iframe-"+a.tabOrder;Ext.applyIf(a,{xtype:"zarafa.plugins.chat.ui.panel",layout:"fit",header:!1,border:!1,iconCls:"icon_chat",html:{tag:"iframe",id:this.iframeId,cls:"chat-iframe",src:a.url,style:"display:block",partition:"persist:kw-plugin-chat-"+container.getUser().getUserName(),allow:"geolocation; microphone; camera; midi; encrypted-media"},listeners:{afterrender:this.onAfterRender,
scope:this}});Zarafa.plugins.chat.ui.Panel.superclass.constructor.call(this,a)},onAfterRender:function(){this.showLoadMask();var a=document.getElementById(this.iframeId);a.addEventListener("webview"===this.tag?"contentload":"load",function(){this.hideLoadMask();Zarafa.plugins.chat.Notifications.initialize(a)}.createDelegate(this))},handleDialogRequests:function(a){if("alert"===a.messageType)window.alert(a.messageText);else if("confirm"===a.messageType)window.confirm(a.messageText)?a.dialog.ok():a.dialog.cancel();
else if("prompt"===a.messageType){var b=window.prompt(a.messageText);null===b?a.dialog.cancel():a.dialog.ok(b)}},handlePermissionRequests:function(a){a.preventDefault();switch(a.permission){case "download":case "media":case "loadplugin":a.request.allow();break;case "pointerLock":case "fullscreen":case "geolocation":a.request.deny();break;default:a.request.deny()}},handleNewWindowRequests:function(a){a.window.discard()},showLoadMask:function(a){!0!==this.isLoadMaskShown&&(this.loadMask||(this.loadMask=
new Zarafa.common.ui.LoadMask(this.ownerCt.el)),a?this.loadMask.showError():(this.loadMask.show(),this.isLoadMaskShown=!0))},hideLoadMask:function(){!1!==this.isLoadMaskShown&&this.loadMask&&(this.loadMask.hide(),this.isLoadMaskShown=!1)}});Ext.reg("zarafa.plugins.chat.ui.panel",Zarafa.plugins.chat.ui.Panel);Ext.namespace("Zarafa.plugins.chat.settings");
Zarafa.plugins.chat.settings.Category=Ext.extend(Zarafa.settings.ui.SettingsCategory,{constructor:function(a){a=a||{};Ext.applyIf(a,{title:"Chat",categoryIndex:12,iconCls:"k-chat-settings-category",items:[{xtype:"zarafa.plugins.chat.settings.generalsettingswidget"}]});Zarafa.plugins.chat.settings.Category.superclass.constructor.call(this,a)}});Ext.reg("zarafa.plugins.chat.settings.category",Zarafa.plugins.chat.settings.Category);Ext.namespace("Zarafa.plugins.chat.settings");
Zarafa.plugins.chat.settings.GeneralSettingsWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{constructor:function(a){a=a||{};Ext.applyIf(a,{cls:"chat-settings-panel zarafa-settings-widget",title:"Chat",items:[{xtype:"checkbox",ref:"autostart",hideLabel:!0,boxLabel:_("Open Chat at start"),listeners:{check:this.onCheckAutoStart,scope:this}}]});Zarafa.plugins.chat.settings.GeneralSettingsWidget.superclass.constructor.call(this,a)},onCheckAutoStart:function(a,b){this.updating||this.updateSettings(this.settingsModel)},
update:function(a){this.updating=!0;this.settingsModel=a;a=!0===a.get("zarafa/v1/plugins/chat/autostart");this.autostart.setValue(a);this.updating=!1},updateSettings:function(a){a.set("zarafa/v1/plugins/chat/autostart",this.autostart.getValue())}});Ext.reg("zarafa.plugins.chat.settings.generalsettingswidget",Zarafa.plugins.chat.settings.GeneralSettingsWidget);Ext.namespace("Zarafa.plugins.chat");
Zarafa.plugins.chat.Notifications={iframe:null,timer:void 0,enabled:!1,messageHandlerAdded:!1,notifications:{},maxRetry:100,retryCount:0,retryDelay:200,initialize:function(a){window.Notification&&(this.iframe=a,this.messageHandlerAdded||(window.addEventListener("message",this.onMessage.bind(this),!1),this.messageHandlerAdded=!0),this.enabled=!1,this.retryCount=0,this.enable())},enable:function(){this.enabled||(++this.retryCount>this.maxRetry?clearTimeout(this.timer):(this.sendMessage("enable",Notification.permission),
this.timer=setTimeout(function(){this.enable()}.bind(this),this.retryDelay)))},onMessage:function(a){if(a.source===this.iframe.contentWindow&&a.data&&a.data.type&&0===a.data.type.indexOf("notifymatters."))switch(a.data.type){case "notifymatters.ok":this.enabled=!0;clearTimeout(this.timer);break;case "notifymatters.notification.requestPermission":window.Notification.requestPermission(function(c){this.sendMessage("ref.resolve",c,a.data.ref)}.bind(this));break;case "notifymatters.notification.new":a.data.data.options.icon=
a.origin+a.data.data.options.icon;var b=new Notification(a.data.data.title,a.data.data.options);this.notifications[a.data.data.id]=b;b.onclick=function(){const c=container.getPluginByName("chat");c&&c.openTab();window.blur();window.focus();this.sendMessage("notification.onclick",null,a.data.data.id)}.bind(this);b.onclose=function(){delete this.notifications[a.data.data.id];this.sendMessage("notification.onclose",null,a.data.data.id)}.bind(this);break;case "notifymatters.notification.close":b=this.notifications[a.data.data.id];
if(!b)break;b.close();break;default:console.warn("received unknown notifymatters message type",a.data.type)}},sendMessage:function(a,b,c){a={type:"notifymatters."+a,data:b,ref:Ext.isNumber(c)?c:null,notifymatters:"20171130"};this.iframe.contentWindow.postMessage(a,this.iframe.src)}};//# sourceMappingURL=chat.js.map
