3 * Copyright(c) 2008-2011 Alan Knowles
10 * @class Roo.form.ComboNested
11 * @extends Roo.form.ComboBox
12 * A combobox for that allows selection of nested items in a list,
27 * Create a new ComboNested
28 * @param {Object} config Configuration options
30 Roo.form.ComboNested = function(config){
31 Roo.form.ComboCheck.superclass.constructor.call(this, config);
32 // should verify some data...
34 // hiddenName = required..
35 // displayField = required
36 // valudField == required
37 var req= [ 'hiddenName', 'displayField', 'valueField' ];
39 Roo.each(req, function(e) {
40 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
41 throw "Roo.form.ComboNested : missing value for: " + e;
48 Roo.extend(Roo.form.ComboNested, Roo.form.ComboBox, {
51 list : null, // the outermost div..
52 innerLists : null, // the
56 onRender : function(ct, position)
58 Roo.form.ComboBox.superclass.onRender.call(this, ct, position); // skip parent call - got to above..
61 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
63 this.hiddenField.value =
64 this.hiddenValue !== undefined ? this.hiddenValue :
65 this.value !== undefined ? this.value : '';
67 // prevent input submission
68 this.el.dom.removeAttribute('name');
74 this.el.dom.setAttribute('autocomplete', 'off');
77 var cls = 'x-combo-list';
79 this.list = new Roo.Layer({
80 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
83 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
84 this.list.setWidth(lw);
85 this.list.swallowEvent('mousewheel');
89 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
90 this.assetHeight += this.header.getHeight();
95 for (var i =0 ; i < 3; i++) {
96 this.onRenderList( cls, i);
99 // always needs footer, as we are going to have an 'OK' button.
100 this.footer = this.list.createChild({cls:cls+'-ft'});
101 this.pageTb = new Roo.Toolbar(this.footer);
105 if (this.pageTb && this.allowBlank && !this.disableClear) {
107 this.pageTb.add(new Roo.Toolbar.Fill(), {
108 cls: 'x-btn-icon x-btn-clear',
114 _this.onSelect(false, -1);
119 this.assetHeight += this.footer.getHeight();
123 onRenderList : function ( cls, i)
127 ((this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')) / 3
130 this.list.setWidth(lw); // default to '1'
132 var il = this.innerLists[i] = this.list.createChild({cls:cls+'-inner'});
133 //il.on('mouseover', this.onViewOver, this, { list: i });
134 //il.on('mousemove', this.onViewMove, this, { list: i });
136 il.setStyle({ 'overflow-x' : 'hidden'});
139 this.tpl = new Roo.Template({
140 html : '<div class="'+cls+'-item '+cls+'-item-{cn:this.isEmpty}">{' + this.displayField + '}</div>',
141 isEmpty: function (value, allValues) {
142 return value.length ? 'has-children' : 'no-children'
147 var store = this.store;
149 store = new Roo.data.SimpleStore({
150 reader : this.store.reader,
154 this.stores[i] = store;
158 var view = this.views[i] = new Roo.View(
164 selectedClass: this.selectedClass
167 view.getEl().setWidth(lw);
168 view.getEl().setStyle({
169 position: i < 1 ? 'relative' : 'absolute',
171 left: (i * lw ) + 'px',
172 display : i > 0 ? 'none' : 'block'
174 view.on('selectionchange', this.onSelectChange, this, {list : i });
175 view.on('dblclick', this.onDoubleClick, this, {list : i });
176 //view.on('click', this.onViewClick, this, { list : i });
178 store.on('beforeload', this.onBeforeLoad, this);
179 store.on('load', this.onStoreLoad, this, { list : i});
180 store.on('loadexception', this.onLoadException, this);
182 // hide the other vies..
187 onResize : function() {},
189 restrictHeight : function()
192 Roo.each(this.innerLists, function(il,i) {
193 var el = this.views[i].getEl();
194 el.dom.style.height = '';
196 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
197 // only adjust heights on other ones..
200 el.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
201 il.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
202 mh = Math.max(el.getHeight(), mh);
208 this.list.beginUpdate();
209 this.list.setHeight(mh+this.list.getFrameWidth('tb')+this.assetHeight);
210 this.list.alignTo(this.el, this.listAlign);
211 this.list.endUpdate();
216 // -- store handlers..
219 onLoad : function(a,b,c,d)
226 if(this.store.getCount() > 0) {
228 this.restrictHeight();
230 this.onEmptyResults();
233 this.stores[1].loadData([]);
234 this.stores[2].loadData([]);
240 onStoreLoad : function ()
246 onLoadException : function()
249 Roo.log(this.store.reader.jsonData);
250 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
251 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
259 onSelectChange : function (view, sels, opts )
261 var ix = view.getSelectedIndexes();
266 this.setFromData(ix.length ? view.store.getAt(ix[0]).data : {});
271 this.setFromData({});
272 this.stores[opts.list+1].loadData( [] );
276 var rec = view.store.getAt(ix[0]);
277 this.setFromData(rec.data)
280 ((this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')) / 3
283 this.stores[opts.list+1].loadData( typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn);
284 this.views[opts.list+1].getEl().setHeight( this.innerLists[0].getHeight());
285 this.views[opts.list+1].getEl().setStyle({ display : rec.data.cn.length ? 'block' : 'none' });
286 this.innerLists[opts.list+1].setHeight( this.innerLists[0].getHeight());
287 this.list.setWidth(lw * (opts.list + (rec.data.cn.length ? 2 : 1)));
289 onDoubleClick : function()
291 this.collapse(); //??