X-Git-Url: http://git.roojs.org/?p=roojs1;a=blobdiff_plain;f=roojs-ui-debug.js;h=5bfabbbc987d15cc31e774f200f49948cba962d4;hp=2464e27ae70bef9e1731d16a47f953e310b123ba;hb=dc5d9380aff25134bf025953bdafe40b580337ff;hpb=005e5a076296b98923366bf594e1499fd7af6568 diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index 2464e27ae7..5bfabbbc98 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -784,6 +784,16 @@ Roo.extend(Roo.data.Store, Roo.util.Observable, { var r = this.reader.readRecords(o); this.loadRecords(r, {add: append}, true); }, + + /** + * using 'cn' the nested child reader read the child array into it's child stores. + * @param {Object} rec The record with a 'children array + */ + loadDataFromChildren : function(rec) + { + this.loadData(this.reader.toLoadData(rec)); + }, + /** * Gets the number of cached records. @@ -1088,14 +1098,16 @@ Roo.extend(Roo.data.Store, Roo.util.Observable, { * Small helper class to make creating Stores from Array data easier. * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids. * @cfg {Array} fields An array of field definition objects, or field name strings. + * @cfg {Object} an existing reader (eg. copied from another store) * @cfg {Array} data The multi-dimensional array of data * @constructor * @param {Object} config */ -Roo.data.SimpleStore = function(config){ +Roo.data.SimpleStore = function(config) +{ Roo.data.SimpleStore.superclass.constructor.call(this, { isLocal : true, - reader: new Roo.data.ArrayReader({ + reader: typeof(config.reader) != 'undefined' ? config.reader : new Roo.data.ArrayReader({ id: config.id }, Roo.data.Record.create(config.fields) @@ -1272,6 +1284,9 @@ Roo.data.DataReader = function(meta, recordType){ }; Roo.data.DataReader.prototype = { + + + readerType : 'Data', /** * Create an empty record * @param {Object} data (optional) - overlay some values @@ -1292,6 +1307,7 @@ Roo.data.DataReader.prototype = { return new this.recordType(Roo.apply(da, d)); } + };/* * Based on: * Ext JS Library 1.1.1 @@ -1830,6 +1846,8 @@ Roo.data.JsonReader = function(meta, recordType){ }; Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, { + readerType : 'Json', + /** * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source. * Used by Store query builder to append _requestMeta to params. @@ -1971,6 +1989,14 @@ Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, { records : records, totalRecords : totalRecords }; + }, + // used when loading children.. @see loadDataFromChildren + toLoadData: function(rec) + { + // expect rec just to be an array.. eg [a,b,c, [...] << cn ] + var data = typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn; + return { data : data, total : data.length }; + } });/* * Based on: @@ -2041,6 +2067,9 @@ Roo.data.XmlReader = function(meta, recordType){ Roo.data.XmlReader.superclass.constructor.call(this, meta, recordType||meta.fields); }; Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, { + + readerType : 'Xml', + /** * This method is only used by a DataProxy which has retrieved data from a remote server. * @param {Object} response The XHR object which contains the parsed XML document. The response is expected @@ -2152,44 +2181,54 @@ var myReader = new Roo.data.ArrayReader({ * * created using {@link Roo.data.Record#create}. */ -Roo.data.ArrayReader = function(meta, recordType){ - - +Roo.data.ArrayReader = function(meta, recordType) +{ Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType||meta.fields); }; Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, { - /** + + /** * Create a data block containing Roo.data.Records from an XML document. * @param {Object} o An Array of row objects which represents the dataset. * @return {Object} A data block which is used by an {@link Roo.data.Store} object as * a cache of Roo.data.Records. */ - readRecords : function(o){ + readRecords : 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[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); - values[f.name] = v; - } - var record = new recordType(values, id); - record.json = n; - records[records.length] = record; + 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); + values[f.name] = v; } - return { - records : records, - totalRecords : records.length - }; + var record = new recordType(values, id); + record.json = n; + records[records.length] = record; + } + return { + records : records, + totalRecords : records.length + }; + }, + // used when loading children.. @see loadDataFromChildren + toLoadData: function(rec) + { + // expect rec just to be an array.. eg [a,b,c, [...] << cn ] + return typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn; + } + + });/* * Based on: * Ext JS Library 1.1.1 @@ -18914,9 +18953,11 @@ Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, { // element that contains real text value.. (when hidden is used..) // private - onRender : function(ct, position){ + onRender : function(ct, position) + { Roo.form.ComboBox.superclass.onRender.call(this, ct, position); - if(this.hiddenName){ + + if(this.hiddenName){ this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)}, 'before', true); this.hiddenField.value = @@ -18928,6 +18969,7 @@ Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, { } + if(Roo.isGecko){ this.el.dom.setAttribute('autocomplete', 'off'); } @@ -18988,7 +19030,9 @@ Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, { } this.view = new Roo.View(this.innerList, this.tpl, { - singleSelect:true, store: this.store, selectedClass: this.selectedClass + singleSelect:true, + store: this.store, + selectedClass: this.selectedClass }); this.view.on('click', this.onViewClick, this); @@ -19789,7 +19833,10 @@ Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField, * @cfg {String} hiddenName The hidden name of the field, often contains an comma seperated list of names */ hiddenName : false, - + /** + * @cfg {String} seperator The value seperator normally ',' + */ + seperator : ',', // private the array of items that are displayed.. items : false, @@ -19964,7 +20011,7 @@ Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField, this.items.each(function(f) { ar.push(f.data[idField]); }); - this.hiddenEl.dom.value = ar.join(','); + this.hiddenEl.dom.value = ar.join(this.seperator); this.validate(); }, @@ -19996,7 +20043,7 @@ Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField, // comma seperated at present.. this needs to allow JSON based encoding.. this.hiddenEl.value = v; var v_ar = []; - Roo.each(v.split(','), function(k) { + Roo.each(v.split(this.seperator), function(k) { Roo.log("CHECK " + this.valueField + ',' + k); var li = this.store.query(this.valueField, k); if (!li.length) { @@ -20035,10 +20082,9 @@ Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField, dv = typeof(dv) != 'string' ? '' : dv; - var keys = kv.split(','); - var display = dv.split(','); + var keys = kv.split(this.seperator); + var display = dv.split(this.seperator); for (var i = 0 ; i < keys.length; i++) { - add = {}; add[this.valueField] = keys[i]; add[this.displayField] = display[i]; @@ -20086,7 +20132,7 @@ Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField, originalValue.push(d[i][this.valueField]); } - return String(this.getValue()) !== String(originalValue.join(',')); + return String(this.getValue()) !== String(originalValue.join(this.seperator)); } @@ -20174,6 +20220,434 @@ Roo.extend(Roo.form.ComboBoxArray.Item, Roo.BoxComponent, { } } +});/* + * RooJS Library 1.1.1 + * Copyright(c) 2008-2011 Alan Knowles + * + * License - LGPL + */ + + +/** + * @class Roo.form.ComboNested + * @extends Roo.form.ComboBox + * A combobox for that allows selection of nested items in a list, + * eg. + * + * Book + * -> red + * -> green + * Table + * -> square + * ->red + * ->green + * -> rectangle + * ->green + * + * + * @constructor + * Create a new ComboNested + * @param {Object} config Configuration options + */ +Roo.form.ComboNested = function(config){ + Roo.form.ComboCheck.superclass.constructor.call(this, config); + // should verify some data... + // like + // hiddenName = required.. + // displayField = required + // valudField == required + var req= [ 'hiddenName', 'displayField', 'valueField' ]; + var _t = this; + Roo.each(req, function(e) { + if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) { + throw "Roo.form.ComboNested : missing value for: " + e; + } + }); + + +}; + +Roo.extend(Roo.form.ComboNested, Roo.form.ComboBox, { + + /* + * @config {Number} max Number of columns to show + */ + + maxColumns : 3, + + list : null, // the outermost div.. + innerLists : null, // the + views : null, + stores : null, + // private + loadingChildren : false, + + onRender : function(ct, position) + { + Roo.form.ComboBox.superclass.onRender.call(this, ct, position); // skip parent call - got to above.. + + if(this.hiddenName){ + this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)}, + 'before', true); + this.hiddenField.value = + this.hiddenValue !== undefined ? this.hiddenValue : + this.value !== undefined ? this.value : ''; + + // prevent input submission + this.el.dom.removeAttribute('name'); + + + } + + if(Roo.isGecko){ + this.el.dom.setAttribute('autocomplete', 'off'); + } + + var cls = 'x-combo-list'; + + this.list = new Roo.Layer({ + shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false + }); + + var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth); + this.list.setWidth(lw); + this.list.swallowEvent('mousewheel'); + this.assetHeight = 0; + + if(this.title){ + this.header = this.list.createChild({cls:cls+'-hd', html: this.title}); + this.assetHeight += this.header.getHeight(); + } + this.innerLists = []; + this.views = []; + this.stores = []; + for (var i =0 ; i < this.maxColumns; i++) { + this.onRenderList( cls, i); + } + + // always needs footer, as we are going to have an 'OK' button. + this.footer = this.list.createChild({cls:cls+'-ft'}); + this.pageTb = new Roo.Toolbar(this.footer); + var _this = this; + this.pageTb.add( { + + text: 'Done', + handler: function() + { + _this.collapse(); + } + }); + + if ( this.allowBlank && !this.disableClear) { + + this.pageTb.add(new Roo.Toolbar.Fill(), { + cls: 'x-btn-icon x-btn-clear', + text: ' ', + handler: function() + { + _this.collapse(); + _this.clearValue(); + _this.onSelect(false, -1); + } + }); + } + if (this.footer) { + this.assetHeight += this.footer.getHeight(); + } + + }, + onRenderList : function ( cls, i) + { + + var lw = Math.floor( + ((this.listWidth * this.maxColumns || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')) / this.maxColumns + ); + + this.list.setWidth(lw); // default to '1' + + var il = this.innerLists[i] = this.list.createChild({cls:cls+'-inner'}); + //il.on('mouseover', this.onViewOver, this, { list: i }); + //il.on('mousemove', this.onViewMove, this, { list: i }); + il.setWidth(lw); + il.setStyle({ 'overflow-x' : 'hidden'}); + + if(!this.tpl){ + this.tpl = new Roo.Template({ + html : '