javascripts/basepack.js in netzke-basepack-0.6.2 vs javascripts/basepack.js in netzke-basepack-0.6.3

- old
+ new

@@ -1,6 +1,7 @@ Ext.ns("Netzke.pre"); +Ext.ns("Netzke.pre.Basepack"); Ext.ns("Ext.ux.grid"); Ext.apply(Ext.History, new Ext.util.Observable()); // A convenient passfield @@ -36,94 +37,35 @@ this.on('specialkey', function(cb, event){ if (event.getKey() == 9 || event.getKey() == 13) {cb.setValue(cb.getRawValue());} }); var parent = Ext.getCmp(this.parentId); - // Is parent a grid? - if (parent.getSelectionModel) { - this.on('beforequery',function(qe) { - delete qe.combo.lastQuery; - },this); - } + // Is parent a grid? + if (parent.getSelectionModel) { + this.on('beforequery',function(qe) { + delete qe.combo.lastQuery; + },this); + } // A not-so-clean approach to submit the current record id store.on('beforeload',function(store, options){ if (parent.getSelectionModel) { var selected = parent.getSelectionModel().getSelected(); if (selected) options.params.id = selected.get('id'); } else { // TODO: also for the FormPanel } - },this) + }, this); } }); Ext.reg('combobox', Ext.netzke.ComboBox); Ext.util.Format.mask = function(v){ return "********"; }; -// Implementation of totalProperty, successProperty and root configuration options for ArrayReader -Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, { - readRecords : function(o){ - var sid = this.meta ? this.meta.id : null; - var recordType = this.recordType, fields = recordType.prototype.fields; - var records = []; - var root = o[this.meta.root] || o, totalRecords = o[this.meta.totalProperty], success = o[this.meta.successProperty]; - for(var i = 0; i < root.length; i++){ - var n = root[i]; - var values = {}; - var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null); - for(var j = 0, jlen = fields.length; j < jlen; j++){ - var f = fields.items[j]; - var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j; - var v = n[k] !== undefined ? n[k] : f.defaultValue; - v = f.convert(v, n); - values[f.name] = v; - } - var record = new recordType(values, id); - record.json = n; - records[records.length] = record; - } - return { - records : records, - totalRecords : totalRecords, - success : success - }; - } -}); - - -Ext.data.RecordArrayReader = Ext.extend(Ext.data.JsonReader, { - /** - * Create a data block containing Ext.data.Records from an Array. - * @param {Object} o An Array of row objects which represents the dataset. - * @return {Object} data A data block which is used by an Ext.data.Store object as - * a cache of Ext.data.Records. - */ - readRecord : function(o){ - var sid = this.meta ? this.meta.id : null; - var recordType = this.recordType, fields = recordType.prototype.fields; - var records = []; - var root = o; - var n = root; - var values = {}; - var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null); - for(var j = 0, jlen = fields.length; j < jlen; j++){ - var f = fields.items[j]; - var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j; - var v = n[k] !== undefined ? n[k] : f.defaultValue; - v = f.convert(v, n); - values[f.name] = v; - } - var record = new recordType(values, id); - record.json = n; - return record; - } -}); - Ext.netzke.JsonField = Ext.extend(Ext.form.TextField, { validator: function(value) { try{ var d = Ext.decode(value); return true; @@ -792,187 +734,168 @@ return true; } return false; }; -// Temporary fix for Ext 3.1 resize problem: -Ext.override(Ext.Panel, { +Ext.ns('Ext.ux.form'); +Ext.ux.form.TriCheckbox = Ext.extend(Ext.form.Checkbox, { + checked: null, + valueList: [null, false, true], + stateClassList: ['x-checkbox-undef', null, 'x-checkbox-checked'], + overClass: 'x-form-check-over', + clickClass: 'x-form-check-down', + triState: true, + defaultAutoCreate: {tag: 'input', type: 'hidden', autocomplete: 'off'}, + initComponent: function() { + this.value = this.checked; + Ext.ux.form.TriCheckbox.superclass.initComponent.apply(this, arguments); + // make a copy before modifying valueList and stateClassList arrays + this.vList = this.valueList.slice(0); + this.cList = this.stateClassList.slice(0); + if(this.triState !== true) { + // consider 'undefined' value and its class go first in arrays + this.vList.shift(); + this.cList.shift(); + } + if(this.overCls !== undefined) { + this.overClass = this.overCls; + delete this.overCls; + } + this.value = this.normalizeValue(this.value); + }, + onRender : function(ct, position){ + Ext.form.Checkbox.superclass.onRender.call(this, ct, position); - // private - onResize : function(w, h, rw, rh){ - if(Ext.isDefined(w) || Ext.isDefined(h)){ - if(!this.collapsed){ - // First, set the the Panel's body width. - // If we have auto-widthed it, get the resulting full offset width so we can size the Toolbars to match - // The Toolbars must not buffer this resize operation because we need to know their heights. + this.innerWrap = this.el.wrap({tag: 'span', cls: 'x-form-check-innerwrap'}); + this.wrap = this.innerWrap.wrap({cls: 'x-form-check-wrap'}); - if(Ext.isNumber(w)){ - this.body.setWidth(w = this.adjustBodyWidth(w - this.getFrameWidth())); - } else if (w == 'auto') { - w = this.body.setWidth('auto').dom.offsetWidth; - } else { - w = this.body.dom.offsetWidth; - } + this.currCls = this.getCls(this.value); + this.wrap.addClass(this.currCls); + if(this.clickClass && !this.disabled && !this.readOnly) + this.innerWrap.addClassOnClick(this.clickClass); + if(this.overClass && !this.disabled && !this.readOnly) + this.innerWrap.addClassOnOver(this.overClass); - if(this.tbar){ - this.tbar.setWidth(w); - if(this.topToolbar){ - this.topToolbar.setSize(w); - } - } - if(this.bbar){ - this.bbar.setWidth(w); - if(this.bottomToolbar){ - this.bottomToolbar.setSize(w); - // The bbar does not move on resize without this. - if (Ext.isIE) { - this.bbar.setStyle('position', 'static'); - this.bbar.setStyle('position', ''); - } - } - } - if(this.footer){ - this.footer.setWidth(w); - if(this.fbar){ - this.fbar.setSize(Ext.isIE ? (w - this.footer.getFrameWidth('lr')) : 'auto'); - } - } + this.imageEl = this.innerWrap.createChild({ + tag: 'img', + src: Ext.BLANK_IMAGE_URL, + cls: 'x-form-tscheckbox' + }, this.el); + if(this.fieldClass) this.imageEl.addClass(this.fieldClass); - // At this point, the Toolbars must be layed out for getFrameHeight to find a result. - if(Ext.isNumber(h)){ - h = Math.max(0, this.adjustBodyHeight(h - this.getFrameHeight())); - this.body.setHeight(h); - }else if(h == 'auto'){ - this.body.setHeight(h); - } + if(this.boxLabel){ + this.innerWrap.createChild({ + tag: 'label', + htmlFor: this.el.id, + cls: 'x-form-cb-label', + html: this.boxLabel + }); + } - if(this.disabled && this.el._mask){ - this.el._mask.setSize(this.el.dom.clientWidth, this.el.getHeight()); - } - }else{ - this.queuedBodySize = {width: w, height: h}; - if(!this.queuedExpand && this.allowQueuedExpand !== false){ - this.queuedExpand = true; - this.on('expand', function(){ - delete this.queuedExpand; - this.onResize(this.queuedBodySize.width, this.queuedBodySize.height); - }, this, {single:true}); - } - } - this.onBodyResize(w, h); - } - this.syncShadow(); - Ext.Panel.superclass.onResize.call(this, w, h, rw, rh); + // Need to repaint for IE, otherwise positioning is broken + if(Ext.isIE){ + this.wrap.repaint(); } -}); + this.resizeEl = this.positionEl = this.wrap; + }, + onResize : function(){ + Ext.form.Checkbox.superclass.onResize.apply(this, arguments); + if(!this.boxLabel && !this.fieldLabel && this.imageEl){ + this.imageEl.alignTo(this.wrap, 'c-c'); + } + }, + initEvents : function(){ + Ext.form.Checkbox.superclass.initEvents.call(this); + this.mon(this.innerWrap, { + scope: this, + click: this.onClick + }); + }, + onClick : function(){ + if (!this.disabled && !this.readOnly) { + this.setValue(this.vList[(this.vList.indexOf(this.value) + 1) % this.vList.length]); + } + }, + getValue : function(){ + return this.value; + }, + setValue : function(v){ + var value = this.value; + this.value = this.normalizeValue(v); + if(this.rendered) this.el.dom.value = this.value; -Ext.ns('Ext.ux.form'); -Ext.ux.form.TriCheckbox = Ext.extend(Ext.form.Checkbox, { - checked: null, - valueList: [null, false, true], - stateClassList: ['x-checkbox-undef', null, 'x-checkbox-checked'], - overClass: 'x-form-check-over', - clickClass: 'x-form-check-down', - triState: true, - defaultAutoCreate: {tag: 'input', type: 'hidden', autocomplete: 'off'}, - initComponent: function() { - this.value = this.checked; - Ext.ux.form.TriCheckbox.superclass.initComponent.apply(this, arguments); - // make a copy before modifying valueList and stateClassList arrays - this.vList = this.valueList.slice(0); - this.cList = this.stateClassList.slice(0); - if(this.triState !== true) { - // consider 'undefined' value and its class go first in arrays - this.vList.shift(); - this.cList.shift(); - } - if(this.overCls !== undefined) { - this.overClass = this.overCls; - delete this.overCls; - } - this.value = this.normalizeValue(this.value); - }, - onRender : function(ct, position){ - Ext.form.Checkbox.superclass.onRender.call(this, ct, position); + if(value !== this.value){ + this.updateView(); + this.fireEvent('check', this, this.value); + if(this.handler) this.handler.call(this.scope || this, this, this.value); + } + return this; + }, + normalizeValue: function(v) { + return (v === null || v === undefined) && this.triState ? null : + (v === true || (['true', 'yes', 'on', '1']).indexOf(String(v).toLowerCase()) != -1); + }, + getCls: function(v) { + var idx = this.vList.indexOf(this.value); + return idx > -1 ? this.cList[idx] : undefined; + }, + updateView: function() { + var cls = this.getCls(this.value); + if (!this.wrap || cls === undefined) return; - this.innerWrap = this.el.wrap({tag: 'span', cls: 'x-form-check-innerwrap'}); - this.wrap = this.innerWrap.wrap({cls: 'x-form-check-wrap'}); + this.wrap.replaceClass(this.currCls, cls); + this.currCls = cls; + } +}); +Ext.reg('tricheckbox', Ext.ux.form.TriCheckbox); - this.currCls = this.getCls(this.value); - this.wrap.addClass(this.currCls); - if(this.clickClass && !this.disabled && !this.readOnly) - this.innerWrap.addClassOnClick(this.clickClass); - if(this.overClass && !this.disabled && !this.readOnly) - this.innerWrap.addClassOnOver(this.overClass); - this.imageEl = this.innerWrap.createChild({ - tag: 'img', - src: Ext.BLANK_IMAGE_URL, - cls: 'x-form-tscheckbox' - }, this.el); - if(this.fieldClass) this.imageEl.addClass(this.fieldClass); +// Enabling checkbox submission when unchecked +(function() { + origCheckboxRender = Ext.form.Checkbox.prototype.onRender; + origCheckboxSetValue = Ext.form.Checkbox.prototype.setValue; - if(this.boxLabel){ - this.innerWrap.createChild({ - tag: 'label', - htmlFor: this.el.id, - cls: 'x-form-cb-label', - html: this.boxLabel - }); - } + Ext.override(Ext.form.Checkbox, { + onRender: function() { + // call the original onRender() function + origCheckboxRender.apply(this, arguments); - // Need to repaint for IE, otherwise positioning is broken - if(Ext.isIE){ - this.wrap.repaint(); - } - this.resizeEl = this.positionEl = this.wrap; - }, - onResize : function(){ - Ext.form.Checkbox.superclass.onResize.apply(this, arguments); - if(!this.boxLabel && !this.fieldLabel && this.imageEl){ - this.imageEl.alignTo(this.wrap, 'c-c'); - } - }, - initEvents : function(){ - Ext.form.Checkbox.superclass.initEvents.call(this); - this.mon(this.innerWrap, { - scope: this, - click: this.onClick - }); - }, - onClick : function(){ - if (!this.disabled && !this.readOnly) { - this.setValue(this.vList[(this.vList.indexOf(this.value) + 1) % this.vList.length]); - } - }, - getValue : function(){ - return this.value; - }, - setValue : function(v){ - var value = this.value; - this.value = this.normalizeValue(v); - if(this.rendered) this.el.dom.value = this.value; + if (this.getXType() === 'radio') return; - if(value !== this.value){ - this.updateView(); - this.fireEvent('check', this, this.value); - if(this.handler) this.handler.call(this.scope || this, this, this.value); - } - return this; - }, - normalizeValue: function(v) { - return (v === null || v === undefined) && this.triState ? null : - (v === true || (['true', 'yes', 'on', '1']).indexOf(String(v).toLowerCase()) != -1); - }, - getCls: function(v) { - var idx = this.vList.indexOf(this.value); - return idx > -1 ? this.cList[idx] : undefined; - }, - updateView: function() { - var cls = this.getCls(this.value); - if (!this.wrap || cls === undefined) return; + // Handle initial case based on this.checked + if (this.checked == false) { + this.noValEl = Ext.DomHelper.insertAfter(this.el, { + tag: 'input', + type: 'hidden', + value: false, + name: this.getName() + }, true); + } + else { + this.noValEl = null; + } + }, + setValue: function() { + // call original setValue() function + origCheckboxSetValue.apply(this, arguments); - this.wrap.replaceClass(this.currCls, cls); - this.currCls = cls; - } -}); -Ext.reg('tricheckbox', Ext.ux.form.TriCheckbox); \ No newline at end of file + if (this.getXType() === 'radio') return; + + if (this.checked) { + if (this.noValEl != null) { + // Remove the extra hidden element + this.noValEl.remove(); + this.noValEl = null; + } + } + else { + // Add our hidden element for (unchecked) value + if (this.noValEl == null) this.noValEl = Ext.DomHelper.insertAfter(this.el, { + tag: 'input', + type: 'hidden', + value: false, + name: this.getName() + }, true); + } + } + }); +})();