﻿
Ext.namespace("Credit360","Credit360.Portlets");Credit360.Portlets.PortletBase=function(config){if(!config.readOnly||config.readOnly==false){isReadOnly=false;this.prepareTools();}
this.heightFieldId=Ext.id();this.panelColorFieldId=Ext.id();this.portletNameFieldId=Ext.id();this.height=config.state.portletHeight?config.state.portletHeight:200;config.title=config.state.portletTitle?config.state.portletTitle:config.title;Credit360.Portlets.PortletBase.superclass.constructor.call(this,config);}
Ext.extend(Credit360.Portlets.PortletBase,Ext.ux.Portlet,{hasShowSettingsButton:false,hasCloseButton:false,isConfigured:true,isReadOnly:true,colors:{red:"FFB0B0",lightblue:"B5E5FF",lightgreen:"B1FFB8",gray:"CCCCCC"},panelColorsStore:new Ext.data.SimpleStore({fields:[{name:"value"},{name:"name"}],data:[["FFB0B0",__tr('Red')],["B1FFB8",__tr('Green')],["B5E5FF",__tr('Blue')],["CCCCCC",__tr('Grey')]]}),renderNotConfiguredPanel:function(msg){this.isConfigured=false;this.notConfiguredPanel=this.getCustomMessagePanel(msg);this.add(this.notConfiguredPanel);},getCustomMessagePanel:function(msg){var panel=new Ext.Panel({layout:'fit',height:200,items:{cls:'msgInPortlet',html:msg}});return panel;},hideNotConfiguredPanel:function(){if(this.isConfigured==false){this.isConfigured=true;this.remove(this.notConfiguredPanel);}},checkValidHeight:function(val){return val>99?true:__tr('Portlet height has to be larger than 100.');},getSettingsFields:function(_focusIdx){var focusIdx=_focusIdx||0;var fields=[];var titleField={id:this.portletNameFieldId,tabIndex:focusIdx++,allowBlank:false,xtype:'textfield',value:this.title,fieldLabel:__tr('Title')};fields.push(titleField);var heightField={id:this.heightFieldId,tabIndex:focusIdx++,allowBlank:false,allowNegative:false,allowDecimals:false,xtype:'numberfield',value:this.state.portletHeight?this.state.portletHeight:this.getSize().height,validator:this.checkValidHeight,fieldLabel:__tr('Height')}
fields.push(heightField);return fields;},updatePortletSettings:function(){this.state.portletHeight=this.getHeightValue();this.state.portletTitle=this.getPortletTitleValue();this.updatePortletView();},updatePortletView:function(){this.setTitle(this.state.portletTitle)},getName:function(){return this.name;},getHeightValue:function(){var field=Ext.getCmp(this.heightFieldId)
return field.isValid()?field.getValue():-1;},getPanelColorValue:function(){var field=Ext.getCmp(this.panelColorFieldId)
return field.getValue();},getPortletTitleValue:function(){var field=Ext.getCmp(this.portletNameFieldId)
return field.isValid()?field.getValue():this.getName();},prepareTools:function(){this.tools=[];if(this.hasShowSettingsButton){this.tools.push({id:'gear',qtip:__tr('Settings'),handler:function(){this.showSettings();},scope:this});}
if(this.hasCloseButton){this.tools.push({id:'close',qtip:__tr('Remove'),handler:function(e,target,panel){Ext.Msg.show({title:__tr('Are you sure?'),msg:__tr('This will delete the \'{0}\' item. Click \'OK\' to confirm.',this.title),buttons:Ext.Msg.OKCANCEL,fn:function(btn){if(btn=='ok'){panel.ownerCt.remove(panel,true);HomeHandler.removePortlet(this.tabPortletId,function(){Credit360.Page.showMessage(__tr('Removed'));},this);}},scope:this,animEl:target,icon:Ext.MessageBox.QUESTION});},scope:this});}},renderPortlet:function(){return null;},showSettings:function(){var win=new Ext.Window({title:__tr('Settings'),closable:true,width:400,height:300,layout:'fit',modal:true,shadow:true,items:{xtype:'form',style:'padding: 5px',plain:true,border:false,frame:false,items:this.getSettingsFields()},buttons:[{text:__tr('Save'),handler:function(e,target,panel){this.updatePortletSettings();HomeHandler.saveState(this.tabPortletId,this.state,function(){Credit360.Page.showMessage(__tr('Updated.'));},this);win.close();},scope:this},{text:__tr('Close'),handler:function(){win.close();}}]});win.show();}});