Ext.namespace("Zarafa.plugins.intranet");Zarafa.plugins.intranet.isDeskApp=function(){return Ext.isFunction(Zarafa.isDeskApp)?Zarafa.isDeskApp():Ext.isDefined(window.nw)};
Zarafa.plugins.intranet.Intranet=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){for(var a=container.getSettingsModel().get("zarafa/v1/plugins/intranet",true),b=[{buttonText:a["button-title"],url:a.url,tabOrder:15}],c=1;Ext.isDefined(a["url-"+c]);){b.push({buttonText:a["button-title-"+c],url:a["url-"+c],tabOrder:15+c});c++}Ext.each(b,function(d){this.registerInsertionPoint("main.maintabbar.left",this.createMainTab.createDelegate(this,[d]),this)},this);Zarafa.core.data.SharedComponentType.addProperty("plugins.intranet.panel")},
createMainTab:function(a){return{text:a.buttonText,url:a.url,tabOrderIndex:a.tabOrder,cls:"mainmenu-button-intranet",handler:this.openTab}},openTab:function(a){var b;Ext.each(container.getTabPanel().items.items,function(c,d){if(c.url===a.url&&c.title===a.text)b=d});Ext.isDefined(b)?container.getMainPanel().contentPanel.activate(b):Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["plugins.intranet.panel"],null,{url:a.url,title:a.text,tabOrder:a.tabOrderIndex})},bidSharedComponent:function(a){var b=
-1;switch(a){case Zarafa.core.data.SharedComponentType["plugins.intranet.panel"]:b=1}return b},getSharedComponent:function(a){switch(a){case Zarafa.core.data.SharedComponentType["plugins.intranet.panel"]:return Zarafa.plugins.intranet.ui.ContentPanel}}});Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"intranet",displayName:_("Intranet"),pluginConstructor:Zarafa.plugins.intranet.Intranet}))});Ext.namespace("Zarafa.plugins.intranet.ui");
Zarafa.plugins.intranet.ui.ContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"zarafa.plugins.intranet.ui.contentpanel",layout:"fit",header:false,iconCls:"icon_intranet",border:false,items:[{xtype:"zarafa.plugins.intranet.ui.panel",url:a.url,tabOrder:a.tabOrder}]});Zarafa.plugins.intranet.ui.ContentPanel.superclass.constructor.call(this,a)}});Ext.reg("zarafa.plugins.intranet.ui.contentpanel",Zarafa.plugins.intranet.ui.ContentPanel);Ext.namespace("Zarafa.plugins.intranet.ui");
Zarafa.plugins.intranet.ui.Panel=Ext.extend(Ext.Panel,{iframeId:undefined,isLoadMaskShown:false,loadMask:undefined,constructor:function(a){a=a||{};this.iframeId="intranet-iframe-"+a.tabOrder;this.tag=Zarafa.plugins.intranet.isDeskApp()?"webview":"iframe";Ext.applyIf(a,{xtype:"zarafa.plugins.intranet.ui.panel",layout:"fit",header:false,iconCls:"icon_intranet",html:{tag:this.tag,id:this.iframeId,cls:"intranet-iframe",src:a.url,style:"display:block"},listeners:{afterrender:this.onAfterRender,scope:this}});
Zarafa.plugins.intranet.ui.Panel.superclass.constructor.call(this,a)},onAfterRender:function(){this.showLoadMask();var a=document.getElementById(this.iframeId);a.addEventListener(this.tag==="webview"?"contentload":"load",function(){this.hideLoadMask()}.createDelegate(this));if(this.tag==="webview"){a.addEventListener("permissionrequest",this.handlePermissionRequests);a.addEventListener("dialog",this.handleDialogRequests,this);a.addEventListener("newwindow",this.handleNewWindowRequests,this)}},handleDialogRequests:function(a){if(a.messageType===
"alert")window.alert(a.messageText);else if(a.messageType==="confirm")window.confirm(a.messageText)?a.dialog.ok():a.dialog.cancel();else if(a.messageType==="prompt"){var b=window.prompt(a.messageText);b===null?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();break}},
handleNewWindowRequests:function(a){a.window.discard();nw.Shell.openExternal(a.targetUrl)},showLoadMask:function(a){if(this.isLoadMaskShown!==true){if(!this.loadMask)this.loadMask=new Zarafa.common.ui.LoadMask(this.ownerCt.el);if(a)this.loadMask.showError();else{this.loadMask.show();this.isLoadMaskShown=true}}},hideLoadMask:function(){if(this.isLoadMaskShown!==false)if(this.loadMask){this.loadMask.hide();this.isLoadMaskShown=false}}});Ext.reg("zarafa.plugins.intranet.ui.panel",Zarafa.plugins.intranet.ui.Panel);
