Ext.namespace("GO.emailportlet");GO.mainLayout.onReady(function(){if(GO.summary&&GO.email){this.store=new GO.data.JsonStore({url:GO.settings.modules.email.url+"json.php",baseParams:{task:"messages"},root:"results",totalProperty:"total",id:"uid",fields:["uid","icon","flagged","attachments","new","subject","from","sender","size","date","priority","answered","forwarded"],remoteSort:true});this.emailTabPanel=new Ext.TabPanel({region:"north",title:"test",border:false});GO.emailportlet.messagesGrid=new GO.email.MessagesGrid({id:"emp-messagesgrid",store:this.store,hideSearch:true});GO.emailportlet.messagesGrid.on("rowdblclick",function(b,c){var a=b.getStore().getAt(c);if(!GO.emailportlet.messageDialog){GO.emailportlet.messageDialog=new GO.email.MessageDialog({})}GO.emailportlet.messageDialog.show(a.id,a.store.baseParams.mailbox,a.store.baseParams.account_id)},this);GO.summary.portlets["portlet-email"]=new GO.summary.Portlet({id:"portlet-email",title:GO.email.lang.email,layout:"border",tools:[{id:"close",handler:function(c,b,a){a.removePortlet()}}],items:[this.emailTabPanel,new Ext.Panel({region:"center",id:"email-portlet-grid",layout:"fit",items:GO.emailportlet.messagesGrid})],height:300});GO.emailportlet.foldersStore=new GO.data.JsonStore({url:GO.settings.modules.emailportlet.url+"json.php",baseParams:{task:"get_folders"},root:"data",totalProperty:"total",id:"fid",waitMsg:GO.lang.waitMsgLoad,waitMsgTarget:"portlet-email",fields:["name","account_id","id","title","fid"],remoteSort:true});GO.emailportlet.foldersStore.on("load",function(){this.emailTabPanel.removeAll(true);var d=GO.emailportlet.foldersStore.data;GO.emailportlet.messagesGrid.setDisabled(d.length==0);if(d.length==0){this.emailTabPanel.add(new Ext.Panel({title:GO.emailportlet.lang.noEmailFolders}))}else{for(var b=0;b<d.length;b++){var c=d.items[b].data;var a=new Ext.Panel({id:"account_"+c.account_id+":"+c.name,account_id:c.account_id,folder_id:c.id,title:c.title,mailbox:c.name,layout:"fit",closable:true});a.on("show",function(f){GO.emailportlet.messagesGrid.store.baseParams.account_id=f.account_id;GO.emailportlet.messagesGrid.store.baseParams.folder_id=f.folder_id;GO.emailportlet.messagesGrid.store.baseParams.mailbox=f.mailbox;GO.emailportlet.messagesGrid.store.load()},this);a.on("close",function(g){var f=GO.emailportlet.foldersStore.getById(g.id);GO.emailportlet.foldersStore.remove(f);Ext.Ajax.request({url:GO.settings.modules.emailportlet.url+"json.php",params:{folder_id:g.folder_id,task:"hide_folder"},scope:this,callback:function(h,j,e){var i=Ext.decode(e.responseText);if(!i.success){Ext.MessageBox.alert(GO.lang.strError,GO.lang.strRequestError)}if(GO.emailportlet.foldersStore.data.items.length==0){this.emailTabPanel.add(new Ext.Panel({title:GO.emailportlet.lang.noEmailFolders}));GO.emailportlet.messagesGrid.store.removeAll();GO.emailportlet.messagesGrid.disable();this.emailTabPanel.setActiveTab(0)}}})},this);this.emailTabPanel.add(a)}}this.emailTabPanel.setActiveTab(0);this.emailTabPanel.doLayout()},this);GO.summary.portlets["portlet-email"].on("render",function(){GO.emailportlet.foldersStore.load()})}});GO.moduleManager.onModuleReady("email",function(a){if(GO.summary){GO.email.extraTreeContextMenuItems.push("-");GO.email.extraTreeContextMenuItems.push({iconCls:"btn-refresh",text:GO.emailportlet.lang.showOnSummary,cls:"x-btn-text-icon",handler:function(){var c=GO.email.treePanel.getSelectionModel();var b=c.getSelectedNode();Ext.Ajax.request({url:GO.settings.modules.emailportlet.url+"json.php",params:{folder_id:b.attributes.folder_id,task:"show_folder"},scope:this,callback:function(e,g,d){var f=Ext.decode(d.responseText);if(!f.success){Ext.MessageBox.alert(GO.lang.strError,GO.lang.strRequestError)}else{Ext.MessageBox.alert(GO.lang.strSuccess,GO.emailportlet.lang.folderAdded);GO.emailportlet.foldersStore.reload()}}})},scope:this})}});