javascripts/basepack.js in netzke-basepack-0.3.0 vs javascripts/basepack.js in netzke-basepack-0.3.1

- old
+ new

@@ -1,82 +1,110 @@ // Editors for grid cells and form fields Ext.netzke.editors = { - combo_box: function(c, config){ - var row = Ext.data.Record.create([{name:'id'}]) + combo_box: function(c, config){ + var row = Ext.data.Record.create([{name:'id'}]) var store = new Ext.data.Store({ - proxy: new Ext.data.HttpProxy({url:config.interface.getCbChoices, jsonData:{column:c.name}}), - reader: new Ext.data.ArrayReader({root:'data', id:0}, row) + proxy : new Ext.data.HttpProxy({url:config.interface.getCbChoices, jsonData:{column:c.name}}), + reader : new Ext.data.ArrayReader({root:'data', id:0}, row) }) - return new Ext.form.ComboBox({ - mode: 'remote', - displayField:'id', - valueField:'id', - triggerAction:'all', - store: store + + var comboBox = new Ext.form.ComboBox({ + mode : 'remote', + displayField : 'id', + valueField : 'id', + triggerAction : 'all', + typeAhead : true, + selectOnFocus : true, + store : store }) - }, + + // let user enter values that are not in the store + comboBox.on('blur', function(cb){ + cb.setValue(cb.getRawValue()); + }); + comboBox.on('specialkey', function(cb, event){ + if (event.getKey() == 9 || event.getKey() == 13) {cb.setValue(cb.getRawValue());} + }); + + return comboBox; + }, - text_field: function(c, config){ - return new Ext.form.TextField({ - selectOnFocus:true - }) - }, - - checkbox: function(c, config){ - return new Ext.form.TextField({ - selectOnFocus:true - }) - }, - - number_field: function(c, config){ - return new Ext.form.NumberField({ - selectOnFocus:true - }) - }, - - // TODO: it's simply a text field for now - datetime: function(c, config){ - return new Ext.form.TextField({ - selectOnFocus:true - }) - } + text_field: function(c, config){ + return new Ext.form.TextField({ + selectOnFocus:true + }) + }, + + checkbox: function(c, config){ + return new Ext.form.TextField({ + selectOnFocus:true + }) + }, + + number_field: function(c, config){ + return new Ext.form.NumberField({ + selectOnFocus:true + }) + }, + + // TODO: it's simply a text field for now + datetime: function(c, config){ + return new Ext.form.TextField({ + selectOnFocus:true + }) + } }; +Ext.netzke.renderer = function(renderer, c, config){ + res = Ext.emptyFn; + switch (renderer) { + + // custom renderers can be later added like this: + case 'my_renderer': + res = function(value){ return "Not implemented" }; + break + + // falls back to Ext.util.Format renderers + default: + res = Ext.util.Format[renderer] + break + } + return res +} + // Mapping of editor field to grid filters Ext.netzke.filterMap = { - number_field:'Numeric', - text_field:'String', - datetime:'String', - checkbox:'Boolean', - combo_box:'String', - date:'Date' + number_field:'Numeric', + text_field:'String', + datetime:'String', + checkbox:'Boolean', + combo_box:'String', + date:'Date' } 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; - // for(var i = 0; i < root.length; i++){ - 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; + /** + * 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; + } }); \ No newline at end of file