Upgrade to ExtJS 3.2.1 - Released 04/27/2010
[extjs.git] / examples / ux / ux-all-debug.js
1 /*!
2  * Ext JS Library 3.2.1
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 Ext.ns('Ext.ux.grid');
8
9 /**
10  * @class Ext.ux.grid.BufferView
11  * @extends Ext.grid.GridView
12  * A custom GridView which renders rows on an as-needed basis.
13  */
14 Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
15         /**
16          * @cfg {Number} rowHeight
17          * The height of a row in the grid.
18          */
19         rowHeight: 19,
20
21         /**
22          * @cfg {Number} borderHeight
23          * The combined height of border-top and border-bottom of a row.
24          */
25         borderHeight: 2,
26
27         /**
28          * @cfg {Boolean/Number} scrollDelay
29          * The number of milliseconds before rendering rows out of the visible
30          * viewing area. Defaults to 100. Rows will render immediately with a config
31          * of false.
32          */
33         scrollDelay: 100,
34
35         /**
36          * @cfg {Number} cacheSize
37          * The number of rows to look forward and backwards from the currently viewable
38          * area.  The cache applies only to rows that have been rendered already.
39          */
40         cacheSize: 20,
41
42         /**
43          * @cfg {Number} cleanDelay
44          * The number of milliseconds to buffer cleaning of extra rows not in the
45          * cache.
46          */
47         cleanDelay: 500,
48
49         initTemplates : function(){
50                 Ext.ux.grid.BufferView.superclass.initTemplates.call(this);
51                 var ts = this.templates;
52                 // empty div to act as a place holder for a row
53                 ts.rowHolder = new Ext.Template(
54                         '<div class="x-grid3-row {alt}" style="{tstyle}"></div>'
55                 );
56                 ts.rowHolder.disableFormats = true;
57                 ts.rowHolder.compile();
58
59                 ts.rowBody = new Ext.Template(
60                         '<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
61                         '<tbody><tr>{cells}</tr>',
62                         (this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
63                         '</tbody></table>'
64                 );
65                 ts.rowBody.disableFormats = true;
66                 ts.rowBody.compile();
67         },
68
69         getStyleRowHeight : function(){
70                 return Ext.isBorderBox ? (this.rowHeight + this.borderHeight) : this.rowHeight;
71         },
72
73         getCalculatedRowHeight : function(){
74                 return this.rowHeight + this.borderHeight;
75         },
76
77         getVisibleRowCount : function(){
78                 var rh = this.getCalculatedRowHeight(),
79                     visibleHeight = this.scroller.dom.clientHeight;
80                 return (visibleHeight < 1) ? 0 : Math.ceil(visibleHeight / rh);
81         },
82
83         getVisibleRows: function(){
84                 var count = this.getVisibleRowCount(),
85                     sc = this.scroller.dom.scrollTop,
86                     start = (sc === 0 ? 0 : Math.floor(sc/this.getCalculatedRowHeight())-1);
87                 return {
88                         first: Math.max(start, 0),
89                         last: Math.min(start + count + 2, this.ds.getCount()-1)
90                 };
91         },
92
93         doRender : function(cs, rs, ds, startRow, colCount, stripe, onlyBody){
94                 var ts = this.templates, 
95             ct = ts.cell, 
96             rt = ts.row, 
97             rb = ts.rowBody, 
98             last = colCount-1,
99                     rh = this.getStyleRowHeight(),
100                     vr = this.getVisibleRows(),
101                     tstyle = 'width:'+this.getTotalWidth()+';height:'+rh+'px;',
102                     // buffers
103                     buf = [], 
104             cb, 
105             c, 
106             p = {}, 
107             rp = {tstyle: tstyle}, 
108             r;
109                 for (var j = 0, len = rs.length; j < len; j++) {
110                         r = rs[j]; cb = [];
111                         var rowIndex = (j+startRow),
112                             visible = rowIndex >= vr.first && rowIndex <= vr.last;
113                         if (visible) {
114                                 for (var i = 0; i < colCount; i++) {
115                                         c = cs[i];
116                                         p.id = c.id;
117                                         p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
118                                         p.attr = p.cellAttr = "";
119                                         p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
120                                         p.style = c.style;
121                                         if (p.value === undefined || p.value === "") {
122                                                 p.value = "&#160;";
123                                         }
124                                         if (r.dirty && typeof r.modified[c.name] !== 'undefined') {
125                                                 p.css += ' x-grid3-dirty-cell';
126                                         }
127                                         cb[cb.length] = ct.apply(p);
128                                 }
129                         }
130                         var alt = [];
131                         if(stripe && ((rowIndex+1) % 2 === 0)){
132                             alt[0] = "x-grid3-row-alt";
133                         }
134                         if(r.dirty){
135                             alt[1] = " x-grid3-dirty-row";
136                         }
137                         rp.cols = colCount;
138                         if(this.getRowClass){
139                             alt[2] = this.getRowClass(r, rowIndex, rp, ds);
140                         }
141                         rp.alt = alt.join(" ");
142                         rp.cells = cb.join("");
143                         buf[buf.length] =  !visible ? ts.rowHolder.apply(rp) : (onlyBody ? rb.apply(rp) : rt.apply(rp));
144                 }
145                 return buf.join("");
146         },
147
148         isRowRendered: function(index){
149                 var row = this.getRow(index);
150                 return row && row.childNodes.length > 0;
151         },
152
153         syncScroll: function(){
154                 Ext.ux.grid.BufferView.superclass.syncScroll.apply(this, arguments);
155                 this.update();
156         },
157
158         // a (optionally) buffered method to update contents of gridview
159         update: function(){
160                 if (this.scrollDelay) {
161                         if (!this.renderTask) {
162                                 this.renderTask = new Ext.util.DelayedTask(this.doUpdate, this);
163                         }
164                         this.renderTask.delay(this.scrollDelay);
165                 }else{
166                         this.doUpdate();
167                 }
168         },
169     
170     onRemove : function(ds, record, index, isUpdate){
171         Ext.ux.grid.BufferView.superclass.onRemove.apply(this, arguments);
172         if(isUpdate !== true){
173             this.update();
174         }
175     },
176
177         doUpdate: function(){
178                 if (this.getVisibleRowCount() > 0) {
179                         var g = this.grid, 
180                 cm = g.colModel, 
181                 ds = g.store,
182                 cs = this.getColumnData(),
183                         vr = this.getVisibleRows(),
184                 row;
185                         for (var i = vr.first; i <= vr.last; i++) {
186                                 // if row is NOT rendered and is visible, render it
187                                 if(!this.isRowRendered(i) && (row = this.getRow(i))){
188                                         var html = this.doRender(cs, [ds.getAt(i)], ds, i, cm.getColumnCount(), g.stripeRows, true);
189                                         row.innerHTML = html;
190                                 }
191                         }
192                         this.clean();
193                 }
194         },
195
196         // a buffered method to clean rows
197         clean : function(){
198                 if(!this.cleanTask){
199                         this.cleanTask = new Ext.util.DelayedTask(this.doClean, this);
200                 }
201                 this.cleanTask.delay(this.cleanDelay);
202         },
203
204         doClean: function(){
205                 if (this.getVisibleRowCount() > 0) {
206                         var vr = this.getVisibleRows();
207                         vr.first -= this.cacheSize;
208                         vr.last += this.cacheSize;
209
210                         var i = 0, rows = this.getRows();
211                         // if first is less than 0, all rows have been rendered
212                         // so lets clean the end...
213                         if(vr.first <= 0){
214                                 i = vr.last + 1;
215                         }
216                         for(var len = this.ds.getCount(); i < len; i++){
217                                 // if current row is outside of first and last and
218                                 // has content, update the innerHTML to nothing
219                                 if ((i < vr.first || i > vr.last) && rows[i].innerHTML) {
220                                         rows[i].innerHTML = '';
221                                 }
222                         }
223                 }
224         },
225     
226     removeTask: function(name){
227         var task = this[name];
228         if(task && task.cancel){
229             task.cancel();
230             this[name] = null;
231         }
232     },
233     
234     destroy : function(){
235         this.removeTask('cleanTask');
236         this.removeTask('renderTask');  
237         Ext.ux.grid.BufferView.superclass.destroy.call(this);
238     },
239
240         layout: function(){
241                 Ext.ux.grid.BufferView.superclass.layout.call(this);
242                 this.update();
243         }
244 });// We are adding these custom layouts to a namespace that does not
245 // exist by default in Ext, so we have to add the namespace first:
246 Ext.ns('Ext.ux.layout');
247
248 /**
249  * @class Ext.ux.layout.CenterLayout
250  * @extends Ext.layout.FitLayout
251  * <p>This is a very simple layout style used to center contents within a container.  This layout works within
252  * nested containers and can also be used as expected as a Viewport layout to center the page layout.</p>
253  * <p>As a subclass of FitLayout, CenterLayout expects to have a single child panel of the container that uses
254  * the layout.  The layout does not require any config options, although the child panel contained within the
255  * layout must provide a fixed or percentage width.  The child panel's height will fit to the container by
256  * default, but you can specify <tt>autoHeight:true</tt> to allow it to autosize based on its content height.
257  * Example usage:</p>
258  * <pre><code>
259 // The content panel is centered in the container
260 var p = new Ext.Panel({
261     title: 'Center Layout',
262     layout: 'ux.center',
263     items: [{
264         title: 'Centered Content',
265         width: '75%',
266         html: 'Some content'
267     }]
268 });
269
270 // If you leave the title blank and specify no border
271 // you'll create a non-visual, structural panel just
272 // for centering the contents in the main container.
273 var p = new Ext.Panel({
274     layout: 'ux.center',
275     border: false,
276     items: [{
277         title: 'Centered Content',
278         width: 300,
279         autoHeight: true,
280         html: 'Some content'
281     }]
282 });
283 </code></pre>
284  */
285 Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.FitLayout, {
286         // private
287     setItemSize : function(item, size){
288         this.container.addClass('ux-layout-center');
289         item.addClass('ux-layout-center-item');
290         if(item && size.height > 0){
291             if(item.width){
292                 size.width = item.width;
293             }
294             item.setSize(size);
295         }
296     }
297 });
298
299 Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout;
300 Ext.ns('Ext.ux.grid');
301
302 /**
303  * @class Ext.ux.grid.CheckColumn
304  * @extends Object
305  * GridPanel plugin to add a column with check boxes to a grid.
306  * <p>Example usage:</p>
307  * <pre><code>
308 // create the column
309 var checkColumn = new Ext.grid.CheckColumn({
310    header: 'Indoor?',
311    dataIndex: 'indoor',
312    id: 'check',
313    width: 55
314 });
315
316 // add the column to the column model
317 var cm = new Ext.grid.ColumnModel([{
318        header: 'Foo',
319        ...
320     },
321     checkColumn
322 ]);
323
324 // create the grid
325 var grid = new Ext.grid.EditorGridPanel({
326     ...
327     cm: cm,
328     plugins: [checkColumn], // include plugin
329     ...
330 });
331  * </code></pre>
332  * In addition to storing a Boolean value within the record data, this
333  * class toggles a css class between <tt>'x-grid3-check-col'</tt> and
334  * <tt>'x-grid3-check-col-on'</tt> to alter the background image used for
335  * a column.
336  */
337 Ext.ux.grid.CheckColumn = function(config){
338     Ext.apply(this, config);
339     if(!this.id){
340         this.id = Ext.id();
341     }
342     this.renderer = this.renderer.createDelegate(this);
343 };
344
345 Ext.ux.grid.CheckColumn.prototype ={
346     init : function(grid){
347         this.grid = grid;
348         this.grid.on('render', function(){
349             var view = this.grid.getView();
350             view.mainBody.on('mousedown', this.onMouseDown, this);
351         }, this);
352     },
353
354     onMouseDown : function(e, t){
355         if(Ext.fly(t).hasClass(this.createId())){
356             e.stopEvent();
357             var index = this.grid.getView().findRowIndex(t);
358             var record = this.grid.store.getAt(index);
359             record.set(this.dataIndex, !record.data[this.dataIndex]);
360         }
361     },
362
363     renderer : function(v, p, record){
364         p.css += ' x-grid3-check-col-td'; 
365         return String.format('<div class="x-grid3-check-col{0} {1}">&#160;</div>', v ? '-on' : '', this.createId());
366     },
367     
368     createId : function(){
369         return 'x-grid3-cc-' + this.id;
370     }
371 };
372
373 // register ptype
374 Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn);
375
376 // backwards compat
377 Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn;Ext.ns('Ext.ux.grid');
378
379 Ext.ux.grid.ColumnHeaderGroup = Ext.extend(Ext.util.Observable, {
380
381     constructor: function(config){
382         this.config = config;
383     },
384
385     init: function(grid){
386         Ext.applyIf(grid.colModel, this.config);
387         Ext.apply(grid.getView(), this.viewConfig);
388     },
389
390     viewConfig: {
391         initTemplates: function(){
392             this.constructor.prototype.initTemplates.apply(this, arguments);
393             var ts = this.templates || {};
394             if(!ts.gcell){
395                 ts.gcell = new Ext.XTemplate('<td class="x-grid3-hd x-grid3-gcell x-grid3-td-{id} ux-grid-hd-group-row-{row} {cls}" style="{style}">', '<div {tooltip} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '', '{value}</div></td>');
396             }
397             this.templates = ts;
398             this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", "");
399         },
400
401         renderHeaders: function(){
402             var ts = this.templates, headers = [], cm = this.cm, rows = cm.rows, tstyle = 'width:' + this.getTotalWidth() + ';';
403
404             for(var row = 0, rlen = rows.length; row < rlen; row++){
405                 var r = rows[row], cells = [];
406                 for(var i = 0, gcol = 0, len = r.length; i < len; i++){
407                     var group = r[i];
408                     group.colspan = group.colspan || 1;
409                     var id = this.getColumnId(group.dataIndex ? cm.findColumnIndex(group.dataIndex) : gcol), gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
410                     cells[i] = ts.gcell.apply({
411                         cls: 'ux-grid-hd-group-cell',
412                         id: id,
413                         row: row,
414                         style: 'width:' + gs.width + ';' + (gs.hidden ? 'display:none;' : '') + (group.align ? 'text-align:' + group.align + ';' : ''),
415                         tooltip: group.tooltip ? (Ext.QuickTips.isEnabled() ? 'ext:qtip' : 'title') + '="' + group.tooltip + '"' : '',
416                         istyle: group.align == 'right' ? 'padding-right:16px' : '',
417                         btn: this.grid.enableHdMenu && group.header,
418                         value: group.header || '&nbsp;'
419                     });
420                     gcol += group.colspan;
421                 }
422                 headers[row] = ts.header.apply({
423                     tstyle: tstyle,
424                     cells: cells.join('')
425                 });
426             }
427             headers.push(this.constructor.prototype.renderHeaders.apply(this, arguments));
428             return headers.join('');
429         },
430
431         onColumnWidthUpdated: function(){
432             this.constructor.prototype.onColumnWidthUpdated.apply(this, arguments);
433             Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
434         },
435
436         onAllColumnWidthsUpdated: function(){
437             this.constructor.prototype.onAllColumnWidthsUpdated.apply(this, arguments);
438             Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
439         },
440
441         onColumnHiddenUpdated: function(){
442             this.constructor.prototype.onColumnHiddenUpdated.apply(this, arguments);
443             Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
444         },
445
446         getHeaderCell: function(index){
447             return this.mainHd.query(this.cellSelector)[index];
448         },
449
450         findHeaderCell: function(el){
451             return el ? this.fly(el).findParent('td.x-grid3-hd', this.cellSelectorDepth) : false;
452         },
453
454         findHeaderIndex: function(el){
455             var cell = this.findHeaderCell(el);
456             return cell ? this.getCellIndex(cell) : false;
457         },
458
459         updateSortIcon: function(col, dir){
460             var sc = this.sortClasses, hds = this.mainHd.select(this.cellSelector).removeClass(sc);
461             hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
462         },
463
464         handleHdDown: function(e, t){
465             var el = Ext.get(t);
466             if(el.hasClass('x-grid3-hd-btn')){
467                 e.stopEvent();
468                 var hd = this.findHeaderCell(t);
469                 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
470                 var index = this.getCellIndex(hd);
471                 this.hdCtxIndex = index;
472                 var ms = this.hmenu.items, cm = this.cm;
473                 ms.get('asc').setDisabled(!cm.isSortable(index));
474                 ms.get('desc').setDisabled(!cm.isSortable(index));
475                 this.hmenu.on('hide', function(){
476                     Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
477                 }, this, {
478                     single: true
479                 });
480                 this.hmenu.show(t, 'tl-bl?');
481             }else if(el.hasClass('ux-grid-hd-group-cell') || Ext.fly(t).up('.ux-grid-hd-group-cell')){
482                 e.stopEvent();
483             }
484         },
485
486         handleHdMove: function(e, t){
487             var hd = this.findHeaderCell(this.activeHdRef);
488             if(hd && !this.headersDisabled && !Ext.fly(hd).hasClass('ux-grid-hd-group-cell')){
489                 var hw = this.splitHandleWidth || 5, r = this.activeHdRegion, x = e.getPageX(), ss = hd.style, cur = '';
490                 if(this.grid.enableColumnResize !== false){
491                     if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex - 1)){
492                         cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize
493                                                                                                 // not
494                                                                                                 // always
495                                                                                                 // supported
496                     }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
497                         cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
498                     }
499                 }
500                 ss.cursor = cur;
501             }
502         },
503
504         handleHdOver: function(e, t){
505             var hd = this.findHeaderCell(t);
506             if(hd && !this.headersDisabled){
507                 this.activeHdRef = t;
508                 this.activeHdIndex = this.getCellIndex(hd);
509                 var fly = this.fly(hd);
510                 this.activeHdRegion = fly.getRegion();
511                 if(!(this.cm.isMenuDisabled(this.activeHdIndex) || fly.hasClass('ux-grid-hd-group-cell'))){
512                     fly.addClass('x-grid3-hd-over');
513                     this.activeHdBtn = fly.child('.x-grid3-hd-btn');
514                     if(this.activeHdBtn){
515                         this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight - 1) + 'px';
516                     }
517                 }
518             }
519         },
520
521         handleHdOut: function(e, t){
522             var hd = this.findHeaderCell(t);
523             if(hd && (!Ext.isIE || !e.within(hd, true))){
524                 this.activeHdRef = null;
525                 this.fly(hd).removeClass('x-grid3-hd-over');
526                 hd.style.cursor = '';
527             }
528         },
529
530         handleHdMenuClick: function(item){
531             var index = this.hdCtxIndex, cm = this.cm, ds = this.ds, id = item.getItemId();
532             switch(id){
533                 case 'asc':
534                     ds.sort(cm.getDataIndex(index), 'ASC');
535                     break;
536                 case 'desc':
537                     ds.sort(cm.getDataIndex(index), 'DESC');
538                     break;
539                 default:
540                     if(id.substr(0, 5) == 'group'){
541                         var i = id.split('-'), row = parseInt(i[1], 10), col = parseInt(i[2], 10), r = this.cm.rows[row], group, gcol = 0;
542                         for(var i = 0, len = r.length; i < len; i++){
543                             group = r[i];
544                             if(col >= gcol && col < gcol + group.colspan){
545                                 break;
546                             }
547                             gcol += group.colspan;
548                         }
549                         if(item.checked){
550                             var max = cm.getColumnsBy(this.isHideableColumn, this).length;
551                             for(var i = gcol, len = gcol + group.colspan; i < len; i++){
552                                 if(!cm.isHidden(i)){
553                                     max--;
554                                 }
555                             }
556                             if(max < 1){
557                                 this.onDenyColumnHide();
558                                 return false;
559                             }
560                         }
561                         for(var i = gcol, len = gcol + group.colspan; i < len; i++){
562                             if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
563                                 cm.setHidden(i, item.checked);
564                             }
565                         }
566                     }else{
567                         index = cm.getIndexById(id.substr(4));
568                         if(index != -1){
569                             if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
570                                 this.onDenyColumnHide();
571                                 return false;
572                             }
573                             cm.setHidden(index, item.checked);
574                         }
575                     }
576                     item.checked = !item.checked;
577                     if(item.menu){
578                         var updateChildren = function(menu){
579                             menu.items.each(function(childItem){
580                                 if(!childItem.disabled){
581                                     childItem.setChecked(item.checked, false);
582                                     if(childItem.menu){
583                                         updateChildren(childItem.menu);
584                                     }
585                                 }
586                             });
587                         }
588                         updateChildren(item.menu);
589                     }
590                     var parentMenu = item, parentItem;
591                     while(parentMenu = parentMenu.parentMenu){
592                         if(!parentMenu.parentMenu || !(parentItem = parentMenu.parentMenu.items.get(parentMenu.getItemId())) || !parentItem.setChecked){
593                             break;
594                         }
595                         var checked = parentMenu.items.findIndexBy(function(m){
596                             return m.checked;
597                         }) >= 0;
598                         parentItem.setChecked(checked, true);
599                     }
600                     item.checked = !item.checked;
601             }
602             return true;
603         },
604
605         beforeColMenuShow: function(){
606             var cm = this.cm, rows = this.cm.rows;
607             this.colMenu.removeAll();
608             for(var col = 0, clen = cm.getColumnCount(); col < clen; col++){
609                 var menu = this.colMenu, title = cm.getColumnHeader(col), text = [];
610                 if(cm.config[col].fixed !== true && cm.config[col].hideable !== false){
611                     for(var row = 0, rlen = rows.length; row < rlen; row++){
612                         var r = rows[row], group, gcol = 0;
613                         for(var i = 0, len = r.length; i < len; i++){
614                             group = r[i];
615                             if(col >= gcol && col < gcol + group.colspan){
616                                 break;
617                             }
618                             gcol += group.colspan;
619                         }
620                         if(group && group.header){
621                             if(cm.hierarchicalColMenu){
622                                 var gid = 'group-' + row + '-' + gcol;
623                                 var item = menu.items.item(gid);
624                                 var submenu = item ? item.menu : null;
625                                 if(!submenu){
626                                     submenu = new Ext.menu.Menu({
627                                         itemId: gid
628                                     });
629                                     submenu.on("itemclick", this.handleHdMenuClick, this);
630                                     var checked = false, disabled = true;
631                                     for(var c = gcol, lc = gcol + group.colspan; c < lc; c++){
632                                         if(!cm.isHidden(c)){
633                                             checked = true;
634                                         }
635                                         if(cm.config[c].hideable !== false){
636                                             disabled = false;
637                                         }
638                                     }
639                                     menu.add({
640                                         itemId: gid,
641                                         text: group.header,
642                                         menu: submenu,
643                                         hideOnClick: false,
644                                         checked: checked,
645                                         disabled: disabled
646                                     });
647                                 }
648                                 menu = submenu;
649                             }else{
650                                 text.push(group.header);
651                             }
652                         }
653                     }
654                     text.push(title);
655                     menu.add(new Ext.menu.CheckItem({
656                         itemId: "col-" + cm.getColumnId(col),
657                         text: text.join(' '),
658                         checked: !cm.isHidden(col),
659                         hideOnClick: false,
660                         disabled: cm.config[col].hideable === false
661                     }));
662                 }
663             }
664         },
665
666         renderUI: function(){
667             this.constructor.prototype.renderUI.apply(this, arguments);
668             Ext.apply(this.columnDrop, Ext.ux.grid.ColumnHeaderGroup.prototype.columnDropConfig);
669             Ext.apply(this.splitZone, Ext.ux.grid.ColumnHeaderGroup.prototype.splitZoneConfig);
670         }
671     },
672
673     splitZoneConfig: {
674         allowHeaderDrag: function(e){
675             return !e.getTarget(null, null, true).hasClass('ux-grid-hd-group-cell');
676         }
677     },
678
679     columnDropConfig: {
680         getTargetFromEvent: function(e){
681             var t = Ext.lib.Event.getTarget(e);
682             return this.view.findHeaderCell(t);
683         },
684
685         positionIndicator: function(h, n, e){
686             var data = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
687             if(data === false){
688                 return false;
689             }
690             var px = data.px + this.proxyOffsets[0];
691             this.proxyTop.setLeftTop(px, data.r.top + this.proxyOffsets[1]);
692             this.proxyTop.show();
693             this.proxyBottom.setLeftTop(px, data.r.bottom);
694             this.proxyBottom.show();
695             return data.pt;
696         },
697
698         onNodeDrop: function(n, dd, e, data){
699             var h = data.header;
700             if(h != n){
701                 var d = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
702                 if(d === false){
703                     return false;
704                 }
705                 var cm = this.grid.colModel, right = d.oldIndex < d.newIndex, rows = cm.rows;
706                 for(var row = d.row, rlen = rows.length; row < rlen; row++){
707                     var r = rows[row], len = r.length, fromIx = 0, span = 1, toIx = len;
708                     for(var i = 0, gcol = 0; i < len; i++){
709                         var group = r[i];
710                         if(d.oldIndex >= gcol && d.oldIndex < gcol + group.colspan){
711                             fromIx = i;
712                         }
713                         if(d.oldIndex + d.colspan - 1 >= gcol && d.oldIndex + d.colspan - 1 < gcol + group.colspan){
714                             span = i - fromIx + 1;
715                         }
716                         if(d.newIndex >= gcol && d.newIndex < gcol + group.colspan){
717                             toIx = i;
718                         }
719                         gcol += group.colspan;
720                     }
721                     var groups = r.splice(fromIx, span);
722                     rows[row] = r.splice(0, toIx - (right ? span : 0)).concat(groups).concat(r);
723                 }
724                 for(var c = 0; c < d.colspan; c++){
725                     var oldIx = d.oldIndex + (right ? 0 : c), newIx = d.newIndex + (right ? -1 : c);
726                     cm.moveColumn(oldIx, newIx);
727                     this.grid.fireEvent("columnmove", oldIx, newIx);
728                 }
729                 return true;
730             }
731             return false;
732         }
733     },
734
735     getGroupStyle: function(group, gcol){
736         var width = 0, hidden = true;
737         for(var i = gcol, len = gcol + group.colspan; i < len; i++){
738             if(!this.cm.isHidden(i)){
739                 var cw = this.cm.getColumnWidth(i);
740                 if(typeof cw == 'number'){
741                     width += cw;
742                 }
743                 hidden = false;
744             }
745         }
746         return {
747             width: (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? width : Math.max(width - this.borderWidth, 0)) + 'px',
748             hidden: hidden
749         };
750     },
751
752     updateGroupStyles: function(col){
753         var tables = this.mainHd.query('.x-grid3-header-offset > table'), tw = this.getTotalWidth(), rows = this.cm.rows;
754         for(var row = 0; row < tables.length; row++){
755             tables[row].style.width = tw;
756             if(row < rows.length){
757                 var cells = tables[row].firstChild.firstChild.childNodes;
758                 for(var i = 0, gcol = 0; i < cells.length; i++){
759                     var group = rows[row][i];
760                     if((typeof col != 'number') || (col >= gcol && col < gcol + group.colspan)){
761                         var gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
762                         cells[i].style.width = gs.width;
763                         cells[i].style.display = gs.hidden ? 'none' : '';
764                     }
765                     gcol += group.colspan;
766                 }
767             }
768         }
769     },
770
771     getGroupRowIndex: function(el){
772         if(el){
773             var m = el.className.match(this.hrowRe);
774             if(m && m[1]){
775                 return parseInt(m[1], 10);
776             }
777         }
778         return this.cm.rows.length;
779     },
780
781     getGroupSpan: function(row, col){
782         if(row < 0){
783             return {
784                 col: 0,
785                 colspan: this.cm.getColumnCount()
786             };
787         }
788         var r = this.cm.rows[row];
789         if(r){
790             for(var i = 0, gcol = 0, len = r.length; i < len; i++){
791                 var group = r[i];
792                 if(col >= gcol && col < gcol + group.colspan){
793                     return {
794                         col: gcol,
795                         colspan: group.colspan
796                     };
797                 }
798                 gcol += group.colspan;
799             }
800             return {
801                 col: gcol,
802                 colspan: 0
803             };
804         }
805         return {
806             col: col,
807             colspan: 1
808         };
809     },
810
811     getDragDropData: function(h, n, e){
812         if(h.parentNode != n.parentNode){
813             return false;
814         }
815         var cm = this.grid.colModel, x = Ext.lib.Event.getPageX(e), r = Ext.lib.Dom.getRegion(n.firstChild), px, pt;
816         if((r.right - x) <= (r.right - r.left) / 2){
817             px = r.right + this.view.borderWidth;
818             pt = "after";
819         }else{
820             px = r.left;
821             pt = "before";
822         }
823         var oldIndex = this.view.getCellIndex(h), newIndex = this.view.getCellIndex(n);
824         if(cm.isFixed(newIndex)){
825             return false;
826         }
827         var row = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupRowIndex.call(this.view, h),
828             oldGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, oldIndex),
829             newGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, newIndex),
830             oldIndex = oldGroup.col;
831             newIndex = newGroup.col + (pt == "after" ? newGroup.colspan : 0);
832         if(newIndex >= oldGroup.col && newIndex <= oldGroup.col + oldGroup.colspan){
833             return false;
834         }
835         var parentGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row - 1, oldIndex);
836         if(newIndex < parentGroup.col || newIndex > parentGroup.col + parentGroup.colspan){
837             return false;
838         }
839         return {
840             r: r,
841             px: px,
842             pt: pt,
843             row: row,
844             oldIndex: oldIndex,
845             newIndex: newIndex,
846             colspan: oldGroup.colspan
847         };
848     }
849 });Ext.ns('Ext.ux.tree');
850
851 /**
852  * @class Ext.ux.tree.ColumnTree
853  * @extends Ext.tree.TreePanel
854  * 
855  * @xtype columntree
856  */
857 Ext.ux.tree.ColumnTree = Ext.extend(Ext.tree.TreePanel, {
858     lines : false,
859     borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
860     cls : 'x-column-tree',
861
862     onRender : function(){
863         Ext.tree.ColumnTree.superclass.onRender.apply(this, arguments);
864         this.headers = this.header.createChild({cls:'x-tree-headers'});
865
866         var cols = this.columns, c;
867         var totalWidth = 0;
868         var scrollOffset = 19; // similar to Ext.grid.GridView default
869
870         for(var i = 0, len = cols.length; i < len; i++){
871              c = cols[i];
872              totalWidth += c.width;
873              this.headers.createChild({
874                  cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
875                  cn: {
876                      cls:'x-tree-hd-text',
877                      html: c.header
878                  },
879                  style:'width:'+(c.width-this.borderWidth)+'px;'
880              });
881         }
882         this.headers.createChild({cls:'x-clear'});
883         // prevent floats from wrapping when clipped
884         this.headers.setWidth(totalWidth+scrollOffset);
885         this.innerCt.setWidth(totalWidth);
886     }
887 });
888
889 Ext.reg('columntree', Ext.ux.tree.ColumnTree);
890
891 //backwards compat
892 Ext.tree.ColumnTree = Ext.ux.tree.ColumnTree;
893
894
895 /**
896  * @class Ext.ux.tree.ColumnNodeUI
897  * @extends Ext.tree.TreeNodeUI
898  */
899 Ext.ux.tree.ColumnNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
900     focus: Ext.emptyFn, // prevent odd scrolling behavior
901
902     renderElements : function(n, a, targetNode, bulkRender){
903         this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
904
905         var t = n.getOwnerTree();
906         var cols = t.columns;
907         var bw = t.borderWidth;
908         var c = cols[0];
909
910         var buf = [
911              '<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf ', a.cls,'">',
912                 '<div class="x-tree-col" style="width:',c.width-bw,'px;">',
913                     '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
914                     '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
915                     '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on">',
916                     '<a hidefocus="on" class="x-tree-node-anchor" href="',a.href ? a.href : "#",'" tabIndex="1" ',
917                     a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '>',
918                     '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</span></a>",
919                 "</div>"];
920          for(var i = 1, len = cols.length; i < len; i++){
921              c = cols[i];
922
923              buf.push('<div class="x-tree-col ',(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
924                         '<div class="x-tree-col-text">',(c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</div>",
925                       "</div>");
926          }
927          buf.push(
928             '<div class="x-clear"></div></div>',
929             '<ul class="x-tree-node-ct" style="display:none;"></ul>',
930             "</li>");
931
932         if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
933             this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
934                                 n.nextSibling.ui.getEl(), buf.join(""));
935         }else{
936             this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
937         }
938
939         this.elNode = this.wrap.childNodes[0];
940         this.ctNode = this.wrap.childNodes[1];
941         var cs = this.elNode.firstChild.childNodes;
942         this.indentNode = cs[0];
943         this.ecNode = cs[1];
944         this.iconNode = cs[2];
945         this.anchor = cs[3];
946         this.textNode = cs[3].firstChild;
947     }
948 });
949
950 //backwards compat
951 Ext.tree.ColumnNodeUI = Ext.ux.tree.ColumnNodeUI;
952 /**
953  * @class Ext.DataView.LabelEditor
954  * @extends Ext.Editor
955  * 
956  */
957 Ext.DataView.LabelEditor = Ext.extend(Ext.Editor, {
958     alignment: "tl-tl",
959     hideEl : false,
960     cls: "x-small-editor",
961     shim: false,
962     completeOnEnter: true,
963     cancelOnEsc: true,
964     labelSelector: 'span.x-editable',
965     
966     constructor: function(cfg, field){
967         Ext.DataView.LabelEditor.superclass.constructor.call(this,
968             field || new Ext.form.TextField({
969                 allowBlank: false,
970                 growMin:90,
971                 growMax:240,
972                 grow:true,
973                 selectOnFocus:true
974             }), cfg
975         );
976     },
977     
978     init : function(view){
979         this.view = view;
980         view.on('render', this.initEditor, this);
981         this.on('complete', this.onSave, this);
982     },
983
984     initEditor : function(){
985         this.view.on({
986             scope: this,
987             containerclick: this.doBlur,
988             click: this.doBlur
989         });
990         this.view.getEl().on('mousedown', this.onMouseDown, this, {delegate: this.labelSelector});
991     },
992     
993     doBlur: function(){
994         if(this.editing){
995             this.field.blur();
996         }
997     },
998
999     onMouseDown : function(e, target){
1000         if(!e.ctrlKey && !e.shiftKey){
1001             var item = this.view.findItemFromChild(target);
1002             e.stopEvent();
1003             var record = this.view.store.getAt(this.view.indexOf(item));
1004             this.startEdit(target, record.data[this.dataIndex]);
1005             this.activeRecord = record;
1006         }else{
1007             e.preventDefault();
1008         }
1009     },
1010
1011     onSave : function(ed, value){
1012         this.activeRecord.set(this.dataIndex, value);
1013     }
1014 });
1015
1016
1017 Ext.DataView.DragSelector = function(cfg){
1018     cfg = cfg || {};
1019     var view, proxy, tracker;
1020     var rs, bodyRegion, dragRegion = new Ext.lib.Region(0,0,0,0);
1021     var dragSafe = cfg.dragSafe === true;
1022
1023     this.init = function(dataView){
1024         view = dataView;
1025         view.on('render', onRender);
1026     };
1027
1028     function fillRegions(){
1029         rs = [];
1030         view.all.each(function(el){
1031             rs[rs.length] = el.getRegion();
1032         });
1033         bodyRegion = view.el.getRegion();
1034     }
1035
1036     function cancelClick(){
1037         return false;
1038     }
1039
1040     function onBeforeStart(e){
1041         return !dragSafe || e.target == view.el.dom;
1042     }
1043
1044     function onStart(e){
1045         view.on('containerclick', cancelClick, view, {single:true});
1046         if(!proxy){
1047             proxy = view.el.createChild({cls:'x-view-selector'});
1048         }else{
1049             if(proxy.dom.parentNode !== view.el.dom){
1050                 view.el.dom.appendChild(proxy.dom);
1051             }
1052             proxy.setDisplayed('block');
1053         }
1054         fillRegions();
1055         view.clearSelections();
1056     }
1057
1058     function onDrag(e){
1059         var startXY = tracker.startXY;
1060         var xy = tracker.getXY();
1061
1062         var x = Math.min(startXY[0], xy[0]);
1063         var y = Math.min(startXY[1], xy[1]);
1064         var w = Math.abs(startXY[0] - xy[0]);
1065         var h = Math.abs(startXY[1] - xy[1]);
1066
1067         dragRegion.left = x;
1068         dragRegion.top = y;
1069         dragRegion.right = x+w;
1070         dragRegion.bottom = y+h;
1071
1072         dragRegion.constrainTo(bodyRegion);
1073         proxy.setRegion(dragRegion);
1074
1075         for(var i = 0, len = rs.length; i < len; i++){
1076             var r = rs[i], sel = dragRegion.intersect(r);
1077             if(sel && !r.selected){
1078                 r.selected = true;
1079                 view.select(i, true);
1080             }else if(!sel && r.selected){
1081                 r.selected = false;
1082                 view.deselect(i);
1083             }
1084         }
1085     }
1086
1087     function onEnd(e){
1088         if (!Ext.isIE) {
1089             view.un('containerclick', cancelClick, view);    
1090         }        
1091         if(proxy){
1092             proxy.setDisplayed(false);
1093         }
1094     }
1095
1096     function onRender(view){
1097         tracker = new Ext.dd.DragTracker({
1098             onBeforeStart: onBeforeStart,
1099             onStart: onStart,
1100             onDrag: onDrag,
1101             onEnd: onEnd
1102         });
1103         tracker.initEl(view.el);
1104     }
1105 };Ext.ns('Ext.ux.form');
1106
1107 /**
1108  * @class Ext.ux.form.FileUploadField
1109  * @extends Ext.form.TextField
1110  * Creates a file upload field.
1111  * @xtype fileuploadfield
1112  */
1113 Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField,  {
1114     /**
1115      * @cfg {String} buttonText The button text to display on the upload button (defaults to
1116      * 'Browse...').  Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
1117      * value will be used instead if available.
1118      */
1119     buttonText: 'Browse...',
1120     /**
1121      * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
1122      * text field (defaults to false).  If true, all inherited TextField members will still be available.
1123      */
1124     buttonOnly: false,
1125     /**
1126      * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
1127      * (defaults to 3).  Note that this only applies if {@link #buttonOnly} = false.
1128      */
1129     buttonOffset: 3,
1130     /**
1131      * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
1132      */
1133
1134     // private
1135     readOnly: true,
1136
1137     /**
1138      * @hide
1139      * @method autoSize
1140      */
1141     autoSize: Ext.emptyFn,
1142
1143     // private
1144     initComponent: function(){
1145         Ext.ux.form.FileUploadField.superclass.initComponent.call(this);
1146
1147         this.addEvents(
1148             /**
1149              * @event fileselected
1150              * Fires when the underlying file input field's value has changed from the user
1151              * selecting a new file from the system file selection dialog.
1152              * @param {Ext.ux.form.FileUploadField} this
1153              * @param {String} value The file value returned by the underlying file input field
1154              */
1155             'fileselected'
1156         );
1157     },
1158
1159     // private
1160     onRender : function(ct, position){
1161         Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct, position);
1162
1163         this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
1164         this.el.addClass('x-form-file-text');
1165         this.el.dom.removeAttribute('name');
1166         this.createFileInput();
1167
1168         var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
1169             text: this.buttonText
1170         });
1171         this.button = new Ext.Button(Ext.apply(btnCfg, {
1172             renderTo: this.wrap,
1173             cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
1174         }));
1175
1176         if(this.buttonOnly){
1177             this.el.hide();
1178             this.wrap.setWidth(this.button.getEl().getWidth());
1179         }
1180
1181         this.bindListeners();
1182         this.resizeEl = this.positionEl = this.wrap;
1183     },
1184     
1185     bindListeners: function(){
1186         this.fileInput.on({
1187             scope: this,
1188             mouseenter: function() {
1189                 this.button.addClass(['x-btn-over','x-btn-focus'])
1190             },
1191             mouseleave: function(){
1192                 this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
1193             },
1194             mousedown: function(){
1195                 this.button.addClass('x-btn-click')
1196             },
1197             mouseup: function(){
1198                 this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
1199             },
1200             change: function(){
1201                 var v = this.fileInput.dom.value;
1202                 this.setValue(v);
1203                 this.fireEvent('fileselected', this, v);    
1204             }
1205         }); 
1206     },
1207     
1208     createFileInput : function() {
1209         this.fileInput = this.wrap.createChild({
1210             id: this.getFileInputId(),
1211             name: this.name||this.getId(),
1212             cls: 'x-form-file',
1213             tag: 'input',
1214             type: 'file',
1215             size: 1
1216         });
1217     },
1218     
1219     reset : function(){
1220         this.fileInput.remove();
1221         this.createFileInput();
1222         this.bindListeners();
1223         Ext.ux.form.FileUploadField.superclass.reset.call(this);
1224     },
1225
1226     // private
1227     getFileInputId: function(){
1228         return this.id + '-file';
1229     },
1230
1231     // private
1232     onResize : function(w, h){
1233         Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
1234
1235         this.wrap.setWidth(w);
1236
1237         if(!this.buttonOnly){
1238             var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
1239             this.el.setWidth(w);
1240         }
1241     },
1242
1243     // private
1244     onDestroy: function(){
1245         Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
1246         Ext.destroy(this.fileInput, this.button, this.wrap);
1247     },
1248     
1249     onDisable: function(){
1250         Ext.ux.form.FileUploadField.superclass.onDisable.call(this);
1251         this.doDisable(true);
1252     },
1253     
1254     onEnable: function(){
1255         Ext.ux.form.FileUploadField.superclass.onEnable.call(this);
1256         this.doDisable(false);
1257
1258     },
1259     
1260     // private
1261     doDisable: function(disabled){
1262         this.fileInput.dom.disabled = disabled;
1263         this.button.setDisabled(disabled);
1264     },
1265
1266
1267     // private
1268     preFocus : Ext.emptyFn,
1269
1270     // private
1271     alignErrorIcon : function(){
1272         this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
1273     }
1274
1275 });
1276
1277 Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
1278
1279 // backwards compat
1280 Ext.form.FileUploadField = Ext.ux.form.FileUploadField;
1281 /**
1282  * @class Ext.ux.GMapPanel
1283  * @extends Ext.Panel
1284  * @author Shea Frederick
1285  */
1286 Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
1287     initComponent : function(){
1288         
1289         var defConfig = {
1290             plain: true,
1291             zoomLevel: 3,
1292             yaw: 180,
1293             pitch: 0,
1294             zoom: 0,
1295             gmapType: 'map',
1296             border: false
1297         };
1298         
1299         Ext.applyIf(this,defConfig);
1300         
1301         Ext.ux.GMapPanel.superclass.initComponent.call(this);        
1302
1303     },
1304     afterRender : function(){
1305         
1306         var wh = this.ownerCt.getSize();
1307         Ext.applyIf(this, wh);
1308         
1309         Ext.ux.GMapPanel.superclass.afterRender.call(this);    
1310         
1311         if (this.gmapType === 'map'){
1312             this.gmap = new GMap2(this.body.dom);
1313         }
1314         
1315         if (this.gmapType === 'panorama'){
1316             this.gmap = new GStreetviewPanorama(this.body.dom);
1317         }
1318         
1319         if (typeof this.addControl == 'object' && this.gmapType === 'map') {
1320             this.gmap.addControl(this.addControl);
1321         }
1322         
1323         if (typeof this.setCenter === 'object') {
1324             if (typeof this.setCenter.geoCodeAddr === 'string'){
1325                 this.geoCodeLookup(this.setCenter.geoCodeAddr);
1326             }else{
1327                 if (this.gmapType === 'map'){
1328                     var point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
1329                     this.gmap.setCenter(point, this.zoomLevel);    
1330                 }
1331                 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
1332                     this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
1333                 }
1334             }
1335             if (this.gmapType === 'panorama'){
1336                 this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
1337             }
1338         }
1339
1340         GEvent.bind(this.gmap, 'load', this, function(){
1341             this.onMapReady();
1342         });
1343
1344     },
1345     onMapReady : function(){
1346         this.addMarkers(this.markers);
1347         this.addMapControls();
1348         this.addOptions();  
1349     },
1350     onResize : function(w, h){
1351
1352         if (typeof this.getMap() == 'object') {
1353             this.gmap.checkResize();
1354         }
1355         
1356         Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);
1357
1358     },
1359     setSize : function(width, height, animate){
1360         
1361         if (typeof this.getMap() == 'object') {
1362             this.gmap.checkResize();
1363         }
1364         
1365         Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
1366         
1367     },
1368     getMap : function(){
1369         
1370         return this.gmap;
1371         
1372     },
1373     getCenter : function(){
1374         
1375         return this.getMap().getCenter();
1376         
1377     },
1378     getCenterLatLng : function(){
1379         
1380         var ll = this.getCenter();
1381         return {lat: ll.lat(), lng: ll.lng()};
1382         
1383     },
1384     addMarkers : function(markers) {
1385         
1386         if (Ext.isArray(markers)){
1387             for (var i = 0; i < markers.length; i++) {
1388                 var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
1389                 this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
1390             }
1391         }
1392         
1393     },
1394     addMarker : function(point, marker, clear, center, listeners){
1395         
1396         Ext.applyIf(marker,G_DEFAULT_ICON);
1397
1398         if (clear === true){
1399             this.getMap().clearOverlays();
1400         }
1401         if (center === true) {
1402             this.getMap().setCenter(point, this.zoomLevel);
1403         }
1404
1405         var mark = new GMarker(point,marker);
1406         if (typeof listeners === 'object'){
1407             for (evt in listeners) {
1408                 GEvent.bind(mark, evt, this, listeners[evt]);
1409             }
1410         }
1411         this.getMap().addOverlay(mark);
1412
1413     },
1414     addMapControls : function(){
1415         
1416         if (this.gmapType === 'map') {
1417             if (Ext.isArray(this.mapControls)) {
1418                 for(i=0;i<this.mapControls.length;i++){
1419                     this.addMapControl(this.mapControls[i]);
1420                 }
1421             }else if(typeof this.mapControls === 'string'){
1422                 this.addMapControl(this.mapControls);
1423             }else if(typeof this.mapControls === 'object'){
1424                 this.getMap().addControl(this.mapControls);
1425             }
1426         }
1427         
1428     },
1429     addMapControl : function(mc){
1430         
1431         var mcf = window[mc];
1432         if (typeof mcf === 'function') {
1433             this.getMap().addControl(new mcf());
1434         }    
1435         
1436     },
1437     addOptions : function(){
1438         
1439         if (Ext.isArray(this.mapConfOpts)) {
1440             var mc;
1441             for(i=0;i<this.mapConfOpts.length;i++){
1442                 this.addOption(this.mapConfOpts[i]);
1443             }
1444         }else if(typeof this.mapConfOpts === 'string'){
1445             this.addOption(this.mapConfOpts);
1446         }        
1447         
1448     },
1449     addOption : function(mc){
1450         
1451         var mcf = this.getMap()[mc];
1452         if (typeof mcf === 'function') {
1453             this.getMap()[mc]();
1454         }    
1455         
1456     },
1457     geoCodeLookup : function(addr) {
1458         
1459         this.geocoder = new GClientGeocoder();
1460         this.geocoder.getLocations(addr, this.addAddressToMap.createDelegate(this));
1461         
1462     },
1463     addAddressToMap : function(response) {
1464         
1465         if (!response || response.Status.code != 200) {
1466             Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
1467         }else{
1468             place = response.Placemark[0];
1469             addressinfo = place.AddressDetails;
1470             accuracy = addressinfo.Accuracy;
1471             if (accuracy === 0) {
1472                 Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
1473             }else{
1474                 if (accuracy < 7) {
1475                     Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
1476                 }else{
1477                     point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
1478                     if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
1479                         this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);
1480                     }
1481                 }
1482             }
1483         }
1484         
1485     }
1486  
1487 });
1488
1489 Ext.reg('gmappanel', Ext.ux.GMapPanel); Ext.namespace('Ext.ux.grid');
1490
1491 /**
1492  * @class Ext.ux.grid.GridFilters
1493  * @extends Ext.util.Observable
1494  * <p>GridFilter is a plugin (<code>ptype='gridfilters'</code>) for grids that
1495  * allow for a slightly more robust representation of filtering than what is
1496  * provided by the default store.</p>
1497  * <p>Filtering is adjusted by the user using the grid's column header menu
1498  * (this menu can be disabled through configuration). Through this menu users
1499  * can configure, enable, and disable filters for each column.</p>
1500  * <p><b><u>Features:</u></b></p>
1501  * <div class="mdetail-params"><ul>
1502  * <li><b>Filtering implementations</b> :
1503  * <div class="sub-desc">
1504  * Default filtering for Strings, Numeric Ranges, Date Ranges, Lists (which can
1505  * be backed by a Ext.data.Store), and Boolean. Additional custom filter types
1506  * and menus are easily created by extending Ext.ux.grid.filter.Filter.
1507  * </div></li>
1508  * <li><b>Graphical indicators</b> :
1509  * <div class="sub-desc">
1510  * Columns that are filtered have {@link #filterCls a configurable css class}
1511  * applied to the column headers.
1512  * </div></li>
1513  * <li><b>Paging</b> :
1514  * <div class="sub-desc">
1515  * If specified as a plugin to the grid's configured PagingToolbar, the current page
1516  * will be reset to page 1 whenever you update the filters.
1517  * </div></li>
1518  * <li><b>Automatic Reconfiguration</b> :
1519  * <div class="sub-desc">
1520  * Filters automatically reconfigure when the grid 'reconfigure' event fires.
1521  * </div></li>
1522  * <li><b>Stateful</b> :
1523  * Filter information will be persisted across page loads by specifying a
1524  * <code>stateId</code> in the Grid configuration.
1525  * <div class="sub-desc">
1526  * The filter collection binds to the
1527  * <code>{@link Ext.grid.GridPanel#beforestaterestore beforestaterestore}</code>
1528  * and <code>{@link Ext.grid.GridPanel#beforestatesave beforestatesave}</code>
1529  * events in order to be stateful.
1530  * </div></li>
1531  * <li><b>Grid Changes</b> :
1532  * <div class="sub-desc"><ul>
1533  * <li>A <code>filters</code> <i>property</i> is added to the grid pointing to
1534  * this plugin.</li>
1535  * <li>A <code>filterupdate</code> <i>event</i> is added to the grid and is
1536  * fired upon onStateChange completion.</li>
1537  * </ul></div></li>
1538  * <li><b>Server side code examples</b> :
1539  * <div class="sub-desc"><ul>
1540  * <li><a href="http://www.vinylfox.com/extjs/grid-filter-php-backend-code.php">PHP</a> - (Thanks VinylFox)</li>
1541  * <li><a href="http://extjs.com/forum/showthread.php?p=77326#post77326">Ruby on Rails</a> - (Thanks Zyclops)</li>
1542  * <li><a href="http://extjs.com/forum/showthread.php?p=176596#post176596">Ruby on Rails</a> - (Thanks Rotomaul)</li>
1543  * <li><a href="http://www.debatablybeta.com/posts/using-extjss-grid-filtering-with-django/">Python</a> - (Thanks Matt)</li>
1544  * <li><a href="http://mcantrell.wordpress.com/2008/08/22/extjs-grids-and-grails/">Grails</a> - (Thanks Mike)</li>
1545  * </ul></div></li>
1546  * </ul></div>
1547  * <p><b><u>Example usage:</u></b></p>
1548  * <pre><code>
1549 var store = new Ext.data.GroupingStore({
1550     ...
1551 });
1552
1553 var filters = new Ext.ux.grid.GridFilters({
1554     autoReload: false, //don&#39;t reload automatically
1555     local: true, //only filter locally
1556     // filters may be configured through the plugin,
1557     // or in the column definition within the column model configuration
1558     filters: [{
1559         type: 'numeric',
1560         dataIndex: 'id'
1561     }, {
1562         type: 'string',
1563         dataIndex: 'name'
1564     }, {
1565         type: 'numeric',
1566         dataIndex: 'price'
1567     }, {
1568         type: 'date',
1569         dataIndex: 'dateAdded'
1570     }, {
1571         type: 'list',
1572         dataIndex: 'size',
1573         options: ['extra small', 'small', 'medium', 'large', 'extra large'],
1574         phpMode: true
1575     }, {
1576         type: 'boolean',
1577         dataIndex: 'visible'
1578     }]
1579 });
1580 var cm = new Ext.grid.ColumnModel([{
1581     ...
1582 }]);
1583
1584 var grid = new Ext.grid.GridPanel({
1585      ds: store,
1586      cm: cm,
1587      view: new Ext.grid.GroupingView(),
1588      plugins: [filters],
1589      height: 400,
1590      width: 700,
1591      bbar: new Ext.PagingToolbar({
1592          store: store,
1593          pageSize: 15,
1594          plugins: [filters] //reset page to page 1 if filters change
1595      })
1596  });
1597
1598 store.load({params: {start: 0, limit: 15}});
1599
1600 // a filters property is added to the grid
1601 grid.filters
1602  * </code></pre>
1603  */
1604 Ext.ux.grid.GridFilters = Ext.extend(Ext.util.Observable, {
1605     /**
1606      * @cfg {Boolean} autoReload
1607      * Defaults to true, reloading the datasource when a filter change happens.
1608      * Set this to false to prevent the datastore from being reloaded if there
1609      * are changes to the filters.  See <code>{@link updateBuffer}</code>.
1610      */
1611     autoReload : true,
1612     /**
1613      * @cfg {Boolean} encode
1614      * Specify true for {@link #buildQuery} to use Ext.util.JSON.encode to
1615      * encode the filter query parameter sent with a remote request.
1616      * Defaults to false.
1617      */
1618     /**
1619      * @cfg {Array} filters
1620      * An Array of filters config objects. Refer to each filter type class for
1621      * configuration details specific to each filter type. Filters for Strings,
1622      * Numeric Ranges, Date Ranges, Lists, and Boolean are the standard filters
1623      * available.
1624      */
1625     /**
1626      * @cfg {String} filterCls
1627      * The css class to be applied to column headers with active filters.
1628      * Defaults to <tt>'ux-filterd-column'</tt>.
1629      */
1630     filterCls : 'ux-filtered-column',
1631     /**
1632      * @cfg {Boolean} local
1633      * <tt>true</tt> to use Ext.data.Store filter functions (local filtering)
1634      * instead of the default (<tt>false</tt>) server side filtering.
1635      */
1636     local : false,
1637     /**
1638      * @cfg {String} menuFilterText
1639      * defaults to <tt>'Filters'</tt>.
1640      */
1641     menuFilterText : 'Filters',
1642     /**
1643      * @cfg {String} paramPrefix
1644      * The url parameter prefix for the filters.
1645      * Defaults to <tt>'filter'</tt>.
1646      */
1647     paramPrefix : 'filter',
1648     /**
1649      * @cfg {Boolean} showMenu
1650      * Defaults to true, including a filter submenu in the default header menu.
1651      */
1652     showMenu : true,
1653     /**
1654      * @cfg {String} stateId
1655      * Name of the value to be used to store state information.
1656      */
1657     stateId : undefined,
1658     /**
1659      * @cfg {Integer} updateBuffer
1660      * Number of milliseconds to defer store updates since the last filter change.
1661      */
1662     updateBuffer : 500,
1663
1664     /** @private */
1665     constructor : function (config) {
1666         config = config || {};
1667         this.deferredUpdate = new Ext.util.DelayedTask(this.reload, this);
1668         this.filters = new Ext.util.MixedCollection();
1669         this.filters.getKey = function (o) {
1670             return o ? o.dataIndex : null;
1671         };
1672         this.addFilters(config.filters);
1673         delete config.filters;
1674         Ext.apply(this, config);
1675     },
1676
1677     /** @private */
1678     init : function (grid) {
1679         if (grid instanceof Ext.grid.GridPanel) {
1680             this.grid = grid;
1681
1682             this.bindStore(this.grid.getStore(), true);
1683             // assumes no filters were passed in the constructor, so try and use ones from the colModel
1684             if(this.filters.getCount() == 0){
1685                 this.addFilters(this.grid.getColumnModel());
1686             }
1687
1688             this.grid.filters = this;
1689
1690             this.grid.addEvents({'filterupdate': true});
1691
1692             grid.on({
1693                 scope: this,
1694                 beforestaterestore: this.applyState,
1695                 beforestatesave: this.saveState,
1696                 beforedestroy: this.destroy,
1697                 reconfigure: this.onReconfigure
1698             });
1699
1700             if (grid.rendered){
1701                 this.onRender();
1702             } else {
1703                 grid.on({
1704                     scope: this,
1705                     single: true,
1706                     render: this.onRender
1707                 });
1708             }
1709
1710         } else if (grid instanceof Ext.PagingToolbar) {
1711             this.toolbar = grid;
1712         }
1713     },
1714
1715     /**
1716      * @private
1717      * Handler for the grid's beforestaterestore event (fires before the state of the
1718      * grid is restored).
1719      * @param {Object} grid The grid object
1720      * @param {Object} state The hash of state values returned from the StateProvider.
1721      */
1722     applyState : function (grid, state) {
1723         var key, filter;
1724         this.applyingState = true;
1725         this.clearFilters();
1726         if (state.filters) {
1727             for (key in state.filters) {
1728                 filter = this.filters.get(key);
1729                 if (filter) {
1730                     filter.setValue(state.filters[key]);
1731                     filter.setActive(true);
1732                 }
1733             }
1734         }
1735         this.deferredUpdate.cancel();
1736         if (this.local) {
1737             this.reload();
1738         }
1739         delete this.applyingState;
1740         delete state.filters;
1741     },
1742
1743     /**
1744      * Saves the state of all active filters
1745      * @param {Object} grid
1746      * @param {Object} state
1747      * @return {Boolean}
1748      */
1749     saveState : function (grid, state) {
1750         var filters = {};
1751         this.filters.each(function (filter) {
1752             if (filter.active) {
1753                 filters[filter.dataIndex] = filter.getValue();
1754             }
1755         });
1756         return (state.filters = filters);
1757     },
1758
1759     /**
1760      * @private
1761      * Handler called when the grid is rendered
1762      */
1763     onRender : function () {
1764         this.grid.getView().on('refresh', this.onRefresh, this);
1765         this.createMenu();
1766     },
1767
1768     /**
1769      * @private
1770      * Handler called by the grid 'beforedestroy' event
1771      */
1772     destroy : function () {
1773         this.removeAll();
1774         this.purgeListeners();
1775
1776         if(this.filterMenu){
1777             Ext.menu.MenuMgr.unregister(this.filterMenu);
1778             this.filterMenu.destroy();
1779              this.filterMenu = this.menu.menu = null;
1780         }
1781     },
1782
1783     /**
1784      * Remove all filters, permanently destroying them.
1785      */
1786     removeAll : function () {
1787         if(this.filters){
1788             Ext.destroy.apply(Ext, this.filters.items);
1789             // remove all items from the collection
1790             this.filters.clear();
1791         }
1792     },
1793
1794
1795     /**
1796      * Changes the data store bound to this view and refreshes it.
1797      * @param {Store} store The store to bind to this view
1798      */
1799     bindStore : function(store, initial){
1800         if(!initial && this.store){
1801             if (this.local) {
1802                 store.un('load', this.onLoad, this);
1803             } else {
1804                 store.un('beforeload', this.onBeforeLoad, this);
1805             }
1806         }
1807         if(store){
1808             if (this.local) {
1809                 store.on('load', this.onLoad, this);
1810             } else {
1811                 store.on('beforeload', this.onBeforeLoad, this);
1812             }
1813         }
1814         this.store = store;
1815     },
1816
1817     /**
1818      * @private
1819      * Handler called when the grid reconfigure event fires
1820      */
1821     onReconfigure : function () {
1822         this.bindStore(this.grid.getStore());
1823         this.store.clearFilter();
1824         this.removeAll();
1825         this.addFilters(this.grid.getColumnModel());
1826         this.updateColumnHeadings();
1827     },
1828
1829     createMenu : function () {
1830         var view = this.grid.getView(),
1831             hmenu = view.hmenu;
1832
1833         if (this.showMenu && hmenu) {
1834
1835             this.sep  = hmenu.addSeparator();
1836             this.filterMenu = new Ext.menu.Menu({
1837                 id: this.grid.id + '-filters-menu'
1838             });
1839             this.menu = hmenu.add({
1840                 checked: false,
1841                 itemId: 'filters',
1842                 text: this.menuFilterText,
1843                 menu: this.filterMenu
1844             });
1845
1846             this.menu.on({
1847                 scope: this,
1848                 checkchange: this.onCheckChange,
1849                 beforecheckchange: this.onBeforeCheck
1850             });
1851             hmenu.on('beforeshow', this.onMenu, this);
1852         }
1853         this.updateColumnHeadings();
1854     },
1855
1856     /**
1857      * @private
1858      * Get the filter menu from the filters MixedCollection based on the clicked header
1859      */
1860     getMenuFilter : function () {
1861         var view = this.grid.getView();
1862         if (!view || view.hdCtxIndex === undefined) {
1863             return null;
1864         }
1865         return this.filters.get(
1866             view.cm.config[view.hdCtxIndex].dataIndex
1867         );
1868     },
1869
1870     /**
1871      * @private
1872      * Handler called by the grid's hmenu beforeshow event
1873      */
1874     onMenu : function (filterMenu) {
1875         var filter = this.getMenuFilter();
1876
1877         if (filter) {
1878 /*
1879 TODO: lazy rendering
1880             if (!filter.menu) {
1881                 filter.menu = filter.createMenu();
1882             }
1883 */
1884             this.menu.menu = filter.menu;
1885             this.menu.setChecked(filter.active, false);
1886             // disable the menu if filter.disabled explicitly set to true
1887             this.menu.setDisabled(filter.disabled === true);
1888         }
1889
1890         this.menu.setVisible(filter !== undefined);
1891         this.sep.setVisible(filter !== undefined);
1892     },
1893
1894     /** @private */
1895     onCheckChange : function (item, value) {
1896         this.getMenuFilter().setActive(value);
1897     },
1898
1899     /** @private */
1900     onBeforeCheck : function (check, value) {
1901         return !value || this.getMenuFilter().isActivatable();
1902     },
1903
1904     /**
1905      * @private
1906      * Handler for all events on filters.
1907      * @param {String} event Event name
1908      * @param {Object} filter Standard signature of the event before the event is fired
1909      */
1910     onStateChange : function (event, filter) {
1911         if (event === 'serialize') {
1912             return;
1913         }
1914
1915         if (filter == this.getMenuFilter()) {
1916             this.menu.setChecked(filter.active, false);
1917         }
1918
1919         if ((this.autoReload || this.local) && !this.applyingState) {
1920             this.deferredUpdate.delay(this.updateBuffer);
1921         }
1922         this.updateColumnHeadings();
1923
1924         if (!this.applyingState) {
1925             this.grid.saveState();
1926         }
1927         this.grid.fireEvent('filterupdate', this, filter);
1928     },
1929
1930     /**
1931      * @private
1932      * Handler for store's beforeload event when configured for remote filtering
1933      * @param {Object} store
1934      * @param {Object} options
1935      */
1936     onBeforeLoad : function (store, options) {
1937         options.params = options.params || {};
1938         this.cleanParams(options.params);
1939         var params = this.buildQuery(this.getFilterData());
1940         Ext.apply(options.params, params);
1941     },
1942
1943     /**
1944      * @private
1945      * Handler for store's load event when configured for local filtering
1946      * @param {Object} store
1947      * @param {Object} options
1948      */
1949     onLoad : function (store, options) {
1950         store.filterBy(this.getRecordFilter());
1951     },
1952
1953     /**
1954      * @private
1955      * Handler called when the grid's view is refreshed
1956      */
1957     onRefresh : function () {
1958         this.updateColumnHeadings();
1959     },
1960
1961     /**
1962      * Update the styles for the header row based on the active filters
1963      */
1964     updateColumnHeadings : function () {
1965         var view = this.grid.getView(),
1966             i, len, filter;
1967         if (view.mainHd) {
1968             for (i = 0, len = view.cm.config.length; i < len; i++) {
1969                 filter = this.getFilter(view.cm.config[i].dataIndex);
1970                 Ext.fly(view.getHeaderCell(i))[filter && filter.active ? 'addClass' : 'removeClass'](this.filterCls);
1971             }
1972         }
1973     },
1974
1975     /** @private */
1976     reload : function () {
1977         if (this.local) {
1978             this.grid.store.clearFilter(true);
1979             this.grid.store.filterBy(this.getRecordFilter());
1980         } else {
1981             var start,
1982                 store = this.grid.store;
1983             this.deferredUpdate.cancel();
1984             if (this.toolbar) {
1985                 start = store.paramNames.start;
1986                 if (store.lastOptions && store.lastOptions.params && store.lastOptions.params[start]) {
1987                     store.lastOptions.params[start] = 0;
1988                 }
1989             }
1990             store.reload();
1991         }
1992     },
1993
1994     /**
1995      * Method factory that generates a record validator for the filters active at the time
1996      * of invokation.
1997      * @private
1998      */
1999     getRecordFilter : function () {
2000         var f = [], len, i;
2001         this.filters.each(function (filter) {
2002             if (filter.active) {
2003                 f.push(filter);
2004             }
2005         });
2006
2007         len = f.length;
2008         return function (record) {
2009             for (i = 0; i < len; i++) {
2010                 if (!f[i].validateRecord(record)) {
2011                     return false;
2012                 }
2013             }
2014             return true;
2015         };
2016     },
2017
2018     /**
2019      * Adds a filter to the collection and observes it for state change.
2020      * @param {Object/Ext.ux.grid.filter.Filter} config A filter configuration or a filter object.
2021      * @return {Ext.ux.grid.filter.Filter} The existing or newly created filter object.
2022      */
2023     addFilter : function (config) {
2024         var Cls = this.getFilterClass(config.type),
2025             filter = config.menu ? config : (new Cls(config));
2026         this.filters.add(filter);
2027
2028         Ext.util.Observable.capture(filter, this.onStateChange, this);
2029         return filter;
2030     },
2031
2032     /**
2033      * Adds filters to the collection.
2034      * @param {Array/Ext.grid.ColumnModel} filters Either an Array of
2035      * filter configuration objects or an Ext.grid.ColumnModel.  The columns
2036      * of a passed Ext.grid.ColumnModel will be examined for a <code>filter</code>
2037      * property and, if present, will be used as the filter configuration object.
2038      */
2039     addFilters : function (filters) {
2040         if (filters) {
2041             var i, len, filter, cm = false, dI;
2042             if (filters instanceof Ext.grid.ColumnModel) {
2043                 filters = filters.config;
2044                 cm = true;
2045             }
2046             for (i = 0, len = filters.length; i < len; i++) {
2047                 filter = false;
2048                 if (cm) {
2049                     dI = filters[i].dataIndex;
2050                     filter = filters[i].filter || filters[i].filterable;
2051                     if (filter){
2052                         filter = (filter === true) ? {} : filter;
2053                         Ext.apply(filter, {dataIndex:dI});
2054                         // filter type is specified in order of preference:
2055                         //     filter type specified in config
2056                         //     type specified in store's field's type config
2057                         filter.type = filter.type || this.store.fields.get(dI).type;
2058                     }
2059                 } else {
2060                     filter = filters[i];
2061                 }
2062                 // if filter config found add filter for the column
2063                 if (filter) {
2064                     this.addFilter(filter);
2065                 }
2066             }
2067         }
2068     },
2069
2070     /**
2071      * Returns a filter for the given dataIndex, if one exists.
2072      * @param {String} dataIndex The dataIndex of the desired filter object.
2073      * @return {Ext.ux.grid.filter.Filter}
2074      */
2075     getFilter : function (dataIndex) {
2076         return this.filters.get(dataIndex);
2077     },
2078
2079     /**
2080      * Turns all filters off. This does not clear the configuration information
2081      * (see {@link #removeAll}).
2082      */
2083     clearFilters : function () {
2084         this.filters.each(function (filter) {
2085             filter.setActive(false);
2086         });
2087     },
2088
2089     /**
2090      * Returns an Array of the currently active filters.
2091      * @return {Array} filters Array of the currently active filters.
2092      */
2093     getFilterData : function () {
2094         var filters = [], i, len;
2095
2096         this.filters.each(function (f) {
2097             if (f.active) {
2098                 var d = [].concat(f.serialize());
2099                 for (i = 0, len = d.length; i < len; i++) {
2100                     filters.push({
2101                         field: f.dataIndex,
2102                         data: d[i]
2103                     });
2104                 }
2105             }
2106         });
2107         return filters;
2108     },
2109
2110     /**
2111      * Function to take the active filters data and build it into a query.
2112      * The format of the query depends on the <code>{@link #encode}</code>
2113      * configuration:
2114      * <div class="mdetail-params"><ul>
2115      *
2116      * <li><b><tt>false</tt></b> : <i>Default</i>
2117      * <div class="sub-desc">
2118      * Flatten into query string of the form (assuming <code>{@link #paramPrefix}='filters'</code>:
2119      * <pre><code>
2120 filters[0][field]="someDataIndex"&
2121 filters[0][data][comparison]="someValue1"&
2122 filters[0][data][type]="someValue2"&
2123 filters[0][data][value]="someValue3"&
2124      * </code></pre>
2125      * </div></li>
2126      * <li><b><tt>true</tt></b> :
2127      * <div class="sub-desc">
2128      * JSON encode the filter data
2129      * <pre><code>
2130 filters[0][field]="someDataIndex"&
2131 filters[0][data][comparison]="someValue1"&
2132 filters[0][data][type]="someValue2"&
2133 filters[0][data][value]="someValue3"&
2134      * </code></pre>
2135      * </div></li>
2136      * </ul></div>
2137      * Override this method to customize the format of the filter query for remote requests.
2138      * @param {Array} filters A collection of objects representing active filters and their configuration.
2139      *    Each element will take the form of {field: dataIndex, data: filterConf}. dataIndex is not assured
2140      *    to be unique as any one filter may be a composite of more basic filters for the same dataIndex.
2141      * @return {Object} Query keys and values
2142      */
2143     buildQuery : function (filters) {
2144         var p = {}, i, f, root, dataPrefix, key, tmp,
2145             len = filters.length;
2146
2147         if (!this.encode){
2148             for (i = 0; i < len; i++) {
2149                 f = filters[i];
2150                 root = [this.paramPrefix, '[', i, ']'].join('');
2151                 p[root + '[field]'] = f.field;
2152
2153                 dataPrefix = root + '[data]';
2154                 for (key in f.data) {
2155                     p[[dataPrefix, '[', key, ']'].join('')] = f.data[key];
2156                 }
2157             }
2158         } else {
2159             tmp = [];
2160             for (i = 0; i < len; i++) {
2161                 f = filters[i];
2162                 tmp.push(Ext.apply(
2163                     {},
2164                     {field: f.field},
2165                     f.data
2166                 ));
2167             }
2168             // only build if there is active filter
2169             if (tmp.length > 0){
2170                 p[this.paramPrefix] = Ext.util.JSON.encode(tmp);
2171             }
2172         }
2173         return p;
2174     },
2175
2176     /**
2177      * Removes filter related query parameters from the provided object.
2178      * @param {Object} p Query parameters that may contain filter related fields.
2179      */
2180     cleanParams : function (p) {
2181         // if encoding just delete the property
2182         if (this.encode) {
2183             delete p[this.paramPrefix];
2184         // otherwise scrub the object of filter data
2185         } else {
2186             var regex, key;
2187             regex = new RegExp('^' + this.paramPrefix + '\[[0-9]+\]');
2188             for (key in p) {
2189                 if (regex.test(key)) {
2190                     delete p[key];
2191                 }
2192             }
2193         }
2194     },
2195
2196     /**
2197      * Function for locating filter classes, overwrite this with your favorite
2198      * loader to provide dynamic filter loading.
2199      * @param {String} type The type of filter to load ('Filter' is automatically
2200      * appended to the passed type; eg, 'string' becomes 'StringFilter').
2201      * @return {Class} The Ext.ux.grid.filter.Class
2202      */
2203     getFilterClass : function (type) {
2204         // map the supported Ext.data.Field type values into a supported filter
2205         switch(type) {
2206             case 'auto':
2207               type = 'string';
2208               break;
2209             case 'int':
2210             case 'float':
2211               type = 'numeric';
2212               break;
2213         }
2214         return Ext.ux.grid.filter[type.substr(0, 1).toUpperCase() + type.substr(1) + 'Filter'];
2215     }
2216 });
2217
2218 // register ptype
2219 Ext.preg('gridfilters', Ext.ux.grid.GridFilters);
2220 Ext.namespace('Ext.ux.grid.filter');
2221
2222 /** 
2223  * @class Ext.ux.grid.filter.Filter
2224  * @extends Ext.util.Observable
2225  * Abstract base class for filter implementations.
2226  */
2227 Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {
2228     /**
2229      * @cfg {Boolean} active
2230      * Indicates the initial status of the filter (defaults to false).
2231      */
2232     active : false,
2233     /**
2234      * True if this filter is active.  Use setActive() to alter after configuration.
2235      * @type Boolean
2236      * @property active
2237      */
2238     /**
2239      * @cfg {String} dataIndex 
2240      * The {@link Ext.data.Store} dataIndex of the field this filter represents.
2241      * The dataIndex does not actually have to exist in the store.
2242      */
2243     dataIndex : null,
2244     /**
2245      * The filter configuration menu that will be installed into the filter submenu of a column menu.
2246      * @type Ext.menu.Menu
2247      * @property
2248      */
2249     menu : null,
2250     /**
2251      * @cfg {Number} updateBuffer
2252      * Number of milliseconds to wait after user interaction to fire an update. Only supported 
2253      * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
2254      */
2255     updateBuffer : 500,
2256
2257     constructor : function (config) {
2258         Ext.apply(this, config);
2259             
2260         this.addEvents(
2261             /**
2262              * @event activate
2263              * Fires when an inactive filter becomes active
2264              * @param {Ext.ux.grid.filter.Filter} this
2265              */
2266             'activate',
2267             /**
2268              * @event deactivate
2269              * Fires when an active filter becomes inactive
2270              * @param {Ext.ux.grid.filter.Filter} this
2271              */
2272             'deactivate',
2273             /**
2274              * @event serialize
2275              * Fires after the serialization process. Use this to attach additional parameters to serialization
2276              * data before it is encoded and sent to the server.
2277              * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
2278              * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
2279              */
2280             'serialize',
2281             /**
2282              * @event update
2283              * Fires when a filter configuration has changed
2284              * @param {Ext.ux.grid.filter.Filter} this The filter object.
2285              */
2286             'update'
2287         );
2288         Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
2289
2290         this.menu = new Ext.menu.Menu();
2291         this.init(config);
2292         if(config && config.value){
2293             this.setValue(config.value);
2294             this.setActive(config.active !== false, true);
2295             delete config.value;
2296         }
2297     },
2298
2299     /**
2300      * Destroys this filter by purging any event listeners, and removing any menus.
2301      */
2302     destroy : function(){
2303         if (this.menu){
2304             this.menu.destroy();
2305         }
2306         this.purgeListeners();
2307     },
2308
2309     /**
2310      * Template method to be implemented by all subclasses that is to
2311      * initialize the filter and install required menu items.
2312      * Defaults to Ext.emptyFn.
2313      */
2314     init : Ext.emptyFn,
2315     
2316     /**
2317      * Template method to be implemented by all subclasses that is to
2318      * get and return the value of the filter.
2319      * Defaults to Ext.emptyFn.
2320      * @return {Object} The 'serialized' form of this filter
2321      * @methodOf Ext.ux.grid.filter.Filter
2322      */
2323     getValue : Ext.emptyFn,
2324     
2325     /**
2326      * Template method to be implemented by all subclasses that is to
2327      * set the value of the filter and fire the 'update' event.
2328      * Defaults to Ext.emptyFn.
2329      * @param {Object} data The value to set the filter
2330      * @methodOf Ext.ux.grid.filter.Filter
2331      */ 
2332     setValue : Ext.emptyFn,
2333     
2334     /**
2335      * Template method to be implemented by all subclasses that is to
2336      * return <tt>true</tt> if the filter has enough configuration information to be activated.
2337      * Defaults to <tt>return true</tt>.
2338      * @return {Boolean}
2339      */
2340     isActivatable : function(){
2341         return true;
2342     },
2343     
2344     /**
2345      * Template method to be implemented by all subclasses that is to
2346      * get and return serialized filter data for transmission to the server.
2347      * Defaults to Ext.emptyFn.
2348      */
2349     getSerialArgs : Ext.emptyFn,
2350
2351     /**
2352      * Template method to be implemented by all subclasses that is to
2353      * validates the provided Ext.data.Record against the filters configuration.
2354      * Defaults to <tt>return true</tt>.
2355      * @param {Ext.data.Record} record The record to validate
2356      * @return {Boolean} true if the record is valid within the bounds
2357      * of the filter, false otherwise.
2358      */
2359     validateRecord : function(){
2360         return true;
2361     },
2362
2363     /**
2364      * Returns the serialized filter data for transmission to the server
2365      * and fires the 'serialize' event.
2366      * @return {Object/Array} An object or collection of objects containing
2367      * key value pairs representing the current configuration of the filter.
2368      * @methodOf Ext.ux.grid.filter.Filter
2369      */
2370     serialize : function(){
2371         var args = this.getSerialArgs();
2372         this.fireEvent('serialize', args, this);
2373         return args;
2374     },
2375
2376     /** @private */
2377     fireUpdate : function(){
2378         if (this.active) {
2379             this.fireEvent('update', this);
2380         }
2381         this.setActive(this.isActivatable());
2382     },
2383     
2384     /**
2385      * Sets the status of the filter and fires the appropriate events.
2386      * @param {Boolean} active        The new filter state.
2387      * @param {Boolean} suppressEvent True to prevent events from being fired.
2388      * @methodOf Ext.ux.grid.filter.Filter
2389      */
2390     setActive : function(active, suppressEvent){
2391         if(this.active != active){
2392             this.active = active;
2393             if (suppressEvent !== true) {
2394                 this.fireEvent(active ? 'activate' : 'deactivate', this);
2395             }
2396         }
2397     }    
2398 });/** 
2399  * @class Ext.ux.grid.filter.BooleanFilter
2400  * @extends Ext.ux.grid.filter.Filter
2401  * Boolean filters use unique radio group IDs (so you can have more than one!)
2402  * <p><b><u>Example Usage:</u></b></p>
2403  * <pre><code>    
2404 var filters = new Ext.ux.grid.GridFilters({
2405     ...
2406     filters: [{
2407         // required configs
2408         type: 'boolean',
2409         dataIndex: 'visible'
2410
2411         // optional configs
2412         defaultValue: null, // leave unselected (false selected by default)
2413         yesText: 'Yes',     // default
2414         noText: 'No'        // default
2415     }]
2416 });
2417  * </code></pre>
2418  */
2419 Ext.ux.grid.filter.BooleanFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2420         /**
2421          * @cfg {Boolean} defaultValue
2422          * Set this to null if you do not want either option to be checked by default. Defaults to false.
2423          */
2424         defaultValue : false,
2425         /**
2426          * @cfg {String} yesText
2427          * Defaults to 'Yes'.
2428          */
2429         yesText : 'Yes',
2430         /**
2431          * @cfg {String} noText
2432          * Defaults to 'No'.
2433          */
2434         noText : 'No',
2435
2436     /**  
2437      * @private
2438      * Template method that is to initialize the filter and install required menu items.
2439      */
2440     init : function (config) {
2441         var gId = Ext.id();
2442                 this.options = [
2443                         new Ext.menu.CheckItem({text: this.yesText, group: gId, checked: this.defaultValue === true}),
2444                         new Ext.menu.CheckItem({text: this.noText, group: gId, checked: this.defaultValue === false})];
2445                 
2446                 this.menu.add(this.options[0], this.options[1]);
2447                 
2448                 for(var i=0; i<this.options.length; i++){
2449                         this.options[i].on('click', this.fireUpdate, this);
2450                         this.options[i].on('checkchange', this.fireUpdate, this);
2451                 }
2452         },
2453         
2454     /**
2455      * @private
2456      * Template method that is to get and return the value of the filter.
2457      * @return {String} The value of this filter
2458      */
2459     getValue : function () {
2460                 return this.options[0].checked;
2461         },
2462
2463     /**
2464      * @private
2465      * Template method that is to set the value of the filter.
2466      * @param {Object} value The value to set the filter
2467      */ 
2468         setValue : function (value) {
2469                 this.options[value ? 0 : 1].setChecked(true);
2470         },
2471
2472     /**
2473      * @private
2474      * Template method that is to get and return serialized filter data for
2475      * transmission to the server.
2476      * @return {Object/Array} An object or collection of objects containing
2477      * key value pairs representing the current configuration of the filter.
2478      */
2479     getSerialArgs : function () {
2480                 var args = {type: 'boolean', value: this.getValue()};
2481                 return args;
2482         },
2483         
2484     /**
2485      * Template method that is to validate the provided Ext.data.Record
2486      * against the filters configuration.
2487      * @param {Ext.data.Record} record The record to validate
2488      * @return {Boolean} true if the record is valid within the bounds
2489      * of the filter, false otherwise.
2490      */
2491     validateRecord : function (record) {
2492                 return record.get(this.dataIndex) == this.getValue();
2493         }
2494 });/** 
2495  * @class Ext.ux.grid.filter.DateFilter
2496  * @extends Ext.ux.grid.filter.Filter
2497  * Filter by a configurable Ext.menu.DateMenu
2498  * <p><b><u>Example Usage:</u></b></p>
2499  * <pre><code>    
2500 var filters = new Ext.ux.grid.GridFilters({
2501     ...
2502     filters: [{
2503         // required configs
2504         type: 'date',
2505         dataIndex: 'dateAdded',
2506         
2507         // optional configs
2508         dateFormat: 'm/d/Y',  // default
2509         beforeText: 'Before', // default
2510         afterText: 'After',   // default
2511         onText: 'On',         // default
2512         pickerOpts: {
2513             // any DateMenu configs
2514         },
2515
2516         active: true // default is false
2517     }]
2518 });
2519  * </code></pre>
2520  */
2521 Ext.ux.grid.filter.DateFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2522     /**
2523      * @cfg {String} afterText
2524      * Defaults to 'After'.
2525      */
2526     afterText : 'After',
2527     /**
2528      * @cfg {String} beforeText
2529      * Defaults to 'Before'.
2530      */
2531     beforeText : 'Before',
2532     /**
2533      * @cfg {Object} compareMap
2534      * Map for assigning the comparison values used in serialization.
2535      */
2536     compareMap : {
2537         before: 'lt',
2538         after:  'gt',
2539         on:     'eq'
2540     },
2541     /**
2542      * @cfg {String} dateFormat
2543      * The date format to return when using getValue.
2544      * Defaults to 'm/d/Y'.
2545      */
2546     dateFormat : 'm/d/Y',
2547
2548     /**
2549      * @cfg {Date} maxDate
2550      * Allowable date as passed to the Ext.DatePicker
2551      * Defaults to undefined.
2552      */
2553     /**
2554      * @cfg {Date} minDate
2555      * Allowable date as passed to the Ext.DatePicker
2556      * Defaults to undefined.
2557      */
2558     /**
2559      * @cfg {Array} menuItems
2560      * The items to be shown in this menu
2561      * Defaults to:<pre>
2562      * menuItems : ['before', 'after', '-', 'on'],
2563      * </pre>
2564      */
2565     menuItems : ['before', 'after', '-', 'on'],
2566
2567     /**
2568      * @cfg {Object} menuItemCfgs
2569      * Default configuration options for each menu item
2570      */
2571     menuItemCfgs : {
2572         selectOnFocus: true,
2573         width: 125
2574     },
2575
2576     /**
2577      * @cfg {String} onText
2578      * Defaults to 'On'.
2579      */
2580     onText : 'On',
2581     
2582     /**
2583      * @cfg {Object} pickerOpts
2584      * Configuration options for the date picker associated with each field.
2585      */
2586     pickerOpts : {},
2587
2588     /**  
2589      * @private
2590      * Template method that is to initialize the filter and install required menu items.
2591      */
2592     init : function (config) {
2593         var menuCfg, i, len, item, cfg, Cls;
2594
2595         menuCfg = Ext.apply(this.pickerOpts, {
2596             minDate: this.minDate, 
2597             maxDate: this.maxDate, 
2598             format:  this.dateFormat,
2599             listeners: {
2600                 scope: this,
2601                 select: this.onMenuSelect
2602             }
2603         });
2604
2605         this.fields = {};
2606         for (i = 0, len = this.menuItems.length; i < len; i++) {
2607             item = this.menuItems[i];
2608             if (item !== '-') {
2609                 cfg = {
2610                     itemId: 'range-' + item,
2611                     text: this[item + 'Text'],
2612                     menu: new Ext.menu.DateMenu(
2613                         Ext.apply(menuCfg, {
2614                             itemId: item
2615                         })
2616                     ),
2617                     listeners: {
2618                         scope: this,
2619                         checkchange: this.onCheckChange
2620                     }
2621                 };
2622                 Cls = Ext.menu.CheckItem;
2623                 item = this.fields[item] = new Cls(cfg);
2624             }
2625             //this.add(item);
2626             this.menu.add(item);
2627         }
2628     },
2629
2630     onCheckChange : function () {
2631         this.setActive(this.isActivatable());
2632         this.fireEvent('update', this);
2633     },
2634
2635     /**  
2636      * @private
2637      * Handler method called when there is a keyup event on an input
2638      * item of this menu.
2639      */
2640     onInputKeyUp : function (field, e) {
2641         var k = e.getKey();
2642         if (k == e.RETURN && field.isValid()) {
2643             e.stopEvent();
2644             this.menu.hide(true);
2645             return;
2646         }
2647     },
2648
2649     /**
2650      * Handler for when the menu for a field fires the 'select' event
2651      * @param {Object} date
2652      * @param {Object} menuItem
2653      * @param {Object} value
2654      * @param {Object} picker
2655      */
2656     onMenuSelect : function (menuItem, value, picker) {
2657         var fields = this.fields,
2658             field = this.fields[menuItem.itemId];
2659         
2660         field.setChecked(true);
2661         
2662         if (field == fields.on) {
2663             fields.before.setChecked(false, true);
2664             fields.after.setChecked(false, true);
2665         } else {
2666             fields.on.setChecked(false, true);
2667             if (field == fields.after && fields.before.menu.picker.value < value) {
2668                 fields.before.setChecked(false, true);
2669             } else if (field == fields.before && fields.after.menu.picker.value > value) {
2670                 fields.after.setChecked(false, true);
2671             }
2672         }
2673         this.fireEvent('update', this);
2674     },
2675
2676     /**
2677      * @private
2678      * Template method that is to get and return the value of the filter.
2679      * @return {String} The value of this filter
2680      */
2681     getValue : function () {
2682         var key, result = {};
2683         for (key in this.fields) {
2684             if (this.fields[key].checked) {
2685                 result[key] = this.fields[key].menu.picker.getValue();
2686             }
2687         }
2688         return result;
2689     },
2690
2691     /**
2692      * @private
2693      * Template method that is to set the value of the filter.
2694      * @param {Object} value The value to set the filter
2695      * @param {Boolean} preserve true to preserve the checked status
2696      * of the other fields.  Defaults to false, unchecking the
2697      * other fields
2698      */ 
2699     setValue : function (value, preserve) {
2700         var key;
2701         for (key in this.fields) {
2702             if(value[key]){
2703                 this.fields[key].menu.picker.setValue(value[key]);
2704                 this.fields[key].setChecked(true);
2705             } else if (!preserve) {
2706                 this.fields[key].setChecked(false);
2707             }
2708         }
2709         this.fireEvent('update', this);
2710     },
2711
2712     /**
2713      * @private
2714      * Template method that is to return <tt>true</tt> if the filter
2715      * has enough configuration information to be activated.
2716      * @return {Boolean}
2717      */
2718     isActivatable : function () {
2719         var key;
2720         for (key in this.fields) {
2721             if (this.fields[key].checked) {
2722                 return true;
2723             }
2724         }
2725         return false;
2726     },
2727
2728     /**
2729      * @private
2730      * Template method that is to get and return serialized filter data for
2731      * transmission to the server.
2732      * @return {Object/Array} An object or collection of objects containing
2733      * key value pairs representing the current configuration of the filter.
2734      */
2735     getSerialArgs : function () {
2736         var args = [];
2737         for (var key in this.fields) {
2738             if(this.fields[key].checked){
2739                 args.push({
2740                     type: 'date',
2741                     comparison: this.compareMap[key],
2742                     value: this.getFieldValue(key).format(this.dateFormat)
2743                 });
2744             }
2745         }
2746         return args;
2747     },
2748
2749     /**
2750      * Get and return the date menu picker value
2751      * @param {String} item The field identifier ('before', 'after', 'on')
2752      * @return {Date} Gets the current selected value of the date field
2753      */
2754     getFieldValue : function(item){
2755         return this.fields[item].menu.picker.getValue();
2756     },
2757     
2758     /**
2759      * Gets the menu picker associated with the passed field
2760      * @param {String} item The field identifier ('before', 'after', 'on')
2761      * @return {Object} The menu picker
2762      */
2763     getPicker : function(item){
2764         return this.fields[item].menu.picker;
2765     },
2766
2767     /**
2768      * Template method that is to validate the provided Ext.data.Record
2769      * against the filters configuration.
2770      * @param {Ext.data.Record} record The record to validate
2771      * @return {Boolean} true if the record is valid within the bounds
2772      * of the filter, false otherwise.
2773      */
2774     validateRecord : function (record) {
2775         var key,
2776             pickerValue,
2777             val = record.get(this.dataIndex);
2778             
2779         if(!Ext.isDate(val)){
2780             return false;
2781         }
2782         val = val.clearTime(true).getTime();
2783         
2784         for (key in this.fields) {
2785             if (this.fields[key].checked) {
2786                 pickerValue = this.getFieldValue(key).clearTime(true).getTime();
2787                 if (key == 'before' && pickerValue <= val) {
2788                     return false;
2789                 }
2790                 if (key == 'after' && pickerValue >= val) {
2791                     return false;
2792                 }
2793                 if (key == 'on' && pickerValue != val) {
2794                     return false;
2795                 }
2796             }
2797         }
2798         return true;
2799     }
2800 });/** 
2801  * @class Ext.ux.grid.filter.ListFilter
2802  * @extends Ext.ux.grid.filter.Filter
2803  * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load
2804  * their options the first time they are shown. ListFilter utilizes the
2805  * {@link Ext.ux.menu.ListMenu} component.</p>
2806  * <p>Although not shown here, this class accepts all configuration options
2807  * for {@link Ext.ux.menu.ListMenu}.</p>
2808  * 
2809  * <p><b><u>Example Usage:</u></b></p>
2810  * <pre><code>    
2811 var filters = new Ext.ux.grid.GridFilters({
2812     ...
2813     filters: [{
2814         type: 'list',
2815         dataIndex: 'size',
2816         phpMode: true,
2817         // options will be used as data to implicitly creates an ArrayStore
2818         options: ['extra small', 'small', 'medium', 'large', 'extra large']
2819     }]
2820 });
2821  * </code></pre>
2822  * 
2823  */
2824 Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2825
2826     /**
2827      * @cfg {Array} options
2828      * <p><code>data</code> to be used to implicitly create a data store
2829      * to back this list when the data source is <b>local</b>. If the
2830      * data for the list is remote, use the <code>{@link #store}</code>
2831      * config instead.</p>
2832      * <br><p>Each item within the provided array may be in one of the
2833      * following formats:</p>
2834      * <div class="mdetail-params"><ul>
2835      * <li><b>Array</b> :
2836      * <pre><code>
2837 options: [
2838     [11, 'extra small'], 
2839     [18, 'small'],
2840     [22, 'medium'],
2841     [35, 'large'],
2842     [44, 'extra large']
2843 ]
2844      * </code></pre>
2845      * </li>
2846      * <li><b>Object</b> :
2847      * <pre><code>
2848 labelField: 'name', // override default of 'text'
2849 options: [
2850     {id: 11, name:'extra small'}, 
2851     {id: 18, name:'small'}, 
2852     {id: 22, name:'medium'}, 
2853     {id: 35, name:'large'}, 
2854     {id: 44, name:'extra large'} 
2855 ]
2856      * </code></pre>
2857      * </li>
2858      * <li><b>String</b> :
2859      * <pre><code>
2860      * options: ['extra small', 'small', 'medium', 'large', 'extra large']
2861      * </code></pre>
2862      * </li>
2863      */
2864     /**
2865      * @cfg {Boolean} phpMode
2866      * <p>Adjust the format of this filter. Defaults to false.</p>
2867      * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>
2868      * <pre><code>
2869 // phpMode == false (default):
2870 filter[0][data][type] list
2871 filter[0][data][value] value1
2872 filter[0][data][value] value2
2873 filter[0][field] prod 
2874
2875 // phpMode == true:
2876 filter[0][data][type] list
2877 filter[0][data][value] value1, value2
2878 filter[0][field] prod 
2879      * </code></pre>
2880      * When GridFilters <code>@cfg encode = true</code>:
2881      * <pre><code>
2882 // phpMode == false (default):
2883 filter : [{"type":"list","value":["small","medium"],"field":"size"}]
2884
2885 // phpMode == true:
2886 filter : [{"type":"list","value":"small,medium","field":"size"}]
2887      * </code></pre>
2888      */
2889     phpMode : false,
2890     /**
2891      * @cfg {Ext.data.Store} store
2892      * The {@link Ext.data.Store} this list should use as its data source
2893      * when the data source is <b>remote</b>. If the data for the list
2894      * is local, use the <code>{@link #options}</code> config instead.
2895      */
2896
2897     /**  
2898      * @private
2899      * Template method that is to initialize the filter and install required menu items.
2900      * @param {Object} config
2901      */
2902     init : function (config) {
2903         this.dt = new Ext.util.DelayedTask(this.fireUpdate, this);
2904
2905         // if a menu already existed, do clean up first
2906         if (this.menu){
2907             this.menu.destroy();
2908         }
2909         this.menu = new Ext.ux.menu.ListMenu(config);
2910         this.menu.on('checkchange', this.onCheckChange, this);
2911     },
2912     
2913     /**
2914      * @private
2915      * Template method that is to get and return the value of the filter.
2916      * @return {String} The value of this filter
2917      */
2918     getValue : function () {
2919         return this.menu.getSelected();
2920     },
2921     /**
2922      * @private
2923      * Template method that is to set the value of the filter.
2924      * @param {Object} value The value to set the filter
2925      */ 
2926     setValue : function (value) {
2927         this.menu.setSelected(value);
2928         this.fireEvent('update', this);
2929     },
2930
2931     /**
2932      * @private
2933      * Template method that is to return <tt>true</tt> if the filter
2934      * has enough configuration information to be activated.
2935      * @return {Boolean}
2936      */
2937     isActivatable : function () {
2938         return this.getValue().length > 0;
2939     },
2940     
2941     /**
2942      * @private
2943      * Template method that is to get and return serialized filter data for
2944      * transmission to the server.
2945      * @return {Object/Array} An object or collection of objects containing
2946      * key value pairs representing the current configuration of the filter.
2947      */
2948     getSerialArgs : function () {
2949         var args = {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
2950         return args;
2951     },
2952
2953     /** @private */
2954     onCheckChange : function(){
2955         this.dt.delay(this.updateBuffer);
2956     },
2957     
2958     
2959     /**
2960      * Template method that is to validate the provided Ext.data.Record
2961      * against the filters configuration.
2962      * @param {Ext.data.Record} record The record to validate
2963      * @return {Boolean} true if the record is valid within the bounds
2964      * of the filter, false otherwise.
2965      */
2966     validateRecord : function (record) {
2967         return this.getValue().indexOf(record.get(this.dataIndex)) > -1;
2968     }
2969 });/** 
2970  * @class Ext.ux.grid.filter.NumericFilter
2971  * @extends Ext.ux.grid.filter.Filter
2972  * Filters using an Ext.ux.menu.RangeMenu.
2973  * <p><b><u>Example Usage:</u></b></p>
2974  * <pre><code>    
2975 var filters = new Ext.ux.grid.GridFilters({
2976     ...
2977     filters: [{
2978         type: 'numeric',
2979         dataIndex: 'price'
2980     }]
2981 });
2982  * </code></pre> 
2983  */
2984 Ext.ux.grid.filter.NumericFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2985
2986     /**
2987      * @cfg {Object} fieldCls
2988      * The Class to use to construct each field item within this menu
2989      * Defaults to:<pre>
2990      * fieldCls : Ext.form.NumberField
2991      * </pre>
2992      */
2993     fieldCls : Ext.form.NumberField,
2994     /**
2995      * @cfg {Object} fieldCfg
2996      * The default configuration options for any field item unless superseded
2997      * by the <code>{@link #fields}</code> configuration.
2998      * Defaults to:<pre>
2999      * fieldCfg : {}
3000      * </pre>
3001      * Example usage:
3002      * <pre><code>
3003 fieldCfg : {
3004     width: 150,
3005 },
3006      * </code></pre>
3007      */
3008     /**
3009      * @cfg {Object} fields
3010      * The field items may be configured individually
3011      * Defaults to <tt>undefined</tt>.
3012      * Example usage:
3013      * <pre><code>
3014 fields : {
3015     gt: { // override fieldCfg options
3016         width: 200,
3017         fieldCls: Ext.ux.form.CustomNumberField // to override default {@link #fieldCls}
3018     }
3019 },
3020      * </code></pre>
3021      */
3022     /**
3023      * @cfg {Object} iconCls
3024      * The iconCls to be applied to each comparator field item.
3025      * Defaults to:<pre>
3026 iconCls : {
3027     gt : 'ux-rangemenu-gt',
3028     lt : 'ux-rangemenu-lt',
3029     eq : 'ux-rangemenu-eq'
3030 }
3031      * </pre>
3032      */
3033     iconCls : {
3034         gt : 'ux-rangemenu-gt',
3035         lt : 'ux-rangemenu-lt',
3036         eq : 'ux-rangemenu-eq'
3037     },
3038
3039     /**
3040      * @cfg {Object} menuItemCfgs
3041      * Default configuration options for each menu item
3042      * Defaults to:<pre>
3043 menuItemCfgs : {
3044     emptyText: 'Enter Filter Text...',
3045     selectOnFocus: true,
3046     width: 125
3047 }
3048      * </pre>
3049      */
3050     menuItemCfgs : {
3051         emptyText: 'Enter Filter Text...',
3052         selectOnFocus: true,
3053         width: 125
3054     },
3055
3056     /**
3057      * @cfg {Array} menuItems
3058      * The items to be shown in this menu.  Items are added to the menu
3059      * according to their position within this array. Defaults to:<pre>
3060      * menuItems : ['lt','gt','-','eq']
3061      * </pre>
3062      */
3063     menuItems : ['lt', 'gt', '-', 'eq'],
3064
3065     /**  
3066      * @private
3067      * Template method that is to initialize the filter and install required menu items.
3068      */
3069     init : function (config) {
3070         // if a menu already existed, do clean up first
3071         if (this.menu){
3072             this.menu.destroy();
3073         }        
3074         this.menu = new Ext.ux.menu.RangeMenu(Ext.apply(config, {
3075             // pass along filter configs to the menu
3076             fieldCfg : this.fieldCfg || {},
3077             fieldCls : this.fieldCls,
3078             fields : this.fields || {},
3079             iconCls: this.iconCls,
3080             menuItemCfgs: this.menuItemCfgs,
3081             menuItems: this.menuItems,
3082             updateBuffer: this.updateBuffer
3083         }));
3084         // relay the event fired by the menu
3085         this.menu.on('update', this.fireUpdate, this);
3086     },
3087     
3088     /**
3089      * @private
3090      * Template method that is to get and return the value of the filter.
3091      * @return {String} The value of this filter
3092      */
3093     getValue : function () {
3094         return this.menu.getValue();
3095     },
3096
3097     /**
3098      * @private
3099      * Template method that is to set the value of the filter.
3100      * @param {Object} value The value to set the filter
3101      */ 
3102     setValue : function (value) {
3103         this.menu.setValue(value);
3104     },
3105
3106     /**
3107      * @private
3108      * Template method that is to return <tt>true</tt> if the filter
3109      * has enough configuration information to be activated.
3110      * @return {Boolean}
3111      */
3112     isActivatable : function () {
3113         var values = this.getValue();
3114         for (key in values) {
3115             if (values[key] !== undefined) {
3116                 return true;
3117             }
3118         }
3119         return false;
3120     },
3121     
3122     /**
3123      * @private
3124      * Template method that is to get and return serialized filter data for
3125      * transmission to the server.
3126      * @return {Object/Array} An object or collection of objects containing
3127      * key value pairs representing the current configuration of the filter.
3128      */
3129     getSerialArgs : function () {
3130         var key,
3131             args = [],
3132             values = this.menu.getValue();
3133         for (key in values) {
3134             args.push({
3135                 type: 'numeric',
3136                 comparison: key,
3137                 value: values[key]
3138             });
3139         }
3140         return args;
3141     },
3142
3143     /**
3144      * Template method that is to validate the provided Ext.data.Record
3145      * against the filters configuration.
3146      * @param {Ext.data.Record} record The record to validate
3147      * @return {Boolean} true if the record is valid within the bounds
3148      * of the filter, false otherwise.
3149      */
3150     validateRecord : function (record) {
3151         var val = record.get(this.dataIndex),
3152             values = this.getValue();
3153         if (values.eq !== undefined && val != values.eq) {
3154             return false;
3155         }
3156         if (values.lt !== undefined && val >= values.lt) {
3157             return false;
3158         }
3159         if (values.gt !== undefined && val <= values.gt) {
3160             return false;
3161         }
3162         return true;
3163     }
3164 });/** 
3165  * @class Ext.ux.grid.filter.StringFilter
3166  * @extends Ext.ux.grid.filter.Filter
3167  * Filter by a configurable Ext.form.TextField
3168  * <p><b><u>Example Usage:</u></b></p>
3169  * <pre><code>    
3170 var filters = new Ext.ux.grid.GridFilters({
3171     ...
3172     filters: [{
3173         // required configs
3174         type: 'string',
3175         dataIndex: 'name',
3176         
3177         // optional configs
3178         value: 'foo',
3179         active: true, // default is false
3180         iconCls: 'ux-gridfilter-text-icon' // default
3181         // any Ext.form.TextField configs accepted
3182     }]
3183 });
3184  * </code></pre>
3185  */
3186 Ext.ux.grid.filter.StringFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
3187
3188     /**
3189      * @cfg {String} iconCls
3190      * The iconCls to be applied to the menu item.
3191      * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
3192      */
3193     iconCls : 'ux-gridfilter-text-icon',
3194
3195     emptyText: 'Enter Filter Text...',
3196     selectOnFocus: true,
3197     width: 125,
3198     
3199     /**  
3200      * @private
3201      * Template method that is to initialize the filter and install required menu items.
3202      */
3203     init : function (config) {
3204         Ext.applyIf(config, {
3205             enableKeyEvents: true,
3206             iconCls: this.iconCls,
3207             listeners: {
3208                 scope: this,
3209                 keyup: this.onInputKeyUp
3210             }
3211         });
3212
3213         this.inputItem = new Ext.form.TextField(config); 
3214         this.menu.add(this.inputItem);
3215         this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
3216     },
3217     
3218     /**
3219      * @private
3220      * Template method that is to get and return the value of the filter.
3221      * @return {String} The value of this filter
3222      */
3223     getValue : function () {
3224         return this.inputItem.getValue();
3225     },
3226     
3227     /**
3228      * @private
3229      * Template method that is to set the value of the filter.
3230      * @param {Object} value The value to set the filter
3231      */ 
3232     setValue : function (value) {
3233         this.inputItem.setValue(value);
3234         this.fireEvent('update', this);
3235     },
3236
3237     /**
3238      * @private
3239      * Template method that is to return <tt>true</tt> if the filter
3240      * has enough configuration information to be activated.
3241      * @return {Boolean}
3242      */
3243     isActivatable : function () {
3244         return this.inputItem.getValue().length > 0;
3245     },
3246
3247     /**
3248      * @private
3249      * Template method that is to get and return serialized filter data for
3250      * transmission to the server.
3251      * @return {Object/Array} An object or collection of objects containing
3252      * key value pairs representing the current configuration of the filter.
3253      */
3254     getSerialArgs : function () {
3255         return {type: 'string', value: this.getValue()};
3256     },
3257
3258     /**
3259      * Template method that is to validate the provided Ext.data.Record
3260      * against the filters configuration.
3261      * @param {Ext.data.Record} record The record to validate
3262      * @return {Boolean} true if the record is valid within the bounds
3263      * of the filter, false otherwise.
3264      */
3265     validateRecord : function (record) {
3266         var val = record.get(this.dataIndex);
3267
3268         if(typeof val != 'string') {
3269             return (this.getValue().length === 0);
3270         }
3271
3272         return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
3273     },
3274     
3275     /**  
3276      * @private
3277      * Handler method called when there is a keyup event on this.inputItem
3278      */
3279     onInputKeyUp : function (field, e) {
3280         var k = e.getKey();
3281         if (k == e.RETURN && field.isValid()) {
3282             e.stopEvent();
3283             this.menu.hide(true);
3284             return;
3285         }
3286         // restart the timer
3287         this.updateTask.delay(this.updateBuffer);
3288     }
3289 });
3290 Ext.namespace('Ext.ux.menu');
3291
3292 /** 
3293  * @class Ext.ux.menu.ListMenu
3294  * @extends Ext.menu.Menu
3295  * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.
3296  * Although not listed as configuration options for this class, this class
3297  * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.
3298  */
3299 Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
3300     /**
3301      * @cfg {String} labelField
3302      * Defaults to 'text'.
3303      */
3304     labelField :  'text',
3305     /**
3306      * @cfg {String} paramPrefix
3307      * Defaults to 'Loading...'.
3308      */
3309     loadingText : 'Loading...',
3310     /**
3311      * @cfg {Boolean} loadOnShow
3312      * Defaults to true.
3313      */
3314     loadOnShow : true,
3315     /**
3316      * @cfg {Boolean} single
3317      * Specify true to group all items in this list into a single-select
3318      * radio button group. Defaults to false.
3319      */
3320     single : false,
3321
3322     constructor : function (cfg) {
3323         this.selected = [];
3324         this.addEvents(
3325             /**
3326              * @event checkchange
3327              * Fires when there is a change in checked items from this list
3328              * @param {Object} item Ext.menu.CheckItem
3329              * @param {Object} checked The checked value that was set
3330              */
3331             'checkchange'
3332         );
3333       
3334         Ext.ux.menu.ListMenu.superclass.constructor.call(this, cfg = cfg || {});
3335     
3336         if(!cfg.store && cfg.options){
3337             var options = [];
3338             for(var i=0, len=cfg.options.length; i<len; i++){
3339                 var value = cfg.options[i];
3340                 switch(Ext.type(value)){
3341                     case 'array':  options.push(value); break;
3342                     case 'object': options.push([value.id, value[this.labelField]]); break;
3343                     case 'string': options.push([value, value]); break;
3344                 }
3345             }
3346             
3347             this.store = new Ext.data.Store({
3348                 reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]),
3349                 data:   options,
3350                 listeners: {
3351                     'load': this.onLoad,
3352                     scope:  this
3353                 }
3354             });
3355             this.loaded = true;
3356         } else {
3357             this.add({text: this.loadingText, iconCls: 'loading-indicator'});
3358             this.store.on('load', this.onLoad, this);
3359         }
3360     },
3361
3362     destroy : function () {
3363         if (this.store) {
3364             this.store.destroy();    
3365         }
3366         Ext.ux.menu.ListMenu.superclass.destroy.call(this);
3367     },
3368
3369     /**
3370      * Lists will initially show a 'loading' item while the data is retrieved from the store.
3371      * In some cases the loaded data will result in a list that goes off the screen to the
3372      * right (as placement calculations were done with the loading item). This adapter will
3373      * allow show to be called with no arguments to show with the previous arguments and
3374      * thus recalculate the width and potentially hang the menu from the left.
3375      */
3376     show : function () {
3377         var lastArgs = null;
3378         return function(){
3379             if(arguments.length === 0){
3380                 Ext.ux.menu.ListMenu.superclass.show.apply(this, lastArgs);
3381             } else {
3382                 lastArgs = arguments;
3383                 if (this.loadOnShow && !this.loaded) {
3384                     this.store.load();
3385                 }
3386                 Ext.ux.menu.ListMenu.superclass.show.apply(this, arguments);
3387             }
3388         };
3389     }(),
3390     
3391     /** @private */
3392     onLoad : function (store, records) {
3393         var visible = this.isVisible();
3394         this.hide(false);
3395         
3396         this.removeAll(true);
3397         
3398         var gid = this.single ? Ext.id() : null;
3399         for(var i=0, len=records.length; i<len; i++){
3400             var item = new Ext.menu.CheckItem({
3401                 text:    records[i].get(this.labelField), 
3402                 group:   gid,
3403                 checked: this.selected.indexOf(records[i].id) > -1,
3404                 hideOnClick: false});
3405             
3406             item.itemId = records[i].id;
3407             item.on('checkchange', this.checkChange, this);
3408                         
3409             this.add(item);
3410         }
3411         
3412         this.loaded = true;
3413         
3414         if (visible) {
3415             this.show();
3416         }       
3417         this.fireEvent('load', this, records);
3418     },
3419
3420     /**
3421      * Get the selected items.
3422      * @return {Array} selected
3423      */
3424     getSelected : function () {
3425         return this.selected;
3426     },
3427     
3428     /** @private */
3429     setSelected : function (value) {
3430         value = this.selected = [].concat(value);
3431
3432         if (this.loaded) {
3433             this.items.each(function(item){
3434                 item.setChecked(false, true);
3435                 for (var i = 0, len = value.length; i < len; i++) {
3436                     if (item.itemId == value[i]) {
3437                         item.setChecked(true, true);
3438                     }
3439                 }
3440             }, this);
3441         }
3442     },
3443     
3444     /**
3445      * Handler for the 'checkchange' event from an check item in this menu
3446      * @param {Object} item Ext.menu.CheckItem
3447      * @param {Object} checked The checked value that was set
3448      */
3449     checkChange : function (item, checked) {
3450         var value = [];
3451         this.items.each(function(item){
3452             if (item.checked) {
3453                 value.push(item.itemId);
3454             }
3455         },this);
3456         this.selected = value;
3457         
3458         this.fireEvent('checkchange', item, checked);
3459     }    
3460 });Ext.ns('Ext.ux.menu');
3461
3462 /** 
3463  * @class Ext.ux.menu.RangeMenu
3464  * @extends Ext.menu.Menu
3465  * Custom implementation of Ext.menu.Menu that has preconfigured
3466  * items for gt, lt, eq.
3467  * <p><b><u>Example Usage:</u></b></p>
3468  * <pre><code>    
3469
3470  * </code></pre> 
3471  */
3472 Ext.ux.menu.RangeMenu = Ext.extend(Ext.menu.Menu, {
3473
3474     constructor : function (config) {
3475
3476         Ext.ux.menu.RangeMenu.superclass.constructor.call(this, config);
3477
3478         this.addEvents(
3479             /**
3480              * @event update
3481              * Fires when a filter configuration has changed
3482              * @param {Ext.ux.grid.filter.Filter} this The filter object.
3483              */
3484             'update'
3485         );
3486       
3487         this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
3488     
3489         var i, len, item, cfg, Cls;
3490
3491         for (i = 0, len = this.menuItems.length; i < len; i++) {
3492             item = this.menuItems[i];
3493             if (item !== '-') {
3494                 // defaults
3495                 cfg = {
3496                     itemId: 'range-' + item,
3497                     enableKeyEvents: true,
3498                     iconCls: this.iconCls[item] || 'no-icon',
3499                     listeners: {
3500                         scope: this,
3501                         keyup: this.onInputKeyUp
3502                     }
3503                 };
3504                 Ext.apply(
3505                     cfg,
3506                     // custom configs
3507                     Ext.applyIf(this.fields[item] || {}, this.fieldCfg[item]),
3508                     // configurable defaults
3509                     this.menuItemCfgs
3510                 );
3511                 Cls = cfg.fieldCls || this.fieldCls;
3512                 item = this.fields[item] = new Cls(cfg);
3513             }
3514             this.add(item);
3515         }
3516     },
3517
3518     /**
3519      * @private
3520      * called by this.updateTask
3521      */
3522     fireUpdate : function () {
3523         this.fireEvent('update', this);
3524     },
3525     
3526     /**
3527      * Get and return the value of the filter.
3528      * @return {String} The value of this filter
3529      */
3530     getValue : function () {
3531         var result = {}, key, field;
3532         for (key in this.fields) {
3533             field = this.fields[key];
3534             if (field.isValid() && String(field.getValue()).length > 0) {
3535                 result[key] = field.getValue();
3536             }
3537         }
3538         return result;
3539     },
3540   
3541     /**
3542      * Set the value of this menu and fires the 'update' event.
3543      * @param {Object} data The data to assign to this menu
3544      */ 
3545     setValue : function (data) {
3546         var key;
3547         for (key in this.fields) {
3548             this.fields[key].setValue(data[key] !== undefined ? data[key] : '');
3549         }
3550         this.fireEvent('update', this);
3551     },
3552
3553     /**  
3554      * @private
3555      * Handler method called when there is a keyup event on an input
3556      * item of this menu.
3557      */
3558     onInputKeyUp : function (field, e) {
3559         var k = e.getKey();
3560         if (k == e.RETURN && field.isValid()) {
3561             e.stopEvent();
3562             this.hide(true);
3563             return;
3564         }
3565         
3566         if (field == this.fields.eq) {
3567             if (this.fields.gt) {
3568                 this.fields.gt.setValue(null);
3569             }
3570             if (this.fields.lt) {
3571                 this.fields.lt.setValue(null);
3572             }
3573         }
3574         else {
3575             this.fields.eq.setValue(null);
3576         }
3577         
3578         // restart the timer
3579         this.updateTask.delay(this.updateBuffer);
3580     }
3581 });
3582 /*!
3583  * Ext JS Library 3.2.0
3584  * Copyright(c) 2006-2010 Ext JS, Inc.
3585  * licensing@extjs.com
3586  * http://www.extjs.com/license
3587  */
3588 Ext.ns('Ext.ux.grid');
3589
3590 /**
3591  * @class Ext.ux.grid.GroupSummary
3592  * @extends Ext.util.Observable
3593  * A GridPanel plugin that enables dynamic column calculations and a dynamically
3594  * updated grouped summary row.
3595  */
3596 Ext.ux.grid.GroupSummary = Ext.extend(Ext.util.Observable, {
3597     /**
3598      * @cfg {Function} summaryRenderer Renderer example:<pre><code>
3599 summaryRenderer: function(v, params, data){
3600     return ((v === 0 || v > 1) ? '(' + v +' Tasks)' : '(1 Task)');
3601 },
3602      * </code></pre>
3603      */
3604     /**
3605      * @cfg {String} summaryType (Optional) The type of
3606      * calculation to be used for the column.  For options available see
3607      * {@link #Calculations}.
3608      */
3609
3610     constructor : function(config){
3611         Ext.apply(this, config);
3612         Ext.ux.grid.GroupSummary.superclass.constructor.call(this);
3613     },
3614     init : function(grid){
3615         this.grid = grid;
3616         var v = this.view = grid.getView();
3617         v.doGroupEnd = this.doGroupEnd.createDelegate(this);
3618
3619         v.afterMethod('onColumnWidthUpdated', this.doWidth, this);
3620         v.afterMethod('onAllColumnWidthsUpdated', this.doAllWidths, this);
3621         v.afterMethod('onColumnHiddenUpdated', this.doHidden, this);
3622         v.afterMethod('onUpdate', this.doUpdate, this);
3623         v.afterMethod('onRemove', this.doRemove, this);
3624
3625         if(!this.rowTpl){
3626             this.rowTpl = new Ext.Template(
3627                 '<div class="x-grid3-summary-row" style="{tstyle}">',
3628                 '<table class="x-grid3-summary-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
3629                     '<tbody><tr>{cells}</tr></tbody>',
3630                 '</table></div>'
3631             );
3632             this.rowTpl.disableFormats = true;
3633         }
3634         this.rowTpl.compile();
3635
3636         if(!this.cellTpl){
3637             this.cellTpl = new Ext.Template(
3638                 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
3639                 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on">{value}</div>',
3640                 "</td>"
3641             );
3642             this.cellTpl.disableFormats = true;
3643         }
3644         this.cellTpl.compile();
3645     },
3646
3647     /**
3648      * Toggle the display of the summary row on/off
3649      * @param {Boolean} visible <tt>true</tt> to show the summary, <tt>false</tt> to hide the summary.
3650      */
3651     toggleSummaries : function(visible){
3652         var el = this.grid.getGridEl();
3653         if(el){
3654             if(visible === undefined){
3655                 visible = el.hasClass('x-grid-hide-summary');
3656             }
3657             el[visible ? 'removeClass' : 'addClass']('x-grid-hide-summary');
3658         }
3659     },
3660
3661     renderSummary : function(o, cs){
3662         cs = cs || this.view.getColumnData();
3663         var cfg = this.grid.getColumnModel().config,
3664             buf = [], c, p = {}, cf, last = cs.length-1;
3665         for(var i = 0, len = cs.length; i < len; i++){
3666             c = cs[i];
3667             cf = cfg[i];
3668             p.id = c.id;
3669             p.style = c.style;
3670             p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
3671             if(cf.summaryType || cf.summaryRenderer){
3672                 p.value = (cf.summaryRenderer || c.renderer)(o.data[c.name], p, o);
3673             }else{
3674                 p.value = '';
3675             }
3676             if(p.value == undefined || p.value === "") p.value = "&#160;";
3677             buf[buf.length] = this.cellTpl.apply(p);
3678         }
3679
3680         return this.rowTpl.apply({
3681             tstyle: 'width:'+this.view.getTotalWidth()+';',
3682             cells: buf.join('')
3683         });
3684     },
3685
3686     /**
3687      * @private
3688      * @param {Object} rs
3689      * @param {Object} cs
3690      */
3691     calculate : function(rs, cs){
3692         var data = {}, r, c, cfg = this.grid.getColumnModel().config, cf;
3693         for(var j = 0, jlen = rs.length; j < jlen; j++){
3694             r = rs[j];
3695             for(var i = 0, len = cs.length; i < len; i++){
3696                 c = cs[i];
3697                 cf = cfg[i];
3698                 if(cf.summaryType){
3699                     data[c.name] = Ext.ux.grid.GroupSummary.Calculations[cf.summaryType](data[c.name] || 0, r, c.name, data);
3700                 }
3701             }
3702         }
3703         return data;
3704     },
3705
3706     doGroupEnd : function(buf, g, cs, ds, colCount){
3707         var data = this.calculate(g.rs, cs);
3708         buf.push('</div>', this.renderSummary({data: data}, cs), '</div>');
3709     },
3710
3711     doWidth : function(col, w, tw){
3712         if(!this.isGrouped()){
3713             return;
3714         }
3715         var gs = this.view.getGroups(),
3716             len = gs.length,
3717             i = 0,
3718             s;
3719         for(; i < len; ++i){
3720             s = gs[i].childNodes[2];
3721             s.style.width = tw;
3722             s.firstChild.style.width = tw;
3723             s.firstChild.rows[0].childNodes[col].style.width = w;
3724         }
3725     },
3726
3727     doAllWidths : function(ws, tw){
3728         if(!this.isGrouped()){
3729             return;
3730         }
3731         var gs = this.view.getGroups(),
3732             len = gs.length,
3733             i = 0,
3734             j, 
3735             s, 
3736             cells, 
3737             wlen = ws.length;
3738             
3739         for(; i < len; i++){
3740             s = gs[i].childNodes[2];
3741             s.style.width = tw;
3742             s.firstChild.style.width = tw;
3743             cells = s.firstChild.rows[0].childNodes;
3744             for(j = 0; j < wlen; j++){
3745                 cells[j].style.width = ws[j];
3746             }
3747         }
3748     },
3749
3750     doHidden : function(col, hidden, tw){
3751         if(!this.isGrouped()){
3752             return;
3753         }
3754         var gs = this.view.getGroups(),
3755             len = gs.length,
3756             i = 0,
3757             s, 
3758             display = hidden ? 'none' : '';
3759         for(; i < len; i++){
3760             s = gs[i].childNodes[2];
3761             s.style.width = tw;
3762             s.firstChild.style.width = tw;
3763             s.firstChild.rows[0].childNodes[col].style.display = display;
3764         }
3765     },
3766     
3767     isGrouped : function(){
3768         return !Ext.isEmpty(this.grid.getStore().groupField);
3769     },
3770
3771     // Note: requires that all (or the first) record in the
3772     // group share the same group value. Returns false if the group
3773     // could not be found.
3774     refreshSummary : function(groupValue){
3775         return this.refreshSummaryById(this.view.getGroupId(groupValue));
3776     },
3777
3778     getSummaryNode : function(gid){
3779         var g = Ext.fly(gid, '_gsummary');
3780         if(g){
3781             return g.down('.x-grid3-summary-row', true);
3782         }
3783         return null;
3784     },
3785
3786     refreshSummaryById : function(gid){
3787         var g = Ext.getDom(gid);
3788         if(!g){
3789             return false;
3790         }
3791         var rs = [];
3792         this.grid.getStore().each(function(r){
3793             if(r._groupId == gid){
3794                 rs[rs.length] = r;
3795             }
3796         });
3797         var cs = this.view.getColumnData(),
3798             data = this.calculate(rs, cs),
3799             markup = this.renderSummary({data: data}, cs),
3800             existing = this.getSummaryNode(gid);
3801             
3802         if(existing){
3803             g.removeChild(existing);
3804         }
3805         Ext.DomHelper.append(g, markup);
3806         return true;
3807     },
3808
3809     doUpdate : function(ds, record){
3810         this.refreshSummaryById(record._groupId);
3811     },
3812
3813     doRemove : function(ds, record, index, isUpdate){
3814         if(!isUpdate){
3815             this.refreshSummaryById(record._groupId);
3816         }
3817     },
3818
3819     /**
3820      * Show a message in the summary row.
3821      * <pre><code>
3822 grid.on('afteredit', function(){
3823     var groupValue = 'Ext Forms: Field Anchoring';
3824     summary.showSummaryMsg(groupValue, 'Updating Summary...');
3825 });
3826      * </code></pre>
3827      * @param {String} groupValue
3828      * @param {String} msg Text to use as innerHTML for the summary row.
3829      */
3830     showSummaryMsg : function(groupValue, msg){
3831         var gid = this.view.getGroupId(groupValue),
3832              node = this.getSummaryNode(gid);
3833         if(node){
3834             node.innerHTML = '<div class="x-grid3-summary-msg">' + msg + '</div>';
3835         }
3836     }
3837 });
3838
3839 //backwards compat
3840 Ext.grid.GroupSummary = Ext.ux.grid.GroupSummary;
3841
3842
3843 /**
3844  * Calculation types for summary row:</p><div class="mdetail-params"><ul>
3845  * <li><b><tt>sum</tt></b> : <div class="sub-desc"></div></li>
3846  * <li><b><tt>count</tt></b> : <div class="sub-desc"></div></li>
3847  * <li><b><tt>max</tt></b> : <div class="sub-desc"></div></li>
3848  * <li><b><tt>min</tt></b> : <div class="sub-desc"></div></li>
3849  * <li><b><tt>average</tt></b> : <div class="sub-desc"></div></li>
3850  * </ul></div>
3851  * <p>Custom calculations may be implemented.  An example of
3852  * custom <code>summaryType=totalCost</code>:</p><pre><code>
3853 // define a custom summary function
3854 Ext.ux.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field){
3855     return v + (record.data.estimate * record.data.rate);
3856 };
3857  * </code></pre>
3858  * @property Calculations
3859  */
3860
3861 Ext.ux.grid.GroupSummary.Calculations = {
3862     'sum' : function(v, record, field){
3863         return v + (record.data[field]||0);
3864     },
3865
3866     'count' : function(v, record, field, data){
3867         return data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
3868     },
3869
3870     'max' : function(v, record, field, data){
3871         var v = record.data[field];
3872         var max = data[field+'max'] === undefined ? (data[field+'max'] = v) : data[field+'max'];
3873         return v > max ? (data[field+'max'] = v) : max;
3874     },
3875
3876     'min' : function(v, record, field, data){
3877         var v = record.data[field];
3878         var min = data[field+'min'] === undefined ? (data[field+'min'] = v) : data[field+'min'];
3879         return v < min ? (data[field+'min'] = v) : min;
3880     },
3881
3882     'average' : function(v, record, field, data){
3883         var c = data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
3884         var t = (data[field+'total'] = ((data[field+'total']||0) + (record.data[field]||0)));
3885         return t === 0 ? 0 : t / c;
3886     }
3887 };
3888 Ext.grid.GroupSummary.Calculations = Ext.ux.grid.GroupSummary.Calculations;
3889
3890 /**
3891  * @class Ext.ux.grid.HybridSummary
3892  * @extends Ext.ux.grid.GroupSummary
3893  * Adds capability to specify the summary data for the group via json as illustrated here:
3894  * <pre><code>
3895 {
3896     data: [
3897         {
3898             projectId: 100,     project: 'House',
3899             taskId:    112, description: 'Paint',
3900             estimate:    6,        rate:     150,
3901             due:'06/24/2007'
3902         },
3903         ...
3904     ],
3905
3906     summaryData: {
3907         'House': {
3908             description: 14, estimate: 9,
3909                    rate: 99, due: new Date(2009, 6, 29),
3910                    cost: 999
3911         }
3912     }
3913 }
3914  * </code></pre>
3915  *
3916  */
3917 Ext.ux.grid.HybridSummary = Ext.extend(Ext.ux.grid.GroupSummary, {
3918     /**
3919      * @private
3920      * @param {Object} rs
3921      * @param {Object} cs
3922      */
3923     calculate : function(rs, cs){
3924         var gcol = this.view.getGroupField(),
3925             gvalue = rs[0].data[gcol],
3926             gdata = this.getSummaryData(gvalue);
3927         return gdata || Ext.ux.grid.HybridSummary.superclass.calculate.call(this, rs, cs);
3928     },
3929
3930     /**
3931      * <pre><code>
3932 grid.on('afteredit', function(){
3933     var groupValue = 'Ext Forms: Field Anchoring';
3934     summary.showSummaryMsg(groupValue, 'Updating Summary...');
3935     setTimeout(function(){ // simulate server call
3936         // HybridSummary class implements updateSummaryData
3937         summary.updateSummaryData(groupValue,
3938             // create data object based on configured dataIndex
3939             {description: 22, estimate: 888, rate: 888, due: new Date(), cost: 8});
3940     }, 2000);
3941 });
3942      * </code></pre>
3943      * @param {String} groupValue
3944      * @param {Object} data data object
3945      * @param {Boolean} skipRefresh (Optional) Defaults to false
3946      */
3947     updateSummaryData : function(groupValue, data, skipRefresh){
3948         var json = this.grid.getStore().reader.jsonData;
3949         if(!json.summaryData){
3950             json.summaryData = {};
3951         }
3952         json.summaryData[groupValue] = data;
3953         if(!skipRefresh){
3954             this.refreshSummary(groupValue);
3955         }
3956     },
3957
3958     /**
3959      * Returns the summaryData for the specified groupValue or null.
3960      * @param {String} groupValue
3961      * @return {Object} summaryData
3962      */
3963     getSummaryData : function(groupValue){
3964         var reader = this.grid.getStore().reader,
3965             json = reader.jsonData,
3966             fields = reader.recordType.prototype.fields,
3967             v;
3968             
3969         if(json && json.summaryData){
3970             v = json.summaryData[groupValue];
3971             if(v){
3972                 return reader.extractValues(v, fields.items, fields.length);
3973             }
3974         }
3975         return null;
3976     }
3977 });
3978
3979 //backwards compat
3980 Ext.grid.HybridSummary = Ext.ux.grid.HybridSummary;
3981 Ext.ux.GroupTab = Ext.extend(Ext.Container, {
3982     mainItem: 0,
3983     
3984     expanded: true,
3985     
3986     deferredRender: true,
3987     
3988     activeTab: null,
3989     
3990     idDelimiter: '__',
3991     
3992     headerAsText: false,
3993     
3994     frame: false,
3995     
3996     hideBorders: true,
3997     
3998     initComponent: function(config){
3999         Ext.apply(this, config);
4000         this.frame = false;
4001         
4002         Ext.ux.GroupTab.superclass.initComponent.call(this);
4003         
4004         this.addEvents('activate', 'deactivate', 'changemainitem', 'beforetabchange', 'tabchange');
4005         
4006         this.setLayout(new Ext.layout.CardLayout({
4007             deferredRender: this.deferredRender
4008         }));
4009         
4010         if (!this.stack) {
4011             this.stack = Ext.TabPanel.AccessStack();
4012         }
4013         
4014         this.initItems();
4015         
4016         this.on('beforerender', function(){
4017             this.groupEl = this.ownerCt.getGroupEl(this);
4018         }, this);
4019         
4020         this.on('add', this.onAdd, this, {
4021             target: this
4022         });
4023         this.on('remove', this.onRemove, this, {
4024             target: this
4025         });
4026         
4027         if (this.mainItem !== undefined) {
4028             var item = (typeof this.mainItem == 'object') ? this.mainItem : this.items.get(this.mainItem);
4029             delete this.mainItem;
4030             this.setMainItem(item);
4031         }
4032     },
4033     
4034     /**
4035      * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which
4036      * can return false to cancel the tab change.
4037      * @param {String/Panel} tab The id or tab Panel to activate
4038      */
4039     setActiveTab : function(item){
4040         item = this.getComponent(item);
4041         if(!item){
4042             return false;
4043         }
4044         if(!this.rendered){
4045             this.activeTab = item;
4046             return true;
4047         }
4048         if(this.activeTab != item && this.fireEvent('beforetabchange', this, item, this.activeTab) !== false){
4049             if(this.activeTab && this.activeTab != this.mainItem){
4050                 var oldEl = this.getTabEl(this.activeTab);
4051                 if(oldEl){
4052                     Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
4053                 }
4054             }
4055             var el = this.getTabEl(item);
4056             Ext.fly(el).addClass('x-grouptabs-strip-active');
4057             this.activeTab = item;
4058             this.stack.add(item);
4059
4060             this.layout.setActiveItem(item);
4061             if(this.layoutOnTabChange && item.doLayout){
4062                 item.doLayout();
4063             }
4064             if(this.scrolling){
4065                 this.scrollToTab(item, this.animScroll);
4066             }
4067
4068             this.fireEvent('tabchange', this, item);
4069             return true;
4070         }
4071         return false;
4072     },
4073     
4074     getTabEl: function(item){
4075         if (item == this.mainItem) {
4076             return this.groupEl;
4077         }
4078         return Ext.TabPanel.prototype.getTabEl.call(this, item);
4079     },
4080     
4081     onRender: function(ct, position){
4082         Ext.ux.GroupTab.superclass.onRender.call(this, ct, position);
4083         
4084         this.strip = Ext.fly(this.groupEl).createChild({
4085             tag: 'ul',
4086             cls: 'x-grouptabs-sub'
4087         });
4088
4089         this.tooltip = new Ext.ToolTip({
4090            target: this.groupEl,
4091            delegate: 'a.x-grouptabs-text',
4092            trackMouse: true,
4093            renderTo: document.body,
4094            listeners: {
4095                beforeshow: function(tip) {
4096                    var item = (tip.triggerElement.parentNode === this.mainItem.tabEl)
4097                        ? this.mainItem
4098                        : this.findById(tip.triggerElement.parentNode.id.split(this.idDelimiter)[1]);
4099
4100                    if(!item.tabTip) {
4101                        return false;
4102                    }
4103                    tip.body.dom.innerHTML = item.tabTip;
4104                },
4105                scope: this
4106            }
4107         });
4108                 
4109         if (!this.itemTpl) {
4110             var tt = new Ext.Template('<li class="{cls}" id="{id}">', '<a onclick="return false;" class="x-grouptabs-text {iconCls}">{text}</a>', '</li>');
4111             tt.disableFormats = true;
4112             tt.compile();
4113             Ext.ux.GroupTab.prototype.itemTpl = tt;
4114         }
4115         
4116         this.items.each(this.initTab, this);
4117     },
4118     
4119     afterRender: function(){
4120         Ext.ux.GroupTab.superclass.afterRender.call(this);
4121         
4122         if (this.activeTab !== undefined) {
4123             var item = (typeof this.activeTab == 'object') ? this.activeTab : this.items.get(this.activeTab);
4124             delete this.activeTab;
4125             this.setActiveTab(item);
4126         }
4127     },
4128     
4129     // private
4130     initTab: function(item, index){
4131         var before = this.strip.dom.childNodes[index];
4132         var p = Ext.TabPanel.prototype.getTemplateArgs.call(this, item);
4133         
4134         if (item === this.mainItem) {
4135             item.tabEl = this.groupEl;
4136             p.cls += ' x-grouptabs-main-item';
4137         }
4138         
4139         var el = before ? this.itemTpl.insertBefore(before, p) : this.itemTpl.append(this.strip, p);
4140         
4141         item.tabEl = item.tabEl || el;
4142                 
4143         item.on('disable', this.onItemDisabled, this);
4144         item.on('enable', this.onItemEnabled, this);
4145         item.on('titlechange', this.onItemTitleChanged, this);
4146         item.on('iconchange', this.onItemIconChanged, this);
4147         item.on('beforeshow', this.onBeforeShowItem, this);
4148     },
4149     
4150     setMainItem: function(item){
4151         item = this.getComponent(item);
4152         if (!item || this.fireEvent('changemainitem', this, item, this.mainItem) === false) {
4153             return;
4154         }
4155         
4156         this.mainItem = item;
4157     },
4158     
4159     getMainItem: function(){
4160         return this.mainItem || null;
4161     },
4162     
4163     // private
4164     onBeforeShowItem: function(item){
4165         if (item != this.activeTab) {
4166             this.setActiveTab(item);
4167             return false;
4168         }
4169     },
4170     
4171     // private
4172     onAdd: function(gt, item, index){
4173         if (this.rendered) {
4174             this.initTab.call(this, item, index);
4175         }
4176     },
4177     
4178     // private
4179     onRemove: function(tp, item){
4180         Ext.destroy(Ext.get(this.getTabEl(item)));
4181         this.stack.remove(item);
4182         item.un('disable', this.onItemDisabled, this);
4183         item.un('enable', this.onItemEnabled, this);
4184         item.un('titlechange', this.onItemTitleChanged, this);
4185         item.un('iconchange', this.onItemIconChanged, this);
4186         item.un('beforeshow', this.onBeforeShowItem, this);
4187         if (item == this.activeTab) {
4188             var next = this.stack.next();
4189             if (next) {
4190                 this.setActiveTab(next);
4191             }
4192             else if (this.items.getCount() > 0) {
4193                 this.setActiveTab(0);
4194             }
4195             else {
4196                 this.activeTab = null;
4197             }
4198         }
4199     },
4200     
4201     // private
4202     onBeforeAdd: function(item){
4203         var existing = item.events ? (this.items.containsKey(item.getItemId()) ? item : null) : this.items.get(item);
4204         if (existing) {
4205             this.setActiveTab(item);
4206             return false;
4207         }
4208         Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments);
4209         var es = item.elements;
4210         item.elements = es ? es.replace(',header', '') : es;
4211         item.border = (item.border === true);
4212     },
4213     
4214     // private
4215     onItemDisabled: Ext.TabPanel.prototype.onItemDisabled,
4216     onItemEnabled: Ext.TabPanel.prototype.onItemEnabled,
4217     
4218     // private
4219     onItemTitleChanged: function(item){
4220         var el = this.getTabEl(item);
4221         if (el) {
4222             Ext.fly(el).child('a.x-grouptabs-text', true).innerHTML = item.title;
4223         }
4224     },
4225     
4226     //private
4227     onItemIconChanged: function(item, iconCls, oldCls){
4228         var el = this.getTabEl(item);
4229         if (el) {
4230             Ext.fly(el).child('a.x-grouptabs-text').replaceClass(oldCls, iconCls);
4231         }
4232     },
4233     
4234     beforeDestroy: function(){
4235         Ext.TabPanel.prototype.beforeDestroy.call(this);
4236         this.tooltip.destroy();
4237     }
4238 });
4239
4240 Ext.reg('grouptab', Ext.ux.GroupTab);
4241 Ext.ns('Ext.ux');
4242
4243 Ext.ux.GroupTabPanel = Ext.extend(Ext.TabPanel, {
4244     tabPosition: 'left',
4245
4246     alternateColor: false,
4247
4248     alternateCls: 'x-grouptabs-panel-alt',
4249
4250     defaultType: 'grouptab',
4251
4252     deferredRender: false,
4253
4254     activeGroup : null,
4255
4256     initComponent: function(){
4257         Ext.ux.GroupTabPanel.superclass.initComponent.call(this);
4258         
4259         this.addEvents(
4260             'beforegroupchange',
4261             'groupchange'
4262         );
4263         this.elements = 'body,header';
4264         this.stripTarget = 'header';
4265
4266         this.tabPosition = this.tabPosition == 'right' ? 'right' : 'left';
4267
4268         this.addClass('x-grouptabs-panel');
4269
4270         if (this.tabStyle && this.tabStyle != '') {
4271             this.addClass('x-grouptabs-panel-' + this.tabStyle);
4272         }
4273
4274         if (this.alternateColor) {
4275             this.addClass(this.alternateCls);
4276         }
4277
4278         this.on('beforeadd', function(gtp, item, index){
4279             this.initGroup(item, index);
4280         });
4281         this.items.each(function(item){
4282             item.on('tabchange',function(item){
4283                 this.fireEvent('tabchange', this, item.activeTab);
4284             }, this);
4285         },this);
4286     },
4287
4288     initEvents : function() {
4289         this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
4290     },
4291
4292     onRender: function(ct, position){
4293         Ext.TabPanel.superclass.onRender.call(this, ct, position);
4294         if(this.plain){
4295             var pos = this.tabPosition == 'top' ? 'header' : 'footer';
4296             this[pos].addClass('x-tab-panel-'+pos+'-plain');
4297         }
4298
4299         var st = this[this.stripTarget];
4300
4301         this.stripWrap = st.createChild({cls:'x-tab-strip-wrap ', cn:{
4302             tag:'ul', cls:'x-grouptabs-strip x-grouptabs-tab-strip-'+this.tabPosition}});
4303
4304         var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
4305         this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
4306
4307         this.header.addClass('x-grouptabs-panel-header');
4308         this.bwrap.addClass('x-grouptabs-bwrap');
4309         this.body.addClass('x-tab-panel-body-'+this.tabPosition + ' x-grouptabs-panel-body');
4310
4311         if (!this.groupTpl) {
4312             var tt = new Ext.Template(
4313                 '<li class="{cls}" id="{id}">',
4314                 '<a class="x-grouptabs-expand" onclick="return false;"></a>',
4315                 '<a class="x-grouptabs-text {iconCls}" href="#" onclick="return false;">',
4316                 '<span>{text}</span></a>',
4317                 '</li>'
4318             );
4319             tt.disableFormats = true;
4320             tt.compile();
4321             Ext.ux.GroupTabPanel.prototype.groupTpl = tt;
4322         }
4323         this.items.each(this.initGroup, this);
4324     },
4325
4326     afterRender: function(){
4327         Ext.ux.GroupTabPanel.superclass.afterRender.call(this);
4328
4329         this.tabJoint = Ext.fly(this.body.dom.parentNode).createChild({
4330             cls: 'x-tab-joint'
4331         });
4332
4333         this.addClass('x-tab-panel-' + this.tabPosition);
4334         this.header.setWidth(this.tabWidth);
4335
4336         if (this.activeGroup !== undefined) {
4337             var group = (typeof this.activeGroup == 'object') ? this.activeGroup : this.items.get(this.activeGroup);
4338             delete this.activeGroup;
4339             this.setActiveGroup(group);
4340             group.setActiveTab(group.getMainItem());
4341         }
4342     },
4343
4344     getGroupEl : Ext.TabPanel.prototype.getTabEl,
4345
4346     // private
4347     findTargets: function(e){
4348         var item = null,
4349             itemEl = e.getTarget('li', this.strip);
4350         if (itemEl) {
4351             item = this.findById(itemEl.id.split(this.idDelimiter)[1]);
4352             if (item.disabled) {
4353                 return {
4354                     expand: null,
4355                     item: null,
4356                     el: null
4357                 };
4358             }
4359         }
4360         return {
4361             expand: e.getTarget('.x-grouptabs-expand', this.strip),
4362             isGroup: !e.getTarget('ul.x-grouptabs-sub', this.strip),
4363             item: item,
4364             el: itemEl
4365         };
4366     },
4367
4368     // private
4369     onStripMouseDown: function(e){
4370         if (e.button != 0) {
4371             return;
4372         }
4373         e.preventDefault();
4374         var t = this.findTargets(e);
4375         if (t.expand) {
4376             this.toggleGroup(t.el);
4377         }
4378         else if (t.item) {
4379             if(t.isGroup) {
4380                 t.item.setActiveTab(t.item.getMainItem());
4381             }
4382             else {
4383                 t.item.ownerCt.setActiveTab(t.item);
4384             }
4385         }
4386     },
4387
4388     expandGroup: function(groupEl){
4389         if(groupEl.isXType) {
4390             groupEl = this.getGroupEl(groupEl);
4391         }
4392         Ext.fly(groupEl).addClass('x-grouptabs-expanded');
4393         this.syncTabJoint();
4394     },
4395
4396     toggleGroup: function(groupEl){
4397         if(groupEl.isXType) {
4398             groupEl = this.getGroupEl(groupEl);
4399         }
4400         Ext.fly(groupEl).toggleClass('x-grouptabs-expanded');
4401         this.syncTabJoint();
4402     },
4403
4404     collapseGroup: function(groupEl){
4405         if(groupEl.isXType) {
4406             groupEl = this.getGroupEl(groupEl);
4407         }
4408         Ext.fly(groupEl).removeClass('x-grouptabs-expanded');
4409         this.syncTabJoint();
4410     },
4411
4412     syncTabJoint: function(groupEl){
4413         if (!this.tabJoint) {
4414             return;
4415         }
4416
4417         groupEl = groupEl || this.getGroupEl(this.activeGroup);
4418         if(groupEl) {
4419             this.tabJoint.setHeight(Ext.fly(groupEl).getHeight() - 2);
4420
4421             var y = Ext.isGecko2 ? 0 : 1;
4422             if (this.tabPosition == 'left'){
4423                 this.tabJoint.alignTo(groupEl, 'tl-tr', [-2,y]);
4424             }
4425             else {
4426                 this.tabJoint.alignTo(groupEl, 'tr-tl', [1,y]);
4427             }
4428         }
4429         else {
4430             this.tabJoint.hide();
4431         }
4432     },
4433
4434     getActiveTab : function() {
4435         if(!this.activeGroup) return null;
4436         return this.activeGroup.getTabEl(this.activeGroup.activeTab) || null;
4437     },
4438
4439     onResize: function(){
4440         Ext.ux.GroupTabPanel.superclass.onResize.apply(this, arguments);
4441         this.syncTabJoint();
4442     },
4443
4444     createCorner: function(el, pos){
4445         return Ext.fly(el).createChild({
4446             cls: 'x-grouptabs-corner x-grouptabs-corner-' + pos
4447         });
4448     },
4449
4450     initGroup: function(group, index){
4451         var before = this.strip.dom.childNodes[index],
4452             p = this.getTemplateArgs(group);
4453         if (index === 0) {
4454             p.cls += ' x-tab-first';
4455         }
4456         p.cls += ' x-grouptabs-main';
4457         p.text = group.getMainItem().title;
4458
4459         var el = before ? this.groupTpl.insertBefore(before, p) : this.groupTpl.append(this.strip, p),
4460             tl = this.createCorner(el, 'top-' + this.tabPosition),
4461             bl = this.createCorner(el, 'bottom-' + this.tabPosition);
4462
4463         group.tabEl = el;
4464         if (group.expanded) {
4465             this.expandGroup(el);
4466         }
4467
4468         if (Ext.isIE6 || (Ext.isIE && !Ext.isStrict)){
4469             bl.setLeft('-10px');
4470             bl.setBottom('-5px');
4471             tl.setLeft('-10px');
4472             tl.setTop('-5px');
4473         }
4474
4475         this.mon(group, {
4476             scope: this,
4477             changemainitem: this.onGroupChangeMainItem,
4478             beforetabchange: this.onGroupBeforeTabChange
4479         });
4480     },
4481
4482     setActiveGroup : function(group) {
4483         group = this.getComponent(group);
4484         if(!group){
4485             return false;
4486         }
4487         if(!this.rendered){
4488             this.activeGroup = group;
4489             return true;
4490         }
4491         if(this.activeGroup != group && this.fireEvent('beforegroupchange', this, group, this.activeGroup) !== false){
4492             if(this.activeGroup){
4493                 this.activeGroup.activeTab = null;
4494                 var oldEl = this.getGroupEl(this.activeGroup);
4495                 if(oldEl){
4496                     Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
4497                 }
4498             }
4499
4500             var groupEl = this.getGroupEl(group);
4501             Ext.fly(groupEl).addClass('x-grouptabs-strip-active');
4502
4503             this.activeGroup = group;
4504             this.stack.add(group);
4505
4506             this.layout.setActiveItem(group);
4507             this.syncTabJoint(groupEl);
4508
4509             this.fireEvent('groupchange', this, group);
4510             return true;
4511         }
4512         return false;
4513     },
4514
4515     onGroupBeforeTabChange: function(group, newTab, oldTab){
4516         if(group !== this.activeGroup || newTab !== oldTab) {
4517             this.strip.select('.x-grouptabs-sub > li.x-grouptabs-strip-active', true).removeClass('x-grouptabs-strip-active');
4518         }
4519         this.expandGroup(this.getGroupEl(group));
4520         if(group !== this.activeGroup) {
4521             return this.setActiveGroup(group);
4522         }
4523     },
4524
4525     getFrameHeight: function(){
4526         var h = this.el.getFrameWidth('tb');
4527         h += (this.tbar ? this.tbar.getHeight() : 0) +
4528         (this.bbar ? this.bbar.getHeight() : 0);
4529
4530         return h;
4531     },
4532
4533     adjustBodyWidth: function(w){
4534         return w - this.tabWidth;
4535     }
4536 });
4537
4538 Ext.reg('grouptabpanel', Ext.ux.GroupTabPanel);
4539 /*
4540  * Note that this control will most likely remain as an example, and not as a core Ext form
4541  * control.  However, the API will be changing in a future release and so should not yet be
4542  * treated as a final, stable API at this time.
4543  */
4544
4545 /**
4546  * @class Ext.ux.form.ItemSelector
4547  * @extends Ext.form.Field
4548  * A control that allows selection of between two Ext.ux.form.MultiSelect controls.
4549  *
4550  *  @history
4551  *    2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
4552  *
4553  * @constructor
4554  * Create a new ItemSelector
4555  * @param {Object} config Configuration options
4556  * @xtype itemselector 
4557  */
4558 Ext.ux.form.ItemSelector = Ext.extend(Ext.form.Field,  {
4559     hideNavIcons:false,
4560     imagePath:"",
4561     iconUp:"up2.gif",
4562     iconDown:"down2.gif",
4563     iconLeft:"left2.gif",
4564     iconRight:"right2.gif",
4565     iconTop:"top2.gif",
4566     iconBottom:"bottom2.gif",
4567     drawUpIcon:true,
4568     drawDownIcon:true,
4569     drawLeftIcon:true,
4570     drawRightIcon:true,
4571     drawTopIcon:true,
4572     drawBotIcon:true,
4573     delimiter:',',
4574     bodyStyle:null,
4575     border:false,
4576     defaultAutoCreate:{tag: "div"},
4577     /**
4578      * @cfg {Array} multiselects An array of {@link Ext.ux.form.MultiSelect} config objects, with at least all required parameters (e.g., store)
4579      */
4580     multiselects:null,
4581
4582     initComponent: function(){
4583         Ext.ux.form.ItemSelector.superclass.initComponent.call(this);
4584         this.addEvents({
4585             'rowdblclick' : true,
4586             'change' : true
4587         });
4588     },
4589
4590     onRender: function(ct, position){
4591         Ext.ux.form.ItemSelector.superclass.onRender.call(this, ct, position);
4592
4593         // Internal default configuration for both multiselects
4594         var msConfig = [{
4595             legend: 'Available',
4596             draggable: true,
4597             droppable: true,
4598             width: 100,
4599             height: 100
4600         },{
4601             legend: 'Selected',
4602             droppable: true,
4603             draggable: true,
4604             width: 100,
4605             height: 100
4606         }];
4607
4608         this.fromMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[0], msConfig[0]));
4609         this.fromMultiselect.on('dblclick', this.onRowDblClick, this);
4610
4611         this.toMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[1], msConfig[1]));
4612         this.toMultiselect.on('dblclick', this.onRowDblClick, this);
4613
4614         var p = new Ext.Panel({
4615             bodyStyle:this.bodyStyle,
4616             border:this.border,
4617             layout:"table",
4618             layoutConfig:{columns:3}
4619         });
4620
4621         p.add(this.fromMultiselect);
4622         var icons = new Ext.Panel({header:false});
4623         p.add(icons);
4624         p.add(this.toMultiselect);
4625         p.render(this.el);
4626         icons.el.down('.'+icons.bwrapCls).remove();
4627
4628         // ICON HELL!!!
4629         if (this.imagePath!="" && this.imagePath.charAt(this.imagePath.length-1)!="/")
4630             this.imagePath+="/";
4631         this.iconUp = this.imagePath + (this.iconUp || 'up2.gif');
4632         this.iconDown = this.imagePath + (this.iconDown || 'down2.gif');
4633         this.iconLeft = this.imagePath + (this.iconLeft || 'left2.gif');
4634         this.iconRight = this.imagePath + (this.iconRight || 'right2.gif');
4635         this.iconTop = this.imagePath + (this.iconTop || 'top2.gif');
4636         this.iconBottom = this.imagePath + (this.iconBottom || 'bottom2.gif');
4637         var el=icons.getEl();
4638         this.toTopIcon = el.createChild({tag:'img', src:this.iconTop, style:{cursor:'pointer', margin:'2px'}});
4639         el.createChild({tag: 'br'});
4640         this.upIcon = el.createChild({tag:'img', src:this.iconUp, style:{cursor:'pointer', margin:'2px'}});
4641         el.createChild({tag: 'br'});
4642         this.addIcon = el.createChild({tag:'img', src:this.iconRight, style:{cursor:'pointer', margin:'2px'}});
4643         el.createChild({tag: 'br'});
4644         this.removeIcon = el.createChild({tag:'img', src:this.iconLeft, style:{cursor:'pointer', margin:'2px'}});
4645         el.createChild({tag: 'br'});
4646         this.downIcon = el.createChild({tag:'img', src:this.iconDown, style:{cursor:'pointer', margin:'2px'}});
4647         el.createChild({tag: 'br'});
4648         this.toBottomIcon = el.createChild({tag:'img', src:this.iconBottom, style:{cursor:'pointer', margin:'2px'}});
4649         this.toTopIcon.on('click', this.toTop, this);
4650         this.upIcon.on('click', this.up, this);
4651         this.downIcon.on('click', this.down, this);
4652         this.toBottomIcon.on('click', this.toBottom, this);
4653         this.addIcon.on('click', this.fromTo, this);
4654         this.removeIcon.on('click', this.toFrom, this);
4655         if (!this.drawUpIcon || this.hideNavIcons) { this.upIcon.dom.style.display='none'; }
4656         if (!this.drawDownIcon || this.hideNavIcons) { this.downIcon.dom.style.display='none'; }
4657         if (!this.drawLeftIcon || this.hideNavIcons) { this.addIcon.dom.style.display='none'; }
4658         if (!this.drawRightIcon || this.hideNavIcons) { this.removeIcon.dom.style.display='none'; }
4659         if (!this.drawTopIcon || this.hideNavIcons) { this.toTopIcon.dom.style.display='none'; }
4660         if (!this.drawBotIcon || this.hideNavIcons) { this.toBottomIcon.dom.style.display='none'; }
4661
4662         var tb = p.body.first();
4663         this.el.setWidth(p.body.first().getWidth());
4664         p.body.removeClass();
4665
4666         this.hiddenName = this.name;
4667         var hiddenTag = {tag: "input", type: "hidden", value: "", name: this.name};
4668         this.hiddenField = this.el.createChild(hiddenTag);
4669     },
4670     
4671     doLayout: function(){
4672         if(this.rendered){
4673             this.fromMultiselect.fs.doLayout();
4674             this.toMultiselect.fs.doLayout();
4675         }
4676     },
4677
4678     afterRender: function(){
4679         Ext.ux.form.ItemSelector.superclass.afterRender.call(this);
4680
4681         this.toStore = this.toMultiselect.store;
4682         this.toStore.on('add', this.valueChanged, this);
4683         this.toStore.on('remove', this.valueChanged, this);
4684         this.toStore.on('load', this.valueChanged, this);
4685         this.valueChanged(this.toStore);
4686     },
4687
4688     toTop : function() {
4689         var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4690         var records = [];
4691         if (selectionsArray.length > 0) {
4692             selectionsArray.sort();
4693             for (var i=0; i<selectionsArray.length; i++) {
4694                 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4695                 records.push(record);
4696             }
4697             selectionsArray = [];
4698             for (var i=records.length-1; i>-1; i--) {
4699                 record = records[i];
4700                 this.toMultiselect.view.store.remove(record);
4701                 this.toMultiselect.view.store.insert(0, record);
4702                 selectionsArray.push(((records.length - 1) - i));
4703             }
4704         }
4705         this.toMultiselect.view.refresh();
4706         this.toMultiselect.view.select(selectionsArray);
4707     },
4708
4709     toBottom : function() {
4710         var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4711         var records = [];
4712         if (selectionsArray.length > 0) {
4713             selectionsArray.sort();
4714             for (var i=0; i<selectionsArray.length; i++) {
4715                 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4716                 records.push(record);
4717             }
4718             selectionsArray = [];
4719             for (var i=0; i<records.length; i++) {
4720                 record = records[i];
4721                 this.toMultiselect.view.store.remove(record);
4722                 this.toMultiselect.view.store.add(record);
4723                 selectionsArray.push((this.toMultiselect.view.store.getCount()) - (records.length - i));
4724             }
4725         }
4726         this.toMultiselect.view.refresh();
4727         this.toMultiselect.view.select(selectionsArray);
4728     },
4729
4730     up : function() {
4731         var record = null;
4732         var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4733         selectionsArray.sort();
4734         var newSelectionsArray = [];
4735         if (selectionsArray.length > 0) {
4736             for (var i=0; i<selectionsArray.length; i++) {
4737                 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4738                 if ((selectionsArray[i] - 1) >= 0) {
4739                     this.toMultiselect.view.store.remove(record);
4740                     this.toMultiselect.view.store.insert(selectionsArray[i] - 1, record);
4741                     newSelectionsArray.push(selectionsArray[i] - 1);
4742                 }
4743             }
4744             this.toMultiselect.view.refresh();
4745             this.toMultiselect.view.select(newSelectionsArray);
4746         }
4747     },
4748
4749     down : function() {
4750         var record = null;
4751         var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4752         selectionsArray.sort();
4753         selectionsArray.reverse();
4754         var newSelectionsArray = [];
4755         if (selectionsArray.length > 0) {
4756             for (var i=0; i<selectionsArray.length; i++) {
4757                 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4758                 if ((selectionsArray[i] + 1) < this.toMultiselect.view.store.getCount()) {
4759                     this.toMultiselect.view.store.remove(record);
4760                     this.toMultiselect.view.store.insert(selectionsArray[i] + 1, record);
4761                     newSelectionsArray.push(selectionsArray[i] + 1);
4762                 }
4763             }
4764             this.toMultiselect.view.refresh();
4765             this.toMultiselect.view.select(newSelectionsArray);
4766         }
4767     },
4768
4769     fromTo : function() {
4770         var selectionsArray = this.fromMultiselect.view.getSelectedIndexes();
4771         var records = [];
4772         if (selectionsArray.length > 0) {
4773             for (var i=0; i<selectionsArray.length; i++) {
4774                 record = this.fromMultiselect.view.store.getAt(selectionsArray[i]);
4775                 records.push(record);
4776             }
4777             if(!this.allowDup)selectionsArray = [];
4778             for (var i=0; i<records.length; i++) {
4779                 record = records[i];
4780                 if(this.allowDup){
4781                     var x=new Ext.data.Record();
4782                     record.id=x.id;
4783                     delete x;
4784                     this.toMultiselect.view.store.add(record);
4785                 }else{
4786                     this.fromMultiselect.view.store.remove(record);
4787                     this.toMultiselect.view.store.add(record);
4788                     selectionsArray.push((this.toMultiselect.view.store.getCount() - 1));
4789                 }
4790             }
4791         }
4792         this.toMultiselect.view.refresh();
4793         this.fromMultiselect.view.refresh();
4794         var si = this.toMultiselect.store.sortInfo;
4795         if(si){
4796             this.toMultiselect.store.sort(si.field, si.direction);
4797         }
4798         this.toMultiselect.view.select(selectionsArray);
4799     },
4800
4801     toFrom : function() {
4802         var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4803         var records = [];
4804         if (selectionsArray.length > 0) {
4805             for (var i=0; i<selectionsArray.length; i++) {
4806                 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4807                 records.push(record);
4808             }
4809             selectionsArray = [];
4810             for (var i=0; i<records.length; i++) {
4811                 record = records[i];
4812                 this.toMultiselect.view.store.remove(record);
4813                 if(!this.allowDup){
4814                     this.fromMultiselect.view.store.add(record);
4815                     selectionsArray.push((this.fromMultiselect.view.store.getCount() - 1));
4816                 }
4817             }
4818         }
4819         this.fromMultiselect.view.refresh();
4820         this.toMultiselect.view.refresh();
4821         var si = this.fromMultiselect.store.sortInfo;
4822         if (si){
4823             this.fromMultiselect.store.sort(si.field, si.direction);
4824         }
4825         this.fromMultiselect.view.select(selectionsArray);
4826     },
4827
4828     valueChanged: function(store) {
4829         var record = null;
4830         var values = [];
4831         for (var i=0; i<store.getCount(); i++) {
4832             record = store.getAt(i);
4833             values.push(record.get(this.toMultiselect.valueField));
4834         }
4835         this.hiddenField.dom.value = values.join(this.delimiter);
4836         this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
4837     },
4838
4839     getValue : function() {
4840         return this.hiddenField.dom.value;
4841     },
4842
4843     onRowDblClick : function(vw, index, node, e) {
4844         if (vw == this.toMultiselect.view){
4845             this.toFrom();
4846         } else if (vw == this.fromMultiselect.view) {
4847             this.fromTo();
4848         }
4849         return this.fireEvent('rowdblclick', vw, index, node, e);
4850     },
4851
4852     reset: function(){
4853         range = this.toMultiselect.store.getRange();
4854         this.toMultiselect.store.removeAll();
4855         this.fromMultiselect.store.add(range);
4856         var si = this.fromMultiselect.store.sortInfo;
4857         if (si){
4858             this.fromMultiselect.store.sort(si.field, si.direction);
4859         }
4860         this.valueChanged(this.toMultiselect.store);
4861     }
4862 });
4863
4864 Ext.reg('itemselector', Ext.ux.form.ItemSelector);
4865
4866 //backwards compat
4867 Ext.ux.ItemSelector = Ext.ux.form.ItemSelector;
4868 Ext.ns('Ext.ux.grid');
4869
4870 Ext.ux.grid.LockingGridView = Ext.extend(Ext.grid.GridView, {
4871     lockText : 'Lock',
4872     unlockText : 'Unlock',
4873     rowBorderWidth : 1,
4874     lockedBorderWidth : 1,
4875
4876     /*
4877      * This option ensures that height between the rows is synchronized
4878      * between the locked and unlocked sides. This option only needs to be used
4879      * when the row heights aren't predictable.
4880      */
4881     syncHeights: false,
4882
4883     initTemplates : function(){
4884         var ts = this.templates || {};
4885
4886         if (!ts.master) {
4887             ts.master = new Ext.Template(
4888                 '<div class="x-grid3" hidefocus="true">',
4889                     '<div class="x-grid3-locked">',
4890                         '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{lstyle}">{lockedHeader}</div></div><div class="x-clear"></div></div>',
4891                         '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{lstyle}">{lockedBody}</div><div class="x-grid3-scroll-spacer"></div></div>',
4892                     '</div>',
4893                     '<div class="x-grid3-viewport x-grid3-unlocked">',
4894                         '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
4895                         '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
4896                     '</div>',
4897                     '<div class="x-grid3-resize-marker">&#160;</div>',
4898                     '<div class="x-grid3-resize-proxy">&#160;</div>',
4899                 '</div>'
4900             );
4901         }
4902
4903         this.templates = ts;
4904
4905         Ext.ux.grid.LockingGridView.superclass.initTemplates.call(this);
4906     },
4907
4908     getEditorParent : function(ed){
4909         return this.el.dom;
4910     },
4911
4912     initElements : function(){
4913         var E  = Ext.Element,
4914             el = this.grid.getGridEl().dom.firstChild,
4915             cs = el.childNodes;
4916
4917         this.el             = new E(el);
4918         this.lockedWrap     = new E(cs[0]);
4919         this.lockedHd       = new E(this.lockedWrap.dom.firstChild);
4920         this.lockedInnerHd  = this.lockedHd.dom.firstChild;
4921         this.lockedScroller = new E(this.lockedWrap.dom.childNodes[1]);
4922         this.lockedBody     = new E(this.lockedScroller.dom.firstChild);
4923         this.mainWrap       = new E(cs[1]);
4924         this.mainHd         = new E(this.mainWrap.dom.firstChild);
4925
4926         if (this.grid.hideHeaders) {
4927             this.lockedHd.setDisplayed(false);
4928             this.mainHd.setDisplayed(false);
4929         }
4930
4931         this.innerHd  = this.mainHd.dom.firstChild;
4932         this.scroller = new E(this.mainWrap.dom.childNodes[1]);
4933
4934         if(this.forceFit){
4935             this.scroller.setStyle('overflow-x', 'hidden');
4936         }
4937
4938         this.mainBody     = new E(this.scroller.dom.firstChild);
4939         this.focusEl      = new E(this.scroller.dom.childNodes[1]);
4940         this.resizeMarker = new E(cs[2]);
4941         this.resizeProxy  = new E(cs[3]);
4942
4943         this.focusEl.swallowEvent('click', true);
4944     },
4945
4946     getLockedRows : function(){
4947         return this.hasRows() ? this.lockedBody.dom.childNodes : [];
4948     },
4949
4950     getLockedRow : function(row){
4951         return this.getLockedRows()[row];
4952     },
4953
4954     getCell : function(row, col){
4955         var llen = this.cm.getLockedCount();
4956         if(col < llen){
4957             return this.getLockedRow(row).getElementsByTagName('td')[col];
4958         }
4959         return Ext.ux.grid.LockingGridView.superclass.getCell.call(this, row, col - llen);
4960     },
4961
4962     getHeaderCell : function(index){
4963         var llen = this.cm.getLockedCount();
4964         if(index < llen){
4965             return this.lockedHd.dom.getElementsByTagName('td')[index];
4966         }
4967         return Ext.ux.grid.LockingGridView.superclass.getHeaderCell.call(this, index - llen);
4968     },
4969
4970     addRowClass : function(row, cls){
4971         var r = this.getLockedRow(row);
4972         if(r){
4973             this.fly(r).addClass(cls);
4974         }
4975         Ext.ux.grid.LockingGridView.superclass.addRowClass.call(this, row, cls);
4976     },
4977
4978     removeRowClass : function(row, cls){
4979         var r = this.getLockedRow(row);
4980         if(r){
4981             this.fly(r).removeClass(cls);
4982         }
4983         Ext.ux.grid.LockingGridView.superclass.removeRowClass.call(this, row, cls);
4984     },
4985
4986     removeRow : function(row) {
4987         Ext.removeNode(this.getLockedRow(row));
4988         Ext.ux.grid.LockingGridView.superclass.removeRow.call(this, row);
4989     },
4990
4991     removeRows : function(firstRow, lastRow){
4992         var bd = this.lockedBody.dom;
4993         for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
4994             Ext.removeNode(bd.childNodes[firstRow]);
4995         }
4996         Ext.ux.grid.LockingGridView.superclass.removeRows.call(this, firstRow, lastRow);
4997     },
4998
4999     syncScroll : function(e){
5000         var mb = this.scroller.dom;
5001         this.lockedScroller.dom.scrollTop = mb.scrollTop;
5002         Ext.ux.grid.LockingGridView.superclass.syncScroll.call(this, e);
5003     },
5004
5005     updateSortIcon : function(col, dir){
5006         var sc = this.sortClasses,
5007             lhds = this.lockedHd.select('td').removeClass(sc),
5008             hds = this.mainHd.select('td').removeClass(sc),
5009             llen = this.cm.getLockedCount(),
5010             cls = sc[dir == 'DESC' ? 1 : 0];
5011         if(col < llen){
5012             lhds.item(col).addClass(cls);
5013         }else{
5014             hds.item(col - llen).addClass(cls);
5015         }
5016     },
5017
5018     updateAllColumnWidths : function(){
5019         var tw = this.getTotalWidth(),
5020             clen = this.cm.getColumnCount(),
5021             lw = this.getLockedWidth(),
5022             llen = this.cm.getLockedCount(),
5023             ws = [], len, i;
5024         this.updateLockedWidth();
5025         for(i = 0; i < clen; i++){
5026             ws[i] = this.getColumnWidth(i);
5027             var hd = this.getHeaderCell(i);
5028             hd.style.width = ws[i];
5029         }
5030         var lns = this.getLockedRows(), ns = this.getRows(), row, trow, j;
5031         for(i = 0, len = ns.length; i < len; i++){
5032             row = lns[i];
5033             row.style.width = lw;
5034             if(row.firstChild){
5035                 row.firstChild.style.width = lw;
5036                 trow = row.firstChild.rows[0];
5037                 for (j = 0; j < llen; j++) {
5038                    trow.childNodes[j].style.width = ws[j];
5039                 }
5040             }
5041             row = ns[i];
5042             row.style.width = tw;
5043             if(row.firstChild){
5044                 row.firstChild.style.width = tw;
5045                 trow = row.firstChild.rows[0];
5046                 for (j = llen; j < clen; j++) {
5047                    trow.childNodes[j - llen].style.width = ws[j];
5048                 }
5049             }
5050         }
5051         this.onAllColumnWidthsUpdated(ws, tw);
5052         this.syncHeaderHeight();
5053     },
5054
5055     updateColumnWidth : function(col, width){
5056         var w = this.getColumnWidth(col),
5057             llen = this.cm.getLockedCount(),
5058             ns, rw, c, row;
5059         this.updateLockedWidth();
5060         if(col < llen){
5061             ns = this.getLockedRows();
5062             rw = this.getLockedWidth();
5063             c = col;
5064         }else{
5065             ns = this.getRows();
5066             rw = this.getTotalWidth();
5067             c = col - llen;
5068         }
5069         var hd = this.getHeaderCell(col);
5070         hd.style.width = w;
5071         for(var i = 0, len = ns.length; i < len; i++){
5072             row = ns[i];
5073             row.style.width = rw;
5074             if(row.firstChild){
5075                 row.firstChild.style.width = rw;
5076                 row.firstChild.rows[0].childNodes[c].style.width = w;
5077             }
5078         }
5079         this.onColumnWidthUpdated(col, w, this.getTotalWidth());
5080         this.syncHeaderHeight();
5081     },
5082
5083     updateColumnHidden : function(col, hidden){
5084         var llen = this.cm.getLockedCount(),
5085             ns, rw, c, row,
5086             display = hidden ? 'none' : '';
5087         this.updateLockedWidth();
5088         if(col < llen){
5089             ns = this.getLockedRows();
5090             rw = this.getLockedWidth();
5091             c = col;
5092         }else{
5093             ns = this.getRows();
5094             rw = this.getTotalWidth();
5095             c = col - llen;
5096         }
5097         var hd = this.getHeaderCell(col);
5098         hd.style.display = display;
5099         for(var i = 0, len = ns.length; i < len; i++){
5100             row = ns[i];
5101             row.style.width = rw;
5102             if(row.firstChild){
5103                 row.firstChild.style.width = rw;
5104                 row.firstChild.rows[0].childNodes[c].style.display = display;
5105             }
5106         }
5107         this.onColumnHiddenUpdated(col, hidden, this.getTotalWidth());
5108         delete this.lastViewWidth;
5109         this.layout();
5110     },
5111
5112     doRender : function(cs, rs, ds, startRow, colCount, stripe){
5113         var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1,
5114             tstyle = 'width:'+this.getTotalWidth()+';',
5115             lstyle = 'width:'+this.getLockedWidth()+';',
5116             buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r;
5117         for(var j = 0, len = rs.length; j < len; j++){
5118             r = rs[j]; cb = []; lcb = [];
5119             var rowIndex = (j+startRow);
5120             for(var i = 0; i < colCount; i++){
5121                 c = cs[i];
5122                 p.id = c.id;
5123                 p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
5124                     (this.cm.config[i].cellCls ? ' ' + this.cm.config[i].cellCls : '');
5125                 p.attr = p.cellAttr = '';
5126                 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
5127                 p.style = c.style;
5128                 if(Ext.isEmpty(p.value)){
5129                     p.value = '&#160;';
5130                 }
5131                 if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
5132                     p.css += ' x-grid3-dirty-cell';
5133                 }
5134                 if(c.locked){
5135                     lcb[lcb.length] = ct.apply(p);
5136                 }else{
5137                     cb[cb.length] = ct.apply(p);
5138                 }
5139             }
5140             var alt = [];
5141             if(stripe && ((rowIndex+1) % 2 === 0)){
5142                 alt[0] = 'x-grid3-row-alt';
5143             }
5144             if(r.dirty){
5145                 alt[1] = ' x-grid3-dirty-row';
5146             }
5147             rp.cols = colCount;
5148             if(this.getRowClass){
5149                 alt[2] = this.getRowClass(r, rowIndex, rp, ds);
5150             }
5151             rp.alt = alt.join(' ');
5152             rp.cells = cb.join('');
5153             rp.tstyle = tstyle;
5154             buf[buf.length] = rt.apply(rp);
5155             rp.cells = lcb.join('');
5156             rp.tstyle = lstyle;
5157             lbuf[lbuf.length] = rt.apply(rp);
5158         }
5159         return [buf.join(''), lbuf.join('')];
5160     },
5161     processRows : function(startRow, skipStripe){
5162         if(!this.ds || this.ds.getCount() < 1){
5163             return;
5164         }
5165         var rows = this.getRows(),
5166             lrows = this.getLockedRows(),
5167             row, lrow;
5168         skipStripe = skipStripe || !this.grid.stripeRows;
5169         startRow = startRow || 0;
5170         for(var i = 0, len = rows.length; i < len; ++i){
5171             row = rows[i];
5172             lrow = lrows[i];
5173             row.rowIndex = i;
5174             lrow.rowIndex = i;
5175             if(!skipStripe){
5176                 row.className = row.className.replace(this.rowClsRe, ' ');
5177                 lrow.className = lrow.className.replace(this.rowClsRe, ' ');
5178                 if ((i + 1) % 2 === 0){
5179                     row.className += ' x-grid3-row-alt';
5180                     lrow.className += ' x-grid3-row-alt';
5181                 }
5182             }
5183             if(this.syncHeights){
5184                 var el1 = Ext.get(row),
5185                     el2 = Ext.get(lrow),
5186                     h1 = el1.getHeight(),
5187                     h2 = el2.getHeight();
5188
5189                 if(h1 > h2){
5190                     el2.setHeight(h1);
5191                 }else if(h2 > h1){
5192                     el1.setHeight(h2);
5193                 }
5194             }
5195         }
5196         if(startRow === 0){
5197             Ext.fly(rows[0]).addClass(this.firstRowCls);
5198             Ext.fly(lrows[0]).addClass(this.firstRowCls);
5199         }
5200         Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
5201         Ext.fly(lrows[lrows.length - 1]).addClass(this.lastRowCls);
5202     },
5203
5204     afterRender : function(){
5205         if(!this.ds || !this.cm){
5206             return;
5207         }
5208         var bd = this.renderRows() || ['&#160;', '&#160;'];
5209         this.mainBody.dom.innerHTML = bd[0];
5210         this.lockedBody.dom.innerHTML = bd[1];
5211         this.processRows(0, true);
5212         if(this.deferEmptyText !== true){
5213             this.applyEmptyText();
5214         }
5215     },
5216
5217     renderUI : function(){
5218         var header = this.renderHeaders();
5219         var body = this.templates.body.apply({rows:'&#160;'});
5220         var html = this.templates.master.apply({
5221             body: body,
5222             header: header[0],
5223             ostyle: 'width:'+this.getOffsetWidth()+';',
5224             bstyle: 'width:'+this.getTotalWidth()+';',
5225             lockedBody: body,
5226             lockedHeader: header[1],
5227             lstyle: 'width:'+this.getLockedWidth()+';'
5228         });
5229         var g = this.grid;
5230         g.getGridEl().dom.innerHTML = html;
5231         this.initElements();
5232         Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
5233         Ext.fly(this.lockedInnerHd).on('click', this.handleHdDown, this);
5234         this.mainHd.on({
5235             scope: this,
5236             mouseover: this.handleHdOver,
5237             mouseout: this.handleHdOut,
5238             mousemove: this.handleHdMove
5239         });
5240         this.lockedHd.on({
5241             scope: this,
5242             mouseover: this.handleHdOver,
5243             mouseout: this.handleHdOut,
5244             mousemove: this.handleHdMove
5245         });
5246         this.scroller.on('scroll', this.syncScroll,  this);
5247         if(g.enableColumnResize !== false){
5248             this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
5249             this.splitZone.setOuterHandleElId(Ext.id(this.lockedHd.dom));
5250             this.splitZone.setOuterHandleElId(Ext.id(this.mainHd.dom));
5251         }
5252         if(g.enableColumnMove){
5253             this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
5254             this.columnDrag.setOuterHandleElId(Ext.id(this.lockedInnerHd));
5255             this.columnDrag.setOuterHandleElId(Ext.id(this.innerHd));
5256             this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
5257         }
5258         if(g.enableHdMenu !== false){
5259             this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
5260             this.hmenu.add(
5261                 {itemId: 'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
5262                 {itemId: 'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
5263             );
5264             if(this.grid.enableColLock !== false){
5265                 this.hmenu.add('-',
5266                     {itemId: 'lock', text: this.lockText, cls: 'xg-hmenu-lock'},
5267                     {itemId: 'unlock', text: this.unlockText, cls: 'xg-hmenu-unlock'}
5268                 );
5269             }
5270             if(g.enableColumnHide !== false){
5271                 this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
5272                 this.colMenu.on({
5273                     scope: this,
5274                     beforeshow: this.beforeColMenuShow,
5275                     itemclick: this.handleHdMenuClick
5276                 });
5277                 this.hmenu.add('-', {
5278                     itemId:'columns',
5279                     hideOnClick: false,
5280                     text: this.columnsText,
5281                     menu: this.colMenu,
5282                     iconCls: 'x-cols-icon'
5283                 });
5284             }
5285             this.hmenu.on('itemclick', this.handleHdMenuClick, this);
5286         }
5287         if(g.trackMouseOver){
5288             this.mainBody.on({
5289                 scope: this,
5290                 mouseover: this.onRowOver,
5291                 mouseout: this.onRowOut
5292             });
5293             this.lockedBody.on({
5294                 scope: this,
5295                 mouseover: this.onRowOver,
5296                 mouseout: this.onRowOut
5297             });
5298         }
5299
5300         if(g.enableDragDrop || g.enableDrag){
5301             this.dragZone = new Ext.grid.GridDragZone(g, {
5302                 ddGroup : g.ddGroup || 'GridDD'
5303             });
5304         }
5305         this.updateHeaderSortState();
5306     },
5307
5308     layout : function(){
5309         if(!this.mainBody){
5310             return;
5311         }
5312         var g = this.grid;
5313         var c = g.getGridEl();
5314         var csize = c.getSize(true);
5315         var vw = csize.width;
5316         if(!g.hideHeaders && (vw < 20 || csize.height < 20)){
5317             return;
5318         }
5319         this.syncHeaderHeight();
5320         if(g.autoHeight){
5321             this.scroller.dom.style.overflow = 'visible';
5322             this.lockedScroller.dom.style.overflow = 'visible';
5323             if(Ext.isWebKit){
5324                 this.scroller.dom.style.position = 'static';
5325                 this.lockedScroller.dom.style.position = 'static';
5326             }
5327         }else{
5328             this.el.setSize(csize.width, csize.height);
5329             var hdHeight = this.mainHd.getHeight();
5330             var vh = csize.height - (hdHeight);
5331         }
5332         this.updateLockedWidth();
5333         if(this.forceFit){
5334             if(this.lastViewWidth != vw){
5335                 this.fitColumns(false, false);
5336                 this.lastViewWidth = vw;
5337             }
5338         }else {
5339             this.autoExpand();
5340             this.syncHeaderScroll();
5341         }
5342         this.onLayout(vw, vh);
5343     },
5344
5345     getOffsetWidth : function() {
5346         return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth() + this.getScrollOffset()) + 'px';
5347     },
5348
5349     renderHeaders : function(){
5350         var cm = this.cm,
5351             ts = this.templates,
5352             ct = ts.hcell,
5353             cb = [], lcb = [],
5354             p = {},
5355             len = cm.getColumnCount(),
5356             last = len - 1;
5357         for(var i = 0; i < len; i++){
5358             p.id = cm.getColumnId(i);
5359             p.value = cm.getColumnHeader(i) || '';
5360             p.style = this.getColumnStyle(i, true);
5361             p.tooltip = this.getColumnTooltip(i);
5362             p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
5363                 (cm.config[i].headerCls ? ' ' + cm.config[i].headerCls : '');
5364             if(cm.config[i].align == 'right'){
5365                 p.istyle = 'padding-right:16px';
5366             } else {
5367                 delete p.istyle;
5368             }
5369             if(cm.isLocked(i)){
5370                 lcb[lcb.length] = ct.apply(p);
5371             }else{
5372                 cb[cb.length] = ct.apply(p);
5373             }
5374         }
5375         return [ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'}),
5376                 ts.header.apply({cells: lcb.join(''), tstyle:'width:'+this.getLockedWidth()+';'})];
5377     },
5378
5379     updateHeaders : function(){
5380         var hd = this.renderHeaders();
5381         this.innerHd.firstChild.innerHTML = hd[0];
5382         this.innerHd.firstChild.style.width = this.getOffsetWidth();
5383         this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
5384         this.lockedInnerHd.firstChild.innerHTML = hd[1];
5385         var lw = this.getLockedWidth();
5386         this.lockedInnerHd.firstChild.style.width = lw;
5387         this.lockedInnerHd.firstChild.firstChild.style.width = lw;
5388     },
5389
5390     getResolvedXY : function(resolved){
5391         if(!resolved){
5392             return null;
5393         }
5394         var c = resolved.cell, r = resolved.row;
5395         return c ? Ext.fly(c).getXY() : [this.scroller.getX(), Ext.fly(r).getY()];
5396     },
5397
5398     syncFocusEl : function(row, col, hscroll){
5399         Ext.ux.grid.LockingGridView.superclass.syncFocusEl.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
5400     },
5401
5402     ensureVisible : function(row, col, hscroll){
5403         return Ext.ux.grid.LockingGridView.superclass.ensureVisible.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
5404     },
5405
5406     insertRows : function(dm, firstRow, lastRow, isUpdate){
5407         var last = dm.getCount() - 1;
5408         if(!isUpdate && firstRow === 0 && lastRow >= last){
5409             this.refresh();
5410         }else{
5411             if(!isUpdate){
5412                 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
5413             }
5414             var html = this.renderRows(firstRow, lastRow),
5415                 before = this.getRow(firstRow);
5416             if(before){
5417                 if(firstRow === 0){
5418                     this.removeRowClass(0, this.firstRowCls);
5419                 }
5420                 Ext.DomHelper.insertHtml('beforeBegin', before, html[0]);
5421                 before = this.getLockedRow(firstRow);
5422                 Ext.DomHelper.insertHtml('beforeBegin', before, html[1]);
5423             }else{
5424                 this.removeRowClass(last - 1, this.lastRowCls);
5425                 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html[0]);
5426                 Ext.DomHelper.insertHtml('beforeEnd', this.lockedBody.dom, html[1]);
5427             }
5428             if(!isUpdate){
5429                 this.fireEvent('rowsinserted', this, firstRow, lastRow);
5430                 this.processRows(firstRow);
5431             }else if(firstRow === 0 || firstRow >= last){
5432                 this.addRowClass(firstRow, firstRow === 0 ? this.firstRowCls : this.lastRowCls);
5433             }
5434         }
5435         this.syncFocusEl(firstRow);
5436     },
5437
5438     getColumnStyle : function(col, isHeader){
5439         var style = !isHeader ? this.cm.config[col].cellStyle || this.cm.config[col].css || '' : this.cm.config[col].headerStyle || '';
5440         style += 'width:'+this.getColumnWidth(col)+';';
5441         if(this.cm.isHidden(col)){
5442             style += 'display:none;';
5443         }
5444         var align = this.cm.config[col].align;
5445         if(align){
5446             style += 'text-align:'+align+';';
5447         }
5448         return style;
5449     },
5450
5451     getLockedWidth : function() {
5452         return this.cm.getTotalLockedWidth() + 'px';
5453     },
5454
5455     getTotalWidth : function() {
5456         return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth()) + 'px';
5457     },
5458
5459     getColumnData : function(){
5460         var cs = [], cm = this.cm, colCount = cm.getColumnCount();
5461         for(var i = 0; i < colCount; i++){
5462             var name = cm.getDataIndex(i);
5463             cs[i] = {
5464                 name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
5465                 renderer : cm.getRenderer(i),
5466                 id : cm.getColumnId(i),
5467                 style : this.getColumnStyle(i),
5468                 locked : cm.isLocked(i)
5469             };
5470         }
5471         return cs;
5472     },
5473
5474     renderBody : function(){
5475         var markup = this.renderRows() || ['&#160;', '&#160;'];
5476         return [this.templates.body.apply({rows: markup[0]}), this.templates.body.apply({rows: markup[1]})];
5477     },
5478
5479     refreshRow : function(record){
5480         Ext.ux.grid.LockingGridView.superclass.refreshRow.call(this, record);
5481         var index = Ext.isNumber(record) ? record : this.ds.indexOf(record);
5482         this.getLockedRow(index).rowIndex = index;
5483     },
5484
5485     refresh : function(headersToo){
5486         this.fireEvent('beforerefresh', this);
5487         this.grid.stopEditing(true);
5488         var result = this.renderBody();
5489         this.mainBody.update(result[0]).setWidth(this.getTotalWidth());
5490         this.lockedBody.update(result[1]).setWidth(this.getLockedWidth());
5491         if(headersToo === true){
5492             this.updateHeaders();
5493             this.updateHeaderSortState();
5494         }
5495         this.processRows(0, true);
5496         this.layout();
5497         this.applyEmptyText();
5498         this.fireEvent('refresh', this);
5499     },
5500
5501     onDenyColumnLock : function(){
5502
5503     },
5504
5505     initData : function(ds, cm){
5506         if(this.cm){
5507             this.cm.un('columnlockchange', this.onColumnLock, this);
5508         }
5509         Ext.ux.grid.LockingGridView.superclass.initData.call(this, ds, cm);
5510         if(this.cm){
5511             this.cm.on('columnlockchange', this.onColumnLock, this);
5512         }
5513     },
5514
5515     onColumnLock : function(){
5516         this.refresh(true);
5517     },
5518
5519     handleHdMenuClick : function(item){
5520         var index = this.hdCtxIndex,
5521             cm = this.cm,
5522             id = item.getItemId(),
5523             llen = cm.getLockedCount();
5524         switch(id){
5525             case 'lock':
5526                 if(cm.getColumnCount(true) <= llen + 1){
5527                     this.onDenyColumnLock();
5528                     return;
5529                 }
5530                 cm.setLocked(index, true);
5531                 if(llen != index){
5532                     cm.moveColumn(index, llen);
5533                     this.grid.fireEvent('columnmove', index, llen);
5534                 }
5535             break;
5536             case 'unlock':
5537                 if(llen - 1 != index){
5538                     cm.setLocked(index, false, true);
5539                     cm.moveColumn(index, llen - 1);
5540                     this.grid.fireEvent('columnmove', index, llen - 1);
5541                 }else{
5542                     cm.setLocked(index, false);
5543                 }
5544             break;
5545             default:
5546                 return Ext.ux.grid.LockingGridView.superclass.handleHdMenuClick.call(this, item);
5547         }
5548         return true;
5549     },
5550
5551     handleHdDown : function(e, t){
5552         Ext.ux.grid.LockingGridView.superclass.handleHdDown.call(this, e, t);
5553         if(this.grid.enableColLock !== false){
5554             if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
5555                 var hd = this.findHeaderCell(t),
5556                     index = this.getCellIndex(hd),
5557                     ms = this.hmenu.items, cm = this.cm;
5558                 ms.get('lock').setDisabled(cm.isLocked(index));
5559                 ms.get('unlock').setDisabled(!cm.isLocked(index));
5560             }
5561         }
5562     },
5563
5564     syncHeaderHeight: function(){
5565         this.innerHd.firstChild.firstChild.style.height = 'auto';
5566         this.lockedInnerHd.firstChild.firstChild.style.height = 'auto';
5567         var hd = this.innerHd.firstChild.firstChild.offsetHeight,
5568             lhd = this.lockedInnerHd.firstChild.firstChild.offsetHeight,
5569             height = (lhd > hd ? lhd : hd) + 'px';
5570         this.innerHd.firstChild.firstChild.style.height = height;
5571         this.lockedInnerHd.firstChild.firstChild.style.height = height;
5572     },
5573
5574     updateLockedWidth: function(){
5575         var lw = this.cm.getTotalLockedWidth(),
5576             tw = this.cm.getTotalWidth() - lw,
5577             csize = this.grid.getGridEl().getSize(true),
5578             lp = Ext.isBorderBox ? 0 : this.lockedBorderWidth,
5579             rp = Ext.isBorderBox ? 0 : this.rowBorderWidth,
5580             vw = (csize.width - lw - lp - rp) + 'px',
5581             so = this.getScrollOffset();
5582         if(!this.grid.autoHeight){
5583             var vh = (csize.height - this.mainHd.getHeight()) + 'px';
5584             this.lockedScroller.dom.style.height = vh;
5585             this.scroller.dom.style.height = vh;
5586         }
5587         this.lockedWrap.dom.style.width = (lw + rp) + 'px';
5588         this.scroller.dom.style.width = vw;
5589         this.mainWrap.dom.style.left = (lw + lp + rp) + 'px';
5590         if(this.innerHd){
5591             this.lockedInnerHd.firstChild.style.width = lw + 'px';
5592             this.lockedInnerHd.firstChild.firstChild.style.width = lw + 'px';
5593             this.innerHd.style.width = vw;
5594             this.innerHd.firstChild.style.width = (tw + rp + so) + 'px';
5595             this.innerHd.firstChild.firstChild.style.width = tw + 'px';
5596         }
5597         if(this.mainBody){
5598             this.lockedBody.dom.style.width = (lw + rp) + 'px';
5599             this.mainBody.dom.style.width = (tw + rp) + 'px';
5600         }
5601     }
5602 });
5603
5604 Ext.ux.grid.LockingColumnModel = Ext.extend(Ext.grid.ColumnModel, {
5605     /**
5606      * Returns true if the given column index is currently locked
5607      * @param {Number} colIndex The column index
5608      * @return {Boolean} True if the column is locked
5609      */
5610     isLocked : function(colIndex){
5611         return this.config[colIndex].locked === true;
5612     },
5613
5614     /**
5615      * Locks or unlocks a given column
5616      * @param {Number} colIndex The column index
5617      * @param {Boolean} value True to lock, false to unlock
5618      * @param {Boolean} suppressEvent Pass false to cause the columnlockchange event not to fire
5619      */
5620     setLocked : function(colIndex, value, suppressEvent){
5621         if (this.isLocked(colIndex) == value) {
5622             return;
5623         }
5624         this.config[colIndex].locked = value;
5625         if (!suppressEvent) {
5626             this.fireEvent('columnlockchange', this, colIndex, value);
5627         }
5628     },
5629
5630     /**
5631      * Returns the total width of all locked columns
5632      * @return {Number} The width of all locked columns
5633      */
5634     getTotalLockedWidth : function(){
5635         var totalWidth = 0;
5636         for (var i = 0, len = this.config.length; i < len; i++) {
5637             if (this.isLocked(i) && !this.isHidden(i)) {
5638                 totalWidth += this.getColumnWidth(i);
5639             }
5640         }
5641
5642         return totalWidth;
5643     },
5644
5645     /**
5646      * Returns the total number of locked columns
5647      * @return {Number} The number of locked columns
5648      */
5649     getLockedCount : function() {
5650         var len = this.config.length;
5651
5652         for (var i = 0; i < len; i++) {
5653             if (!this.isLocked(i)) {
5654                 return i;
5655             }
5656         }
5657
5658         //if we get to this point all of the columns are locked so we return the total
5659         return len;
5660     },
5661
5662     /**
5663      * Moves a column from one position to another
5664      * @param {Number} oldIndex The current column index
5665      * @param {Number} newIndex The destination column index
5666      */
5667     moveColumn : function(oldIndex, newIndex){
5668         var oldLocked = this.isLocked(oldIndex),
5669             newLocked = this.isLocked(newIndex);
5670
5671         if (oldIndex < newIndex && oldLocked && !newLocked) {
5672             this.setLocked(oldIndex, false, true);
5673         } else if (oldIndex > newIndex && !oldLocked && newLocked) {
5674             this.setLocked(oldIndex, true, true);
5675         }
5676
5677         Ext.ux.grid.LockingColumnModel.superclass.moveColumn.apply(this, arguments);
5678     }
5679 });
5680 Ext.ns('Ext.ux.form');
5681
5682 /**
5683  * @class Ext.ux.form.MultiSelect
5684  * @extends Ext.form.Field
5685  * A control that allows selection and form submission of multiple list items.
5686  *
5687  *  @history
5688  *    2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
5689  *    2008-06-19 bpm Docs and demo code clean up
5690  *
5691  * @constructor
5692  * Create a new MultiSelect
5693  * @param {Object} config Configuration options
5694  * @xtype multiselect
5695  */
5696 Ext.ux.form.MultiSelect = Ext.extend(Ext.form.Field,  {
5697     /**
5698      * @cfg {String} legend Wraps the object with a fieldset and specified legend.
5699      */
5700     /**
5701      * @cfg {Ext.ListView} view The {@link Ext.ListView} used to render the multiselect list.
5702      */
5703     /**
5704      * @cfg {String/Array} dragGroup The ddgroup name(s) for the MultiSelect DragZone (defaults to undefined).
5705      */
5706     /**
5707      * @cfg {String/Array} dropGroup The ddgroup name(s) for the MultiSelect DropZone (defaults to undefined).
5708      */
5709     /**
5710      * @cfg {Boolean} ddReorder Whether the items in the MultiSelect list are drag/drop reorderable (defaults to false).
5711      */
5712     ddReorder:false,
5713     /**
5714      * @cfg {Object/Array} tbar The top toolbar of the control. This can be a {@link Ext.Toolbar} object, a
5715      * toolbar config, or an array of buttons/button configs to be added to the toolbar.
5716      */
5717     /**
5718      * @cfg {String} appendOnly True if the list should only allow append drops when drag/drop is enabled
5719      * (use for lists which are sorted, defaults to false).
5720      */
5721     appendOnly:false,
5722     /**
5723      * @cfg {Number} width Width in pixels of the control (defaults to 100).
5724      */
5725     width:100,
5726     /**
5727      * @cfg {Number} height Height in pixels of the control (defaults to 100).
5728      */
5729     height:100,
5730     /**
5731      * @cfg {String/Number} displayField Name/Index of the desired display field in the dataset (defaults to 0).
5732      */
5733     displayField:0,
5734     /**
5735      * @cfg {String/Number} valueField Name/Index of the desired value field in the dataset (defaults to 1).
5736      */
5737     valueField:1,
5738     /**
5739      * @cfg {Boolean} allowBlank False to require at least one item in the list to be selected, true to allow no
5740      * selection (defaults to true).
5741      */
5742     allowBlank:true,
5743     /**
5744      * @cfg {Number} minSelections Minimum number of selections allowed (defaults to 0).
5745      */
5746     minSelections:0,
5747     /**
5748      * @cfg {Number} maxSelections Maximum number of selections allowed (defaults to Number.MAX_VALUE).
5749      */
5750     maxSelections:Number.MAX_VALUE,
5751     /**
5752      * @cfg {String} blankText Default text displayed when the control contains no items (defaults to the same value as
5753      * {@link Ext.form.TextField#blankText}.
5754      */
5755     blankText:Ext.form.TextField.prototype.blankText,
5756     /**
5757      * @cfg {String} minSelectionsText Validation message displayed when {@link #minSelections} is not met (defaults to 'Minimum {0}
5758      * item(s) required').  The {0} token will be replaced by the value of {@link #minSelections}.
5759      */
5760     minSelectionsText:'Minimum {0} item(s) required',
5761     /**
5762      * @cfg {String} maxSelectionsText Validation message displayed when {@link #maxSelections} is not met (defaults to 'Maximum {0}
5763      * item(s) allowed').  The {0} token will be replaced by the value of {@link #maxSelections}.
5764      */
5765     maxSelectionsText:'Maximum {0} item(s) allowed',
5766     /**
5767      * @cfg {String} delimiter The string used to delimit between items when set or returned as a string of values
5768      * (defaults to ',').
5769      */
5770     delimiter:',',
5771     /**
5772      * @cfg {Ext.data.Store/Array} store The data source to which this MultiSelect is bound (defaults to <tt>undefined</tt>).
5773      * Acceptable values for this property are:
5774      * <div class="mdetail-params"><ul>
5775      * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
5776      * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally.
5777      * <div class="mdetail-params"><ul>
5778      * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
5779      * A 1-dimensional array will automatically be expanded (each array item will be the combo
5780      * {@link #valueField value} and {@link #displayField text})</div></li>
5781      * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
5782      * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
5783      * {@link #valueField value}, while the value at index 1 is assumed to be the combo {@link #displayField text}.
5784      * </div></li></ul></div></li></ul></div>
5785      */
5786
5787     // private
5788     defaultAutoCreate : {tag: "div"},
5789
5790     // private
5791     initComponent: function(){
5792         Ext.ux.form.MultiSelect.superclass.initComponent.call(this);
5793
5794         if(Ext.isArray(this.store)){
5795             if (Ext.isArray(this.store[0])){
5796                 this.store = new Ext.data.ArrayStore({
5797                     fields: ['value','text'],
5798                     data: this.store
5799                 });
5800                 this.valueField = 'value';
5801             }else{
5802                 this.store = new Ext.data.ArrayStore({
5803                     fields: ['text'],
5804                     data: this.store,
5805                     expandData: true
5806                 });
5807                 this.valueField = 'text';
5808             }
5809             this.displayField = 'text';
5810         } else {
5811             this.store = Ext.StoreMgr.lookup(this.store);
5812         }
5813
5814         this.addEvents({
5815             'dblclick' : true,
5816             'click' : true,
5817             'change' : true,
5818             'drop' : true
5819         });
5820     },
5821
5822     // private
5823     onRender: function(ct, position){
5824         Ext.ux.form.MultiSelect.superclass.onRender.call(this, ct, position);
5825
5826         var fs = this.fs = new Ext.form.FieldSet({
5827             renderTo: this.el,
5828             title: this.legend,
5829             height: this.height,
5830             width: this.width,
5831             style: "padding:0;",
5832             tbar: this.tbar
5833         });
5834         fs.body.addClass('ux-mselect');
5835
5836         this.view = new Ext.ListView({
5837             multiSelect: true,
5838             store: this.store,
5839             columns: [{ header: 'Value', width: 1, dataIndex: this.displayField }],
5840             hideHeaders: true
5841         });
5842
5843         fs.add(this.view);
5844
5845         this.view.on('click', this.onViewClick, this);
5846         this.view.on('beforeclick', this.onViewBeforeClick, this);
5847         this.view.on('dblclick', this.onViewDblClick, this);
5848
5849         this.hiddenName = this.name || Ext.id();
5850         var hiddenTag = { tag: "input", type: "hidden", value: "", name: this.hiddenName };
5851         this.hiddenField = this.el.createChild(hiddenTag);
5852         this.hiddenField.dom.disabled = this.hiddenName != this.name;
5853         fs.doLayout();
5854     },
5855
5856     // private
5857     afterRender: function(){
5858         Ext.ux.form.MultiSelect.superclass.afterRender.call(this);
5859
5860         if (this.ddReorder && !this.dragGroup && !this.dropGroup){
5861             this.dragGroup = this.dropGroup = 'MultiselectDD-' + Ext.id();
5862         }
5863
5864         if (this.draggable || this.dragGroup){
5865             this.dragZone = new Ext.ux.form.MultiSelect.DragZone(this, {
5866                 ddGroup: this.dragGroup
5867             });
5868         }
5869         if (this.droppable || this.dropGroup){
5870             this.dropZone = new Ext.ux.form.MultiSelect.DropZone(this, {
5871                 ddGroup: this.dropGroup
5872             });
5873         }
5874     },
5875
5876     // private
5877     onViewClick: function(vw, index, node, e) {
5878         this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
5879         this.hiddenField.dom.value = this.getValue();
5880         this.fireEvent('click', this, e);
5881         this.validate();
5882     },
5883
5884     // private
5885     onViewBeforeClick: function(vw, index, node, e) {
5886         if (this.disabled || this.readOnly) {
5887             return false;
5888         }
5889     },
5890
5891     // private
5892     onViewDblClick : function(vw, index, node, e) {
5893         return this.fireEvent('dblclick', vw, index, node, e);
5894     },
5895
5896     /**
5897      * Returns an array of data values for the selected items in the list. The values will be separated
5898      * by {@link #delimiter}.
5899      * @return {Array} value An array of string data values
5900      */
5901     getValue: function(valueField){
5902         var returnArray = [];
5903         var selectionsArray = this.view.getSelectedIndexes();
5904         if (selectionsArray.length == 0) {return '';}
5905         for (var i=0; i<selectionsArray.length; i++) {
5906             returnArray.push(this.store.getAt(selectionsArray[i]).get((valueField != null) ? valueField : this.valueField));
5907         }
5908         return returnArray.join(this.delimiter);
5909     },
5910
5911     /**
5912      * Sets a delimited string (using {@link #delimiter}) or array of data values into the list.
5913      * @param {String/Array} values The values to set
5914      */
5915     setValue: function(values) {
5916         var index;
5917         var selections = [];
5918         this.view.clearSelections();
5919         this.hiddenField.dom.value = '';
5920
5921         if (!values || (values == '')) { return; }
5922
5923         if (!Ext.isArray(values)) { values = values.split(this.delimiter); }
5924         for (var i=0; i<values.length; i++) {
5925             index = this.view.store.indexOf(this.view.store.query(this.valueField,
5926                 new RegExp('^' + values[i] + '$', "i")).itemAt(0));
5927             selections.push(index);
5928         }
5929         this.view.select(selections);
5930         this.hiddenField.dom.value = this.getValue();
5931         this.validate();
5932     },
5933
5934     // inherit docs
5935     reset : function() {
5936         this.setValue('');
5937     },
5938
5939     // inherit docs
5940     getRawValue: function(valueField) {
5941         var tmp = this.getValue(valueField);
5942         if (tmp.length) {
5943             tmp = tmp.split(this.delimiter);
5944         }
5945         else {
5946             tmp = [];
5947         }
5948         return tmp;
5949     },
5950
5951     // inherit docs
5952     setRawValue: function(values){
5953         setValue(values);
5954     },
5955
5956     // inherit docs
5957     validateValue : function(value){
5958         if (value.length < 1) { // if it has no value
5959              if (this.allowBlank) {
5960                  this.clearInvalid();
5961                  return true;
5962              } else {
5963                  this.markInvalid(this.blankText);
5964                  return false;
5965              }
5966         }
5967         if (value.length < this.minSelections) {
5968             this.markInvalid(String.format(this.minSelectionsText, this.minSelections));
5969             return false;
5970         }
5971         if (value.length > this.maxSelections) {
5972             this.markInvalid(String.format(this.maxSelectionsText, this.maxSelections));
5973             return false;
5974         }
5975         return true;
5976     },
5977
5978     // inherit docs
5979     disable: function(){
5980         this.disabled = true;
5981         this.hiddenField.dom.disabled = true;
5982         this.fs.disable();
5983     },
5984
5985     // inherit docs
5986     enable: function(){
5987         this.disabled = false;
5988         this.hiddenField.dom.disabled = false;
5989         this.fs.enable();
5990     },
5991
5992     // inherit docs
5993     destroy: function(){
5994         Ext.destroy(this.fs, this.dragZone, this.dropZone);
5995         Ext.ux.form.MultiSelect.superclass.destroy.call(this);
5996     }
5997 });
5998
5999
6000 Ext.reg('multiselect', Ext.ux.form.MultiSelect);
6001
6002 //backwards compat
6003 Ext.ux.Multiselect = Ext.ux.form.MultiSelect;
6004
6005
6006 Ext.ux.form.MultiSelect.DragZone = function(ms, config){
6007     this.ms = ms;
6008     this.view = ms.view;
6009     var ddGroup = config.ddGroup || 'MultiselectDD';
6010     var dd;
6011     if (Ext.isArray(ddGroup)){
6012         dd = ddGroup.shift();
6013     } else {
6014         dd = ddGroup;
6015         ddGroup = null;
6016     }
6017     Ext.ux.form.MultiSelect.DragZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
6018     this.setDraggable(ddGroup);
6019 };
6020
6021 Ext.extend(Ext.ux.form.MultiSelect.DragZone, Ext.dd.DragZone, {
6022     onInitDrag : function(x, y){
6023         var el = Ext.get(this.dragData.ddel.cloneNode(true));
6024         this.proxy.update(el.dom);
6025         el.setWidth(el.child('em').getWidth());
6026         this.onStartDrag(x, y);
6027         return true;
6028     },
6029
6030     // private
6031     collectSelection: function(data) {
6032         data.repairXY = Ext.fly(this.view.getSelectedNodes()[0]).getXY();
6033         var i = 0;
6034         this.view.store.each(function(rec){
6035             if (this.view.isSelected(i)) {
6036                 var n = this.view.getNode(i);
6037                 var dragNode = n.cloneNode(true);
6038                 dragNode.id = Ext.id();
6039                 data.ddel.appendChild(dragNode);
6040                 data.records.push(this.view.store.getAt(i));
6041                 data.viewNodes.push(n);
6042             }
6043             i++;
6044         }, this);
6045     },
6046
6047     // override
6048     onEndDrag: function(data, e) {
6049         var d = Ext.get(this.dragData.ddel);
6050         if (d && d.hasClass("multi-proxy")) {
6051             d.remove();
6052         }
6053     },
6054
6055     // override
6056     getDragData: function(e){
6057         var target = this.view.findItemFromChild(e.getTarget());
6058         if(target) {
6059             if (!this.view.isSelected(target) && !e.ctrlKey && !e.shiftKey) {
6060                 this.view.select(target);
6061                 this.ms.setValue(this.ms.getValue());
6062             }
6063             if (this.view.getSelectionCount() == 0 || e.ctrlKey || e.shiftKey) return false;
6064             var dragData = {
6065                 sourceView: this.view,
6066                 viewNodes: [],
6067                 records: []
6068             };
6069             if (this.view.getSelectionCount() == 1) {
6070                 var i = this.view.getSelectedIndexes()[0];
6071                 var n = this.view.getNode(i);
6072                 dragData.viewNodes.push(dragData.ddel = n);
6073                 dragData.records.push(this.view.store.getAt(i));
6074                 dragData.repairXY = Ext.fly(n).getXY();
6075             } else {
6076                 dragData.ddel = document.createElement('div');
6077                 dragData.ddel.className = 'multi-proxy';
6078                 this.collectSelection(dragData);
6079             }
6080             return dragData;
6081         }
6082         return false;
6083     },
6084
6085     // override the default repairXY.
6086     getRepairXY : function(e){
6087         return this.dragData.repairXY;
6088     },
6089
6090     // private
6091     setDraggable: function(ddGroup){
6092         if (!ddGroup) return;
6093         if (Ext.isArray(ddGroup)) {
6094             Ext.each(ddGroup, this.setDraggable, this);
6095             return;
6096         }
6097         this.addToGroup(ddGroup);
6098     }
6099 });
6100
6101 Ext.ux.form.MultiSelect.DropZone = function(ms, config){
6102     this.ms = ms;
6103     this.view = ms.view;
6104     var ddGroup = config.ddGroup || 'MultiselectDD';
6105     var dd;
6106     if (Ext.isArray(ddGroup)){
6107         dd = ddGroup.shift();
6108     } else {
6109         dd = ddGroup;
6110         ddGroup = null;
6111     }
6112     Ext.ux.form.MultiSelect.DropZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
6113     this.setDroppable(ddGroup);
6114 };
6115
6116 Ext.extend(Ext.ux.form.MultiSelect.DropZone, Ext.dd.DropZone, {
6117     /**
6118      * Part of the Ext.dd.DropZone interface. If no target node is found, the
6119      * whole Element becomes the target, and this causes the drop gesture to append.
6120      */
6121     getTargetFromEvent : function(e) {
6122         var target = e.getTarget();
6123         return target;
6124     },
6125
6126     // private
6127     getDropPoint : function(e, n, dd){
6128         if (n == this.ms.fs.body.dom) { return "below"; }
6129         var t = Ext.lib.Dom.getY(n), b = t + n.offsetHeight;
6130         var c = t + (b - t) / 2;
6131         var y = Ext.lib.Event.getPageY(e);
6132         if(y <= c) {
6133             return "above";
6134         }else{
6135             return "below";
6136         }
6137     },
6138
6139     // private
6140     isValidDropPoint: function(pt, n, data) {
6141         if (!data.viewNodes || (data.viewNodes.length != 1)) {
6142             return true;
6143         }
6144         var d = data.viewNodes[0];
6145         if (d == n) {
6146             return false;
6147         }
6148         if ((pt == "below") && (n.nextSibling == d)) {
6149             return false;
6150         }
6151         if ((pt == "above") && (n.previousSibling == d)) {
6152             return false;
6153         }
6154         return true;
6155     },
6156
6157     // override
6158     onNodeEnter : function(n, dd, e, data){
6159         return false;
6160     },
6161
6162     // override
6163     onNodeOver : function(n, dd, e, data){
6164         var dragElClass = this.dropNotAllowed;
6165         var pt = this.getDropPoint(e, n, dd);
6166         if (this.isValidDropPoint(pt, n, data)) {
6167             if (this.ms.appendOnly) {
6168                 return "x-tree-drop-ok-below";
6169             }
6170
6171             // set the insert point style on the target node
6172             if (pt) {
6173                 var targetElClass;
6174                 if (pt == "above"){
6175                     dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
6176                     targetElClass = "x-view-drag-insert-above";
6177                 } else {
6178                     dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
6179                     targetElClass = "x-view-drag-insert-below";
6180                 }
6181                 if (this.lastInsertClass != targetElClass){
6182                     Ext.fly(n).replaceClass(this.lastInsertClass, targetElClass);
6183                     this.lastInsertClass = targetElClass;
6184                 }
6185             }
6186         }
6187         return dragElClass;
6188     },
6189
6190     // private
6191     onNodeOut : function(n, dd, e, data){
6192         this.removeDropIndicators(n);
6193     },
6194
6195     // private
6196     onNodeDrop : function(n, dd, e, data){
6197         if (this.ms.fireEvent("drop", this, n, dd, e, data) === false) {
6198             return false;
6199         }
6200         var pt = this.getDropPoint(e, n, dd);
6201         if (n != this.ms.fs.body.dom)
6202             n = this.view.findItemFromChild(n);
6203
6204         if(this.ms.appendOnly) {
6205             insertAt = this.view.store.getCount();
6206         } else {
6207             insertAt = n == this.ms.fs.body.dom ? this.view.store.getCount() - 1 : this.view.indexOf(n);
6208             if (pt == "below") {
6209                 insertAt++;
6210             }
6211         }
6212
6213         var dir = false;
6214
6215         // Validate if dragging within the same MultiSelect
6216         if (data.sourceView == this.view) {
6217             // If the first element to be inserted below is the target node, remove it
6218             if (pt == "below") {
6219                 if (data.viewNodes[0] == n) {
6220                     data.viewNodes.shift();
6221                 }
6222             } else {  // If the last element to be inserted above is the target node, remove it
6223                 if (data.viewNodes[data.viewNodes.length - 1] == n) {
6224                     data.viewNodes.pop();
6225                 }
6226             }
6227
6228             // Nothing to drop...
6229             if (!data.viewNodes.length) {
6230                 return false;
6231             }
6232
6233             // If we are moving DOWN, then because a store.remove() takes place first,
6234             // the insertAt must be decremented.
6235             if (insertAt > this.view.store.indexOf(data.records[0])) {
6236                 dir = 'down';
6237                 insertAt--;
6238             }
6239         }
6240
6241         for (var i = 0; i < data.records.length; i++) {
6242             var r = data.records[i];
6243             if (data.sourceView) {
6244                 data.sourceView.store.remove(r);
6245             }
6246             this.view.store.insert(dir == 'down' ? insertAt : insertAt++, r);
6247             var si = this.view.store.sortInfo;
6248             if(si){
6249                 this.view.store.sort(si.field, si.direction);
6250             }
6251         }
6252         return true;
6253     },
6254
6255     // private
6256     removeDropIndicators : function(n){
6257         if(n){
6258             Ext.fly(n).removeClass([
6259                 "x-view-drag-insert-above",
6260                 "x-view-drag-insert-left",
6261                 "x-view-drag-insert-right",
6262                 "x-view-drag-insert-below"]);
6263             this.lastInsertClass = "_noclass";
6264         }
6265     },
6266
6267     // private
6268     setDroppable: function(ddGroup){
6269         if (!ddGroup) return;
6270         if (Ext.isArray(ddGroup)) {
6271             Ext.each(ddGroup, this.setDroppable, this);
6272             return;
6273         }
6274         this.addToGroup(ddGroup);
6275     }
6276 });
6277
6278 /* Fix for Opera, which does not seem to include the map function on Array's */
6279 if (!Array.prototype.map) {
6280     Array.prototype.map = function(fun){
6281         var len = this.length;
6282         if (typeof fun != 'function') {
6283             throw new TypeError();
6284         }
6285         var res = new Array(len);
6286         var thisp = arguments[1];
6287         for (var i = 0; i < len; i++) {
6288             if (i in this) {
6289                 res[i] = fun.call(thisp, this[i], i, this);
6290             }
6291         }
6292         return res;
6293     };
6294 }
6295
6296 Ext.ns('Ext.ux.data');
6297
6298 /**
6299  * @class Ext.ux.data.PagingMemoryProxy
6300  * @extends Ext.data.MemoryProxy
6301  * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
6302  */
6303 Ext.ux.data.PagingMemoryProxy = Ext.extend(Ext.data.MemoryProxy, {
6304     constructor : function(data){
6305         Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);
6306         this.data = data;
6307     },
6308     doRequest : function(action, rs, params, reader, callback, scope, options){
6309         params = params ||
6310         {};
6311         var result;
6312         try {
6313             result = reader.readRecords(this.data);
6314         } 
6315         catch (e) {
6316             this.fireEvent('loadexception', this, options, null, e);
6317             callback.call(scope, null, options, false);
6318             return;
6319         }
6320         
6321         // filtering
6322         if (params.filter !== undefined) {
6323             result.records = result.records.filter(function(el){
6324                 if (typeof(el) == 'object') {
6325                     var att = params.filterCol || 0;
6326                     return String(el.data[att]).match(params.filter) ? true : false;
6327                 }
6328                 else {
6329                     return String(el).match(params.filter) ? true : false;
6330                 }
6331             });
6332             result.totalRecords = result.records.length;
6333         }
6334         
6335         // sorting
6336         if (params.sort !== undefined) {
6337             // use integer as params.sort to specify column, since arrays are not named
6338             // params.sort=0; would also match a array without columns
6339             var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
6340             var fn = function(v1, v2){
6341                 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
6342             };
6343             result.records.sort(function(a, b){
6344                 var v = 0;
6345                 if (typeof(a) == 'object') {
6346                     v = fn(a.data[params.sort], b.data[params.sort]) * dir;
6347                 }
6348                 else {
6349                     v = fn(a, b) * dir;
6350                 }
6351                 if (v == 0) {
6352                     v = (a.index < b.index ? -1 : 1);
6353                 }
6354                 return v;
6355             });
6356         }
6357         // paging (use undefined cause start can also be 0 (thus false))
6358         if (params.start !== undefined && params.limit !== undefined) {
6359             result.records = result.records.slice(params.start, params.start + params.limit);
6360         }
6361         callback.call(scope, result, options, true);
6362     }
6363 });
6364
6365 //backwards compat.
6366 Ext.data.PagingMemoryProxy = Ext.ux.data.PagingMemoryProxy;
6367 Ext.ux.PanelResizer = Ext.extend(Ext.util.Observable, {
6368     minHeight: 0,
6369     maxHeight:10000000,
6370
6371     constructor: function(config){
6372         Ext.apply(this, config);
6373         this.events = {};
6374         Ext.ux.PanelResizer.superclass.constructor.call(this, config);
6375     },
6376
6377     init : function(p){
6378         this.panel = p;
6379
6380         if(this.panel.elements.indexOf('footer')==-1){
6381             p.elements += ',footer';
6382         }
6383         p.on('render', this.onRender, this);
6384     },
6385
6386     onRender : function(p){
6387         this.handle = p.footer.createChild({cls:'x-panel-resize'});
6388
6389         this.tracker = new Ext.dd.DragTracker({
6390             onStart: this.onDragStart.createDelegate(this),
6391             onDrag: this.onDrag.createDelegate(this),
6392             onEnd: this.onDragEnd.createDelegate(this),
6393             tolerance: 3,
6394             autoStart: 300
6395         });
6396         this.tracker.initEl(this.handle);
6397         p.on('beforedestroy', this.tracker.destroy, this.tracker);
6398     },
6399
6400         // private
6401     onDragStart: function(e){
6402         this.dragging = true;
6403         this.startHeight = this.panel.el.getHeight();
6404         this.fireEvent('dragstart', this, e);
6405     },
6406
6407         // private
6408     onDrag: function(e){
6409         this.panel.setHeight((this.startHeight-this.tracker.getOffset()[1]).constrain(this.minHeight, this.maxHeight));
6410         this.fireEvent('drag', this, e);
6411     },
6412
6413         // private
6414     onDragEnd: function(e){
6415         this.dragging = false;
6416         this.fireEvent('dragend', this, e);
6417     }
6418 });
6419 Ext.preg('panelresizer', Ext.ux.PanelResizer);Ext.ux.Portal = Ext.extend(Ext.Panel, {
6420     layout : 'column',
6421     autoScroll : true,
6422     cls : 'x-portal',
6423     defaultType : 'portalcolumn',
6424     
6425     initComponent : function(){
6426         Ext.ux.Portal.superclass.initComponent.call(this);
6427         this.addEvents({
6428             validatedrop:true,
6429             beforedragover:true,
6430             dragover:true,
6431             beforedrop:true,
6432             drop:true
6433         });
6434     },
6435
6436     initEvents : function(){
6437         Ext.ux.Portal.superclass.initEvents.call(this);
6438         this.dd = new Ext.ux.Portal.DropZone(this, this.dropConfig);
6439     },
6440     
6441     beforeDestroy : function() {
6442         if(this.dd){
6443             this.dd.unreg();
6444         }
6445         Ext.ux.Portal.superclass.beforeDestroy.call(this);
6446     }
6447 });
6448
6449 Ext.reg('portal', Ext.ux.Portal);
6450
6451 Ext.ux.Portal.DropZone = Ext.extend(Ext.dd.DropTarget, {
6452     
6453     constructor : function(portal, cfg){
6454         this.portal = portal;
6455         Ext.dd.ScrollManager.register(portal.body);
6456         Ext.ux.Portal.DropZone.superclass.constructor.call(this, portal.bwrap.dom, cfg);
6457         portal.body.ddScrollConfig = this.ddScrollConfig;
6458     },
6459     
6460     ddScrollConfig : {
6461         vthresh: 50,
6462         hthresh: -1,
6463         animate: true,
6464         increment: 200
6465     },
6466
6467     createEvent : function(dd, e, data, col, c, pos){
6468         return {
6469             portal: this.portal,
6470             panel: data.panel,
6471             columnIndex: col,
6472             column: c,
6473             position: pos,
6474             data: data,
6475             source: dd,
6476             rawEvent: e,
6477             status: this.dropAllowed
6478         };
6479     },
6480
6481     notifyOver : function(dd, e, data){
6482         var xy = e.getXY(), portal = this.portal, px = dd.proxy;
6483
6484         // case column widths
6485         if(!this.grid){
6486             this.grid = this.getGrid();
6487         }
6488
6489         // handle case scroll where scrollbars appear during drag
6490         var cw = portal.body.dom.clientWidth;
6491         if(!this.lastCW){
6492             this.lastCW = cw;
6493         }else if(this.lastCW != cw){
6494             this.lastCW = cw;
6495             portal.doLayout();
6496             this.grid = this.getGrid();
6497         }
6498
6499         // determine column
6500         var col = 0, xs = this.grid.columnX, cmatch = false;
6501         for(var len = xs.length; col < len; col++){
6502             if(xy[0] < (xs[col].x + xs[col].w)){
6503                 cmatch = true;
6504                 break;
6505             }
6506         }
6507         // no match, fix last index
6508         if(!cmatch){
6509             col--;
6510         }
6511
6512         // find insert position
6513         var p, match = false, pos = 0,
6514             c = portal.items.itemAt(col),
6515             items = c.items.items, overSelf = false;
6516
6517         for(var len = items.length; pos < len; pos++){
6518             p = items[pos];
6519             var h = p.el.getHeight();
6520             if(h === 0){
6521                 overSelf = true;
6522             }
6523             else if((p.el.getY()+(h/2)) > xy[1]){
6524                 match = true;
6525                 break;
6526             }
6527         }
6528
6529         pos = (match && p ? pos : c.items.getCount()) + (overSelf ? -1 : 0);
6530         var overEvent = this.createEvent(dd, e, data, col, c, pos);
6531
6532         if(portal.fireEvent('validatedrop', overEvent) !== false &&
6533            portal.fireEvent('beforedragover', overEvent) !== false){
6534
6535             // make sure proxy width is fluid
6536             px.getProxy().setWidth('auto');
6537
6538             if(p){
6539                 px.moveProxy(p.el.dom.parentNode, match ? p.el.dom : null);
6540             }else{
6541                 px.moveProxy(c.el.dom, null);
6542             }
6543
6544             this.lastPos = {c: c, col: col, p: overSelf || (match && p) ? pos : false};
6545             this.scrollPos = portal.body.getScroll();
6546
6547             portal.fireEvent('dragover', overEvent);
6548
6549             return overEvent.status;
6550         }else{
6551             return overEvent.status;
6552         }
6553
6554     },
6555
6556     notifyOut : function(){
6557         delete this.grid;
6558     },
6559
6560     notifyDrop : function(dd, e, data){
6561         delete this.grid;
6562         if(!this.lastPos){
6563             return;
6564         }
6565         var c = this.lastPos.c, 
6566             col = this.lastPos.col, 
6567             pos = this.lastPos.p,
6568             panel = dd.panel,
6569             dropEvent = this.createEvent(dd, e, data, col, c,
6570                 pos !== false ? pos : c.items.getCount());
6571
6572         if(this.portal.fireEvent('validatedrop', dropEvent) !== false &&
6573            this.portal.fireEvent('beforedrop', dropEvent) !== false){
6574
6575             dd.proxy.getProxy().remove();
6576             panel.el.dom.parentNode.removeChild(dd.panel.el.dom);
6577             
6578             if(pos !== false){
6579                 c.insert(pos, panel);
6580             }else{
6581                 c.add(panel);
6582             }
6583             
6584             c.doLayout();
6585
6586             this.portal.fireEvent('drop', dropEvent);
6587
6588             // scroll position is lost on drop, fix it
6589             var st = this.scrollPos.top;
6590             if(st){
6591                 var d = this.portal.body.dom;
6592                 setTimeout(function(){
6593                     d.scrollTop = st;
6594                 }, 10);
6595             }
6596
6597         }
6598         delete this.lastPos;
6599     },
6600
6601     // internal cache of body and column coords
6602     getGrid : function(){
6603         var box = this.portal.bwrap.getBox();
6604         box.columnX = [];
6605         this.portal.items.each(function(c){
6606              box.columnX.push({x: c.el.getX(), w: c.el.getWidth()});
6607         });
6608         return box;
6609     },
6610
6611     // unregister the dropzone from ScrollManager
6612     unreg: function() {
6613         Ext.dd.ScrollManager.unregister(this.portal.body);
6614         Ext.ux.Portal.DropZone.superclass.unreg.call(this);
6615     }
6616 });
6617 Ext.ux.PortalColumn = Ext.extend(Ext.Container, {
6618     layout : 'anchor',
6619     //autoEl : 'div',//already defined by Ext.Component
6620     defaultType : 'portlet',
6621     cls : 'x-portal-column'
6622 });
6623
6624 Ext.reg('portalcolumn', Ext.ux.PortalColumn);
6625 Ext.ux.Portlet = Ext.extend(Ext.Panel, {
6626     anchor : '100%',
6627     frame : true,
6628     collapsible : true,
6629     draggable : true,
6630     cls : 'x-portlet'
6631 });
6632
6633 Ext.reg('portlet', Ext.ux.Portlet);
6634 /**
6635 * @class Ext.ux.ProgressBarPager
6636 * @extends Object 
6637 * Plugin (ptype = 'tabclosemenu') for displaying a progressbar inside of a paging toolbar instead of plain text
6638
6639 * @ptype progressbarpager 
6640 * @constructor
6641 * Create a new ItemSelector
6642 * @param {Object} config Configuration options
6643 * @xtype itemselector 
6644 */
6645 Ext.ux.ProgressBarPager  = Ext.extend(Object, {
6646         /**
6647         * @cfg {Integer} progBarWidth
6648         * <p>The default progress bar width.  Default is 225.</p>
6649         */
6650         progBarWidth   : 225,
6651         /**
6652         * @cfg {String} defaultText
6653         * <p>The text to display while the store is loading.  Default is 'Loading...'</p>
6654         */
6655         defaultText    : 'Loading...',
6656         /**
6657         * @cfg {Object} defaultAnimCfg 
6658         * <p>A {@link Ext.Fx Ext.Fx} configuration object.  Default is  { duration : 1, easing : 'bounceOut' }.</p>
6659         */
6660         defaultAnimCfg : {
6661                 duration   : 1,
6662                 easing     : 'bounceOut'        
6663         },                                                                                                
6664         constructor : function(config) {
6665                 if (config) {
6666                         Ext.apply(this, config);
6667                 }
6668         },
6669         //public
6670         init : function (parent) {
6671                 
6672                 if(parent.displayInfo){
6673                         this.parent = parent;
6674                         var ind  = parent.items.indexOf(parent.displayItem);
6675                         parent.remove(parent.displayItem, true);
6676                         this.progressBar = new Ext.ProgressBar({
6677                                 text    : this.defaultText,
6678                                 width   : this.progBarWidth,
6679                                 animate :  this.defaultAnimCfg
6680                         });                                     
6681                    
6682                         parent.displayItem = this.progressBar;
6683                         
6684                         parent.add(parent.displayItem); 
6685                         parent.doLayout();
6686                         Ext.apply(parent, this.parentOverrides);                
6687                         
6688                         this.progressBar.on('render', function(pb) {
6689                 pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
6690             }, this, {single: true});
6691                                                 
6692                 }
6693                   
6694         },
6695         // private
6696         // This method handles the click for the progress bar
6697         handleProgressBarClick : function(e){
6698                 var parent = this.parent,
6699                     displayItem = parent.displayItem,
6700                     box = this.progressBar.getBox(),
6701                     xy = e.getXY(),
6702                     position = xy[0]-box.x,
6703                     pages = Math.ceil(parent.store.getTotalCount()/parent.pageSize),
6704                     newpage = Math.ceil(position/(displayItem.width/pages));
6705             
6706                 parent.changePage(newpage);
6707         },
6708         
6709         // private, overriddes
6710         parentOverrides  : {
6711                 // private
6712                 // This method updates the information via the progress bar.
6713                 updateInfo : function(){
6714                         if(this.displayItem){
6715                                 var count = this.store.getCount(),
6716                                     pgData = this.getPageData(),
6717                                     pageNum = this.readPage(pgData),
6718                                     msg = count == 0 ?
6719                                         this.emptyMsg :
6720                                         String.format(
6721                                                 this.displayMsg,
6722                                                 this.cursor+1, this.cursor+count, this.store.getTotalCount()
6723                                         );
6724                                         
6725                                 pageNum = pgData.activePage; ;  
6726                                 
6727                                 var pct = pageNum / pgData.pages;       
6728                                 
6729                                 this.displayItem.updateProgress(pct, msg, this.animate || this.defaultAnimConfig);
6730                         }
6731                 }
6732         }
6733 });
6734 Ext.preg('progressbarpager', Ext.ux.ProgressBarPager);
6735
6736 Ext.ns('Ext.ux.grid');
6737
6738 /**
6739  * @class Ext.ux.grid.RowEditor
6740  * @extends Ext.Panel
6741  * Plugin (ptype = 'roweditor') that adds the ability to rapidly edit full rows in a grid.
6742  * A validation mode may be enabled which uses AnchorTips to notify the user of all
6743  * validation errors at once.
6744  *
6745  * @ptype roweditor
6746  */
6747 Ext.ux.grid.RowEditor = Ext.extend(Ext.Panel, {
6748     floating: true,
6749     shadow: false,
6750     layout: 'hbox',
6751     cls: 'x-small-editor',
6752     buttonAlign: 'center',
6753     baseCls: 'x-row-editor',
6754     elements: 'header,footer,body',
6755     frameWidth: 5,
6756     buttonPad: 3,
6757     clicksToEdit: 'auto',
6758     monitorValid: true,
6759     focusDelay: 250,
6760     errorSummary: true,
6761
6762     saveText: 'Save',
6763     cancelText: 'Cancel',
6764     commitChangesText: 'You need to commit or cancel your changes',
6765     errorText: 'Errors',
6766
6767     defaults: {
6768         normalWidth: true
6769     },
6770
6771     initComponent: function(){
6772         Ext.ux.grid.RowEditor.superclass.initComponent.call(this);
6773         this.addEvents(
6774             /**
6775              * @event beforeedit
6776              * Fired before the row editor is activated.
6777              * If the listener returns <tt>false</tt> the editor will not be activated.
6778              * @param {Ext.ux.grid.RowEditor} roweditor This object
6779              * @param {Number} rowIndex The rowIndex of the row just edited
6780              */
6781             'beforeedit',
6782             /**
6783              * @event canceledit
6784              * Fired when the editor is cancelled.
6785              * @param {Ext.ux.grid.RowEditor} roweditor This object
6786              * @param {Boolean} forced True if the cancel button is pressed, false is the editor was invalid.
6787              */
6788             'canceledit',
6789             /**
6790              * @event validateedit
6791              * Fired after a row is edited and passes validation.
6792              * If the listener returns <tt>false</tt> changes to the record will not be set.
6793              * @param {Ext.ux.grid.RowEditor} roweditor This object
6794              * @param {Object} changes Object with changes made to the record.
6795              * @param {Ext.data.Record} r The Record that was edited.
6796              * @param {Number} rowIndex The rowIndex of the row just edited
6797              */
6798             'validateedit',
6799             /**
6800              * @event afteredit
6801              * Fired after a row is edited and passes validation.  This event is fired
6802              * after the store's update event is fired with this edit.
6803              * @param {Ext.ux.grid.RowEditor} roweditor This object
6804              * @param {Object} changes Object with changes made to the record.
6805              * @param {Ext.data.Record} r The Record that was edited.
6806              * @param {Number} rowIndex The rowIndex of the row just edited
6807              */
6808             'afteredit'
6809         );
6810     },
6811
6812     init: function(grid){
6813         this.grid = grid;
6814         this.ownerCt = grid;
6815         if(this.clicksToEdit === 2){
6816             grid.on('rowdblclick', this.onRowDblClick, this);
6817         }else{
6818             grid.on('rowclick', this.onRowClick, this);
6819             if(Ext.isIE){
6820                 grid.on('rowdblclick', this.onRowDblClick, this);
6821             }
6822         }
6823
6824         // stopEditing without saving when a record is removed from Store.
6825         grid.getStore().on('remove', function() {
6826             this.stopEditing(false);
6827         },this);
6828
6829         grid.on({
6830             scope: this,
6831             keydown: this.onGridKey,
6832             columnresize: this.verifyLayout,
6833             columnmove: this.refreshFields,
6834             reconfigure: this.refreshFields,
6835             beforedestroy : this.beforedestroy,
6836             destroy : this.destroy,
6837             bodyscroll: {
6838                 buffer: 250,
6839                 fn: this.positionButtons
6840             }
6841         });
6842         grid.getColumnModel().on('hiddenchange', this.verifyLayout, this, {delay:1});
6843         grid.getView().on('refresh', this.stopEditing.createDelegate(this, []));
6844     },
6845
6846     beforedestroy: function() {
6847         this.stopMonitoring();
6848         this.grid.getStore().un('remove', this.onStoreRemove, this);
6849         this.stopEditing(false);
6850         Ext.destroy(this.btns, this.tooltip);
6851     },
6852
6853     refreshFields: function(){
6854         this.initFields();
6855         this.verifyLayout();
6856     },
6857
6858     isDirty: function(){
6859         var dirty;
6860         this.items.each(function(f){
6861             if(String(this.values[f.id]) !== String(f.getValue())){
6862                 dirty = true;
6863                 return false;
6864             }
6865         }, this);
6866         return dirty;
6867     },
6868
6869     startEditing: function(rowIndex, doFocus){
6870         if(this.editing && this.isDirty()){
6871             this.showTooltip(this.commitChangesText);
6872             return;
6873         }
6874         if(Ext.isObject(rowIndex)){
6875             rowIndex = this.grid.getStore().indexOf(rowIndex);
6876         }
6877         if(this.fireEvent('beforeedit', this, rowIndex) !== false){
6878             this.editing = true;
6879             var g = this.grid, view = g.getView(),
6880                 row = view.getRow(rowIndex),
6881                 record = g.store.getAt(rowIndex);
6882
6883             this.record = record;
6884             this.rowIndex = rowIndex;
6885             this.values = {};
6886             if(!this.rendered){
6887                 this.render(view.getEditorParent());
6888             }
6889             var w = Ext.fly(row).getWidth();
6890             this.setSize(w);
6891             if(!this.initialized){
6892                 this.initFields();
6893             }
6894             var cm = g.getColumnModel(), fields = this.items.items, f, val;
6895             for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6896                 val = this.preEditValue(record, cm.getDataIndex(i));
6897                 f = fields[i];
6898                 f.setValue(val);
6899                 this.values[f.id] = Ext.isEmpty(val) ? '' : val;
6900             }
6901             this.verifyLayout(true);
6902             if(!this.isVisible()){
6903                 this.setPagePosition(Ext.fly(row).getXY());
6904             } else{
6905                 this.el.setXY(Ext.fly(row).getXY(), {duration:0.15});
6906             }
6907             if(!this.isVisible()){
6908                 this.show().doLayout();
6909             }
6910             if(doFocus !== false){
6911                 this.doFocus.defer(this.focusDelay, this);
6912             }
6913         }
6914     },
6915
6916     stopEditing : function(saveChanges){
6917         this.editing = false;
6918         if(!this.isVisible()){
6919             return;
6920         }
6921         if(saveChanges === false || !this.isValid()){
6922             this.hide();
6923             this.fireEvent('canceledit', this, saveChanges === false);
6924             return;
6925         }
6926         var changes = {},
6927             r = this.record,
6928             hasChange = false,
6929             cm = this.grid.colModel,
6930             fields = this.items.items;
6931         for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6932             if(!cm.isHidden(i)){
6933                 var dindex = cm.getDataIndex(i);
6934                 if(!Ext.isEmpty(dindex)){
6935                     var oldValue = r.data[dindex],
6936                         value = this.postEditValue(fields[i].getValue(), oldValue, r, dindex);
6937                     if(String(oldValue) !== String(value)){
6938                         changes[dindex] = value;
6939                         hasChange = true;
6940                     }
6941                 }
6942             }
6943         }
6944         if(hasChange && this.fireEvent('validateedit', this, changes, r, this.rowIndex) !== false){
6945             r.beginEdit();
6946             Ext.iterate(changes, function(name, value){
6947                 r.set(name, value);
6948             });
6949             r.endEdit();
6950             this.fireEvent('afteredit', this, changes, r, this.rowIndex);
6951         }
6952         this.hide();
6953     },
6954
6955     verifyLayout: function(force){
6956         if(this.el && (this.isVisible() || force === true)){
6957             var row = this.grid.getView().getRow(this.rowIndex);
6958             this.setSize(Ext.fly(row).getWidth(), Ext.isIE ? Ext.fly(row).getHeight() + 9 : undefined);
6959             var cm = this.grid.colModel, fields = this.items.items;
6960             for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6961                 if(!cm.isHidden(i)){
6962                     var adjust = 0;
6963                     if(i === (len - 1)){
6964                         adjust += 3; // outer padding
6965                     } else{
6966                         adjust += 1;
6967                     }
6968                     fields[i].show();
6969                     fields[i].setWidth(cm.getColumnWidth(i) - adjust);
6970                 } else{
6971                     fields[i].hide();
6972                 }
6973             }
6974             this.doLayout();
6975             this.positionButtons();
6976         }
6977     },
6978
6979     slideHide : function(){
6980         this.hide();
6981     },
6982
6983     initFields: function(){
6984         var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
6985         this.removeAll(false);
6986         for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6987             var c = cm.getColumnAt(i),
6988                 ed = c.getEditor();
6989             if(!ed){
6990                 ed = c.displayEditor || new Ext.form.DisplayField();
6991             }
6992             if(i == 0){
6993                 ed.margins = pm('0 1 2 1');
6994             } else if(i == len - 1){
6995                 ed.margins = pm('0 0 2 1');
6996             } else{
6997                 if (Ext.isIE) {
6998                     ed.margins = pm('0 0 2 0');
6999                 }
7000                 else {
7001                     ed.margins = pm('0 1 2 0');
7002                 }
7003             }
7004             ed.setWidth(cm.getColumnWidth(i));
7005             ed.column = c;
7006             if(ed.ownerCt !== this){
7007                 ed.on('focus', this.ensureVisible, this);
7008                 ed.on('specialkey', this.onKey, this);
7009             }
7010             this.insert(i, ed);
7011         }
7012         this.initialized = true;
7013     },
7014
7015     onKey: function(f, e){
7016         if(e.getKey() === e.ENTER){
7017             this.stopEditing(true);
7018             e.stopPropagation();
7019         }
7020     },
7021
7022     onGridKey: function(e){
7023         if(e.getKey() === e.ENTER && !this.isVisible()){
7024             var r = this.grid.getSelectionModel().getSelected();
7025             if(r){
7026                 var index = this.grid.store.indexOf(r);
7027                 this.startEditing(index);
7028                 e.stopPropagation();
7029             }
7030         }
7031     },
7032
7033     ensureVisible: function(editor){
7034         if(this.isVisible()){
7035              this.grid.getView().ensureVisible(this.rowIndex, this.grid.colModel.getIndexById(editor.column.id), true);
7036         }
7037     },
7038
7039     onRowClick: function(g, rowIndex, e){
7040         if(this.clicksToEdit == 'auto'){
7041             var li = this.lastClickIndex;
7042             this.lastClickIndex = rowIndex;
7043             if(li != rowIndex && !this.isVisible()){
7044                 return;
7045             }
7046         }
7047         this.startEditing(rowIndex, false);
7048         this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
7049     },
7050
7051     onRowDblClick: function(g, rowIndex, e){
7052         this.startEditing(rowIndex, false);
7053         this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
7054     },
7055
7056     onRender: function(){
7057         Ext.ux.grid.RowEditor.superclass.onRender.apply(this, arguments);
7058         this.el.swallowEvent(['keydown', 'keyup', 'keypress']);
7059         this.btns = new Ext.Panel({
7060             baseCls: 'x-plain',
7061             cls: 'x-btns',
7062             elements:'body',
7063             layout: 'table',
7064             width: (this.minButtonWidth * 2) + (this.frameWidth * 2) + (this.buttonPad * 4), // width must be specified for IE
7065             items: [{
7066                 ref: 'saveBtn',
7067                 itemId: 'saveBtn',
7068                 xtype: 'button',
7069                 text: this.saveText,
7070                 width: this.minButtonWidth,
7071                 handler: this.stopEditing.createDelegate(this, [true])
7072             }, {
7073                 xtype: 'button',
7074                 text: this.cancelText,
7075                 width: this.minButtonWidth,
7076                 handler: this.stopEditing.createDelegate(this, [false])
7077             }]
7078         });
7079         this.btns.render(this.bwrap);
7080     },
7081
7082     afterRender: function(){
7083         Ext.ux.grid.RowEditor.superclass.afterRender.apply(this, arguments);
7084         this.positionButtons();
7085         if(this.monitorValid){
7086             this.startMonitoring();
7087         }
7088     },
7089
7090     onShow: function(){
7091         if(this.monitorValid){
7092             this.startMonitoring();
7093         }
7094         Ext.ux.grid.RowEditor.superclass.onShow.apply(this, arguments);
7095     },
7096
7097     onHide: function(){
7098         Ext.ux.grid.RowEditor.superclass.onHide.apply(this, arguments);
7099         this.stopMonitoring();
7100         this.grid.getView().focusRow(this.rowIndex);
7101     },
7102
7103     positionButtons: function(){
7104         if(this.btns){
7105             var g = this.grid,
7106                 h = this.el.dom.clientHeight,
7107                 view = g.getView(),
7108                 scroll = view.scroller.dom.scrollLeft,
7109                 bw = this.btns.getWidth(),
7110                 width = Math.min(g.getWidth(), g.getColumnModel().getTotalWidth());
7111
7112             this.btns.el.shift({left: (width/2)-(bw/2)+scroll, top: h - 2, stopFx: true, duration:0.2});
7113         }
7114     },
7115
7116     // private
7117     preEditValue : function(r, field){
7118         var value = r.data[field];
7119         return this.autoEncode && typeof value === 'string' ? Ext.util.Format.htmlDecode(value) : value;
7120     },
7121
7122     // private
7123     postEditValue : function(value, originalValue, r, field){
7124         return this.autoEncode && typeof value == 'string' ? Ext.util.Format.htmlEncode(value) : value;
7125     },
7126
7127     doFocus: function(pt){
7128         if(this.isVisible()){
7129             var index = 0,
7130                 cm = this.grid.getColumnModel(),
7131                 c;
7132             if(pt){
7133                 index = this.getTargetColumnIndex(pt);
7134             }
7135             for(var i = index||0, len = cm.getColumnCount(); i < len; i++){
7136                 c = cm.getColumnAt(i);
7137                 if(!c.hidden && c.getEditor()){
7138                     c.getEditor().focus();
7139                     break;
7140                 }
7141             }
7142         }
7143     },
7144
7145     getTargetColumnIndex: function(pt){
7146         var grid = this.grid,
7147             v = grid.view,
7148             x = pt.left,
7149             cms = grid.colModel.config,
7150             i = 0,
7151             match = false;
7152         for(var len = cms.length, c; c = cms[i]; i++){
7153             if(!c.hidden){
7154                 if(Ext.fly(v.getHeaderCell(i)).getRegion().right >= x){
7155                     match = i;
7156                     break;
7157                 }
7158             }
7159         }
7160         return match;
7161     },
7162
7163     startMonitoring : function(){
7164         if(!this.bound && this.monitorValid){
7165             this.bound = true;
7166             Ext.TaskMgr.start({
7167                 run : this.bindHandler,
7168                 interval : this.monitorPoll || 200,
7169                 scope: this
7170             });
7171         }
7172     },
7173
7174     stopMonitoring : function(){
7175         this.bound = false;
7176         if(this.tooltip){
7177             this.tooltip.hide();
7178         }
7179     },
7180
7181     isValid: function(){
7182         var valid = true;
7183         this.items.each(function(f){
7184             if(!f.isValid(true)){
7185                 valid = false;
7186                 return false;
7187             }
7188         });
7189         return valid;
7190     },
7191
7192     // private
7193     bindHandler : function(){
7194         if(!this.bound){
7195             return false; // stops binding
7196         }
7197         var valid = this.isValid();
7198         if(!valid && this.errorSummary){
7199             this.showTooltip(this.getErrorText().join(''));
7200         }
7201         this.btns.saveBtn.setDisabled(!valid);
7202         this.fireEvent('validation', this, valid);
7203     },
7204
7205     lastVisibleColumn : function() {
7206         var i = this.items.getCount() - 1,
7207             c;
7208         for(; i >= 0; i--) {
7209             c = this.items.items[i];
7210             if (!c.hidden) {
7211                 return c;
7212             }
7213         }
7214     },
7215
7216     showTooltip: function(msg){
7217         var t = this.tooltip;
7218         if(!t){
7219             t = this.tooltip = new Ext.ToolTip({
7220                 maxWidth: 600,
7221                 cls: 'errorTip',
7222                 width: 300,
7223                 title: this.errorText,
7224                 autoHide: false,
7225                 anchor: 'left',
7226                 anchorToTarget: true,
7227                 mouseOffset: [40,0]
7228             });
7229         }
7230         var v = this.grid.getView(),
7231             top = parseInt(this.el.dom.style.top, 10),
7232             scroll = v.scroller.dom.scrollTop,
7233             h = this.el.getHeight();
7234
7235         if(top + h >= scroll){
7236             t.initTarget(this.lastVisibleColumn().getEl());
7237             if(!t.rendered){
7238                 t.show();
7239                 t.hide();
7240             }
7241             t.body.update(msg);
7242             t.doAutoWidth(20);
7243             t.show();
7244         }else if(t.rendered){
7245             t.hide();
7246         }
7247     },
7248
7249     getErrorText: function(){
7250         var data = ['<ul>'];
7251         this.items.each(function(f){
7252             if(!f.isValid(true)){
7253                 data.push('<li>', f.getActiveError(), '</li>');
7254             }
7255         });
7256         data.push('</ul>');
7257         return data;
7258     }
7259 });
7260 Ext.preg('roweditor', Ext.ux.grid.RowEditor);
7261 Ext.ns('Ext.ux.grid');
7262
7263 /**
7264  * @class Ext.ux.grid.RowExpander
7265  * @extends Ext.util.Observable
7266  * Plugin (ptype = 'rowexpander') that adds the ability to have a Column in a grid which enables
7267  * a second row body which expands/contracts.  The expand/contract behavior is configurable to react
7268  * on clicking of the column, double click of the row, and/or hitting enter while a row is selected.
7269  *
7270  * @ptype rowexpander
7271  */
7272 Ext.ux.grid.RowExpander = Ext.extend(Ext.util.Observable, {
7273     /**
7274      * @cfg {Boolean} expandOnEnter
7275      * <tt>true</tt> to toggle selected row(s) between expanded/collapsed when the enter
7276      * key is pressed (defaults to <tt>true</tt>).
7277      */
7278     expandOnEnter : true,
7279     /**
7280      * @cfg {Boolean} expandOnDblClick
7281      * <tt>true</tt> to toggle a row between expanded/collapsed when double clicked
7282      * (defaults to <tt>true</tt>).
7283      */
7284     expandOnDblClick : true,
7285
7286     header : '',
7287     width : 20,
7288     sortable : false,
7289     fixed : true,
7290     hideable: false,
7291     menuDisabled : true,
7292     dataIndex : '',
7293     id : 'expander',
7294     lazyRender : true,
7295     enableCaching : true,
7296
7297     constructor: function(config){
7298         Ext.apply(this, config);
7299
7300         this.addEvents({
7301             /**
7302              * @event beforeexpand
7303              * Fires before the row expands. Have the listener return false to prevent the row from expanding.
7304              * @param {Object} this RowExpander object.
7305              * @param {Object} Ext.data.Record Record for the selected row.
7306              * @param {Object} body body element for the secondary row.
7307              * @param {Number} rowIndex The current row index.
7308              */
7309             beforeexpand: true,
7310             /**
7311              * @event expand
7312              * Fires after the row expands.
7313              * @param {Object} this RowExpander object.
7314              * @param {Object} Ext.data.Record Record for the selected row.
7315              * @param {Object} body body element for the secondary row.
7316              * @param {Number} rowIndex The current row index.
7317              */
7318             expand: true,
7319             /**
7320              * @event beforecollapse
7321              * Fires before the row collapses. Have the listener return false to prevent the row from collapsing.
7322              * @param {Object} this RowExpander object.
7323              * @param {Object} Ext.data.Record Record for the selected row.
7324              * @param {Object} body body element for the secondary row.
7325              * @param {Number} rowIndex The current row index.
7326              */
7327             beforecollapse: true,
7328             /**
7329              * @event collapse
7330              * Fires after the row collapses.
7331              * @param {Object} this RowExpander object.
7332              * @param {Object} Ext.data.Record Record for the selected row.
7333              * @param {Object} body body element for the secondary row.
7334              * @param {Number} rowIndex The current row index.
7335              */
7336             collapse: true
7337         });
7338
7339         Ext.ux.grid.RowExpander.superclass.constructor.call(this);
7340
7341         if(this.tpl){
7342             if(typeof this.tpl == 'string'){
7343                 this.tpl = new Ext.Template(this.tpl);
7344             }
7345             this.tpl.compile();
7346         }
7347
7348         this.state = {};
7349         this.bodyContent = {};
7350     },
7351
7352     getRowClass : function(record, rowIndex, p, ds){
7353         p.cols = p.cols-1;
7354         var content = this.bodyContent[record.id];
7355         if(!content && !this.lazyRender){
7356             content = this.getBodyContent(record, rowIndex);
7357         }
7358         if(content){
7359             p.body = content;
7360         }
7361         return this.state[record.id] ? 'x-grid3-row-expanded' : 'x-grid3-row-collapsed';
7362     },
7363
7364     init : function(grid){
7365         this.grid = grid;
7366
7367         var view = grid.getView();
7368         view.getRowClass = this.getRowClass.createDelegate(this);
7369
7370         view.enableRowBody = true;
7371
7372
7373         grid.on('render', this.onRender, this);
7374         grid.on('destroy', this.onDestroy, this);
7375     },
7376
7377     // @private
7378     onRender: function() {
7379         var grid = this.grid;
7380         var mainBody = grid.getView().mainBody;
7381         mainBody.on('mousedown', this.onMouseDown, this, {delegate: '.x-grid3-row-expander'});
7382         if (this.expandOnEnter) {
7383             this.keyNav = new Ext.KeyNav(this.grid.getGridEl(), {
7384                 'enter' : this.onEnter,
7385                 scope: this
7386             });
7387         }
7388         if (this.expandOnDblClick) {
7389             grid.on('rowdblclick', this.onRowDblClick, this);
7390         }
7391     },
7392     
7393     // @private    
7394     onDestroy: function() {
7395         if(this.keyNav){
7396             this.keyNav.disable();
7397             delete this.keyNav;
7398         }
7399         /*
7400          * A majority of the time, the plugin will be destroyed along with the grid,
7401          * which means the mainBody won't be available. On the off chance that the plugin
7402          * isn't destroyed with the grid, take care of removing the listener.
7403          */
7404         var mainBody = this.grid.getView().mainBody;
7405         if(mainBody){
7406             mainBody.un('mousedown', this.onMouseDown, this);
7407         }
7408     },
7409     // @private
7410     onRowDblClick: function(grid, rowIdx, e) {
7411         this.toggleRow(rowIdx);
7412     },
7413
7414     onEnter: function(e) {
7415         var g = this.grid;
7416         var sm = g.getSelectionModel();
7417         var sels = sm.getSelections();
7418         for (var i = 0, len = sels.length; i < len; i++) {
7419             var rowIdx = g.getStore().indexOf(sels[i]);
7420             this.toggleRow(rowIdx);
7421         }
7422     },
7423
7424     getBodyContent : function(record, index){
7425         if(!this.enableCaching){
7426             return this.tpl.apply(record.data);
7427         }
7428         var content = this.bodyContent[record.id];
7429         if(!content){
7430             content = this.tpl.apply(record.data);
7431             this.bodyContent[record.id] = content;
7432         }
7433         return content;
7434     },
7435
7436     onMouseDown : function(e, t){
7437         e.stopEvent();
7438         var row = e.getTarget('.x-grid3-row');
7439         this.toggleRow(row);
7440     },
7441
7442     renderer : function(v, p, record){
7443         p.cellAttr = 'rowspan="2"';
7444         return '<div class="x-grid3-row-expander">&#160;</div>';
7445     },
7446
7447     beforeExpand : function(record, body, rowIndex){
7448         if(this.fireEvent('beforeexpand', this, record, body, rowIndex) !== false){
7449             if(this.tpl && this.lazyRender){
7450                 body.innerHTML = this.getBodyContent(record, rowIndex);
7451             }
7452             return true;
7453         }else{
7454             return false;
7455         }
7456     },
7457
7458     toggleRow : function(row){
7459         if(typeof row == 'number'){
7460             row = this.grid.view.getRow(row);
7461         }
7462         this[Ext.fly(row).hasClass('x-grid3-row-collapsed') ? 'expandRow' : 'collapseRow'](row);
7463     },
7464
7465     expandRow : function(row){
7466         if(typeof row == 'number'){
7467             row = this.grid.view.getRow(row);
7468         }
7469         var record = this.grid.store.getAt(row.rowIndex);
7470         var body = Ext.DomQuery.selectNode('tr:nth(2) div.x-grid3-row-body', row);
7471         if(this.beforeExpand(record, body, row.rowIndex)){
7472             this.state[record.id] = true;
7473             Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
7474             this.fireEvent('expand', this, record, body, row.rowIndex);
7475         }
7476     },
7477
7478     collapseRow : function(row){
7479         if(typeof row == 'number'){
7480             row = this.grid.view.getRow(row);
7481         }
7482         var record = this.grid.store.getAt(row.rowIndex);
7483         var body = Ext.fly(row).child('tr:nth(1) div.x-grid3-row-body', true);
7484         if(this.fireEvent('beforecollapse', this, record, body, row.rowIndex) !== false){
7485             this.state[record.id] = false;
7486             Ext.fly(row).replaceClass('x-grid3-row-expanded', 'x-grid3-row-collapsed');
7487             this.fireEvent('collapse', this, record, body, row.rowIndex);
7488         }
7489     }
7490 });
7491
7492 Ext.preg('rowexpander', Ext.ux.grid.RowExpander);
7493
7494 //backwards compat
7495 Ext.grid.RowExpander = Ext.ux.grid.RowExpander;// We are adding these custom layouts to a namespace that does not
7496 // exist by default in Ext, so we have to add the namespace first:
7497 Ext.ns('Ext.ux.layout');
7498
7499 /**
7500  * @class Ext.ux.layout.RowLayout
7501  * @extends Ext.layout.ContainerLayout
7502  * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of
7503  * each row can be specified as a percentage or fixed height.  Row widths can also be fixed, percentage or auto.
7504  * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config,
7505  * and should generally not need to be created directly via the new keyword.</p>
7506  * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a
7507  * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it.  The
7508  * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel.
7509  * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p>
7510  * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1.
7511  * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and
7512  * less than 1 (e.g., .25).</p>
7513  * <p>The basic rules for specifying row heights are pretty simple.  The logic makes two passes through the
7514  * set of contained panels.  During the first layout pass, all panels that either have a fixed height or none
7515  * specified (auto) are skipped, but their heights are subtracted from the overall container height.  During the second
7516  * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on
7517  * the total <b>remaining</b> container height.  In other words, percentage height panels are designed to fill the space
7518  * left over by all the fixed-height and/or auto-height panels.  Because of this, while you can specify any number of rows
7519  * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your
7520  * layout may not render as expected.  Example usage:</p>
7521  * <pre><code>
7522 // All rows are percentages -- they must add up to 1
7523 var p = new Ext.Panel({
7524     title: 'Row Layout - Percentage Only',
7525     layout:'ux.row',
7526     items: [{
7527         title: 'Row 1',
7528         rowHeight: .25
7529     },{
7530         title: 'Row 2',
7531         rowHeight: .6
7532     },{
7533         title: 'Row 3',
7534         rowHeight: .15
7535     }]
7536 });
7537
7538 // Mix of height and rowHeight -- all rowHeight values must add
7539 // up to 1. The first row will take up exactly 120px, and the last two
7540 // rows will fill the remaining container height.
7541 var p = new Ext.Panel({
7542     title: 'Row Layout - Mixed',
7543     layout:'ux.row',
7544     items: [{
7545         title: 'Row 1',
7546         height: 120,
7547         // standard panel widths are still supported too:
7548         width: '50%' // or 200
7549     },{
7550         title: 'Row 2',
7551         rowHeight: .8,
7552         width: 300
7553     },{
7554         title: 'Row 3',
7555         rowHeight: .2
7556     }]
7557 });
7558 </code></pre>
7559  */
7560 Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
7561     // private
7562     monitorResize:true,
7563
7564     type: 'row',
7565
7566     // private
7567     allowContainerRemove: false,
7568
7569     // private
7570     isValidParent : function(c, target){
7571         return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
7572     },
7573
7574     getLayoutTargetSize : function() {
7575         var target = this.container.getLayoutTarget(), ret;
7576         if (target) {
7577             ret = target.getViewSize();
7578
7579             // IE in strict mode will return a height of 0 on the 1st pass of getViewSize.
7580             // Use getStyleSize to verify the 0 height, the adjustment pass will then work properly
7581             // with getViewSize
7582             if (Ext.isIE && Ext.isStrict && ret.height == 0){
7583                 ret =  target.getStyleSize();
7584             }
7585
7586             ret.width -= target.getPadding('lr');
7587             ret.height -= target.getPadding('tb');
7588         }
7589         return ret;
7590     },
7591
7592     renderAll : function(ct, target) {
7593         if(!this.innerCt){
7594             // the innerCt prevents wrapping and shuffling while
7595             // the container is resizing
7596             this.innerCt = target.createChild({cls:'x-column-inner'});
7597             this.innerCt.createChild({cls:'x-clear'});
7598         }
7599         Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
7600     },
7601
7602     // private
7603     onLayout : function(ct, target){
7604         var rs = ct.items.items,
7605             len = rs.length,
7606             r,
7607             m,
7608             i,
7609             margins = [];
7610
7611         this.renderAll(ct, target);
7612
7613         var size = this.getLayoutTargetSize();
7614
7615         if(size.width < 1 && size.height < 1){ // display none?
7616             return;
7617         }
7618
7619         var h = size.height,
7620             ph = h;
7621
7622         this.innerCt.setSize({height:h});
7623
7624         // some rows can be percentages while others are fixed
7625         // so we need to make 2 passes
7626
7627         for(i = 0; i < len; i++){
7628             r = rs[i];
7629             m = r.getPositionEl().getMargins('tb');
7630             margins[i] = m;
7631             if(!r.rowHeight){
7632                 ph -= (r.getHeight() + m);
7633             }
7634         }
7635
7636         ph = ph < 0 ? 0 : ph;
7637
7638         for(i = 0; i < len; i++){
7639             r = rs[i];
7640             m = margins[i];
7641             if(r.rowHeight){
7642                 r.setSize({height: Math.floor(r.rowHeight*ph) - m});
7643             }
7644         }
7645
7646         // Browsers differ as to when they account for scrollbars.  We need to re-measure to see if the scrollbar
7647         // spaces were accounted for properly.  If not, re-layout.
7648         if (Ext.isIE) {
7649             if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
7650                 var ts = this.getLayoutTargetSize();
7651                 if (ts.width != size.width){
7652                     this.adjustmentPass = true;
7653                     this.onLayout(ct, target);
7654                 }
7655             }
7656         }
7657         delete this.adjustmentPass;
7658     }
7659
7660     /**
7661      * @property activeItem
7662      * @hide
7663      */
7664 });
7665
7666 Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;
7667 Ext.ns('Ext.ux.form');
7668
7669 Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
7670     initComponent : function(){
7671         Ext.ux.form.SearchField.superclass.initComponent.call(this);
7672         this.on('specialkey', function(f, e){
7673             if(e.getKey() == e.ENTER){
7674                 this.onTrigger2Click();
7675             }
7676         }, this);
7677     },
7678
7679     validationEvent:false,
7680     validateOnBlur:false,
7681     trigger1Class:'x-form-clear-trigger',
7682     trigger2Class:'x-form-search-trigger',
7683     hideTrigger1:true,
7684     width:180,
7685     hasSearch : false,
7686     paramName : 'query',
7687
7688     onTrigger1Click : function(){
7689         if(this.hasSearch){
7690             this.el.dom.value = '';
7691             var o = {start: 0};
7692             this.store.baseParams = this.store.baseParams || {};
7693             this.store.baseParams[this.paramName] = '';
7694             this.store.reload({params:o});
7695             this.triggers[0].hide();
7696             this.hasSearch = false;
7697         }
7698     },
7699
7700     onTrigger2Click : function(){
7701         var v = this.getRawValue();
7702         if(v.length < 1){
7703             this.onTrigger1Click();
7704             return;
7705         }
7706         var o = {start: 0};
7707         this.store.baseParams = this.store.baseParams || {};
7708         this.store.baseParams[this.paramName] = v;
7709         this.store.reload({params:o});
7710         this.hasSearch = true;
7711         this.triggers[0].show();
7712     }
7713 });Ext.ns('Ext.ux.form');
7714
7715 /**
7716  * @class Ext.ux.form.SelectBox
7717  * @extends Ext.form.ComboBox
7718  * <p>Makes a ComboBox more closely mimic an HTML SELECT.  Supports clicking and dragging
7719  * through the list, with item selection occurring when the mouse button is released.
7720  * When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}
7721  * on inner elements.  Re-enabling editable after calling this will NOT work.</p>
7722  * @author Corey Gilmore http://extjs.com/forum/showthread.php?t=6392
7723  * @history 2007-07-08 jvs
7724  * Slight mods for Ext 2.0
7725  * @xtype selectbox
7726  */
7727 Ext.ux.form.SelectBox = Ext.extend(Ext.form.ComboBox, {
7728         constructor: function(config){
7729                 this.searchResetDelay = 1000;
7730                 config = config || {};
7731                 config = Ext.apply(config || {}, {
7732                         editable: false,
7733                         forceSelection: true,
7734                         rowHeight: false,
7735                         lastSearchTerm: false,
7736                         triggerAction: 'all',
7737                         mode: 'local'
7738                 });
7739
7740                 Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);
7741
7742                 this.lastSelectedIndex = this.selectedIndex || 0;
7743         },
7744
7745         initEvents : function(){
7746                 Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);
7747                 // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE
7748                 this.el.on('keydown', this.keySearch, this, true);
7749                 this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);
7750         },
7751
7752         keySearch : function(e, target, options) {
7753                 var raw = e.getKey();
7754                 var key = String.fromCharCode(raw);
7755                 var startIndex = 0;
7756
7757                 if( !this.store.getCount() ) {
7758                         return;
7759                 }
7760
7761                 switch(raw) {
7762                         case Ext.EventObject.HOME:
7763                                 e.stopEvent();
7764                                 this.selectFirst();
7765                                 return;
7766
7767                         case Ext.EventObject.END:
7768                                 e.stopEvent();
7769                                 this.selectLast();
7770                                 return;
7771
7772                         case Ext.EventObject.PAGEDOWN:
7773                                 this.selectNextPage();
7774                                 e.stopEvent();
7775                                 return;
7776
7777                         case Ext.EventObject.PAGEUP:
7778                                 this.selectPrevPage();
7779                                 e.stopEvent();
7780                                 return;
7781                 }
7782
7783                 // skip special keys other than the shift key
7784                 if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {
7785                         return;
7786                 }
7787                 if( this.lastSearchTerm == key ) {
7788                         startIndex = this.lastSelectedIndex;
7789                 }
7790                 this.search(this.displayField, key, startIndex);
7791                 this.cshTask.delay(this.searchResetDelay);
7792         },
7793
7794         onRender : function(ct, position) {
7795                 this.store.on('load', this.calcRowsPerPage, this);
7796                 Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);
7797                 if( this.mode == 'local' ) {
7798             this.initList();
7799                         this.calcRowsPerPage();
7800                 }
7801         },
7802
7803         onSelect : function(record, index, skipCollapse){
7804                 if(this.fireEvent('beforeselect', this, record, index) !== false){
7805                         this.setValue(record.data[this.valueField || this.displayField]);
7806                         if( !skipCollapse ) {
7807                                 this.collapse();
7808                         }
7809                         this.lastSelectedIndex = index + 1;
7810                         this.fireEvent('select', this, record, index);
7811                 }
7812         },
7813
7814         afterRender : function() {
7815                 Ext.ux.form.SelectBox.superclass.afterRender.apply(this, arguments);
7816                 if(Ext.isWebKit) {
7817                         this.el.swallowEvent('mousedown', true);
7818                 }
7819                 this.el.unselectable();
7820                 this.innerList.unselectable();
7821                 this.trigger.unselectable();
7822                 this.innerList.on('mouseup', function(e, target, options) {
7823                         if( target.id && target.id == this.innerList.id ) {
7824                                 return;
7825                         }
7826                         this.onViewClick();
7827                 }, this);
7828
7829                 this.innerList.on('mouseover', function(e, target, options) {
7830                         if( target.id && target.id == this.innerList.id ) {
7831                                 return;
7832                         }
7833                         this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;
7834                         this.cshTask.delay(this.searchResetDelay);
7835                 }, this);
7836
7837                 this.trigger.un('click', this.onTriggerClick, this);
7838                 this.trigger.on('mousedown', function(e, target, options) {
7839                         e.preventDefault();
7840                         this.onTriggerClick();
7841                 }, this);
7842
7843                 this.on('collapse', function(e, target, options) {
7844                         Ext.getDoc().un('mouseup', this.collapseIf, this);
7845                 }, this, true);
7846
7847                 this.on('expand', function(e, target, options) {
7848                         Ext.getDoc().on('mouseup', this.collapseIf, this);
7849                 }, this, true);
7850         },
7851
7852         clearSearchHistory : function() {
7853                 this.lastSelectedIndex = 0;
7854                 this.lastSearchTerm = false;
7855         },
7856
7857         selectFirst : function() {
7858                 this.focusAndSelect(this.store.data.first());
7859         },
7860
7861         selectLast : function() {
7862                 this.focusAndSelect(this.store.data.last());
7863         },
7864
7865         selectPrevPage : function() {
7866                 if( !this.rowHeight ) {
7867                         return;
7868                 }
7869                 var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);
7870                 this.focusAndSelect(this.store.getAt(index));
7871         },
7872
7873         selectNextPage : function() {
7874                 if( !this.rowHeight ) {
7875                         return;
7876                 }
7877                 var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);
7878                 this.focusAndSelect(this.store.getAt(index));
7879         },
7880
7881         search : function(field, value, startIndex) {
7882                 field = field || this.displayField;
7883                 this.lastSearchTerm = value;
7884                 var index = this.store.find.apply(this.store, arguments);
7885                 if( index !== -1 ) {
7886                         this.focusAndSelect(index);
7887                 }
7888         },
7889
7890         focusAndSelect : function(record) {
7891         var index = Ext.isNumber(record) ? record : this.store.indexOf(record);
7892         this.select(index, this.isExpanded());
7893         this.onSelect(this.store.getAt(index), index, this.isExpanded());
7894         },
7895
7896         calcRowsPerPage : function() {
7897                 if( this.store.getCount() ) {
7898                         this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();
7899                         this.rowsPerPage = this.maxHeight / this.rowHeight;
7900                 } else {
7901                         this.rowHeight = false;
7902                 }
7903         }
7904
7905 });
7906
7907 Ext.reg('selectbox', Ext.ux.form.SelectBox);
7908
7909 //backwards compat
7910 Ext.ux.SelectBox = Ext.ux.form.SelectBox;
7911 /**
7912  * Plugin for PagingToolbar which replaces the textfield input with a slider 
7913  */
7914 Ext.ux.SlidingPager = Ext.extend(Object, {
7915     init : function(pbar){
7916         var idx = pbar.items.indexOf(pbar.inputItem);
7917         Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
7918             c.hide();
7919         });
7920         var slider = new Ext.Slider({
7921             width: 114,
7922             minValue: 1,
7923             maxValue: 1,
7924             plugins: new Ext.slider.Tip({
7925                 getText : function(thumb) {
7926                     return String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
7927                 }
7928             }),
7929             listeners: {
7930                 changecomplete: function(s, v){
7931                     pbar.changePage(v);
7932                 }
7933             }
7934         });
7935         pbar.insert(idx + 1, slider);
7936         pbar.on({
7937             change: function(pb, data){
7938                 slider.setMaxValue(data.pages);
7939                 slider.setValue(data.activePage);
7940             }
7941         });
7942     }
7943 });Ext.ns('Ext.ux.form');
7944
7945 /**
7946  * @class Ext.ux.form.SpinnerField
7947  * @extends Ext.form.NumberField
7948  * Creates a field utilizing Ext.ux.Spinner
7949  * @xtype spinnerfield
7950  */
7951 Ext.ux.form.SpinnerField = Ext.extend(Ext.form.NumberField, {
7952     actionMode: 'wrap',
7953     deferHeight: true,
7954     autoSize: Ext.emptyFn,
7955     onBlur: Ext.emptyFn,
7956     adjustSize: Ext.BoxComponent.prototype.adjustSize,
7957
7958         constructor: function(config) {
7959                 var spinnerConfig = Ext.copyTo({}, config, 'incrementValue,alternateIncrementValue,accelerate,defaultValue,triggerClass,splitterClass');
7960
7961                 var spl = this.spinner = new Ext.ux.Spinner(spinnerConfig);
7962
7963                 var plugins = config.plugins
7964                         ? (Ext.isArray(config.plugins)
7965                                 ? config.plugins.push(spl)
7966                                 : [config.plugins, spl])
7967                         : spl;
7968
7969                 Ext.ux.form.SpinnerField.superclass.constructor.call(this, Ext.apply(config, {plugins: plugins}));
7970         },
7971
7972     // private
7973     getResizeEl: function(){
7974         return this.wrap;
7975     },
7976
7977     // private
7978     getPositionEl: function(){
7979         return this.wrap;
7980     },
7981
7982     // private
7983     alignErrorIcon: function(){
7984         if (this.wrap) {
7985             this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
7986         }
7987     },
7988
7989     validateBlur: function(){
7990         return true;
7991     }
7992 });
7993
7994 Ext.reg('spinnerfield', Ext.ux.form.SpinnerField);
7995
7996 //backwards compat
7997 Ext.form.SpinnerField = Ext.ux.form.SpinnerField;
7998 /**
7999  * @class Ext.ux.Spinner
8000  * @extends Ext.util.Observable
8001  * Creates a Spinner control utilized by Ext.ux.form.SpinnerField
8002  */
8003 Ext.ux.Spinner = Ext.extend(Ext.util.Observable, {
8004     incrementValue: 1,
8005     alternateIncrementValue: 5,
8006     triggerClass: 'x-form-spinner-trigger',
8007     splitterClass: 'x-form-spinner-splitter',
8008     alternateKey: Ext.EventObject.shiftKey,
8009     defaultValue: 0,
8010     accelerate: false,
8011
8012     constructor: function(config){
8013         Ext.ux.Spinner.superclass.constructor.call(this, config);
8014         Ext.apply(this, config);
8015         this.mimicing = false;
8016     },
8017
8018     init: function(field){
8019         this.field = field;
8020
8021         field.afterMethod('onRender', this.doRender, this);
8022         field.afterMethod('onEnable', this.doEnable, this);
8023         field.afterMethod('onDisable', this.doDisable, this);
8024         field.afterMethod('afterRender', this.doAfterRender, this);
8025         field.afterMethod('onResize', this.doResize, this);
8026         field.afterMethod('onFocus', this.doFocus, this);
8027         field.beforeMethod('onDestroy', this.doDestroy, this);
8028     },
8029
8030     doRender: function(ct, position){
8031         var el = this.el = this.field.getEl();
8032         var f = this.field;
8033
8034         if (!f.wrap) {
8035             f.wrap = this.wrap = el.wrap({
8036                 cls: "x-form-field-wrap"
8037             });
8038         }
8039         else {
8040             this.wrap = f.wrap.addClass('x-form-field-wrap');
8041         }
8042
8043         this.trigger = this.wrap.createChild({
8044             tag: "img",
8045             src: Ext.BLANK_IMAGE_URL,
8046             cls: "x-form-trigger " + this.triggerClass
8047         });
8048
8049         if (!f.width) {
8050             this.wrap.setWidth(el.getWidth() + this.trigger.getWidth());
8051         }
8052
8053         this.splitter = this.wrap.createChild({
8054             tag: 'div',
8055             cls: this.splitterClass,
8056             style: 'width:13px; height:2px;'
8057         });
8058         this.splitter.setRight((Ext.isIE) ? 1 : 2).setTop(10).show();
8059
8060         this.proxy = this.trigger.createProxy('', this.splitter, true);
8061         this.proxy.addClass("x-form-spinner-proxy");
8062         this.proxy.setStyle('left', '0px');
8063         this.proxy.setSize(14, 1);
8064         this.proxy.hide();
8065         this.dd = new Ext.dd.DDProxy(this.splitter.dom.id, "SpinnerDrag", {
8066             dragElId: this.proxy.id
8067         });
8068
8069         this.initTrigger();
8070         this.initSpinner();
8071     },
8072
8073     doAfterRender: function(){
8074         var y;
8075         if (Ext.isIE && this.el.getY() != (y = this.trigger.getY())) {
8076             this.el.position();
8077             this.el.setY(y);
8078         }
8079     },
8080
8081     doEnable: function(){
8082         if (this.wrap) {
8083             this.wrap.removeClass(this.field.disabledClass);
8084         }
8085     },
8086
8087     doDisable: function(){
8088         if (this.wrap) {
8089             this.wrap.addClass(this.field.disabledClass);
8090             this.el.removeClass(this.field.disabledClass);
8091         }
8092     },
8093
8094     doResize: function(w, h){
8095         if (typeof w == 'number') {
8096             this.el.setWidth(w - this.trigger.getWidth());
8097         }
8098         this.wrap.setWidth(this.el.getWidth() + this.trigger.getWidth());
8099     },
8100
8101     doFocus: function(){
8102         if (!this.mimicing) {
8103             this.wrap.addClass('x-trigger-wrap-focus');
8104             this.mimicing = true;
8105             Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {
8106                 delay: 10
8107             });
8108             this.el.on('keydown', this.checkTab, this);
8109         }
8110     },
8111
8112     // private
8113     checkTab: function(e){
8114         if (e.getKey() == e.TAB) {
8115             this.triggerBlur();
8116         }
8117     },
8118
8119     // private
8120     mimicBlur: function(e){
8121         if (!this.wrap.contains(e.target) && this.field.validateBlur(e)) {
8122             this.triggerBlur();
8123         }
8124     },
8125
8126     // private
8127     triggerBlur: function(){
8128         this.mimicing = false;
8129         Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
8130         this.el.un("keydown", this.checkTab, this);
8131         this.field.beforeBlur();
8132         this.wrap.removeClass('x-trigger-wrap-focus');
8133         this.field.onBlur.call(this.field);
8134     },
8135
8136     initTrigger: function(){
8137         this.trigger.addClassOnOver('x-form-trigger-over');
8138         this.trigger.addClassOnClick('x-form-trigger-click');
8139     },
8140
8141     initSpinner: function(){
8142         this.field.addEvents({
8143             'spin': true,
8144             'spinup': true,
8145             'spindown': true
8146         });
8147
8148         this.keyNav = new Ext.KeyNav(this.el, {
8149             "up": function(e){
8150                 e.preventDefault();
8151                 this.onSpinUp();
8152             },
8153
8154             "down": function(e){
8155                 e.preventDefault();
8156                 this.onSpinDown();
8157             },
8158
8159             "pageUp": function(e){
8160                 e.preventDefault();
8161                 this.onSpinUpAlternate();
8162             },
8163
8164             "pageDown": function(e){
8165                 e.preventDefault();
8166                 this.onSpinDownAlternate();
8167             },
8168
8169             scope: this
8170         });
8171
8172         this.repeater = new Ext.util.ClickRepeater(this.trigger, {
8173             accelerate: this.accelerate
8174         });
8175         this.field.mon(this.repeater, "click", this.onTriggerClick, this, {
8176             preventDefault: true
8177         });
8178
8179         this.field.mon(this.trigger, {
8180             mouseover: this.onMouseOver,
8181             mouseout: this.onMouseOut,
8182             mousemove: this.onMouseMove,
8183             mousedown: this.onMouseDown,
8184             mouseup: this.onMouseUp,
8185             scope: this,
8186             preventDefault: true
8187         });
8188
8189         this.field.mon(this.wrap, "mousewheel", this.handleMouseWheel, this);
8190
8191         this.dd.setXConstraint(0, 0, 10)
8192         this.dd.setYConstraint(1500, 1500, 10);
8193         this.dd.endDrag = this.endDrag.createDelegate(this);
8194         this.dd.startDrag = this.startDrag.createDelegate(this);
8195         this.dd.onDrag = this.onDrag.createDelegate(this);
8196     },
8197
8198     onMouseOver: function(){
8199         if (this.disabled) {
8200             return;
8201         }
8202         var middle = this.getMiddle();
8203         this.tmpHoverClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-overup' : 'x-form-spinner-overdown';
8204         this.trigger.addClass(this.tmpHoverClass);
8205     },
8206
8207     //private
8208     onMouseOut: function(){
8209         this.trigger.removeClass(this.tmpHoverClass);
8210     },
8211
8212     //private
8213     onMouseMove: function(){
8214         if (this.disabled) {
8215             return;
8216         }
8217         var middle = this.getMiddle();
8218         if (((Ext.EventObject.getPageY() > middle) && this.tmpHoverClass == "x-form-spinner-overup") ||
8219         ((Ext.EventObject.getPageY() < middle) && this.tmpHoverClass == "x-form-spinner-overdown")) {
8220         }
8221     },
8222
8223     //private
8224     onMouseDown: function(){
8225         if (this.disabled) {
8226             return;
8227         }
8228         var middle = this.getMiddle();
8229         this.tmpClickClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-clickup' : 'x-form-spinner-clickdown';
8230         this.trigger.addClass(this.tmpClickClass);
8231     },
8232
8233     //private
8234     onMouseUp: function(){
8235         this.trigger.removeClass(this.tmpClickClass);
8236     },
8237
8238     //private
8239     onTriggerClick: function(){
8240         if (this.disabled || this.el.dom.readOnly) {
8241             return;
8242         }
8243         var middle = this.getMiddle();
8244         var ud = (Ext.EventObject.getPageY() < middle) ? 'Up' : 'Down';
8245         this['onSpin' + ud]();
8246     },
8247
8248     //private
8249     getMiddle: function(){
8250         var t = this.trigger.getTop();
8251         var h = this.trigger.getHeight();
8252         var middle = t + (h / 2);
8253         return middle;
8254     },
8255
8256     //private
8257     //checks if control is allowed to spin
8258     isSpinnable: function(){
8259         if (this.disabled || this.el.dom.readOnly) {
8260             Ext.EventObject.preventDefault(); //prevent scrolling when disabled/readonly
8261             return false;
8262         }
8263         return true;
8264     },
8265
8266     handleMouseWheel: function(e){
8267         //disable scrolling when not focused
8268         if (this.wrap.hasClass('x-trigger-wrap-focus') == false) {
8269             return;
8270         }
8271
8272         var delta = e.getWheelDelta();
8273         if (delta > 0) {
8274             this.onSpinUp();
8275             e.stopEvent();
8276         }
8277         else
8278             if (delta < 0) {
8279                 this.onSpinDown();
8280                 e.stopEvent();
8281             }
8282     },
8283
8284     //private
8285     startDrag: function(){
8286         this.proxy.show();
8287         this._previousY = Ext.fly(this.dd.getDragEl()).getTop();
8288     },
8289
8290     //private
8291     endDrag: function(){
8292         this.proxy.hide();
8293     },
8294
8295     //private
8296     onDrag: function(){
8297         if (this.disabled) {
8298             return;
8299         }
8300         var y = Ext.fly(this.dd.getDragEl()).getTop();
8301         var ud = '';
8302
8303         if (this._previousY > y) {
8304             ud = 'Up';
8305         } //up
8306         if (this._previousY < y) {
8307             ud = 'Down';
8308         } //down
8309         if (ud != '') {
8310             this['onSpin' + ud]();
8311         }
8312
8313         this._previousY = y;
8314     },
8315
8316     //private
8317     onSpinUp: function(){
8318         if (this.isSpinnable() == false) {
8319             return;
8320         }
8321         if (Ext.EventObject.shiftKey == true) {
8322             this.onSpinUpAlternate();
8323             return;
8324         }
8325         else {
8326             this.spin(false, false);
8327         }
8328         this.field.fireEvent("spin", this);
8329         this.field.fireEvent("spinup", this);
8330     },
8331
8332     //private
8333     onSpinDown: function(){
8334         if (this.isSpinnable() == false) {
8335             return;
8336         }
8337         if (Ext.EventObject.shiftKey == true) {
8338             this.onSpinDownAlternate();
8339             return;
8340         }
8341         else {
8342             this.spin(true, false);
8343         }
8344         this.field.fireEvent("spin", this);
8345         this.field.fireEvent("spindown", this);
8346     },
8347
8348     //private
8349     onSpinUpAlternate: function(){
8350         if (this.isSpinnable() == false) {
8351             return;
8352         }
8353         this.spin(false, true);
8354         this.field.fireEvent("spin", this);
8355         this.field.fireEvent("spinup", this);
8356     },
8357
8358     //private
8359     onSpinDownAlternate: function(){
8360         if (this.isSpinnable() == false) {
8361             return;
8362         }
8363         this.spin(true, true);
8364         this.field.fireEvent("spin", this);
8365         this.field.fireEvent("spindown", this);
8366     },
8367
8368     spin: function(down, alternate){
8369         var v = parseFloat(this.field.getValue());
8370         var incr = (alternate == true) ? this.alternateIncrementValue : this.incrementValue;
8371         (down == true) ? v -= incr : v += incr;
8372
8373         v = (isNaN(v)) ? this.defaultValue : v;
8374         v = this.fixBoundries(v);
8375         this.field.setRawValue(v);
8376     },
8377
8378     fixBoundries: function(value){
8379         var v = value;
8380
8381         if (this.field.minValue != undefined && v < this.field.minValue) {
8382             v = this.field.minValue;
8383         }
8384         if (this.field.maxValue != undefined && v > this.field.maxValue) {
8385             v = this.field.maxValue;
8386         }
8387
8388         return this.fixPrecision(v);
8389     },
8390
8391     // private
8392     fixPrecision: function(value){
8393         var nan = isNaN(value);
8394         if (!this.field.allowDecimals || this.field.decimalPrecision == -1 || nan || !value) {
8395             return nan ? '' : value;
8396         }
8397         return parseFloat(parseFloat(value).toFixed(this.field.decimalPrecision));
8398     },
8399
8400     doDestroy: function(){
8401         if (this.trigger) {
8402             this.trigger.remove();
8403         }
8404         if (this.wrap) {
8405             this.wrap.remove();
8406             delete this.field.wrap;
8407         }
8408
8409         if (this.splitter) {
8410             this.splitter.remove();
8411         }
8412
8413         if (this.dd) {
8414             this.dd.unreg();
8415             this.dd = null;
8416         }
8417
8418         if (this.proxy) {
8419             this.proxy.remove();
8420         }
8421
8422         if (this.repeater) {
8423             this.repeater.purgeListeners();
8424         }
8425     }
8426 });
8427
8428 //backwards compat
8429 Ext.form.Spinner = Ext.ux.Spinner;Ext.ux.Spotlight = function(config){
8430     Ext.apply(this, config);
8431 }
8432 Ext.ux.Spotlight.prototype = {
8433     active : false,
8434     animate : true,
8435     duration: .25,
8436     easing:'easeNone',
8437
8438     // private
8439     animated : false,
8440
8441     createElements : function(){
8442         var bd = Ext.getBody();
8443
8444         this.right = bd.createChild({cls:'x-spotlight'});
8445         this.left = bd.createChild({cls:'x-spotlight'});
8446         this.top = bd.createChild({cls:'x-spotlight'});
8447         this.bottom = bd.createChild({cls:'x-spotlight'});
8448
8449         this.all = new Ext.CompositeElement([this.right, this.left, this.top, this.bottom]);
8450     },
8451
8452     show : function(el, callback, scope){
8453         if(this.animated){
8454             this.show.defer(50, this, [el, callback, scope]);
8455             return;
8456         }
8457         this.el = Ext.get(el);
8458         if(!this.right){
8459             this.createElements();
8460         }
8461         if(!this.active){
8462             this.all.setDisplayed('');
8463             this.applyBounds(true, false);
8464             this.active = true;
8465             Ext.EventManager.onWindowResize(this.syncSize, this);
8466             this.applyBounds(false, this.animate, false, callback, scope);
8467         }else{
8468             this.applyBounds(false, false, false, callback, scope); // all these booleans look hideous
8469         }
8470     },
8471
8472     hide : function(callback, scope){
8473         if(this.animated){
8474             this.hide.defer(50, this, [callback, scope]);
8475             return;
8476         }
8477         Ext.EventManager.removeResizeListener(this.syncSize, this);
8478         this.applyBounds(true, this.animate, true, callback, scope);
8479     },
8480
8481     doHide : function(){
8482         this.active = false;
8483         this.all.setDisplayed(false);
8484     },
8485
8486     syncSize : function(){
8487         this.applyBounds(false, false);
8488     },
8489
8490     applyBounds : function(basePts, anim, doHide, callback, scope){
8491
8492         var rg = this.el.getRegion();
8493
8494         var dw = Ext.lib.Dom.getViewWidth(true);
8495         var dh = Ext.lib.Dom.getViewHeight(true);
8496
8497         var c = 0, cb = false;
8498         if(anim){
8499             cb = {
8500                 callback: function(){
8501                     c++;
8502                     if(c == 4){
8503                         this.animated = false;
8504                         if(doHide){
8505                             this.doHide();
8506                         }
8507                         Ext.callback(callback, scope, [this]);
8508                     }
8509                 },
8510                 scope: this,
8511                 duration: this.duration,
8512                 easing: this.easing
8513             };
8514             this.animated = true;
8515         }
8516
8517         this.right.setBounds(
8518                 rg.right,
8519                 basePts ? dh : rg.top,
8520                 dw - rg.right,
8521                 basePts ? 0 : (dh - rg.top),
8522                 cb);
8523
8524         this.left.setBounds(
8525                 0,
8526                 0,
8527                 rg.left,
8528                 basePts ? 0 : rg.bottom,
8529                 cb);
8530
8531         this.top.setBounds(
8532                 basePts ? dw : rg.left,
8533                 0,
8534                 basePts ? 0 : dw - rg.left,
8535                 rg.top,
8536                 cb);
8537
8538         this.bottom.setBounds(
8539                 0,
8540                 rg.bottom,
8541                 basePts ? 0 : rg.right,
8542                 dh - rg.bottom,
8543                 cb);
8544
8545         if(!anim){
8546             if(doHide){
8547                 this.doHide();
8548             }
8549             if(callback){
8550                 Ext.callback(callback, scope, [this]);
8551             }
8552         }
8553     },
8554
8555     destroy : function(){
8556         this.doHide();
8557         Ext.destroy(
8558             this.right,
8559             this.left,
8560             this.top,
8561             this.bottom);
8562         delete this.el;
8563         delete this.all;
8564     }
8565 };
8566
8567 //backwards compat
8568 Ext.Spotlight = Ext.ux.Spotlight;/**
8569  * @class Ext.ux.StatusBar
8570  * <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}.  In addition to
8571  * supporting the standard {@link Ext.Toolbar} interface for adding buttons, menus and other items, the StatusBar
8572  * provides a greedy status element that can be aligned to either side and has convenient methods for setting the
8573  * status text and icon.  You can also indicate that something is processing using the {@link #showBusy} method.</p>
8574  * <pre><code>
8575 new Ext.Panel({
8576     title: 'StatusBar',
8577     // etc.
8578     bbar: new Ext.ux.StatusBar({
8579         id: 'my-status',
8580
8581         // defaults to use when the status is cleared:
8582         defaultText: 'Default status text',
8583         defaultIconCls: 'default-icon',
8584
8585         // values to set initially:
8586         text: 'Ready',
8587         iconCls: 'ready-icon',
8588
8589         // any standard Toolbar items:
8590         items: [{
8591             text: 'A Button'
8592         }, '-', 'Plain Text']
8593     })
8594 });
8595
8596 // Update the status bar later in code:
8597 var sb = Ext.getCmp('my-status');
8598 sb.setStatus({
8599     text: 'OK',
8600     iconCls: 'ok-icon',
8601     clear: true // auto-clear after a set interval
8602 });
8603
8604 // Set the status bar to show that something is processing:
8605 sb.showBusy();
8606
8607 // processing....
8608
8609 sb.clearStatus(); // once completeed
8610 </code></pre>
8611  * @extends Ext.Toolbar
8612  * @constructor
8613  * Creates a new StatusBar
8614  * @param {Object/Array} config A config object
8615  */
8616 Ext.ux.StatusBar = Ext.extend(Ext.Toolbar, {
8617     /**
8618      * @cfg {String} statusAlign
8619      * The alignment of the status element within the overall StatusBar layout.  When the StatusBar is rendered,
8620      * it creates an internal div containing the status text and icon.  Any additional Toolbar items added in the
8621      * StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be
8622      * rendered, in added order, to the opposite side.  The status element is greedy, so it will automatically
8623      * expand to take up all sapce left over by any other items.  Example usage:
8624      * <pre><code>
8625 // Create a left-aligned status bar containing a button,
8626 // separator and text item that will be right-aligned (default):
8627 new Ext.Panel({
8628     title: 'StatusBar',
8629     // etc.
8630     bbar: new Ext.ux.StatusBar({
8631         defaultText: 'Default status text',
8632         id: 'status-id',
8633         items: [{
8634             text: 'A Button'
8635         }, '-', 'Plain Text']
8636     })
8637 });
8638
8639 // By adding the statusAlign config, this will create the
8640 // exact same toolbar, except the status and toolbar item
8641 // layout will be reversed from the previous example:
8642 new Ext.Panel({
8643     title: 'StatusBar',
8644     // etc.
8645     bbar: new Ext.ux.StatusBar({
8646         defaultText: 'Default status text',
8647         id: 'status-id',
8648         statusAlign: 'right',
8649         items: [{
8650             text: 'A Button'
8651         }, '-', 'Plain Text']
8652     })
8653 });
8654 </code></pre>
8655      */
8656     /**
8657      * @cfg {String} defaultText
8658      * The default {@link #text} value.  This will be used anytime the status bar is cleared with the
8659      * <tt>useDefaults:true</tt> option (defaults to '').
8660      */
8661     /**
8662      * @cfg {String} defaultIconCls
8663      * The default {@link #iconCls} value (see the iconCls docs for additional details about customizing the icon).
8664      * This will be used anytime the status bar is cleared with the <tt>useDefaults:true</tt> option (defaults to '').
8665      */
8666     /**
8667      * @cfg {String} text
8668      * A string that will be <b>initially</b> set as the status message.  This string
8669      * will be set as innerHTML (html tags are accepted) for the toolbar item.
8670      * If not specified, the value set for <code>{@link #defaultText}</code>
8671      * will be used.
8672      */
8673     /**
8674      * @cfg {String} iconCls
8675      * A CSS class that will be <b>initially</b> set as the status bar icon and is
8676      * expected to provide a background image (defaults to '').
8677      * Example usage:<pre><code>
8678 // Example CSS rule:
8679 .x-statusbar .x-status-custom {
8680     padding-left: 25px;
8681     background: transparent url(images/custom-icon.gif) no-repeat 3px 2px;
8682 }
8683
8684 // Setting a default icon:
8685 var sb = new Ext.ux.StatusBar({
8686     defaultIconCls: 'x-status-custom'
8687 });
8688
8689 // Changing the icon:
8690 sb.setStatus({
8691     text: 'New status',
8692     iconCls: 'x-status-custom'
8693 });
8694 </code></pre>
8695      */
8696
8697     /**
8698      * @cfg {String} cls
8699      * The base class applied to the containing element for this component on render (defaults to 'x-statusbar')
8700      */
8701     cls : 'x-statusbar',
8702     /**
8703      * @cfg {String} busyIconCls
8704      * The default <code>{@link #iconCls}</code> applied when calling
8705      * <code>{@link #showBusy}</code> (defaults to <tt>'x-status-busy'</tt>).
8706      * It can be overridden at any time by passing the <code>iconCls</code>
8707      * argument into <code>{@link #showBusy}</code>.
8708      */
8709     busyIconCls : 'x-status-busy',
8710     /**
8711      * @cfg {String} busyText
8712      * The default <code>{@link #text}</code> applied when calling
8713      * <code>{@link #showBusy}</code> (defaults to <tt>'Loading...'</tt>).
8714      * It can be overridden at any time by passing the <code>text</code>
8715      * argument into <code>{@link #showBusy}</code>.
8716      */
8717     busyText : 'Loading...',
8718     /**
8719      * @cfg {Number} autoClear
8720      * The number of milliseconds to wait after setting the status via
8721      * <code>{@link #setStatus}</code> before automatically clearing the status
8722      * text and icon (defaults to <tt>5000</tt>).  Note that this only applies
8723      * when passing the <tt>clear</tt> argument to <code>{@link #setStatus}</code>
8724      * since that is the only way to defer clearing the status.  This can
8725      * be overridden by specifying a different <tt>wait</tt> value in
8726      * <code>{@link #setStatus}</code>. Calls to <code>{@link #clearStatus}</code>
8727      * always clear the status bar immediately and ignore this value.
8728      */
8729     autoClear : 5000,
8730
8731     /**
8732      * @cfg {String} emptyText
8733      * The text string to use if no text has been set.  Defaults to
8734      * <tt>'&nbsp;'</tt>).  If there are no other items in the toolbar using
8735      * an empty string (<tt>''</tt>) for this value would end up in the toolbar
8736      * height collapsing since the empty string will not maintain the toolbar
8737      * height.  Use <tt>''</tt> if the toolbar should collapse in height
8738      * vertically when no text is specified and there are no other items in
8739      * the toolbar.
8740      */
8741     emptyText : '&nbsp;',
8742
8743     // private
8744     activeThreadId : 0,
8745
8746     // private
8747     initComponent : function(){
8748         if(this.statusAlign=='right'){
8749             this.cls += ' x-status-right';
8750         }
8751         Ext.ux.StatusBar.superclass.initComponent.call(this);
8752     },
8753
8754     // private
8755     afterRender : function(){
8756         Ext.ux.StatusBar.superclass.afterRender.call(this);
8757
8758         var right = this.statusAlign == 'right';
8759         this.currIconCls = this.iconCls || this.defaultIconCls;
8760         this.statusEl = new Ext.Toolbar.TextItem({
8761             cls: 'x-status-text ' + (this.currIconCls || ''),
8762             text: this.text || this.defaultText || ''
8763         });
8764
8765         if(right){
8766             this.add('->');
8767             this.add(this.statusEl);
8768         }else{
8769             this.insert(0, this.statusEl);
8770             this.insert(1, '->');
8771         }
8772         this.doLayout();
8773     },
8774
8775     /**
8776      * Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the
8777      * status that was set after a specified interval.
8778      * @param {Object/String} config A config object specifying what status to set, or a string assumed
8779      * to be the status text (and all other options are defaulted as explained below). A config
8780      * object containing any or all of the following properties can be passed:<ul>
8781      * <li><tt>text</tt> {String} : (optional) The status text to display.  If not specified, any current
8782      * status text will remain unchanged.</li>
8783      * <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see
8784      * {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>
8785      * <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will
8786      * automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not
8787      * specified, the new status will not be auto-cleared and will stay until updated again or cleared using
8788      * {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},
8789      * {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,
8790      * it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.
8791      * All other options will be defaulted as with the boolean option.  To customize any other options,
8792      * you can pass an object in the format:<ul>
8793      *    <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing
8794      *    (defaults to {@link #autoClear}).</li>
8795      *    <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback
8796      *    executes (defaults to true which fades the status out).</li>
8797      *    <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls
8798      *    (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>
8799      * </ul></li></ul>
8800      * Example usage:<pre><code>
8801 // Simple call to update the text
8802 statusBar.setStatus('New status');
8803
8804 // Set the status and icon, auto-clearing with default options:
8805 statusBar.setStatus({
8806     text: 'New status',
8807     iconCls: 'x-status-custom',
8808     clear: true
8809 });
8810
8811 // Auto-clear with custom options:
8812 statusBar.setStatus({
8813     text: 'New status',
8814     iconCls: 'x-status-custom',
8815     clear: {
8816         wait: 8000,
8817         anim: false,
8818         useDefaults: false
8819     }
8820 });
8821 </code></pre>
8822      * @return {Ext.ux.StatusBar} this
8823      */
8824     setStatus : function(o){
8825         o = o || {};
8826
8827         if(typeof o == 'string'){
8828             o = {text:o};
8829         }
8830         if(o.text !== undefined){
8831             this.setText(o.text);
8832         }
8833         if(o.iconCls !== undefined){
8834             this.setIcon(o.iconCls);
8835         }
8836
8837         if(o.clear){
8838             var c = o.clear,
8839                 wait = this.autoClear,
8840                 defaults = {useDefaults: true, anim: true};
8841
8842             if(typeof c == 'object'){
8843                 c = Ext.applyIf(c, defaults);
8844                 if(c.wait){
8845                     wait = c.wait;
8846                 }
8847             }else if(typeof c == 'number'){
8848                 wait = c;
8849                 c = defaults;
8850             }else if(typeof c == 'boolean'){
8851                 c = defaults;
8852             }
8853
8854             c.threadId = this.activeThreadId;
8855             this.clearStatus.defer(wait, this, [c]);
8856         }
8857         return this;
8858     },
8859
8860     /**
8861      * Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.
8862      * @param {Object} config (optional) A config object containing any or all of the following properties.  If this
8863      * object is not specified the status will be cleared using the defaults below:<ul>
8864      * <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults
8865      * to false which clears immediately).</li>
8866      * <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and
8867      * {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>
8868      * </ul>
8869      * @return {Ext.ux.StatusBar} this
8870      */
8871     clearStatus : function(o){
8872         o = o || {};
8873
8874         if(o.threadId && o.threadId !== this.activeThreadId){
8875             // this means the current call was made internally, but a newer
8876             // thread has set a message since this call was deferred.  Since
8877             // we don't want to overwrite a newer message just ignore.
8878             return this;
8879         }
8880
8881         var text = o.useDefaults ? this.defaultText : this.emptyText,
8882             iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';
8883
8884         if(o.anim){
8885             // animate the statusEl Ext.Element
8886             this.statusEl.el.fadeOut({
8887                 remove: false,
8888                 useDisplay: true,
8889                 scope: this,
8890                 callback: function(){
8891                     this.setStatus({
8892                             text: text,
8893                             iconCls: iconCls
8894                         });
8895
8896                     this.statusEl.el.show();
8897                 }
8898             });
8899         }else{
8900             // hide/show the el to avoid jumpy text or icon
8901             this.statusEl.hide();
8902                 this.setStatus({
8903                     text: text,
8904                     iconCls: iconCls
8905                 });
8906             this.statusEl.show();
8907         }
8908         return this;
8909     },
8910
8911     /**
8912      * Convenience method for setting the status text directly.  For more flexible options see {@link #setStatus}.
8913      * @param {String} text (optional) The text to set (defaults to '')
8914      * @return {Ext.ux.StatusBar} this
8915      */
8916     setText : function(text){
8917         this.activeThreadId++;
8918         this.text = text || '';
8919         if(this.rendered){
8920             this.statusEl.setText(this.text);
8921         }
8922         return this;
8923     },
8924
8925     /**
8926      * Returns the current status text.
8927      * @return {String} The status text
8928      */
8929     getText : function(){
8930         return this.text;
8931     },
8932
8933     /**
8934      * Convenience method for setting the status icon directly.  For more flexible options see {@link #setStatus}.
8935      * See {@link #iconCls} for complete details about customizing the icon.
8936      * @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)
8937      * @return {Ext.ux.StatusBar} this
8938      */
8939     setIcon : function(cls){
8940         this.activeThreadId++;
8941         cls = cls || '';
8942
8943         if(this.rendered){
8944                 if(this.currIconCls){
8945                     this.statusEl.removeClass(this.currIconCls);
8946                     this.currIconCls = null;
8947                 }
8948                 if(cls.length > 0){
8949                     this.statusEl.addClass(cls);
8950                     this.currIconCls = cls;
8951                 }
8952         }else{
8953             this.currIconCls = cls;
8954         }
8955         return this;
8956     },
8957
8958     /**
8959      * Convenience method for setting the status text and icon to special values that are pre-configured to indicate
8960      * a "busy" state, usually for loading or processing activities.
8961      * @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a
8962      * string to use as the status text (in which case all other options for setStatus will be defaulted).  Use the
8963      * <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}
8964      * and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and
8965      * {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.
8966      * @return {Ext.ux.StatusBar} this
8967      */
8968     showBusy : function(o){
8969         if(typeof o == 'string'){
8970             o = {text:o};
8971         }
8972         o = Ext.applyIf(o || {}, {
8973             text: this.busyText,
8974             iconCls: this.busyIconCls
8975         });
8976         return this.setStatus(o);
8977     }
8978 });
8979 Ext.reg('statusbar', Ext.ux.StatusBar);
8980 /**
8981  * @class Ext.ux.TabCloseMenu
8982  * @extends Object 
8983  * Plugin (ptype = 'tabclosemenu') for adding a close context menu to tabs. Note that the menu respects
8984  * the closable configuration on the tab. As such, commands like remove others and remove all will not
8985  * remove items that are not closable.
8986  * 
8987  * @constructor
8988  * @param {Object} config The configuration options
8989  * @ptype tabclosemenu
8990  */
8991 Ext.ux.TabCloseMenu = Ext.extend(Object, {
8992     /**
8993      * @cfg {String} closeTabText
8994      * The text for closing the current tab. Defaults to <tt>'Close Tab'</tt>.
8995      */
8996     closeTabText: 'Close Tab',
8997
8998     /**
8999      * @cfg {String} closeOtherTabsText
9000      * The text for closing all tabs except the current one. Defaults to <tt>'Close Other Tabs'</tt>.
9001      */
9002     closeOtherTabsText: 'Close Other Tabs',
9003     
9004     /**
9005      * @cfg {Boolean} showCloseAll
9006      * Indicates whether to show the 'Close All' option. Defaults to <tt>true</tt>. 
9007      */
9008     showCloseAll: true,
9009
9010     /**
9011      * @cfg {String} closeAllTabsText
9012      * <p>The text for closing all tabs. Defaults to <tt>'Close All Tabs'</tt>.
9013      */
9014     closeAllTabsText: 'Close All Tabs',
9015     
9016     constructor : function(config){
9017         Ext.apply(this, config || {});
9018     },
9019
9020     //public
9021     init : function(tabs){
9022         this.tabs = tabs;
9023         tabs.on({
9024             scope: this,
9025             contextmenu: this.onContextMenu,
9026             destroy: this.destroy
9027         });
9028     },
9029     
9030     destroy : function(){
9031         Ext.destroy(this.menu);
9032         delete this.menu;
9033         delete this.tabs;
9034         delete this.active;    
9035     },
9036
9037     // private
9038     onContextMenu : function(tabs, item, e){
9039         this.active = item;
9040         var m = this.createMenu(),
9041             disableAll = true,
9042             disableOthers = true,
9043             closeAll = m.getComponent('closeall');
9044         
9045         m.getComponent('close').setDisabled(!item.closable);
9046         tabs.items.each(function(){
9047             if(this.closable){
9048                 disableAll = false;
9049                 if(this != item){
9050                     disableOthers = false;
9051                     return false;
9052                 }
9053             }
9054         });
9055         m.getComponent('closeothers').setDisabled(disableOthers);
9056         if(closeAll){
9057             closeAll.setDisabled(disableAll);
9058         }
9059         
9060         e.stopEvent();
9061         m.showAt(e.getPoint());
9062     },
9063     
9064     createMenu : function(){
9065         if(!this.menu){
9066             var items = [{
9067                 itemId: 'close',
9068                 text: this.closeTabText,
9069                 scope: this,
9070                 handler: this.onClose
9071             }];
9072             if(this.showCloseAll){
9073                 items.push('-');
9074             }
9075             items.push({
9076                 itemId: 'closeothers',
9077                 text: this.closeOtherTabsText,
9078                 scope: this,
9079                 handler: this.onCloseOthers
9080             });
9081             if(this.showCloseAll){
9082                 items.push({
9083                     itemId: 'closeall',
9084                     text: this.closeAllTabsText,
9085                     scope: this,
9086                     handler: this.onCloseAll
9087                 });
9088             }
9089             this.menu = new Ext.menu.Menu({
9090                 items: items
9091             });
9092         }
9093         return this.menu;
9094     },
9095     
9096     onClose : function(){
9097         this.tabs.remove(this.active);
9098     },
9099     
9100     onCloseOthers : function(){
9101         this.doClose(true);
9102     },
9103     
9104     onCloseAll : function(){
9105         this.doClose(false);
9106     },
9107     
9108     doClose : function(excludeActive){
9109         var items = [];
9110         this.tabs.items.each(function(item){
9111             if(item.closable){
9112                 if(!excludeActive || item != this.active){
9113                     items.push(item);
9114                 }    
9115             }
9116         }, this);
9117         Ext.each(items, function(item){
9118             this.tabs.remove(item);
9119         }, this);
9120     }
9121 });
9122
9123 Ext.preg('tabclosemenu', Ext.ux.TabCloseMenu);Ext.ns('Ext.ux.grid');
9124
9125 /**
9126  * @class Ext.ux.grid.TableGrid
9127  * @extends Ext.grid.GridPanel
9128  * A Grid which creates itself from an existing HTML table element.
9129  * @history
9130  * 2007-03-01 Original version by Nige "Animal" White
9131  * 2007-03-10 jvs Slightly refactored to reuse existing classes * @constructor
9132  * @param {String/HTMLElement/Ext.Element} table The table element from which this grid will be created -
9133  * The table MUST have some type of size defined for the grid to fill. The container will be
9134  * automatically set to position relative if it isn't already.
9135  * @param {Object} config A config object that sets properties on this grid and has two additional (optional)
9136  * properties: fields and columns which allow for customizing data fields and columns for this grid.
9137  */
9138 Ext.ux.grid.TableGrid = function(table, config){
9139     config = config ||
9140     {};
9141     Ext.apply(this, config);
9142     var cf = config.fields || [], ch = config.columns || [];
9143     table = Ext.get(table);
9144     
9145     var ct = table.insertSibling();
9146     
9147     var fields = [], cols = [];
9148     var headers = table.query("thead th");
9149     for (var i = 0, h; h = headers[i]; i++) {
9150         var text = h.innerHTML;
9151         var name = 'tcol-' + i;
9152         
9153         fields.push(Ext.applyIf(cf[i] ||
9154         {}, {
9155             name: name,
9156             mapping: 'td:nth(' + (i + 1) + ')/@innerHTML'
9157         }));
9158         
9159         cols.push(Ext.applyIf(ch[i] ||
9160         {}, {
9161             'header': text,
9162             'dataIndex': name,
9163             'width': h.offsetWidth,
9164             'tooltip': h.title,
9165             'sortable': true
9166         }));
9167     }
9168     
9169     var ds = new Ext.data.Store({
9170         reader: new Ext.data.XmlReader({
9171             record: 'tbody tr'
9172         }, fields)
9173     });
9174     
9175     ds.loadData(table.dom);
9176     
9177     var cm = new Ext.grid.ColumnModel(cols);
9178     
9179     if (config.width || config.height) {
9180         ct.setSize(config.width || 'auto', config.height || 'auto');
9181     }
9182     else {
9183         ct.setWidth(table.getWidth());
9184     }
9185     
9186     if (config.remove !== false) {
9187         table.remove();
9188     }
9189     
9190     Ext.applyIf(this, {
9191         'ds': ds,
9192         'cm': cm,
9193         'sm': new Ext.grid.RowSelectionModel(),
9194         autoHeight: true,
9195         autoWidth: false
9196     });
9197     Ext.ux.grid.TableGrid.superclass.constructor.call(this, ct, {});
9198 };
9199
9200 Ext.extend(Ext.ux.grid.TableGrid, Ext.grid.GridPanel);
9201
9202 //backwards compat
9203 Ext.grid.TableGrid = Ext.ux.grid.TableGrid;
9204 Ext.ns('Ext.ux');
9205 /**
9206  * @class Ext.ux.TabScrollerMenu
9207  * @extends Object 
9208  * Plugin (ptype = 'tabscrollermenu') for adding a tab scroller menu to tabs.
9209  * @constructor 
9210  * @param {Object} config Configuration options
9211  * @ptype tabscrollermenu
9212  */
9213 Ext.ux.TabScrollerMenu =  Ext.extend(Object, {
9214     /**
9215      * @cfg {Number} pageSize How many items to allow per submenu.
9216      */
9217         pageSize       : 10,
9218     /**
9219      * @cfg {Number} maxText How long should the title of each {@link Ext.menu.Item} be.
9220      */
9221         maxText        : 15,
9222     /**
9223      * @cfg {String} menuPrefixText Text to prefix the submenus.
9224      */    
9225         menuPrefixText : 'Items',
9226         constructor    : function(config) {
9227                 config = config || {};
9228                 Ext.apply(this, config);
9229         },
9230     //private
9231         init : function(tabPanel) {
9232                 Ext.apply(tabPanel, this.parentOverrides);
9233                 
9234                 tabPanel.tabScrollerMenu = this;
9235                 var thisRef = this;
9236                 
9237                 tabPanel.on({
9238                         render : {
9239                                 scope  : tabPanel,
9240                                 single : true,
9241                                 fn     : function() { 
9242                                         var newFn = tabPanel.createScrollers.createSequence(thisRef.createPanelsMenu, this);
9243                                         tabPanel.createScrollers = newFn;
9244                                 }
9245                         }
9246                 });
9247         },
9248         // private && sequeneced
9249         createPanelsMenu : function() {
9250                 var h = this.stripWrap.dom.offsetHeight;
9251                 
9252                 //move the right menu item to the left 18px
9253                 var rtScrBtn = this.header.dom.firstChild;
9254                 Ext.fly(rtScrBtn).applyStyles({
9255                         right : '18px'
9256                 });
9257                 
9258                 var stripWrap = Ext.get(this.strip.dom.parentNode);
9259                 stripWrap.applyStyles({
9260                          'margin-right' : '36px'
9261                 });
9262                 
9263                 // Add the new righthand menu
9264                 var scrollMenu = this.header.insertFirst({
9265                         cls:'x-tab-tabmenu-right'
9266                 });
9267                 scrollMenu.setHeight(h);
9268                 scrollMenu.addClassOnOver('x-tab-tabmenu-over');
9269                 scrollMenu.on('click', this.showTabsMenu, this);        
9270                 
9271                 this.scrollLeft.show = this.scrollLeft.show.createSequence(function() {
9272                         scrollMenu.show();                                                                                                                                               
9273                 });
9274                 
9275                 this.scrollLeft.hide = this.scrollLeft.hide.createSequence(function() {
9276                         scrollMenu.hide();                                                              
9277                 });
9278                 
9279         },
9280     /**
9281      * Returns an the current page size (this.pageSize);
9282      * @return {Number} this.pageSize The current page size.
9283      */
9284         getPageSize : function() {
9285                 return this.pageSize;
9286         },
9287     /**
9288      * Sets the number of menu items per submenu "page size".
9289      * @param {Number} pageSize The page size
9290      */
9291     setPageSize : function(pageSize) {
9292                 this.pageSize = pageSize;
9293         },
9294     /**
9295      * Returns the current maxText length;
9296      * @return {Number} this.maxText The current max text length.
9297      */
9298     getMaxText : function() {
9299                 return this.maxText;
9300         },
9301     /**
9302      * Sets the maximum text size for each menu item.
9303      * @param {Number} t The max text per each menu item.
9304      */
9305     setMaxText : function(t) {
9306                 this.maxText = t;
9307         },
9308     /**
9309      * Returns the current menu prefix text String.;
9310      * @return {String} this.menuPrefixText The current menu prefix text.
9311      */
9312         getMenuPrefixText : function() {
9313                 return this.menuPrefixText;
9314         },
9315     /**
9316      * Sets the menu prefix text String.
9317      * @param {String} t The menu prefix text.
9318      */    
9319         setMenuPrefixText : function(t) {
9320                 this.menuPrefixText = t;
9321         },
9322         // private && applied to the tab panel itself.
9323         parentOverrides : {
9324                 // all execute within the scope of the tab panel
9325                 // private      
9326                 showTabsMenu : function(e) {            
9327                         if  (this.tabsMenu) {
9328                                 this.tabsMenu.destroy();
9329                 this.un('destroy', this.tabsMenu.destroy, this.tabsMenu);
9330                 this.tabsMenu = null;
9331                         }
9332             this.tabsMenu =  new Ext.menu.Menu();
9333             this.on('destroy', this.tabsMenu.destroy, this.tabsMenu);
9334
9335             this.generateTabMenuItems();
9336
9337             var target = Ext.get(e.getTarget());
9338                         var xy     = target.getXY();
9339 //
9340                         //Y param + 24 pixels
9341                         xy[1] += 24;
9342                         
9343                         this.tabsMenu.showAt(xy);
9344                 },
9345                 // private      
9346                 generateTabMenuItems : function() {
9347                         var curActive  = this.getActiveTab();
9348                         var totalItems = this.items.getCount();
9349                         var pageSize   = this.tabScrollerMenu.getPageSize();
9350                         
9351                         
9352                         if (totalItems > pageSize)  {
9353                                 var numSubMenus = Math.floor(totalItems / pageSize);
9354                                 var remainder   = totalItems % pageSize;
9355                                 
9356                                 // Loop through all of the items and create submenus in chunks of 10
9357                                 for (var i = 0 ; i < numSubMenus; i++) {
9358                                         var curPage = (i + 1) * pageSize;
9359                                         var menuItems = [];
9360                                         
9361                                         
9362                                         for (var x = 0; x < pageSize; x++) {                            
9363                                                 index = x + curPage - pageSize;
9364                                                 var item = this.items.get(index);
9365                                                 menuItems.push(this.autoGenMenuItem(item));
9366                                         }
9367                                         
9368                                         this.tabsMenu.add({
9369                                                 text : this.tabScrollerMenu.getMenuPrefixText() + ' '  + (curPage - pageSize + 1) + ' - ' + curPage,
9370                                                 menu : menuItems
9371                                         });
9372                                         
9373                                 }
9374                                 // remaining items
9375                                 if (remainder > 0) {
9376                                         var start = numSubMenus * pageSize;
9377                                         menuItems = [];
9378                                         for (var i = start ; i < totalItems; i ++ ) {                                   
9379                                                 var item = this.items.get(i);
9380                                                 menuItems.push(this.autoGenMenuItem(item));
9381                                         }
9382                                         
9383                                         this.tabsMenu.add({
9384                                                 text : this.tabScrollerMenu.menuPrefixText  + ' ' + (start + 1) + ' - ' + (start + menuItems.length),
9385                                                 menu : menuItems
9386                                         });
9387
9388                                 }
9389                         }
9390                         else {
9391                                 this.items.each(function(item) {
9392                                         if (item.id != curActive.id && !item.hidden) {
9393                         this.tabsMenu.add(this.autoGenMenuItem(item));
9394                                         }
9395                                 }, this);
9396                         }
9397                 },
9398                 // private
9399                 autoGenMenuItem : function(item) {
9400                         var maxText = this.tabScrollerMenu.getMaxText();
9401                         var text    = Ext.util.Format.ellipsis(item.title, maxText);
9402                         
9403                         return {
9404                                 text      : text,
9405                                 handler   : this.showTabFromMenu,
9406                                 scope     : this,
9407                                 disabled  : item.disabled,
9408                                 tabToShow : item,
9409                                 iconCls   : item.iconCls
9410                         }
9411                 
9412                 },
9413                 // private
9414                 showTabFromMenu : function(menuItem) {
9415                         this.setActiveTab(menuItem.tabToShow);
9416                 }       
9417         }       
9418 });
9419
9420 Ext.reg('tabscrollermenu', Ext.ux.TabScrollerMenu);
9421 Ext.ns('Ext.ux.tree');
9422
9423 /**
9424  * @class Ext.ux.tree.XmlTreeLoader
9425  * @extends Ext.tree.TreeLoader
9426  * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
9427  * Any text value included as a text node in the XML will be added to the parent node as an attribute
9428  * called <tt>innerText</tt>.  Also, the tag name of each XML node will be added to the tree node as
9429  * an attribute called <tt>tagName</tt>.</p>
9430  * <p>By default, this class expects that your source XML will provide the necessary attributes on each
9431  * node as expected by the {@link Ext.tree.TreePanel} to display and load properly.  However, you can
9432  * provide your own custom processing of node attributes by overriding the {@link #processNode} method
9433  * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
9434  * @constructor
9435  * Creates a new XmlTreeloader.
9436  * @param {Object} config A config object containing config properties.
9437  */
9438 Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
9439     /**
9440      * @property  XML_NODE_ELEMENT
9441      * XML element node (value 1, read-only)
9442      * @type Number
9443      */
9444     XML_NODE_ELEMENT : 1,
9445     /**
9446      * @property  XML_NODE_TEXT
9447      * XML text node (value 3, read-only)
9448      * @type Number
9449      */
9450     XML_NODE_TEXT : 3,
9451
9452     // private override
9453     processResponse : function(response, node, callback){
9454         var xmlData = response.responseXML;
9455         var root = xmlData.documentElement || xmlData;
9456
9457         try{
9458             node.beginUpdate();
9459             node.appendChild(this.parseXml(root));
9460             node.endUpdate();
9461
9462             if(typeof callback == "function"){
9463                 callback(this, node);
9464             }
9465         }catch(e){
9466             this.handleFailure(response);
9467         }
9468     },
9469
9470     // private
9471     parseXml : function(node) {
9472         var nodes = [];
9473         Ext.each(node.childNodes, function(n){
9474             if(n.nodeType == this.XML_NODE_ELEMENT){
9475                 var treeNode = this.createNode(n);
9476                 if(n.childNodes.length > 0){
9477                     var child = this.parseXml(n);
9478                     if(typeof child == 'string'){
9479                         treeNode.attributes.innerText = child;
9480                     }else{
9481                         treeNode.appendChild(child);
9482                     }
9483                 }
9484                 nodes.push(treeNode);
9485             }
9486             else if(n.nodeType == this.XML_NODE_TEXT){
9487                 var text = n.nodeValue.trim();
9488                 if(text.length > 0){
9489                     return nodes = text;
9490                 }
9491             }
9492         }, this);
9493
9494         return nodes;
9495     },
9496
9497     // private override
9498     createNode : function(node){
9499         var attr = {
9500             tagName: node.tagName
9501         };
9502
9503         Ext.each(node.attributes, function(a){
9504             attr[a.nodeName] = a.nodeValue;
9505         });
9506
9507         this.processAttributes(attr);
9508
9509         return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
9510     },
9511
9512     /*
9513      * Template method intended to be overridden by subclasses that need to provide
9514      * custom attribute processing prior to the creation of each TreeNode.  This method
9515      * will be passed a config object containing existing TreeNode attribute name/value
9516      * pairs which can be modified as needed directly (no need to return the object).
9517      */
9518     processAttributes: Ext.emptyFn
9519 });
9520
9521 //backwards compat
9522 Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;
9523 /**
9524  * @class Ext.ux.ValidationStatus
9525  * A {@link Ext.StatusBar} plugin that provides automatic error notification when the
9526  * associated form contains validation errors.
9527  * @extends Ext.Component
9528  * @constructor
9529  * Creates a new ValiationStatus plugin
9530  * @param {Object} config A config object
9531  */
9532 Ext.ux.ValidationStatus = Ext.extend(Ext.Component, {
9533     /**
9534      * @cfg {String} errorIconCls
9535      * The {@link #iconCls} value to be applied to the status message when there is a
9536      * validation error. Defaults to <tt>'x-status-error'</tt>.
9537      */
9538     errorIconCls : 'x-status-error',
9539     /**
9540      * @cfg {String} errorListCls
9541      * The css class to be used for the error list when there are validation errors.
9542      * Defaults to <tt>'x-status-error-list'</tt>.
9543      */
9544     errorListCls : 'x-status-error-list',
9545     /**
9546      * @cfg {String} validIconCls
9547      * The {@link #iconCls} value to be applied to the status message when the form
9548      * validates. Defaults to <tt>'x-status-valid'</tt>.
9549      */
9550     validIconCls : 'x-status-valid',
9551     
9552     /**
9553      * @cfg {String} showText
9554      * The {@link #text} value to be applied when there is a form validation error.
9555      * Defaults to <tt>'The form has errors (click for details...)'</tt>.
9556      */
9557     showText : 'The form has errors (click for details...)',
9558     /**
9559      * @cfg {String} showText
9560      * The {@link #text} value to display when the error list is displayed.
9561      * Defaults to <tt>'Click again to hide the error list'</tt>.
9562      */
9563     hideText : 'Click again to hide the error list',
9564     /**
9565      * @cfg {String} submitText
9566      * The {@link #text} value to be applied when the form is being submitted.
9567      * Defaults to <tt>'Saving...'</tt>.
9568      */
9569     submitText : 'Saving...',
9570     
9571     // private
9572     init : function(sb){
9573         sb.on('render', function(){
9574             this.statusBar = sb;
9575             this.monitor = true;
9576             this.errors = new Ext.util.MixedCollection();
9577             this.listAlign = (sb.statusAlign=='right' ? 'br-tr?' : 'bl-tl?');
9578             
9579             if(this.form){
9580                 this.form = Ext.getCmp(this.form).getForm();
9581                 this.startMonitoring();
9582                 this.form.on('beforeaction', function(f, action){
9583                     if(action.type == 'submit'){
9584                         // Ignore monitoring while submitting otherwise the field validation
9585                         // events cause the status message to reset too early
9586                         this.monitor = false;
9587                     }
9588                 }, this);
9589                 var startMonitor = function(){
9590                     this.monitor = true;
9591                 };
9592                 this.form.on('actioncomplete', startMonitor, this);
9593                 this.form.on('actionfailed', startMonitor, this);
9594             }
9595         }, this, {single:true});
9596         sb.on({
9597             scope: this,
9598             afterlayout:{
9599                 single: true,
9600                 fn: function(){
9601                     // Grab the statusEl after the first layout.
9602                     sb.statusEl.getEl().on('click', this.onStatusClick, this, {buffer:200});
9603                 } 
9604             }, 
9605             beforedestroy:{
9606                 single: true,
9607                 fn: this.onDestroy
9608             } 
9609         });
9610     },
9611     
9612     // private
9613     startMonitoring : function(){
9614         this.form.items.each(function(f){
9615             f.on('invalid', this.onFieldValidation, this);
9616             f.on('valid', this.onFieldValidation, this);
9617         }, this);
9618     },
9619     
9620     // private
9621     stopMonitoring : function(){
9622         this.form.items.each(function(f){
9623             f.un('invalid', this.onFieldValidation, this);
9624             f.un('valid', this.onFieldValidation, this);
9625         }, this);
9626     },
9627     
9628     // private
9629     onDestroy : function(){
9630         this.stopMonitoring();
9631         this.statusBar.statusEl.un('click', this.onStatusClick, this);
9632         Ext.ux.ValidationStatus.superclass.onDestroy.call(this);
9633     },
9634     
9635     // private
9636     onFieldValidation : function(f, msg){
9637         if(!this.monitor){
9638             return false;
9639         }
9640         if(msg){
9641             this.errors.add(f.id, {field:f, msg:msg});
9642         }else{
9643             this.errors.removeKey(f.id);
9644         }
9645         this.updateErrorList();
9646         if(this.errors.getCount() > 0){
9647             if(this.statusBar.getText() != this.showText){
9648                 this.statusBar.setStatus({text:this.showText, iconCls:this.errorIconCls});
9649             }
9650         }else{
9651             this.statusBar.clearStatus().setIcon(this.validIconCls);
9652         }
9653     },
9654     
9655     // private
9656     updateErrorList : function(){
9657         if(this.errors.getCount() > 0){
9658                 var msg = '<ul>';
9659                 this.errors.each(function(err){
9660                     msg += ('<li id="x-err-'+ err.field.id +'"><a href="#">' + err.msg + '</a></li>');
9661                 }, this);
9662                 this.getMsgEl().update(msg+'</ul>');
9663         }else{
9664             this.getMsgEl().update('');
9665         }
9666     },
9667     
9668     // private
9669     getMsgEl : function(){
9670         if(!this.msgEl){
9671             this.msgEl = Ext.DomHelper.append(Ext.getBody(), {
9672                 cls: this.errorListCls+' x-hide-offsets'
9673             }, true);
9674             
9675             this.msgEl.on('click', function(e){
9676                 var t = e.getTarget('li', 10, true);
9677                 if(t){
9678                     Ext.getCmp(t.id.split('x-err-')[1]).focus();
9679                     this.hideErrors();
9680                 }
9681             }, this, {stopEvent:true}); // prevent anchor click navigation
9682         }
9683         return this.msgEl;
9684     },
9685     
9686     // private
9687     showErrors : function(){
9688         this.updateErrorList();
9689         this.getMsgEl().alignTo(this.statusBar.getEl(), this.listAlign).slideIn('b', {duration:0.3, easing:'easeOut'});
9690         this.statusBar.setText(this.hideText);
9691         this.form.getEl().on('click', this.hideErrors, this, {single:true}); // hide if the user clicks directly into the form
9692     },
9693     
9694     // private
9695     hideErrors : function(){
9696         var el = this.getMsgEl();
9697         if(el.isVisible()){
9698                 el.slideOut('b', {duration:0.2, easing:'easeIn'});
9699                 this.statusBar.setText(this.showText);
9700         }
9701         this.form.getEl().un('click', this.hideErrors, this);
9702     },
9703     
9704     // private
9705     onStatusClick : function(){
9706         if(this.getMsgEl().isVisible()){
9707             this.hideErrors();
9708         }else if(this.errors.getCount() > 0){
9709             this.showErrors();
9710         }
9711     }
9712 });(function() {
9713     Ext.override(Ext.list.Column, {
9714         init : function() {    
9715             var types = Ext.data.Types,
9716                 st = this.sortType;
9717                     
9718             if(this.type){
9719                 if(Ext.isString(this.type)){
9720                     this.type = Ext.data.Types[this.type.toUpperCase()] || types.AUTO;
9721                 }
9722             }else{
9723                 this.type = types.AUTO;
9724             }
9725
9726             // named sortTypes are supported, here we look them up
9727             if(Ext.isString(st)){
9728                 this.sortType = Ext.data.SortTypes[st];
9729             }else if(Ext.isEmpty(st)){
9730                 this.sortType = this.type.sortType;
9731             }
9732         }
9733     });
9734
9735     Ext.tree.Column = Ext.extend(Ext.list.Column, {});
9736     Ext.tree.NumberColumn = Ext.extend(Ext.list.NumberColumn, {});
9737     Ext.tree.DateColumn = Ext.extend(Ext.list.DateColumn, {});
9738     Ext.tree.BooleanColumn = Ext.extend(Ext.list.BooleanColumn, {});
9739
9740     Ext.reg('tgcolumn', Ext.tree.Column);
9741     Ext.reg('tgnumbercolumn', Ext.tree.NumberColumn);
9742     Ext.reg('tgdatecolumn', Ext.tree.DateColumn);
9743     Ext.reg('tgbooleancolumn', Ext.tree.BooleanColumn);
9744 })();
9745 /**
9746  * @class Ext.ux.tree.TreeGridNodeUI
9747  * @extends Ext.tree.TreeNodeUI
9748  */
9749 Ext.ux.tree.TreeGridNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
9750     isTreeGridNodeUI: true,
9751
9752     renderElements : function(n, a, targetNode, bulkRender){
9753         var t = n.getOwnerTree(),
9754             cols = t.columns,
9755             c = cols[0],
9756             i, buf, len;
9757
9758         this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
9759
9760         buf = [
9761              '<tbody class="x-tree-node">',
9762                 '<tr ext:tree-node-id="', n.id ,'" class="x-tree-node-el x-tree-node-leaf ', a.cls, '">',
9763                     '<td class="x-treegrid-col">',
9764                         '<span class="x-tree-node-indent">', this.indentMarkup, "</span>",
9765                         '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
9766                         '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon', (a.icon ? " x-tree-node-inline-icon" : ""), (a.iconCls ? " "+a.iconCls : ""), '" unselectable="on">',
9767                         '<a hidefocus="on" class="x-tree-node-anchor" href="', a.href ? a.href : '#', '" tabIndex="1" ',
9768                             a.hrefTarget ? ' target="'+a.hrefTarget+'"' : '', '>',
9769                         '<span unselectable="on">', (c.tpl ? c.tpl.apply(a) : a[c.dataIndex] || c.text), '</span></a>',
9770                     '</td>'
9771         ];
9772
9773         for(i = 1, len = cols.length; i < len; i++){
9774             c = cols[i];
9775             buf.push(
9776                     '<td class="x-treegrid-col ', (c.cls ? c.cls : ''), '">',
9777                         '<div unselectable="on" class="x-treegrid-text"', (c.align ? ' style="text-align: ' + c.align + ';"' : ''), '>',
9778                             (c.tpl ? c.tpl.apply(a) : a[c.dataIndex]),
9779                         '</div>',
9780                     '</td>'
9781             );
9782         }
9783
9784         buf.push(
9785             '</tr><tr class="x-tree-node-ct"><td colspan="', cols.length, '">',
9786             '<table class="x-treegrid-node-ct-table" cellpadding="0" cellspacing="0" style="table-layout: fixed; display: none; width: ', t.innerCt.getWidth() ,'px;"><colgroup>'
9787         );
9788         for(i = 0, len = cols.length; i<len; i++) {
9789             buf.push('<col style="width: ', (cols[i].hidden ? 0 : cols[i].width) ,'px;" />');
9790         }
9791         buf.push('</colgroup></table></td></tr></tbody>');
9792
9793         if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
9794             this.wrap = Ext.DomHelper.insertHtml("beforeBegin", n.nextSibling.ui.getEl(), buf.join(''));
9795         }else{
9796             this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(''));
9797         }
9798
9799         this.elNode = this.wrap.childNodes[0];
9800         this.ctNode = this.wrap.childNodes[1].firstChild.firstChild;
9801         var cs = this.elNode.firstChild.childNodes;
9802         this.indentNode = cs[0];
9803         this.ecNode = cs[1];
9804         this.iconNode = cs[2];
9805         this.anchor = cs[3];
9806         this.textNode = cs[3].firstChild;
9807     },
9808
9809     // private
9810     animExpand : function(cb){
9811         this.ctNode.style.display = "";
9812         Ext.ux.tree.TreeGridNodeUI.superclass.animExpand.call(this, cb);
9813     }
9814 });
9815
9816 Ext.ux.tree.TreeGridRootNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
9817     isTreeGridNodeUI: true,
9818
9819     // private
9820     render : function(){
9821         if(!this.rendered){
9822             this.wrap = this.ctNode = this.node.ownerTree.innerCt.dom;
9823             this.node.expanded = true;
9824         }
9825
9826         if(Ext.isWebKit) {
9827             // weird table-layout: fixed issue in webkit
9828             var ct = this.ctNode;
9829             ct.style.tableLayout = null;
9830             (function() {
9831                 ct.style.tableLayout = 'fixed';
9832             }).defer(1);
9833         }
9834     },
9835
9836     destroy : function(){
9837         if(this.elNode){
9838             Ext.dd.Registry.unregister(this.elNode.id);
9839         }
9840         delete this.node;
9841     },
9842
9843     collapse : Ext.emptyFn,
9844     expand : Ext.emptyFn
9845 });/**
9846  * @class Ext.tree.ColumnResizer
9847  * @extends Ext.util.Observable
9848  */
9849 Ext.tree.ColumnResizer = Ext.extend(Ext.util.Observable, {
9850     /**
9851      * @cfg {Number} minWidth The minimum width the column can be dragged to.
9852      * Defaults to <tt>14</tt>.
9853      */
9854     minWidth: 14,
9855
9856     constructor: function(config){
9857         Ext.apply(this, config);
9858         Ext.tree.ColumnResizer.superclass.constructor.call(this);
9859     },
9860
9861     init : function(tree){
9862         this.tree = tree;
9863         tree.on('render', this.initEvents, this);
9864     },
9865
9866     initEvents : function(tree){
9867         tree.mon(tree.innerHd, 'mousemove', this.handleHdMove, this);
9868         this.tracker = new Ext.dd.DragTracker({
9869             onBeforeStart: this.onBeforeStart.createDelegate(this),
9870             onStart: this.onStart.createDelegate(this),
9871             onDrag: this.onDrag.createDelegate(this),
9872             onEnd: this.onEnd.createDelegate(this),
9873             tolerance: 3,
9874             autoStart: 300
9875         });
9876         this.tracker.initEl(tree.innerHd);
9877         tree.on('beforedestroy', this.tracker.destroy, this.tracker);
9878     },
9879
9880     handleHdMove : function(e, t){
9881         var hw = 5,
9882             x = e.getPageX(),
9883             hd = e.getTarget('.x-treegrid-hd', 3, true);
9884         
9885         if(hd){                                 
9886             var r = hd.getRegion(),
9887                 ss = hd.dom.style,
9888                 pn = hd.dom.parentNode;
9889             
9890             if(x - r.left <= hw && hd.dom !== pn.firstChild) {
9891                 var ps = hd.dom.previousSibling;
9892                 while(ps && Ext.fly(ps).hasClass('x-treegrid-hd-hidden')) {
9893                     ps = ps.previousSibling;
9894                 }
9895                 if(ps) {                    
9896                     this.activeHd = Ext.get(ps);
9897                                 ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
9898                 }
9899             } else if(r.right - x <= hw) {
9900                 var ns = hd.dom;
9901                 while(ns && Ext.fly(ns).hasClass('x-treegrid-hd-hidden')) {
9902                     ns = ns.previousSibling;
9903                 }
9904                 if(ns) {
9905                     this.activeHd = Ext.get(ns);
9906                                 ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';                    
9907                 }
9908             } else{
9909                 delete this.activeHd;
9910                 ss.cursor = '';
9911             }
9912         }
9913     },
9914
9915     onBeforeStart : function(e){
9916         this.dragHd = this.activeHd;
9917         return !!this.dragHd;
9918     },
9919
9920     onStart : function(e){
9921         this.tree.headersDisabled = true;
9922         this.proxy = this.tree.body.createChild({cls:'x-treegrid-resizer'});
9923         this.proxy.setHeight(this.tree.body.getHeight());
9924
9925         var x = this.tracker.getXY()[0];
9926
9927         this.hdX = this.dragHd.getX();
9928         this.hdIndex = this.tree.findHeaderIndex(this.dragHd);
9929
9930         this.proxy.setX(this.hdX);
9931         this.proxy.setWidth(x-this.hdX);
9932
9933         this.maxWidth = this.tree.outerCt.getWidth() - this.tree.innerBody.translatePoints(this.hdX).left;
9934     },
9935
9936     onDrag : function(e){
9937         var cursorX = this.tracker.getXY()[0];
9938         this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));
9939     },
9940
9941     onEnd : function(e){
9942         var nw = this.proxy.getWidth(),
9943             tree = this.tree;
9944         
9945         this.proxy.remove();
9946         delete this.dragHd;
9947         
9948         tree.columns[this.hdIndex].width = nw;
9949         tree.updateColumnWidths();
9950         
9951         setTimeout(function(){
9952             tree.headersDisabled = false;
9953         }, 100);
9954     }
9955 });Ext.ns('Ext.ux.tree');
9956
9957 /**
9958  * @class Ext.ux.tree.TreeGridSorter
9959  * @extends Ext.tree.TreeSorter
9960  * Provides sorting of nodes in a {@link Ext.ux.tree.TreeGrid}.  The TreeGridSorter automatically monitors events on the
9961  * associated TreeGrid that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
9962  * Example usage:<br />
9963  * <pre><code>
9964  new Ext.ux.tree.TreeGridSorter(myTreeGrid, {
9965      folderSort: true,
9966      dir: "desc",
9967      sortType: function(node) {
9968          // sort by a custom, typed attribute:
9969          return parseInt(node.id, 10);
9970      }
9971  });
9972  </code></pre>
9973  * @constructor
9974  * @param {TreeGrid} tree
9975  * @param {Object} config
9976  */
9977 Ext.ux.tree.TreeGridSorter = Ext.extend(Ext.tree.TreeSorter, {
9978     /**
9979      * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
9980      */
9981     sortClasses : ['sort-asc', 'sort-desc'],
9982     /**
9983      * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
9984      */
9985     sortAscText : 'Sort Ascending',
9986     /**
9987      * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
9988      */
9989     sortDescText : 'Sort Descending',
9990
9991     constructor : function(tree, config) {
9992         if(!Ext.isObject(config)) {
9993             config = {
9994                 property: tree.columns[0].dataIndex || 'text',
9995                 folderSort: true
9996             }
9997         }
9998
9999         Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this, arguments);
10000
10001         this.tree = tree;
10002         tree.on('headerclick', this.onHeaderClick, this);
10003         tree.ddAppendOnly = true;
10004
10005         me = this;
10006         this.defaultSortFn = function(n1, n2){
10007
10008             var dsc = me.dir && me.dir.toLowerCase() == 'desc';
10009             var p = me.property || 'text';
10010             var sortType = me.sortType;
10011             var fs = me.folderSort;
10012             var cs = me.caseSensitive === true;
10013             var leafAttr = me.leafAttr || 'leaf';
10014
10015             if(fs){
10016                 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
10017                     return 1;
10018                 }
10019                 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
10020                     return -1;
10021                 }
10022             }
10023             var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
10024             var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
10025             if(v1 < v2){
10026                 return dsc ? +1 : -1;
10027             }else if(v1 > v2){
10028                 return dsc ? -1 : +1;
10029             }else{
10030                 return 0;
10031             }
10032         };
10033
10034         tree.on('afterrender', this.onAfterTreeRender, this, {single: true});
10035         tree.on('headermenuclick', this.onHeaderMenuClick, this);
10036     },
10037
10038     onAfterTreeRender : function() {
10039         if(this.tree.hmenu){
10040             this.tree.hmenu.insert(0,
10041                 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
10042                 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
10043             );
10044         }
10045         this.updateSortIcon(0, 'asc');
10046     },
10047
10048     onHeaderMenuClick : function(c, id, index) {
10049         if(id === 'asc' || id === 'desc') {
10050             this.onHeaderClick(c, null, index);
10051             return false;
10052         }
10053     },
10054
10055     onHeaderClick : function(c, el, i) {
10056         if(c && !this.tree.headersDisabled){
10057             var me = this;
10058
10059             me.property = c.dataIndex;
10060             me.dir = c.dir = (c.dir === 'desc' ? 'asc' : 'desc');
10061             me.sortType = c.sortType;
10062             me.caseSensitive === Ext.isBoolean(c.caseSensitive) ? c.caseSensitive : this.caseSensitive;
10063             me.sortFn = c.sortFn || this.defaultSortFn;
10064
10065             this.tree.root.cascade(function(n) {
10066                 if(!n.isLeaf()) {
10067                     me.updateSort(me.tree, n);
10068                 }
10069             });
10070
10071             this.updateSortIcon(i, c.dir);
10072         }
10073     },
10074
10075     // private
10076     updateSortIcon : function(col, dir){
10077         var sc = this.sortClasses;
10078         var hds = this.tree.innerHd.select('td').removeClass(sc);
10079         hds.item(col).addClass(sc[dir == 'desc' ? 1 : 0]);
10080     }
10081 });/**
10082  * @class Ext.ux.tree.TreeGridLoader
10083  * @extends Ext.tree.TreeLoader
10084  */
10085 Ext.ux.tree.TreeGridLoader = Ext.extend(Ext.tree.TreeLoader, {
10086     createNode : function(attr) {
10087         if (!attr.uiProvider) {
10088             attr.uiProvider = Ext.ux.tree.TreeGridNodeUI;
10089         }
10090         return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
10091     }
10092 });/**
10093  * @class Ext.ux.tree.TreeGrid
10094  * @extends Ext.tree.TreePanel
10095  * 
10096  * @xtype treegrid
10097  */
10098 Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, {
10099     rootVisible : false,
10100     useArrows : true,
10101     lines : false,
10102     borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
10103     cls : 'x-treegrid',
10104
10105     columnResize : true,
10106     enableSort : true,
10107     reserveScrollOffset : true,
10108     enableHdMenu : true,
10109     
10110     columnsText : 'Columns',
10111
10112     initComponent : function() {
10113         if(!this.root) {
10114             this.root = new Ext.tree.AsyncTreeNode({text: 'Root'});
10115         }
10116         
10117         // initialize the loader
10118         var l = this.loader;
10119         if(!l){
10120             l = new Ext.ux.tree.TreeGridLoader({
10121                 dataUrl: this.dataUrl,
10122                 requestMethod: this.requestMethod,
10123                 store: this.store
10124             });
10125         }else if(Ext.isObject(l) && !l.load){
10126             l = new Ext.ux.tree.TreeGridLoader(l);
10127         }
10128         else if(l) {
10129             l.createNode = function(attr) {
10130                 if (!attr.uiProvider) {
10131                     attr.uiProvider = Ext.ux.tree.TreeGridNodeUI;
10132                 }
10133                 return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
10134             }
10135         }
10136         this.loader = l;
10137                             
10138         Ext.ux.tree.TreeGrid.superclass.initComponent.call(this);                    
10139         
10140         this.initColumns();
10141         
10142         if(this.enableSort) {
10143             this.treeGridSorter = new Ext.ux.tree.TreeGridSorter(this, this.enableSort);
10144         }
10145         
10146         if(this.columnResize){
10147             this.colResizer = new Ext.tree.ColumnResizer(this.columnResize);
10148             this.colResizer.init(this);
10149         }
10150         
10151         var c = this.columns;
10152         if(!this.internalTpl){                                
10153             this.internalTpl = new Ext.XTemplate(
10154                 '<div class="x-grid3-header">',
10155                     '<div class="x-treegrid-header-inner">',
10156                         '<div class="x-grid3-header-offset">',
10157                             '<table cellspacing="0" cellpadding="0" border="0"><colgroup><tpl for="columns"><col /></tpl></colgroup>',
10158                             '<thead><tr class="x-grid3-hd-row">',
10159                             '<tpl for="columns">',
10160                             '<td class="x-grid3-hd x-grid3-cell x-treegrid-hd" style="text-align: {align};" id="', this.id, '-xlhd-{#}">',
10161                                 '<div class="x-grid3-hd-inner x-treegrid-hd-inner" unselectable="on">',
10162                                      this.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
10163                                      '{header}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
10164                                  '</div>',
10165                             '</td></tpl>',
10166                             '</tr></thead>',
10167                         '</div></table>',
10168                     '</div></div>',
10169                 '</div>',
10170                 '<div class="x-treegrid-root-node">',
10171                     '<table class="x-treegrid-root-table" cellpadding="0" cellspacing="0" style="table-layout: fixed;"></table>',
10172                 '</div>'
10173             );
10174         }
10175         
10176         if(!this.colgroupTpl) {
10177             this.colgroupTpl = new Ext.XTemplate(
10178                 '<colgroup><tpl for="columns"><col style="width: {width}px"/></tpl></colgroup>'
10179             );
10180         }
10181     },
10182
10183     initColumns : function() {
10184         var cs = this.columns,
10185             len = cs.length, 
10186             columns = [],
10187             i, c;
10188
10189         for(i = 0; i < len; i++){
10190             c = cs[i];
10191             if(!c.isColumn) {
10192                 c.xtype = c.xtype ? (/^tg/.test(c.xtype) ? c.xtype : 'tg' + c.xtype) : 'tgcolumn';
10193                 c = Ext.create(c);
10194             }
10195             c.init(this);
10196             columns.push(c);
10197             
10198             if(this.enableSort !== false && c.sortable !== false) {
10199                 c.sortable = true;
10200                 this.enableSort = true;
10201             }
10202         }
10203
10204         this.columns = columns;
10205     },
10206
10207     onRender : function(){
10208         Ext.tree.TreePanel.superclass.onRender.apply(this, arguments);
10209
10210         this.el.addClass('x-treegrid');
10211         
10212         this.outerCt = this.body.createChild({
10213             cls:'x-tree-root-ct x-treegrid-ct ' + (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')
10214         });
10215         
10216         this.internalTpl.overwrite(this.outerCt, {columns: this.columns});
10217         
10218         this.mainHd = Ext.get(this.outerCt.dom.firstChild);
10219         this.innerHd = Ext.get(this.mainHd.dom.firstChild);
10220         this.innerBody = Ext.get(this.outerCt.dom.lastChild);
10221         this.innerCt = Ext.get(this.innerBody.dom.firstChild);
10222         
10223         this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
10224         
10225         if(this.hideHeaders){
10226             this.header.dom.style.display = 'none';
10227         }
10228         else if(this.enableHdMenu !== false){
10229             this.hmenu = new Ext.menu.Menu({id: this.id + '-hctx'});
10230             if(this.enableColumnHide !== false){
10231                 this.colMenu = new Ext.menu.Menu({id: this.id + '-hcols-menu'});
10232                 this.colMenu.on({
10233                     scope: this,
10234                     beforeshow: this.beforeColMenuShow,
10235                     itemclick: this.handleHdMenuClick
10236                 });
10237                 this.hmenu.add({
10238                     itemId:'columns',
10239                     hideOnClick: false,
10240                     text: this.columnsText,
10241                     menu: this.colMenu,
10242                     iconCls: 'x-cols-icon'
10243                 });
10244             }
10245             this.hmenu.on('itemclick', this.handleHdMenuClick, this);
10246         }
10247     },
10248
10249     setRootNode : function(node){
10250         node.attributes.uiProvider = Ext.ux.tree.TreeGridRootNodeUI;        
10251         node = Ext.ux.tree.TreeGrid.superclass.setRootNode.call(this, node);
10252         if(this.innerCt) {
10253             this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
10254         }
10255         return node;
10256     },
10257     
10258     clearInnerCt : function(){
10259         if(Ext.isIE){
10260             var dom = this.innerCt.dom;
10261             while(dom.firstChild){
10262                 dom.removeChild(dom.firstChild);
10263             }
10264         }else{
10265             Ext.ux.tree.TreeGrid.superclass.clearInnerCt.call(this);
10266         }
10267     },
10268     
10269     initEvents : function() {
10270         Ext.ux.tree.TreeGrid.superclass.initEvents.apply(this, arguments);
10271
10272         this.mon(this.innerBody, 'scroll', this.syncScroll, this);
10273         this.mon(this.innerHd, 'click', this.handleHdDown, this);
10274         this.mon(this.mainHd, {
10275             scope: this,
10276             mouseover: this.handleHdOver,
10277             mouseout: this.handleHdOut
10278         });
10279     },
10280     
10281     onResize : function(w, h) {
10282         Ext.ux.tree.TreeGrid.superclass.onResize.apply(this, arguments);
10283         
10284         var bd = this.innerBody.dom;
10285         var hd = this.innerHd.dom;
10286
10287         if(!bd){
10288             return;
10289         }
10290
10291         if(Ext.isNumber(h)){
10292             bd.style.height = this.body.getHeight(true) - hd.offsetHeight + 'px';
10293         }
10294
10295         if(Ext.isNumber(w)){                        
10296             var sw = Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
10297             if(this.reserveScrollOffset || ((bd.offsetWidth - bd.clientWidth) > 10)){
10298                 this.setScrollOffset(sw);
10299             }else{
10300                 var me = this;
10301                 setTimeout(function(){
10302                     me.setScrollOffset(bd.offsetWidth - bd.clientWidth > 10 ? sw : 0);
10303                 }, 10);
10304             }
10305         }
10306     },
10307
10308     updateColumnWidths : function() {
10309         var cols = this.columns,
10310             colCount = cols.length,
10311             groups = this.outerCt.query('colgroup'),
10312             groupCount = groups.length,
10313             c, g, i, j;
10314
10315         for(i = 0; i<colCount; i++) {
10316             c = cols[i];
10317             for(j = 0; j<groupCount; j++) {
10318                 g = groups[j];
10319                 g.childNodes[i].style.width = (c.hidden ? 0 : c.width) + 'px';
10320             }
10321         }
10322         
10323         for(i = 0, groups = this.innerHd.query('td'), len = groups.length; i<len; i++) {
10324             c = Ext.fly(groups[i]);
10325             if(cols[i] && cols[i].hidden) {
10326                 c.addClass('x-treegrid-hd-hidden');
10327             }
10328             else {
10329                 c.removeClass('x-treegrid-hd-hidden');
10330             }
10331         }
10332
10333         var tcw = this.getTotalColumnWidth();                        
10334         Ext.fly(this.innerHd.dom.firstChild).setWidth(tcw + (this.scrollOffset || 0));
10335         this.outerCt.select('table').setWidth(tcw);
10336         this.syncHeaderScroll();    
10337     },
10338                     
10339     getVisibleColumns : function() {
10340         var columns = [],
10341             cs = this.columns,
10342             len = cs.length,
10343             i;
10344             
10345         for(i = 0; i<len; i++) {
10346             if(!cs[i].hidden) {
10347                 columns.push(cs[i]);
10348             }
10349         }        
10350         return columns;
10351     },
10352
10353     getTotalColumnWidth : function() {
10354         var total = 0;
10355         for(var i = 0, cs = this.getVisibleColumns(), len = cs.length; i<len; i++) {
10356             total += cs[i].width;
10357         }
10358         return total;
10359     },
10360
10361     setScrollOffset : function(scrollOffset) {
10362         this.scrollOffset = scrollOffset;                        
10363         this.updateColumnWidths();
10364     },
10365
10366     // private
10367     handleHdDown : function(e, t){
10368         var hd = e.getTarget('.x-treegrid-hd');
10369
10370         if(hd && Ext.fly(t).hasClass('x-grid3-hd-btn')){
10371             var ms = this.hmenu.items,
10372                 cs = this.columns,
10373                 index = this.findHeaderIndex(hd),
10374                 c = cs[index],
10375                 sort = c.sortable;
10376                 
10377             e.stopEvent();
10378             Ext.fly(hd).addClass('x-grid3-hd-menu-open');
10379             this.hdCtxIndex = index;
10380             
10381             this.fireEvent('headerbuttonclick', ms, c, hd, index);
10382             
10383             this.hmenu.on('hide', function(){
10384                 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
10385             }, this, {single:true});
10386             
10387             this.hmenu.show(t, 'tl-bl?');
10388         }
10389         else if(hd) {
10390             var index = this.findHeaderIndex(hd);
10391             this.fireEvent('headerclick', this.columns[index], hd, index);
10392         }
10393     },
10394
10395     // private
10396     handleHdOver : function(e, t){                    
10397         var hd = e.getTarget('.x-treegrid-hd');                        
10398         if(hd && !this.headersDisabled){
10399             index = this.findHeaderIndex(hd);
10400             this.activeHdRef = t;
10401             this.activeHdIndex = index;
10402             var el = Ext.get(hd);
10403             this.activeHdRegion = el.getRegion();
10404             el.addClass('x-grid3-hd-over');
10405             this.activeHdBtn = el.child('.x-grid3-hd-btn');
10406             if(this.activeHdBtn){
10407                 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
10408             }
10409         }
10410     },
10411     
10412     // private
10413     handleHdOut : function(e, t){
10414         var hd = e.getTarget('.x-treegrid-hd');
10415         if(hd && (!Ext.isIE || !e.within(hd, true))){
10416             this.activeHdRef = null;
10417             Ext.fly(hd).removeClass('x-grid3-hd-over');
10418             hd.style.cursor = '';
10419         }
10420     },
10421                     
10422     findHeaderIndex : function(hd){
10423         hd = hd.dom || hd;
10424         var cs = hd.parentNode.childNodes;
10425         for(var i = 0, c; c = cs[i]; i++){
10426             if(c == hd){
10427                 return i;
10428             }
10429         }
10430         return -1;
10431     },
10432     
10433     // private
10434     beforeColMenuShow : function(){
10435         var cols = this.columns,  
10436             colCount = cols.length,
10437             i, c;                        
10438         this.colMenu.removeAll();                    
10439         for(i = 1; i < colCount; i++){
10440             c = cols[i];
10441             if(c.hideable !== false){
10442                 this.colMenu.add(new Ext.menu.CheckItem({
10443                     itemId: 'col-' + i,
10444                     text: c.header,
10445                     checked: !c.hidden,
10446                     hideOnClick:false,
10447                     disabled: c.hideable === false
10448                 }));
10449             }
10450         }
10451     },
10452                     
10453     // private
10454     handleHdMenuClick : function(item){
10455         var index = this.hdCtxIndex,
10456             id = item.getItemId();
10457         
10458         if(this.fireEvent('headermenuclick', this.columns[index], id, index) !== false) {
10459             index = id.substr(4);
10460             if(index > 0 && this.columns[index]) {
10461                 this.setColumnVisible(index, !item.checked);
10462             }     
10463         }
10464         
10465         return true;
10466     },
10467     
10468     setColumnVisible : function(index, visible) {
10469         this.columns[index].hidden = !visible;        
10470         this.updateColumnWidths();
10471     },
10472
10473     /**
10474      * Scrolls the grid to the top
10475      */
10476     scrollToTop : function(){
10477         this.innerBody.dom.scrollTop = 0;
10478         this.innerBody.dom.scrollLeft = 0;
10479     },
10480
10481     // private
10482     syncScroll : function(){
10483         this.syncHeaderScroll();
10484         var mb = this.innerBody.dom;
10485         this.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
10486     },
10487
10488     // private
10489     syncHeaderScroll : function(){
10490         var mb = this.innerBody.dom;
10491         this.innerHd.dom.scrollLeft = mb.scrollLeft;
10492         this.innerHd.dom.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
10493     },
10494     
10495     registerNode : function(n) {
10496         Ext.ux.tree.TreeGrid.superclass.registerNode.call(this, n);
10497         if(!n.uiProvider && !n.isRoot && !n.ui.isTreeGridNodeUI) {
10498             n.ui = new Ext.ux.tree.TreeGridNodeUI(n);
10499         }
10500     }
10501 });
10502
10503 Ext.reg('treegrid', Ext.ux.tree.TreeGrid);