Ext.namespace("Zarafa.plugins.mattermost");Zarafa.plugins.mattermost.isDeskApp=function(){return Ext.isFunction(Zarafa.isDeskApp)?Zarafa.isDeskApp():Ext.isDefined(window.nw)};
Zarafa.plugins.mattermost.Mattermost=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){var a=container.getSettingsModel().get("zarafa/v1/plugins/mattermost",!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.mattermost.panel");if(a.autostart)container.on("webapploaded",
function(){this.openTab(this.createMainTab(b));container.getMainPanel().contentPanel.activate(0)},this)},createMainTab:function(a){return{text:"Mattermost",url:a.url,tabOrderIndex:a.tabOrder,cls:"mainmenu-button-mattermost",handler:this.openTab}},openTab:function(a){var b;Ext.each(container.getTabPanel().items.items,function(a,d){"mattermost"===a.tabId&&(b=d)});Ext.isDefined(b)?container.getMainPanel().contentPanel.activate(b):Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["plugins.mattermost.panel"],
null,{url:a.url,title:a.text,tabOrder:a.tabOrderIndex,tabId:"mattermost"})},createSettingCategory:function(){return{xtype:"zarafa.plugins.mattermost.settings.category"}},bidSharedComponent:function(a,b){var c=-1;switch(a){case Zarafa.core.data.SharedComponentType["plugins.mattermost.panel"]:c=1}return c},getSharedComponent:function(a,b){switch(a){case Zarafa.core.data.SharedComponentType["plugins.mattermost.panel"]:return Zarafa.plugins.mattermost.ui.ContentPanel}}});
Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"mattermost",displayName:"Mattermost",allowUserVisible:!0,pluginConstructor:Zarafa.plugins.mattermost.Mattermost}))});Ext.namespace("Zarafa.plugins.mattermost");
Zarafa.plugins.mattermost.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(b){this.sendMessage("ref.resolve",b,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(){var b=container.getPluginByName("mattermost");b&&b.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)}};Ext.namespace("Zarafa.plugins.mattermost.settings");
Zarafa.plugins.mattermost.settings.Category=Ext.extend(Zarafa.settings.ui.SettingsCategory,{constructor:function(a){a=a||{};Ext.applyIf(a,{title:"Mattermost",categoryIndex:12,iconCls:"k-mattermost-settings-category",items:[{xtype:"zarafa.plugins.mattermost.settings.generalsettingswidget"}]});Zarafa.plugins.mattermost.settings.Category.superclass.constructor.call(this,a)}});Ext.reg("zarafa.plugins.mattermost.settings.category",Zarafa.plugins.mattermost.settings.Category);Ext.namespace("Zarafa.plugins.mattermost.settings");
Zarafa.plugins.mattermost.settings.GeneralSettingsWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{constructor:function(a){a=a||{};var b=Zarafa.plugins.mattermost.isDeskApp()?"DeskApp":"WebApp";Ext.applyIf(a,{cls:"mattermost-settings-panel zarafa-settings-widget",title:"Mattermost",items:[{xtype:"checkbox",ref:"autostart",hideLabel:!0,boxLabel:String.format(_("Open Mattermost when {0} starts","plugin_mattermost"),b),listeners:{check:this.onCheckAutoStart,scope:this}}]});Zarafa.plugins.mattermost.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/mattermost/autostart");this.autostart.setValue(a);this.updating=!1},updateSettings:function(a){a.set("zarafa/v1/plugins/mattermost/autostart",this.autostart.getValue())}});Ext.reg("zarafa.plugins.mattermost.settings.generalsettingswidget",Zarafa.plugins.mattermost.settings.GeneralSettingsWidget);Ext.namespace("Zarafa.plugins.mattermost.ui");
Zarafa.plugins.mattermost.ui.ContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"zarafa.plugins.mattermost.ui.contentpanel",layout:"fit",header:!1,iconCls:"icon_mattermost",border:!1,items:[{xtype:"zarafa.plugins.mattermost.ui.panel",url:a.url,tabOrder:a.tabOrder}]});Zarafa.plugins.mattermost.ui.ContentPanel.superclass.constructor.call(this,a)}});Ext.reg("zarafa.plugins.mattermost.ui.contentpanel",Zarafa.plugins.mattermost.ui.ContentPanel);Ext.namespace("Zarafa.plugins.mattermost.ui");
Zarafa.plugins.mattermost.ui.Panel=Ext.extend(Ext.Panel,{iframeId:void 0,constructor:function(a){a=a||{};this.iframeId="mattermost-iframe-"+a.tabOrder;Zarafa.plugins.mattermost.isDeskApp()?this.tag="webview":this.tag="iframe";Ext.applyIf(a,{xtype:"zarafa.plugins.mattermost.ui.panel",layout:"fit",header:!1,border:!1,iconCls:"icon_mattermost",html:{tag:this.tag,id:this.iframeId,cls:"mattermost-iframe",src:a.url,style:"display:block",partition:"persist:kw-plugin-mattermost-"+container.getUser().getUserName()},
listeners:{afterrender:this.onAfterRender,scope:this}});Zarafa.plugins.mattermost.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.mattermost.Notifications.initialize(a)}.createDelegate(this));"webview"===this.tag&&(a.addEventListener("permissionrequest",this.handlePermissionRequests),a.addEventListener("dialog",
this.handleDialogRequests,this),a.addEventListener("newwindow",this.handleNewWindowRequests,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();nw.Shell.openExternal(a.targetUrl)},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.mattermost.ui.panel",Zarafa.plugins.mattermost.ui.Panel);//# sourceMappingURL=kopano-webapp-plugin-mattermost.js.map
