//Our Ext namespace Ext.namespace("EnertechXchange.CMS"); //Our Ext namespace Ext.namespace("EnertechXchange.CMS"); /** * initialize labelField * @param {} config */ Ext.form.LabelField = function(config){ Ext.form.LabelField.superclass.constructor.call(this, config); }; /** * * @class Ext.form.LabelField * @extends Ext.form.Field * * label class - makes label a form field allowing to add it to forms anywhere */ Ext.extend(Ext.form.LabelField, Ext.form.Field, { defaultAutoCreate : {tag: 'span'}, fieldClass: 'x-form-label', value: '', setValue:function(val) { if(this.rendered){ this.el.update(val); } } }); //register new type - allows to use lazy rendering for this new type (xtype) Ext.reg('labelField', Ext.form.LabelField); /** * * @class Ext.app.SearchField * @extends Ext.form.TwinTriggerField */ Ext.app.SearchField = Ext.extend(Ext.form.TwinTriggerField, { hideMode: 'offsets', initComponent : function(){ Ext.app.SearchField.superclass.initComponent.call(this); this.on('specialkey', function(f, e){ if(e.getKey() == e.ENTER){ this.onTrigger2Click(); } }, this); }, validationEvent:false, validateOnBlur:false, trigger1Class:'x-form-clear-trigger', trigger2Class:'x-form-search-trigger', hideTrigger1:true, width:180, hasSearch : false, paramName : 'query', onTrigger1Click : function(){ if(this.hasSearch){ this.el.dom.value = ''; this.store.load({params:{start:0, limit:20, a: 'l'}}); this.triggers[0].hide(); this.hasSearch = false; } }, onTrigger2Click : function(){ var v = this.getRawValue(); if(v.length < 1){ this.onTrigger1Click(); return; } //var o = {start: 0, value: v, a: 'sl'}; if (v != "") { this.store.load({params:{start:0, limit: 20, a: 'sl', value: v}}); } else { this.store.reload({params:{start:0, limit: 20, a: 'l'}}); } this.hasSearch = true; this.triggers[0].show(); }, listeners: { activate: function(p) { this.doLayout(p); } } }); //register new type Ext.reg('searchField', Ext.app.SearchField); /** * * @class EnertechXchange.CMS.WrapperPanel * @extends Ext.Panel * * wrapper panel class - a panel to hold module content in the CMS system */ EnertechXchange.CMS.WrapperPanel = Ext.extend(Ext.Panel, { autoScroll: true, border: false, frame: false, tabContent: null, title: '', initComponent: function(){ EnertechXchange.CMS.WrapperPanel.superclass.initComponent.apply(this, arguments); } }); Ext.reg('wrapperPanel', EnertechXchange.CMS.WrapperPanel); /** * setup a timer that will launch every 1440 seconds * or 24 minutes (current default length of a session in apache) * plus 10 seconds to ensure that the session has expired */ function startSessionTimer() { //1445000 var sessionTimer = setTimeout("getUserInfoFromSession()", 14410000); // - testing, set to a minute (5000) } /** * get user information * @return */ function getUserInfoFromSession() { // check if user is logged in Ext.Ajax.request({ method: 'post', scope: this, url: 'ajax/session_ajax.php', success: function(action, response) { var obj = Ext.util.JSON.decode(action.responseText); if (obj.session == '') { var loginWindow = new EnertechXchange.CMS.Login(); loginWindow.show(); } else { startSessionTimer(); } }, failure: function(action, response) { } }); } /** * to show combos in IE with hideTrigger: true override afterRender method for TriggerField */ Ext.form.TriggerField.override({ afterRender : function(){ Ext.form.TriggerField.superclass.afterRender.call(this); var y; if(Ext.isIE && !this.hideTrigger && this.el.getY() != (y = this.trigger.getY())){ this.el.position(); this.el.setY(y); } } }); /** * override panel setIconCls method to allow setting new icon classes when panel is inside a tab panel */ Ext.override(Ext.Panel, { /** * Sets the CSS class that provides the icon image for this panel. This method will replace any existing * icon class if one has already been set. * @param {String} cls The new CSS class name */ setIconClass : function(cls) { var old = this.iconCls; this.iconCls = cls; if (this.rendered) { if (this.header) { if (this.frame) { this.header.addClass('x-panel-icon'); this.header.replaceClass(old, this.iconCls); } else { var hd = this.header.dom; var img = hd.firstChild && String(hd.firstChild.tagName).toLowerCase() == 'img' ? hd.firstChild : null; if (img) { Ext.fly(img).replaceClass(old, this.iconCls); } else { Ext.DomHelper.insertBefore(hd.firstChild, { tag:'img', src: Ext.BLANK_IMAGE_URL, cls:'x-panel-inline-icon '+this.iconCls }); } } } else { var ct = this.ownerCt; if (ct && ct.isXType('tabpanel')) { // apply iconCls to tab strip text Ext.fly(ct.getTabEl(this)).child('.x-tab-strip-text').replaceClass(old, this.iconCls); } } } } }); /** * in 2.2 checkbox setValue() method causes "this.wrap is undefined" exception * this override fixes it */ Ext.form.Checkbox.override({ setValue : function(v) { var checked = this.checked; this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on'); if(this.rendered){ this.el.dom.checked = this.checked; this.el.dom.defaultChecked = this.checked; this.wrap[this.checked? 'addClass' : 'removeClass'](this.checkedCls); } if(checked != this.checked){ this.fireEvent("check", this, this.checked); if(this.handler){ this.handler.call(this.scope || this, this, this.checked); } } }, afterRender : function(){ Ext.form.Checkbox.superclass.afterRender.call(this); this.wrap[this.checked? 'addClass' : 'removeClass'](this.checkedCls); } }); /** * override get value for html editor to allow pasting with mouse right click */ Ext.override(Ext.form.HtmlEditor, { getValue : function() { this.syncValue(); Ext.form.HtmlEditor.superclass.getValue.call(this); } }); /** * via Condor @Ext Support Team * * It defers layout on unrendered/hidden/collapsed containers, * thereby speeding up the layout process and avoiding layouts inside display:none. * No more need for layoutOnTabChange:true and a lot of hideMode:'offsets' (but not all) * can be avoided. */ Ext.override(Ext.Container, { doLayout : function(shallow){ if(!this.isVisible() || this.collapsed){ this.deferLayout = this.deferLayout || !shallow; return; } shallow = shallow && !this.deferLayout; delete this.deferLayout; if(this.rendered && this.layout){ this.layout.layout(); } if(shallow !== false && this.items){ var cs = this.items.items; for(var i = 0, len = cs.length; i < len; i++) { var c = cs[i]; if(c.doLayout){ c.doLayout(); } } } }, onShow : function(){ Ext.Container.superclass.onShow.apply(this, arguments); if(this.deferLayout !== undefined){ this.doLayout(true); } } }); Ext.override(Ext.Panel, { afterExpand : function(){ this.collapsed = false; this.afterEffect(); if(this.deferLayout !== undefined){ this.doLayout(true); } this.fireEvent('expand', this); } }); /** * override grid highlight colors * rowOverClass -> row highlight class * colOverClass -> column highlight class * hdOverClass -> column heading highlight class */ Ext.override(Ext.grid.GridView, { rowOverCls: 'highlite-row', //colOverCls: 'yellow-row', //hdOverCls: 'yellow-row', onRowOver: function(e, t){ if(this.rowOverCls){ var row = this.findRowIndex(t); if(row === false){ row = undefined; } if(this.currentRow !== row){ if(this.currentRow !== undefined){ this.removeRowClass(this.currentRow, this.rowOverCls); } this.currentRow = row; if(row !== undefined){ this.addRowClass(row, this.rowOverCls); } } } if(this.colOverCls || this.hdOverCls){ var col = this.findCellIndex(t); if(col === false){ col = undefined; } if(this.currentCol !== col){ if(this.currentCol !== undefined){ if(this.hdOverCls){ this.removeHdClass(this.currentCol, this.hdOverCls); } if(this.colOverCls){ this.removeColClass(this.currentCol, this.colOverCls); } } this.currentCol = col; if(col !== undefined){ if(this.hdOverCls){ this.addHdClass(this.currentCol, this.hdOverCls); } if(this.colOverCls){ this.addColClass(this.currentCol, this.colOverCls); } } } } }, onRowOut: function(e, t){ if(this.rowOverCls && (this.currentRow !== undefined)){ this.removeRowClass(this.currentRow, this.rowOverCls); delete this.currentRow; } if((this.colOverCls || this.hdOverCls) && (this.currentCol !== undefined)){ if(this.hdOverCls){ this.removeHdClass(this.currentCol, this.hdOverCls); } if(this.colOverCls){ this.removeColClass(this.currentCol, this.colOverCls); } delete this.currentCol; } }, addHdClass: function(col, cls){ Ext.fly(this.getHeaderCell(col)).addClass(cls); }, removeHdClass: function(col, cls){ Ext.fly(this.getHeaderCell(col)).removeClass(cls); }, addColClass: function(col, cls){ var rows = this.getRows(); for(var r = 0, len = rows.length; r < len; r++){ Ext.fly(Ext.fly(rows[r]).query(this.cellSelector)[col]).addClass(cls); } }, removeColClass: function(col, cls){ var rows = this.getRows(); for(var r = 0, len = rows.length; r < len; r++){ Ext.fly(Ext.fly(rows[r]).query(this.cellSelector)[col]).removeClass(cls); } } }); /** * an override to not allow a dot when allowDecimals is false on Number fields */ Ext.override(Ext.form.NumberField, { setValue : function(v){ v = typeof v == 'number' ? v : parseFloat(String(v).replace(this.decimalSeparator, ".")); v = isNaN(v) ? '' : v.toFixed(this.decimalPrecision).replace(".", this.decimalSeparator); return Ext.form.NumberField.superclass.setValue.call(this, v); } }); Ext.override(Ext.form.Field, { setFieldLabel : function(text) { if (this.rendered) { this.el.up('.x-form-item', 10, true).child('.x-form-item-label').update(text); } this.fieldLabel = text; } }); /* Ext.override(Ext.PagingToolbar, { onClick : function(which){ var store = this.store; switch(which){ case "first": this.doLoad(0); break; case "prev": this.doLoad(Math.max(0, this.cursor-this.pageSize)); break; case "next": this.doLoad(this.cursor+this.pageSize); break; case "last": var total = store.getTotalCount(); var extra = total % this.pageSize; var lastStart = extra ? (total - extra) : total-this.pageSize; this.doLoad(lastStart); break; case "refresh": delete store.lastParams; this.doLoad(this.cursor); break; } } }); */ // Very simple plugin for adding a close context menu to tabs Ext.ux.TabCloseMenu = function(){ var tabs, menu, ctxItem; this.init = function(tp){ tabs = tp; tabs.on('contextmenu', onContextMenu); }; function onContextMenu(ts, item, e){ if(!menu){ // create context menu on first right click menu = new Ext.menu.Menu([{ id: tabs.id + '-close', text: 'Close Tab', handler : function(){ tabs.remove(ctxItem); } },{ id: tabs.id + '-close-others', text: 'Close Other Tabs', handler : function(){ tabs.items.each(function(item){ if(item.closable && item != ctxItem){ tabs.remove(item); } }); } }]); } ctxItem = item; var items = menu.items; items.get(tabs.id + '-close').setDisabled(!item.closable); var disableOthers = true; tabs.items.each(function(){ if(this != item && this.closable){ disableOthers = false; return false; } }); items.get(tabs.id + '-close-others').setDisabled(disableOthers); e.stopEvent(); menu.showAt(e.getPoint()); } };/* * * File: login.php * * Description: CMS Ext login page * */ EnertechXchange.CMS.Login = new Ext.extend(Ext.form.FormPanel, { scope: this, initComponent:function() { Ext.apply(this, { frame:true, scope: this, title: 'Enertech Administration Login', width: 350, items: [ new Ext.form.FieldSet({ defaults: {labelStyle: 'text-align: right; color: #000000'}, autoHeight: true, style: 'margin: 0', title: 'Login', items: [ this.username = new Ext.form.TextField({ allowBlank: false, fieldLabel: 'User Name', name: 'username', width: 175, listeners: { scope: this, specialkey: function(f,e){ if ( e.getKey() == e.RETURN || e.getKey() == e.ENTER ) { this.doLogin(); } } } }), this.password = new Ext.form.TextField({ allowBlank: false, fieldLabel: 'Password', inputType: 'password', name: 'password', scope: this, width: 175, listeners: { scope: this, specialkey: function(f,e){ if ( e.getKey() == e.RETURN || e.getKey() == e.ENTER ) { this.doLogin(); } } } }) ], buttons:[{ handler: this.doLogin, iconCls: 'iconLogin', scope: this, style: 'margin-right: 30px', text: 'Login' }] }), this.errorMessage = new Ext.Panel ({ bodyStyle: 'margin: 5px 0px 5px 0px; text-align: center', hidden: true }), this.forgotPassword = new Ext.form.Checkbox({ boxLabel: 'Forgot Password', labelSeparator: '', listeners: { check: function() { if (this.getValue() == true) { Ext.getCmp('forgotPasswordForm').getForm().reset(); Ext.getCmp('forgotPasswordForm').errorForgotPasswordMessage.el.dom.innerHTML = ''; document.getElementById('forgot_password').style.display = 'block'; } else { document.getElementById('forgot_password').style.display = 'none'; } } } }) ] //end of items }); EnertechXchange.CMS.Login.superclass.initComponent.apply(this, arguments); }, doLogin:function(){ if (this.username.getValue() == '' && this.password.getValue() == '') { this.username.markInvalid('User Name is required'); this.password.markInvalid('Password is required'); return; } else if (this.username.getValue() == '') { this.username.markInvalid('User Name is required'); return; } else if (this.password.getValue() == '') { this.password.markInvalid('Password is required'); return; } this.getEl().mask('Logging in ...'); this.getForm().submit({ scope: this, url:'ajax/login_ajax.php', success:function(form, action) { var obj = Ext.util.JSON.decode(action.response.responseText); if (obj.success && obj.returnPage) { //if access level < 99 ->redirect, if not show site select window.location = obj.returnPage; this.errorMessage.hide(); } else { // should never occur this.errorMessage.el.dom.innerHTML = '
' + (typeof(action.result)!='undefined'?action.result.errors:'Sorry, we were not able to identify you.') + '
' + (typeof(action.result)!='undefined'?action.result.errors:'Sorry, we were not able to identify you.') + '
' + obj.message + '
' + obj.message + '