javascripts/basepack.js in netzke-basepack-0.5.14 vs javascripts/basepack.js in netzke-basepack-0.6.0

- old
+ new

@@ -1,5 +1,8 @@ +Ext.ns("Netzke.pre"); +Ext.ns("Ext.ux.grid"); + Ext.apply(Ext.History, new Ext.util.Observable()); // A convenient passfield Ext.netzke.PassField = Ext.extend(Ext.form.TextField, { inputType: 'password' @@ -14,14 +17,14 @@ typeAhead : true, initComponent : function(){ var row = Ext.data.Record.create([{name:'id'}]); var store = new Ext.data.Store({ - proxy : new Ext.data.HttpProxy({url: Ext.getCmp(this.parentId).buildApiUrl("get_combobox_options"), jsonData:{column:this.name}}), + proxy : new Ext.data.HttpProxy({url: Ext.getCmp(this.parentId).endpointUrl("get_combobox_options"), jsonData:{column:this.name}}), reader : new Ext.data.ArrayReader({root:'data', id:0}, row) }); - + Ext.apply(this, { store : store }); Ext.netzke.ComboBox.superclass.initComponent.apply(this, arguments); @@ -31,17 +34,66 @@ }); 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); + } + + // 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) } }); 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. \ No newline at end of file