3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
10 * @class Ext.ux.grid.BufferView
11 * @extends Ext.grid.GridView
12 * A custom GridView which renders rows on an as-needed basis.
14 Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
16 * @cfg {Number} rowHeight
17 * The height of a row in the grid.
22 * @cfg {Number} borderHeight
23 * The combined height of border-top and border-bottom of a row.
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
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.
43 * @cfg {Number} cleanDelay
44 * The number of milliseconds to buffer cleaning of extra rows not in the
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>'
56 ts.rowHolder.disableFormats = true;
57 ts.rowHolder.compile();
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>' : ''),
65 ts.rowBody.disableFormats = true;
69 getStyleRowHeight : function(){
70 return Ext.isBorderBox ? (this.rowHeight + this.borderHeight) : this.rowHeight;
73 getCalculatedRowHeight : function(){
74 return this.rowHeight + this.borderHeight;
77 getVisibleRowCount : function(){
78 var rh = this.getCalculatedRowHeight();
79 var visibleHeight = this.scroller.dom.clientHeight;
80 return (visibleHeight < 1) ? 0 : Math.ceil(visibleHeight / rh);
83 getVisibleRows: function(){
84 var count = this.getVisibleRowCount();
85 var sc = this.scroller.dom.scrollTop;
86 var start = (sc == 0 ? 0 : Math.floor(sc/this.getCalculatedRowHeight())-1);
88 first: Math.max(start, 0),
89 last: Math.min(start + count + 2, this.ds.getCount()-1)
93 doRender : function(cs, rs, ds, startRow, colCount, stripe, onlyBody){
94 var ts = this.templates, ct = ts.cell, rt = ts.row, rb = ts.rowBody, last = colCount-1;
95 var rh = this.getStyleRowHeight();
96 var vr = this.getVisibleRows();
97 var tstyle = 'width:'+this.getTotalWidth()+';height:'+rh+'px;';
99 var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
100 for (var j = 0, len = rs.length; j < len; j++) {
102 var rowIndex = (j+startRow);
103 var visible = rowIndex >= vr.first && rowIndex <= vr.last;
105 for (var i = 0; i < colCount; i++) {
108 p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
109 p.attr = p.cellAttr = "";
110 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
112 if (p.value == undefined || p.value === "") {
115 if (r.dirty && typeof r.modified[c.name] !== 'undefined') {
116 p.css += ' x-grid3-dirty-cell';
118 cb[cb.length] = ct.apply(p);
122 if(stripe && ((rowIndex+1) % 2 == 0)){
123 alt[0] = "x-grid3-row-alt";
126 alt[1] = " x-grid3-dirty-row";
129 if(this.getRowClass){
130 alt[2] = this.getRowClass(r, rowIndex, rp, ds);
132 rp.alt = alt.join(" ");
133 rp.cells = cb.join("");
134 buf[buf.length] = !visible ? ts.rowHolder.apply(rp) : (onlyBody ? rb.apply(rp) : rt.apply(rp));
139 isRowRendered: function(index){
140 var row = this.getRow(index);
141 return row && row.childNodes.length > 0;
144 syncScroll: function(){
145 Ext.ux.grid.BufferView.superclass.syncScroll.apply(this, arguments);
149 // a (optionally) buffered method to update contents of gridview
151 if (this.scrollDelay) {
152 if (!this.renderTask) {
153 this.renderTask = new Ext.util.DelayedTask(this.doUpdate, this);
155 this.renderTask.delay(this.scrollDelay);
161 onRemove : function(ds, record, index, isUpdate){
162 Ext.ux.grid.BufferView.superclass.onRemove.apply(this, arguments);
163 if(isUpdate !== true){
168 doUpdate: function(){
169 if (this.getVisibleRowCount() > 0) {
170 var g = this.grid, cm = g.colModel, ds = g.store;
171 var cs = this.getColumnData();
173 var vr = this.getVisibleRows();
174 for (var i = vr.first; i <= vr.last; i++) {
175 // if row is NOT rendered and is visible, render it
176 if(!this.isRowRendered(i)){
177 var html = this.doRender(cs, [ds.getAt(i)], ds, i, cm.getColumnCount(), g.stripeRows, true);
178 this.getRow(i).innerHTML = html;
185 // a buffered method to clean rows
188 this.cleanTask = new Ext.util.DelayedTask(this.doClean, this);
190 this.cleanTask.delay(this.cleanDelay);
194 if (this.getVisibleRowCount() > 0) {
195 var vr = this.getVisibleRows();
196 vr.first -= this.cacheSize;
197 vr.last += this.cacheSize;
199 var i = 0, rows = this.getRows();
200 // if first is less than 0, all rows have been rendered
201 // so lets clean the end...
205 for(var len = this.ds.getCount(); i < len; i++){
206 // if current row is outside of first and last and
207 // has content, update the innerHTML to nothing
208 if ((i < vr.first || i > vr.last) && rows[i].innerHTML) {
209 rows[i].innerHTML = '';
216 Ext.ux.grid.BufferView.superclass.layout.call(this);
220 // We are adding these custom layouts to a namespace that does not
221 // exist by default in Ext, so we have to add the namespace first:
222 Ext.ns('Ext.ux.layout');
225 * @class Ext.ux.layout.CenterLayout
226 * @extends Ext.layout.FitLayout
227 * <p>This is a very simple layout style used to center contents within a container. This layout works within
228 * nested containers and can also be used as expected as a Viewport layout to center the page layout.</p>
229 * <p>As a subclass of FitLayout, CenterLayout expects to have a single child panel of the container that uses
230 * the layout. The layout does not require any config options, although the child panel contained within the
231 * layout must provide a fixed or percentage width. The child panel's height will fit to the container by
232 * default, but you can specify <tt>autoHeight:true</tt> to allow it to autosize based on its content height.
235 // The content panel is centered in the container
236 var p = new Ext.Panel({
237 title: 'Center Layout',
240 title: 'Centered Content',
246 // If you leave the title blank and specify no border
247 // you'll create a non-visual, structural panel just
248 // for centering the contents in the main container.
249 var p = new Ext.Panel({
253 title: 'Centered Content',
261 Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.FitLayout, {
263 setItemSize : function(item, size){
264 this.container.addClass('ux-layout-center');
265 item.addClass('ux-layout-center-item');
266 if(item && size.height > 0){
268 size.width = item.width;
275 Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout;
276 Ext.ns('Ext.ux.grid');
279 * @class Ext.ux.grid.CheckColumn
281 * GridPanel plugin to add a column with check boxes to a grid.
282 * <p>Example usage:</p>
285 var checkColumn = new Ext.grid.CheckColumn({
292 // add the column to the column model
293 var cm = new Ext.grid.ColumnModel([{
301 var grid = new Ext.grid.EditorGridPanel({
304 plugins: [checkColumn], // include plugin
308 * In addition to storing a Boolean value within the record data, this
309 * class toggles a css class between <tt>'x-grid3-check-col'</tt> and
310 * <tt>'x-grid3-check-col-on'</tt> to alter the background image used for
313 Ext.ux.grid.CheckColumn = function(config){
314 Ext.apply(this, config);
318 this.renderer = this.renderer.createDelegate(this);
321 Ext.ux.grid.CheckColumn.prototype ={
322 init : function(grid){
324 this.grid.on('render', function(){
325 var view = this.grid.getView();
326 view.mainBody.on('mousedown', this.onMouseDown, this);
330 onMouseDown : function(e, t){
331 if(Ext.fly(t).hasClass(this.createId())){
333 var index = this.grid.getView().findRowIndex(t);
334 var record = this.grid.store.getAt(index);
335 record.set(this.dataIndex, !record.data[this.dataIndex]);
339 renderer : function(v, p, record){
340 p.css += ' x-grid3-check-col-td';
341 return String.format('<div class="x-grid3-check-col{0} {1}"> </div>', v ? '-on' : '', this.createId());
344 createId : function(){
345 return 'x-grid3-cc-' + this.id;
350 Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn);
353 Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn;Ext.ns('Ext.ux.grid');
355 Ext.ux.grid.ColumnHeaderGroup = Ext.extend(Ext.util.Observable, {
357 constructor: function(config){
358 this.config = config;
361 init: function(grid){
362 Ext.applyIf(grid.colModel, this.config);
363 Ext.apply(grid.getView(), this.viewConfig);
367 initTemplates: function(){
368 this.constructor.prototype.initTemplates.apply(this, arguments);
369 var ts = this.templates || {};
371 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>');
374 this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", "");
377 renderHeaders: function(){
378 var ts = this.templates, headers = [], cm = this.cm, rows = cm.rows, tstyle = 'width:' + this.getTotalWidth() + ';';
380 for(var row = 0, rlen = rows.length; row < rlen; row++){
381 var r = rows[row], cells = [];
382 for(var i = 0, gcol = 0, len = r.length; i < len; i++){
384 group.colspan = group.colspan || 1;
385 var id = this.getColumnId(group.dataIndex ? cm.findColumnIndex(group.dataIndex) : gcol), gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
386 cells[i] = ts.gcell.apply({
387 cls: 'ux-grid-hd-group-cell',
390 style: 'width:' + gs.width + ';' + (gs.hidden ? 'display:none;' : '') + (group.align ? 'text-align:' + group.align + ';' : ''),
391 tooltip: group.tooltip ? (Ext.QuickTips.isEnabled() ? 'ext:qtip' : 'title') + '="' + group.tooltip + '"' : '',
392 istyle: group.align == 'right' ? 'padding-right:16px' : '',
393 btn: this.grid.enableHdMenu && group.header,
394 value: group.header || ' '
396 gcol += group.colspan;
398 headers[row] = ts.header.apply({
400 cells: cells.join('')
403 headers.push(this.constructor.prototype.renderHeaders.apply(this, arguments));
404 return headers.join('');
407 onColumnWidthUpdated: function(){
408 this.constructor.prototype.onColumnWidthUpdated.apply(this, arguments);
409 Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
412 onAllColumnWidthsUpdated: function(){
413 this.constructor.prototype.onAllColumnWidthsUpdated.apply(this, arguments);
414 Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
417 onColumnHiddenUpdated: function(){
418 this.constructor.prototype.onColumnHiddenUpdated.apply(this, arguments);
419 Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
422 getHeaderCell: function(index){
423 return this.mainHd.query(this.cellSelector)[index];
426 findHeaderCell: function(el){
427 return el ? this.fly(el).findParent('td.x-grid3-hd', this.cellSelectorDepth) : false;
430 findHeaderIndex: function(el){
431 var cell = this.findHeaderCell(el);
432 return cell ? this.getCellIndex(cell) : false;
435 updateSortIcon: function(col, dir){
436 var sc = this.sortClasses, hds = this.mainHd.select(this.cellSelector).removeClass(sc);
437 hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
440 handleHdDown: function(e, t){
442 if(el.hasClass('x-grid3-hd-btn')){
444 var hd = this.findHeaderCell(t);
445 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
446 var index = this.getCellIndex(hd);
447 this.hdCtxIndex = index;
448 var ms = this.hmenu.items, cm = this.cm;
449 ms.get('asc').setDisabled(!cm.isSortable(index));
450 ms.get('desc').setDisabled(!cm.isSortable(index));
451 this.hmenu.on('hide', function(){
452 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
456 this.hmenu.show(t, 'tl-bl?');
457 }else if(el.hasClass('ux-grid-hd-group-cell') || Ext.fly(t).up('.ux-grid-hd-group-cell')){
462 handleHdMove: function(e, t){
463 var hd = this.findHeaderCell(this.activeHdRef);
464 if(hd && !this.headersDisabled && !Ext.fly(hd).hasClass('ux-grid-hd-group-cell')){
465 var hw = this.splitHandleWidth || 5, r = this.activeHdRegion, x = e.getPageX(), ss = hd.style, cur = '';
466 if(this.grid.enableColumnResize !== false){
467 if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex - 1)){
468 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize
472 }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
473 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
480 handleHdOver: function(e, t){
481 var hd = this.findHeaderCell(t);
482 if(hd && !this.headersDisabled){
483 this.activeHdRef = t;
484 this.activeHdIndex = this.getCellIndex(hd);
485 var fly = this.fly(hd);
486 this.activeHdRegion = fly.getRegion();
487 if(!(this.cm.isMenuDisabled(this.activeHdIndex) || fly.hasClass('ux-grid-hd-group-cell'))){
488 fly.addClass('x-grid3-hd-over');
489 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
490 if(this.activeHdBtn){
491 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight - 1) + 'px';
497 handleHdOut: function(e, t){
498 var hd = this.findHeaderCell(t);
499 if(hd && (!Ext.isIE || !e.within(hd, true))){
500 this.activeHdRef = null;
501 this.fly(hd).removeClass('x-grid3-hd-over');
502 hd.style.cursor = '';
506 handleHdMenuClick: function(item){
507 var index = this.hdCtxIndex, cm = this.cm, ds = this.ds, id = item.getItemId();
510 ds.sort(cm.getDataIndex(index), 'ASC');
513 ds.sort(cm.getDataIndex(index), 'DESC');
516 if(id.substr(0, 5) == 'group'){
517 var i = id.split('-'), row = parseInt(i[1], 10), col = parseInt(i[2], 10), r = this.cm.rows[row], group, gcol = 0;
518 for(var i = 0, len = r.length; i < len; i++){
520 if(col >= gcol && col < gcol + group.colspan){
523 gcol += group.colspan;
526 var max = cm.getColumnsBy(this.isHideableColumn, this).length;
527 for(var i = gcol, len = gcol + group.colspan; i < len; i++){
533 this.onDenyColumnHide();
537 for(var i = gcol, len = gcol + group.colspan; i < len; i++){
538 if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
539 cm.setHidden(i, item.checked);
543 index = cm.getIndexById(id.substr(4));
545 if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
546 this.onDenyColumnHide();
549 cm.setHidden(index, item.checked);
552 item.checked = !item.checked;
554 var updateChildren = function(menu){
555 menu.items.each(function(childItem){
556 if(!childItem.disabled){
557 childItem.setChecked(item.checked, false);
559 updateChildren(childItem.menu);
564 updateChildren(item.menu);
566 var parentMenu = item, parentItem;
567 while(parentMenu = parentMenu.parentMenu){
568 if(!parentMenu.parentMenu || !(parentItem = parentMenu.parentMenu.items.get(parentMenu.getItemId())) || !parentItem.setChecked){
571 var checked = parentMenu.items.findIndexBy(function(m){
574 parentItem.setChecked(checked, true);
576 item.checked = !item.checked;
581 beforeColMenuShow: function(){
582 var cm = this.cm, rows = this.cm.rows;
583 this.colMenu.removeAll();
584 for(var col = 0, clen = cm.getColumnCount(); col < clen; col++){
585 var menu = this.colMenu, title = cm.getColumnHeader(col), text = [];
586 if(cm.config[col].fixed !== true && cm.config[col].hideable !== false){
587 for(var row = 0, rlen = rows.length; row < rlen; row++){
588 var r = rows[row], group, gcol = 0;
589 for(var i = 0, len = r.length; i < len; i++){
591 if(col >= gcol && col < gcol + group.colspan){
594 gcol += group.colspan;
596 if(group && group.header){
597 if(cm.hierarchicalColMenu){
598 var gid = 'group-' + row + '-' + gcol;
599 var item = menu.items.item(gid);
600 var submenu = item ? item.menu : null;
602 submenu = new Ext.menu.Menu({
605 submenu.on("itemclick", this.handleHdMenuClick, this);
606 var checked = false, disabled = true;
607 for(var c = gcol, lc = gcol + group.colspan; c < lc; c++){
611 if(cm.config[c].hideable !== false){
626 text.push(group.header);
631 menu.add(new Ext.menu.CheckItem({
632 itemId: "col-" + cm.getColumnId(col),
633 text: text.join(' '),
634 checked: !cm.isHidden(col),
636 disabled: cm.config[col].hideable === false
642 renderUI: function(){
643 this.constructor.prototype.renderUI.apply(this, arguments);
644 Ext.apply(this.columnDrop, Ext.ux.grid.ColumnHeaderGroup.prototype.columnDropConfig);
645 Ext.apply(this.splitZone, Ext.ux.grid.ColumnHeaderGroup.prototype.splitZoneConfig);
650 allowHeaderDrag: function(e){
651 return !e.getTarget(null, null, true).hasClass('ux-grid-hd-group-cell');
656 getTargetFromEvent: function(e){
657 var t = Ext.lib.Event.getTarget(e);
658 return this.view.findHeaderCell(t);
661 positionIndicator: function(h, n, e){
662 var data = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
666 var px = data.px + this.proxyOffsets[0];
667 this.proxyTop.setLeftTop(px, data.r.top + this.proxyOffsets[1]);
668 this.proxyTop.show();
669 this.proxyBottom.setLeftTop(px, data.r.bottom);
670 this.proxyBottom.show();
674 onNodeDrop: function(n, dd, e, data){
677 var d = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
681 var cm = this.grid.colModel, right = d.oldIndex < d.newIndex, rows = cm.rows;
682 for(var row = d.row, rlen = rows.length; row < rlen; row++){
683 var r = rows[row], len = r.length, fromIx = 0, span = 1, toIx = len;
684 for(var i = 0, gcol = 0; i < len; i++){
686 if(d.oldIndex >= gcol && d.oldIndex < gcol + group.colspan){
689 if(d.oldIndex + d.colspan - 1 >= gcol && d.oldIndex + d.colspan - 1 < gcol + group.colspan){
690 span = i - fromIx + 1;
692 if(d.newIndex >= gcol && d.newIndex < gcol + group.colspan){
695 gcol += group.colspan;
697 var groups = r.splice(fromIx, span);
698 rows[row] = r.splice(0, toIx - (right ? span : 0)).concat(groups).concat(r);
700 for(var c = 0; c < d.colspan; c++){
701 var oldIx = d.oldIndex + (right ? 0 : c), newIx = d.newIndex + (right ? -1 : c);
702 cm.moveColumn(oldIx, newIx);
703 this.grid.fireEvent("columnmove", oldIx, newIx);
711 getGroupStyle: function(group, gcol){
712 var width = 0, hidden = true;
713 for(var i = gcol, len = gcol + group.colspan; i < len; i++){
714 if(!this.cm.isHidden(i)){
715 var cw = this.cm.getColumnWidth(i);
716 if(typeof cw == 'number'){
723 width: (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? width : Math.max(width - this.borderWidth, 0)) + 'px',
728 updateGroupStyles: function(col){
729 var tables = this.mainHd.query('.x-grid3-header-offset > table'), tw = this.getTotalWidth(), rows = this.cm.rows;
730 for(var row = 0; row < tables.length; row++){
731 tables[row].style.width = tw;
732 if(row < rows.length){
733 var cells = tables[row].firstChild.firstChild.childNodes;
734 for(var i = 0, gcol = 0; i < cells.length; i++){
735 var group = rows[row][i];
736 if((typeof col != 'number') || (col >= gcol && col < gcol + group.colspan)){
737 var gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
738 cells[i].style.width = gs.width;
739 cells[i].style.display = gs.hidden ? 'none' : '';
741 gcol += group.colspan;
747 getGroupRowIndex: function(el){
749 var m = el.className.match(this.hrowRe);
751 return parseInt(m[1], 10);
754 return this.cm.rows.length;
757 getGroupSpan: function(row, col){
761 colspan: this.cm.getColumnCount()
764 var r = this.cm.rows[row];
766 for(var i = 0, gcol = 0, len = r.length; i < len; i++){
768 if(col >= gcol && col < gcol + group.colspan){
771 colspan: group.colspan
774 gcol += group.colspan;
787 getDragDropData: function(h, n, e){
788 if(h.parentNode != n.parentNode){
791 var cm = this.grid.colModel, x = Ext.lib.Event.getPageX(e), r = Ext.lib.Dom.getRegion(n.firstChild), px, pt;
792 if((r.right - x) <= (r.right - r.left) / 2){
793 px = r.right + this.view.borderWidth;
799 var oldIndex = this.view.getCellIndex(h), newIndex = this.view.getCellIndex(n);
800 if(cm.isFixed(newIndex)){
803 var row = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupRowIndex.call(this.view, h),
804 oldGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, oldIndex),
805 newGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, newIndex),
806 oldIndex = oldGroup.col;
807 newIndex = newGroup.col + (pt == "after" ? newGroup.colspan : 0);
808 if(newIndex >= oldGroup.col && newIndex <= oldGroup.col + oldGroup.colspan){
811 var parentGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row - 1, oldIndex);
812 if(newIndex < parentGroup.col || newIndex > parentGroup.col + parentGroup.colspan){
822 colspan: oldGroup.colspan
825 });Ext.ns('Ext.ux.tree');
828 * @class Ext.ux.tree.ColumnTree
829 * @extends Ext.tree.TreePanel
833 Ext.ux.tree.ColumnTree = Ext.extend(Ext.tree.TreePanel, {
835 borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
836 cls : 'x-column-tree',
838 onRender : function(){
839 Ext.tree.ColumnTree.superclass.onRender.apply(this, arguments);
840 this.headers = this.header.createChild({cls:'x-tree-headers'});
842 var cols = this.columns, c;
844 var scrollOffset = 19; // similar to Ext.grid.GridView default
846 for(var i = 0, len = cols.length; i < len; i++){
848 totalWidth += c.width;
849 this.headers.createChild({
850 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
852 cls:'x-tree-hd-text',
855 style:'width:'+(c.width-this.borderWidth)+'px;'
858 this.headers.createChild({cls:'x-clear'});
859 // prevent floats from wrapping when clipped
860 this.headers.setWidth(totalWidth+scrollOffset);
861 this.innerCt.setWidth(totalWidth);
865 Ext.reg('columntree', Ext.ux.tree.ColumnTree);
868 Ext.tree.ColumnTree = Ext.ux.tree.ColumnTree;
872 * @class Ext.ux.tree.ColumnNodeUI
873 * @extends Ext.tree.TreeNodeUI
875 Ext.ux.tree.ColumnNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
876 focus: Ext.emptyFn, // prevent odd scrolling behavior
878 renderElements : function(n, a, targetNode, bulkRender){
879 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
881 var t = n.getOwnerTree();
882 var cols = t.columns;
883 var bw = t.borderWidth;
887 '<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf ', a.cls,'">',
888 '<div class="x-tree-col" style="width:',c.width-bw,'px;">',
889 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
890 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
891 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on">',
892 '<a hidefocus="on" class="x-tree-node-anchor" href="',a.href ? a.href : "#",'" tabIndex="1" ',
893 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '>',
894 '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</span></a>",
896 for(var i = 1, len = cols.length; i < len; i++){
899 buf.push('<div class="x-tree-col ',(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
900 '<div class="x-tree-col-text">',(c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</div>",
904 '<div class="x-clear"></div></div>',
905 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
908 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
909 this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
910 n.nextSibling.ui.getEl(), buf.join(""));
912 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
915 this.elNode = this.wrap.childNodes[0];
916 this.ctNode = this.wrap.childNodes[1];
917 var cs = this.elNode.firstChild.childNodes;
918 this.indentNode = cs[0];
920 this.iconNode = cs[2];
922 this.textNode = cs[3].firstChild;
927 Ext.tree.ColumnNodeUI = Ext.ux.tree.ColumnNodeUI;
929 * @class Ext.DataView.LabelEditor
930 * @extends Ext.Editor
933 Ext.DataView.LabelEditor = Ext.extend(Ext.Editor, {
936 cls: "x-small-editor",
938 completeOnEnter: true,
940 labelSelector: 'span.x-editable',
942 constructor: function(cfg, field){
943 Ext.DataView.LabelEditor.superclass.constructor.call(this,
944 field || new Ext.form.TextField({
954 init : function(view){
956 view.on('render', this.initEditor, this);
957 this.on('complete', this.onSave, this);
960 initEditor : function(){
963 containerclick: this.doBlur,
966 this.view.getEl().on('mousedown', this.onMouseDown, this, {delegate: this.labelSelector});
975 onMouseDown : function(e, target){
976 if(!e.ctrlKey && !e.shiftKey){
977 var item = this.view.findItemFromChild(target);
979 var record = this.view.store.getAt(this.view.indexOf(item));
980 this.startEdit(target, record.data[this.dataIndex]);
981 this.activeRecord = record;
987 onSave : function(ed, value){
988 this.activeRecord.set(this.dataIndex, value);
993 Ext.DataView.DragSelector = function(cfg){
995 var view, proxy, tracker;
996 var rs, bodyRegion, dragRegion = new Ext.lib.Region(0,0,0,0);
997 var dragSafe = cfg.dragSafe === true;
999 this.init = function(dataView){
1001 view.on('render', onRender);
1004 function fillRegions(){
1006 view.all.each(function(el){
1007 rs[rs.length] = el.getRegion();
1009 bodyRegion = view.el.getRegion();
1012 function cancelClick(){
1016 function onBeforeStart(e){
1017 return !dragSafe || e.target == view.el.dom;
1020 function onStart(e){
1021 view.on('containerclick', cancelClick, view, {single:true});
1023 proxy = view.el.createChild({cls:'x-view-selector'});
1025 if(proxy.dom.parentNode !== view.el.dom){
1026 view.el.dom.appendChild(proxy.dom);
1028 proxy.setDisplayed('block');
1031 view.clearSelections();
1035 var startXY = tracker.startXY;
1036 var xy = tracker.getXY();
1038 var x = Math.min(startXY[0], xy[0]);
1039 var y = Math.min(startXY[1], xy[1]);
1040 var w = Math.abs(startXY[0] - xy[0]);
1041 var h = Math.abs(startXY[1] - xy[1]);
1043 dragRegion.left = x;
1045 dragRegion.right = x+w;
1046 dragRegion.bottom = y+h;
1048 dragRegion.constrainTo(bodyRegion);
1049 proxy.setRegion(dragRegion);
1051 for(var i = 0, len = rs.length; i < len; i++){
1052 var r = rs[i], sel = dragRegion.intersect(r);
1053 if(sel && !r.selected){
1055 view.select(i, true);
1056 }else if(!sel && r.selected){
1065 view.un('containerclick', cancelClick, view);
1068 proxy.setDisplayed(false);
1072 function onRender(view){
1073 tracker = new Ext.dd.DragTracker({
1074 onBeforeStart: onBeforeStart,
1079 tracker.initEl(view.el);
1081 };Ext.ns('Ext.ux.form');
1084 * @class Ext.ux.form.FileUploadField
1085 * @extends Ext.form.TextField
1086 * Creates a file upload field.
1087 * @xtype fileuploadfield
1089 Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField, {
1091 * @cfg {String} buttonText The button text to display on the upload button (defaults to
1092 * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
1093 * value will be used instead if available.
1095 buttonText: 'Browse...',
1097 * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
1098 * text field (defaults to false). If true, all inherited TextField members will still be available.
1102 * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
1103 * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
1107 * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
1117 autoSize: Ext.emptyFn,
1120 initComponent: function(){
1121 Ext.ux.form.FileUploadField.superclass.initComponent.call(this);
1125 * @event fileselected
1126 * Fires when the underlying file input field's value has changed from the user
1127 * selecting a new file from the system file selection dialog.
1128 * @param {Ext.ux.form.FileUploadField} this
1129 * @param {String} value The file value returned by the underlying file input field
1136 onRender : function(ct, position){
1137 Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct, position);
1139 this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
1140 this.el.addClass('x-form-file-text');
1141 this.el.dom.removeAttribute('name');
1142 this.createFileInput();
1144 var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
1145 text: this.buttonText
1147 this.button = new Ext.Button(Ext.apply(btnCfg, {
1148 renderTo: this.wrap,
1149 cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
1152 if(this.buttonOnly){
1154 this.wrap.setWidth(this.button.getEl().getWidth());
1157 this.bindListeners();
1158 this.resizeEl = this.positionEl = this.wrap;
1161 bindListeners: function(){
1164 mouseenter: function() {
1165 this.button.addClass(['x-btn-over','x-btn-focus'])
1167 mouseleave: function(){
1168 this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
1170 mousedown: function(){
1171 this.button.addClass('x-btn-click')
1173 mouseup: function(){
1174 this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
1177 var v = this.fileInput.dom.value;
1179 this.fireEvent('fileselected', this, v);
1184 createFileInput : function() {
1185 this.fileInput = this.wrap.createChild({
1186 id: this.getFileInputId(),
1187 name: this.name||this.getId(),
1196 this.fileInput.remove();
1197 this.createFileInput();
1198 this.bindListeners();
1199 Ext.ux.form.FileUploadField.superclass.reset.call(this);
1203 getFileInputId: function(){
1204 return this.id + '-file';
1208 onResize : function(w, h){
1209 Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
1211 this.wrap.setWidth(w);
1213 if(!this.buttonOnly){
1214 var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
1215 this.el.setWidth(w);
1220 onDestroy: function(){
1221 Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
1222 Ext.destroy(this.fileInput, this.button, this.wrap);
1225 onDisable: function(){
1226 Ext.ux.form.FileUploadField.superclass.onDisable.call(this);
1227 this.doDisable(true);
1230 onEnable: function(){
1231 Ext.ux.form.FileUploadField.superclass.onEnable.call(this);
1232 this.doDisable(false);
1237 doDisable: function(disabled){
1238 this.fileInput.dom.disabled = disabled;
1239 this.button.setDisabled(disabled);
1244 preFocus : Ext.emptyFn,
1247 alignErrorIcon : function(){
1248 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
1253 Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
1256 Ext.form.FileUploadField = Ext.ux.form.FileUploadField;
1258 * @class Ext.ux.GMapPanel
1259 * @extends Ext.Panel
1260 * @author Shea Frederick
1262 Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
1263 initComponent : function(){
1275 Ext.applyIf(this,defConfig);
1277 Ext.ux.GMapPanel.superclass.initComponent.call(this);
1280 afterRender : function(){
1282 var wh = this.ownerCt.getSize();
1283 Ext.applyIf(this, wh);
1285 Ext.ux.GMapPanel.superclass.afterRender.call(this);
1287 if (this.gmapType === 'map'){
1288 this.gmap = new GMap2(this.body.dom);
1291 if (this.gmapType === 'panorama'){
1292 this.gmap = new GStreetviewPanorama(this.body.dom);
1295 if (typeof this.addControl == 'object' && this.gmapType === 'map') {
1296 this.gmap.addControl(this.addControl);
1299 if (typeof this.setCenter === 'object') {
1300 if (typeof this.setCenter.geoCodeAddr === 'string'){
1301 this.geoCodeLookup(this.setCenter.geoCodeAddr);
1303 if (this.gmapType === 'map'){
1304 var point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
1305 this.gmap.setCenter(point, this.zoomLevel);
1307 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
1308 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
1311 if (this.gmapType === 'panorama'){
1312 this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
1316 GEvent.bind(this.gmap, 'load', this, function(){
1321 onMapReady : function(){
1322 this.addMarkers(this.markers);
1323 this.addMapControls();
1326 onResize : function(w, h){
1328 if (typeof this.getMap() == 'object') {
1329 this.gmap.checkResize();
1332 Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);
1335 setSize : function(width, height, animate){
1337 if (typeof this.getMap() == 'object') {
1338 this.gmap.checkResize();
1341 Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
1344 getMap : function(){
1349 getCenter : function(){
1351 return this.getMap().getCenter();
1354 getCenterLatLng : function(){
1356 var ll = this.getCenter();
1357 return {lat: ll.lat(), lng: ll.lng()};
1360 addMarkers : function(markers) {
1362 if (Ext.isArray(markers)){
1363 for (var i = 0; i < markers.length; i++) {
1364 var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
1365 this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
1370 addMarker : function(point, marker, clear, center, listeners){
1372 Ext.applyIf(marker,G_DEFAULT_ICON);
1374 if (clear === true){
1375 this.getMap().clearOverlays();
1377 if (center === true) {
1378 this.getMap().setCenter(point, this.zoomLevel);
1381 var mark = new GMarker(point,marker);
1382 if (typeof listeners === 'object'){
1383 for (evt in listeners) {
1384 GEvent.bind(mark, evt, this, listeners[evt]);
1387 this.getMap().addOverlay(mark);
1390 addMapControls : function(){
1392 if (this.gmapType === 'map') {
1393 if (Ext.isArray(this.mapControls)) {
1394 for(i=0;i<this.mapControls.length;i++){
1395 this.addMapControl(this.mapControls[i]);
1397 }else if(typeof this.mapControls === 'string'){
1398 this.addMapControl(this.mapControls);
1399 }else if(typeof this.mapControls === 'object'){
1400 this.getMap().addControl(this.mapControls);
1405 addMapControl : function(mc){
1407 var mcf = window[mc];
1408 if (typeof mcf === 'function') {
1409 this.getMap().addControl(new mcf());
1413 addOptions : function(){
1415 if (Ext.isArray(this.mapConfOpts)) {
1417 for(i=0;i<this.mapConfOpts.length;i++){
1418 this.addOption(this.mapConfOpts[i]);
1420 }else if(typeof this.mapConfOpts === 'string'){
1421 this.addOption(this.mapConfOpts);
1425 addOption : function(mc){
1427 var mcf = this.getMap()[mc];
1428 if (typeof mcf === 'function') {
1429 this.getMap()[mc]();
1433 geoCodeLookup : function(addr) {
1435 this.geocoder = new GClientGeocoder();
1436 this.geocoder.getLocations(addr, this.addAddressToMap.createDelegate(this));
1439 addAddressToMap : function(response) {
1441 if (!response || response.Status.code != 200) {
1442 Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
1444 place = response.Placemark[0];
1445 addressinfo = place.AddressDetails;
1446 accuracy = addressinfo.Accuracy;
1447 if (accuracy === 0) {
1448 Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
1451 Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
1453 point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
1454 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
1455 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);
1465 Ext.reg('gmappanel', Ext.ux.GMapPanel); Ext.namespace('Ext.ux.grid');
1468 * @class Ext.ux.grid.GridFilters
1469 * @extends Ext.util.Observable
1470 * <p>GridFilter is a plugin (<code>ptype='gridfilters'</code>) for grids that
1471 * allow for a slightly more robust representation of filtering than what is
1472 * provided by the default store.</p>
1473 * <p>Filtering is adjusted by the user using the grid's column header menu
1474 * (this menu can be disabled through configuration). Through this menu users
1475 * can configure, enable, and disable filters for each column.</p>
1476 * <p><b><u>Features:</u></b></p>
1477 * <div class="mdetail-params"><ul>
1478 * <li><b>Filtering implementations</b> :
1479 * <div class="sub-desc">
1480 * Default filtering for Strings, Numeric Ranges, Date Ranges, Lists (which can
1481 * be backed by a Ext.data.Store), and Boolean. Additional custom filter types
1482 * and menus are easily created by extending Ext.ux.grid.filter.Filter.
1484 * <li><b>Graphical indicators</b> :
1485 * <div class="sub-desc">
1486 * Columns that are filtered have {@link #filterCls a configurable css class}
1487 * applied to the column headers.
1489 * <li><b>Paging</b> :
1490 * <div class="sub-desc">
1491 * If specified as a plugin to the grid's configured PagingToolbar, the current page
1492 * will be reset to page 1 whenever you update the filters.
1494 * <li><b>Automatic Reconfiguration</b> :
1495 * <div class="sub-desc">
1496 * Filters automatically reconfigure when the grid 'reconfigure' event fires.
1498 * <li><b>Stateful</b> :
1499 * Filter information will be persisted across page loads by specifying a
1500 * <code>stateId</code> in the Grid configuration.
1501 * <div class="sub-desc">
1502 * The filter collection binds to the
1503 * <code>{@link Ext.grid.GridPanel#beforestaterestore beforestaterestore}</code>
1504 * and <code>{@link Ext.grid.GridPanel#beforestatesave beforestatesave}</code>
1505 * events in order to be stateful.
1507 * <li><b>Grid Changes</b> :
1508 * <div class="sub-desc"><ul>
1509 * <li>A <code>filters</code> <i>property</i> is added to the grid pointing to
1511 * <li>A <code>filterupdate</code> <i>event</i> is added to the grid and is
1512 * fired upon onStateChange completion.</li>
1514 * <li><b>Server side code examples</b> :
1515 * <div class="sub-desc"><ul>
1516 * <li><a href="http://www.vinylfox.com/extjs/grid-filter-php-backend-code.php">PHP</a> - (Thanks VinylFox)</li>
1517 * <li><a href="http://extjs.com/forum/showthread.php?p=77326#post77326">Ruby on Rails</a> - (Thanks Zyclops)</li>
1518 * <li><a href="http://extjs.com/forum/showthread.php?p=176596#post176596">Ruby on Rails</a> - (Thanks Rotomaul)</li>
1519 * <li><a href="http://www.debatablybeta.com/posts/using-extjss-grid-filtering-with-django/">Python</a> - (Thanks Matt)</li>
1520 * <li><a href="http://mcantrell.wordpress.com/2008/08/22/extjs-grids-and-grails/">Grails</a> - (Thanks Mike)</li>
1523 * <p><b><u>Example usage:</u></b></p>
1525 var store = new Ext.data.GroupingStore({
1529 var filters = new Ext.ux.grid.GridFilters({
1530 autoReload: false, //don't reload automatically
1531 local: true, //only filter locally
1532 // filters may be configured through the plugin,
1533 // or in the column definition within the column model configuration
1545 dataIndex: 'dateAdded'
1549 options: ['extra small', 'small', 'medium', 'large', 'extra large'],
1553 dataIndex: 'visible'
1556 var cm = new Ext.grid.ColumnModel([{
1560 var grid = new Ext.grid.GridPanel({
1563 view: new Ext.grid.GroupingView(),
1567 bbar: new Ext.PagingToolbar({
1570 plugins: [filters] //reset page to page 1 if filters change
1574 store.load({params: {start: 0, limit: 15}});
1576 // a filters property is added to the grid
1580 Ext.ux.grid.GridFilters = Ext.extend(Ext.util.Observable, {
1582 * @cfg {Boolean} autoReload
1583 * Defaults to true, reloading the datasource when a filter change happens.
1584 * Set this to false to prevent the datastore from being reloaded if there
1585 * are changes to the filters. See <code>{@link updateBuffer}</code>.
1589 * @cfg {Boolean} encode
1590 * Specify true for {@link #buildQuery} to use Ext.util.JSON.encode to
1591 * encode the filter query parameter sent with a remote request.
1592 * Defaults to false.
1595 * @cfg {Array} filters
1596 * An Array of filters config objects. Refer to each filter type class for
1597 * configuration details specific to each filter type. Filters for Strings,
1598 * Numeric Ranges, Date Ranges, Lists, and Boolean are the standard filters
1602 * @cfg {String} filterCls
1603 * The css class to be applied to column headers with active filters.
1604 * Defaults to <tt>'ux-filterd-column'</tt>.
1606 filterCls : 'ux-filtered-column',
1608 * @cfg {Boolean} local
1609 * <tt>true</tt> to use Ext.data.Store filter functions (local filtering)
1610 * instead of the default (<tt>false</tt>) server side filtering.
1614 * @cfg {String} menuFilterText
1615 * defaults to <tt>'Filters'</tt>.
1617 menuFilterText : 'Filters',
1619 * @cfg {String} paramPrefix
1620 * The url parameter prefix for the filters.
1621 * Defaults to <tt>'filter'</tt>.
1623 paramPrefix : 'filter',
1625 * @cfg {Boolean} showMenu
1626 * Defaults to true, including a filter submenu in the default header menu.
1630 * @cfg {String} stateId
1631 * Name of the value to be used to store state information.
1633 stateId : undefined,
1635 * @cfg {Integer} updateBuffer
1636 * Number of milliseconds to defer store updates since the last filter change.
1641 constructor : function (config) {
1642 config = config || {};
1643 this.deferredUpdate = new Ext.util.DelayedTask(this.reload, this);
1644 this.filters = new Ext.util.MixedCollection();
1645 this.filters.getKey = function (o) {
1646 return o ? o.dataIndex : null;
1648 this.addFilters(config.filters);
1649 delete config.filters;
1650 Ext.apply(this, config);
1654 init : function (grid) {
1655 if (grid instanceof Ext.grid.GridPanel) {
1658 this.bindStore(this.grid.getStore(), true);
1659 // assumes no filters were passed in the constructor, so try and use ones from the colModel
1660 if(this.filters.getCount() == 0){
1661 this.addFilters(this.grid.getColumnModel());
1664 this.grid.filters = this;
1666 this.grid.addEvents({'filterupdate': true});
1670 beforestaterestore: this.applyState,
1671 beforestatesave: this.saveState,
1672 beforedestroy: this.destroy,
1673 reconfigure: this.onReconfigure
1682 render: this.onRender
1686 } else if (grid instanceof Ext.PagingToolbar) {
1687 this.toolbar = grid;
1693 * Handler for the grid's beforestaterestore event (fires before the state of the
1694 * grid is restored).
1695 * @param {Object} grid The grid object
1696 * @param {Object} state The hash of state values returned from the StateProvider.
1698 applyState : function (grid, state) {
1700 this.applyingState = true;
1701 this.clearFilters();
1702 if (state.filters) {
1703 for (key in state.filters) {
1704 filter = this.filters.get(key);
1706 filter.setValue(state.filters[key]);
1707 filter.setActive(true);
1711 this.deferredUpdate.cancel();
1715 delete this.applyingState;
1719 * Saves the state of all active filters
1720 * @param {Object} grid
1721 * @param {Object} state
1724 saveState : function (grid, state) {
1726 this.filters.each(function (filter) {
1727 if (filter.active) {
1728 filters[filter.dataIndex] = filter.getValue();
1731 return (state.filters = filters);
1736 * Handler called when the grid is rendered
1738 onRender : function () {
1739 this.grid.getView().on('refresh', this.onRefresh, this);
1745 * Handler called by the grid 'beforedestroy' event
1747 destroy : function () {
1749 this.purgeListeners();
1751 if(this.filterMenu){
1752 Ext.menu.MenuMgr.unregister(this.filterMenu);
1753 this.filterMenu.destroy();
1754 this.filterMenu = this.menu.menu = null;
1759 * Remove all filters, permanently destroying them.
1761 removeAll : function () {
1763 Ext.destroy.apply(Ext, this.filters.items);
1764 // remove all items from the collection
1765 this.filters.clear();
1771 * Changes the data store bound to this view and refreshes it.
1772 * @param {Store} store The store to bind to this view
1774 bindStore : function(store, initial){
1775 if(!initial && this.store){
1777 store.un('load', this.onLoad, this);
1779 store.un('beforeload', this.onBeforeLoad, this);
1784 store.on('load', this.onLoad, this);
1786 store.on('beforeload', this.onBeforeLoad, this);
1794 * Handler called when the grid reconfigure event fires
1796 onReconfigure : function () {
1797 this.bindStore(this.grid.getStore());
1798 this.store.clearFilter();
1800 this.addFilters(this.grid.getColumnModel());
1801 this.updateColumnHeadings();
1804 createMenu : function () {
1805 var view = this.grid.getView(),
1808 if (this.showMenu && hmenu) {
1810 this.sep = hmenu.addSeparator();
1811 this.filterMenu = new Ext.menu.Menu({
1812 id: this.grid.id + '-filters-menu'
1814 this.menu = hmenu.add({
1817 text: this.menuFilterText,
1818 menu: this.filterMenu
1823 checkchange: this.onCheckChange,
1824 beforecheckchange: this.onBeforeCheck
1826 hmenu.on('beforeshow', this.onMenu, this);
1828 this.updateColumnHeadings();
1833 * Get the filter menu from the filters MixedCollection based on the clicked header
1835 getMenuFilter : function () {
1836 var view = this.grid.getView();
1837 if (!view || view.hdCtxIndex === undefined) {
1840 return this.filters.get(
1841 view.cm.config[view.hdCtxIndex].dataIndex
1847 * Handler called by the grid's hmenu beforeshow event
1849 onMenu : function (filterMenu) {
1850 var filter = this.getMenuFilter();
1854 TODO: lazy rendering
1856 filter.menu = filter.createMenu();
1859 this.menu.menu = filter.menu;
1860 this.menu.setChecked(filter.active, false);
1861 // disable the menu if filter.disabled explicitly set to true
1862 this.menu.setDisabled(filter.disabled === true);
1865 this.menu.setVisible(filter !== undefined);
1866 this.sep.setVisible(filter !== undefined);
1870 onCheckChange : function (item, value) {
1871 this.getMenuFilter().setActive(value);
1875 onBeforeCheck : function (check, value) {
1876 return !value || this.getMenuFilter().isActivatable();
1881 * Handler for all events on filters.
1882 * @param {String} event Event name
1883 * @param {Object} filter Standard signature of the event before the event is fired
1885 onStateChange : function (event, filter) {
1886 if (event === 'serialize') {
1890 if (filter == this.getMenuFilter()) {
1891 this.menu.setChecked(filter.active, false);
1894 if ((this.autoReload || this.local) && !this.applyingState) {
1895 this.deferredUpdate.delay(this.updateBuffer);
1897 this.updateColumnHeadings();
1899 if (!this.applyingState) {
1900 this.grid.saveState();
1902 this.grid.fireEvent('filterupdate', this, filter);
1907 * Handler for store's beforeload event when configured for remote filtering
1908 * @param {Object} store
1909 * @param {Object} options
1911 onBeforeLoad : function (store, options) {
1912 options.params = options.params || {};
1913 this.cleanParams(options.params);
1914 var params = this.buildQuery(this.getFilterData());
1915 Ext.apply(options.params, params);
1920 * Handler for store's load event when configured for local filtering
1921 * @param {Object} store
1922 * @param {Object} options
1924 onLoad : function (store, options) {
1925 store.filterBy(this.getRecordFilter());
1930 * Handler called when the grid's view is refreshed
1932 onRefresh : function () {
1933 this.updateColumnHeadings();
1937 * Update the styles for the header row based on the active filters
1939 updateColumnHeadings : function () {
1940 var view = this.grid.getView(),
1943 for (i = 0, len = view.cm.config.length; i < len; i++) {
1944 filter = this.getFilter(view.cm.config[i].dataIndex);
1945 Ext.fly(view.getHeaderCell(i))[filter && filter.active ? 'addClass' : 'removeClass'](this.filterCls);
1951 reload : function () {
1953 this.grid.store.clearFilter(true);
1954 this.grid.store.filterBy(this.getRecordFilter());
1957 store = this.grid.store;
1958 this.deferredUpdate.cancel();
1960 start = store.paramNames.start;
1961 if (store.lastOptions && store.lastOptions.params && store.lastOptions.params[start]) {
1962 store.lastOptions.params[start] = 0;
1970 * Method factory that generates a record validator for the filters active at the time
1974 getRecordFilter : function () {
1976 this.filters.each(function (filter) {
1977 if (filter.active) {
1983 return function (record) {
1984 for (i = 0; i < len; i++) {
1985 if (!f[i].validateRecord(record)) {
1994 * Adds a filter to the collection and observes it for state change.
1995 * @param {Object/Ext.ux.grid.filter.Filter} config A filter configuration or a filter object.
1996 * @return {Ext.ux.grid.filter.Filter} The existing or newly created filter object.
1998 addFilter : function (config) {
1999 var Cls = this.getFilterClass(config.type),
2000 filter = config.menu ? config : (new Cls(config));
2001 this.filters.add(filter);
2003 Ext.util.Observable.capture(filter, this.onStateChange, this);
2008 * Adds filters to the collection.
2009 * @param {Array/Ext.grid.ColumnModel} filters Either an Array of
2010 * filter configuration objects or an Ext.grid.ColumnModel. The columns
2011 * of a passed Ext.grid.ColumnModel will be examined for a <code>filter</code>
2012 * property and, if present, will be used as the filter configuration object.
2014 addFilters : function (filters) {
2016 var i, len, filter, cm = false, dI;
2017 if (filters instanceof Ext.grid.ColumnModel) {
2018 filters = filters.config;
2021 for (i = 0, len = filters.length; i < len; i++) {
2024 dI = filters[i].dataIndex;
2025 filter = filters[i].filter || filters[i].filterable;
2027 filter = (filter === true) ? {} : filter;
2028 Ext.apply(filter, {dataIndex:dI});
2029 // filter type is specified in order of preference:
2030 // filter type specified in config
2031 // type specified in store's field's type config
2032 filter.type = filter.type || this.store.fields.get(dI).type;
2035 filter = filters[i];
2037 // if filter config found add filter for the column
2039 this.addFilter(filter);
2046 * Returns a filter for the given dataIndex, if one exists.
2047 * @param {String} dataIndex The dataIndex of the desired filter object.
2048 * @return {Ext.ux.grid.filter.Filter}
2050 getFilter : function (dataIndex) {
2051 return this.filters.get(dataIndex);
2055 * Turns all filters off. This does not clear the configuration information
2056 * (see {@link #removeAll}).
2058 clearFilters : function () {
2059 this.filters.each(function (filter) {
2060 filter.setActive(false);
2065 * Returns an Array of the currently active filters.
2066 * @return {Array} filters Array of the currently active filters.
2068 getFilterData : function () {
2069 var filters = [], i, len;
2071 this.filters.each(function (f) {
2073 var d = [].concat(f.serialize());
2074 for (i = 0, len = d.length; i < len; i++) {
2086 * Function to take the active filters data and build it into a query.
2087 * The format of the query depends on the <code>{@link #encode}</code>
2089 * <div class="mdetail-params"><ul>
2091 * <li><b><tt>false</tt></b> : <i>Default</i>
2092 * <div class="sub-desc">
2093 * Flatten into query string of the form (assuming <code>{@link #paramPrefix}='filters'</code>:
2095 filters[0][field]="someDataIndex"&
2096 filters[0][data][comparison]="someValue1"&
2097 filters[0][data][type]="someValue2"&
2098 filters[0][data][value]="someValue3"&
2101 * <li><b><tt>true</tt></b> :
2102 * <div class="sub-desc">
2103 * JSON encode the filter data
2105 filters[0][field]="someDataIndex"&
2106 filters[0][data][comparison]="someValue1"&
2107 filters[0][data][type]="someValue2"&
2108 filters[0][data][value]="someValue3"&
2112 * Override this method to customize the format of the filter query for remote requests.
2113 * @param {Array} filters A collection of objects representing active filters and their configuration.
2114 * Each element will take the form of {field: dataIndex, data: filterConf}. dataIndex is not assured
2115 * to be unique as any one filter may be a composite of more basic filters for the same dataIndex.
2116 * @return {Object} Query keys and values
2118 buildQuery : function (filters) {
2119 var p = {}, i, f, root, dataPrefix, key, tmp,
2120 len = filters.length;
2123 for (i = 0; i < len; i++) {
2125 root = [this.paramPrefix, '[', i, ']'].join('');
2126 p[root + '[field]'] = f.field;
2128 dataPrefix = root + '[data]';
2129 for (key in f.data) {
2130 p[[dataPrefix, '[', key, ']'].join('')] = f.data[key];
2135 for (i = 0; i < len; i++) {
2143 // only build if there is active filter
2144 if (tmp.length > 0){
2145 p[this.paramPrefix] = Ext.util.JSON.encode(tmp);
2152 * Removes filter related query parameters from the provided object.
2153 * @param {Object} p Query parameters that may contain filter related fields.
2155 cleanParams : function (p) {
2156 // if encoding just delete the property
2158 delete p[this.paramPrefix];
2159 // otherwise scrub the object of filter data
2162 regex = new RegExp('^' + this.paramPrefix + '\[[0-9]+\]');
2164 if (regex.test(key)) {
2172 * Function for locating filter classes, overwrite this with your favorite
2173 * loader to provide dynamic filter loading.
2174 * @param {String} type The type of filter to load ('Filter' is automatically
2175 * appended to the passed type; eg, 'string' becomes 'StringFilter').
2176 * @return {Class} The Ext.ux.grid.filter.Class
2178 getFilterClass : function (type) {
2179 // map the supported Ext.data.Field type values into a supported filter
2189 return Ext.ux.grid.filter[type.substr(0, 1).toUpperCase() + type.substr(1) + 'Filter'];
2194 Ext.preg('gridfilters', Ext.ux.grid.GridFilters);
2195 Ext.namespace('Ext.ux.grid.filter');
2198 * @class Ext.ux.grid.filter.Filter
2199 * @extends Ext.util.Observable
2200 * Abstract base class for filter implementations.
2202 Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {
2204 * @cfg {Boolean} active
2205 * Indicates the initial status of the filter (defaults to false).
2209 * True if this filter is active. Use setActive() to alter after configuration.
2214 * @cfg {String} dataIndex
2215 * The {@link Ext.data.Store} dataIndex of the field this filter represents.
2216 * The dataIndex does not actually have to exist in the store.
2220 * The filter configuration menu that will be installed into the filter submenu of a column menu.
2221 * @type Ext.menu.Menu
2226 * @cfg {Number} updateBuffer
2227 * Number of milliseconds to wait after user interaction to fire an update. Only supported
2228 * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
2232 constructor : function (config) {
2233 Ext.apply(this, config);
2238 * Fires when an inactive filter becomes active
2239 * @param {Ext.ux.grid.filter.Filter} this
2244 * Fires when an active filter becomes inactive
2245 * @param {Ext.ux.grid.filter.Filter} this
2250 * Fires after the serialization process. Use this to attach additional parameters to serialization
2251 * data before it is encoded and sent to the server.
2252 * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
2253 * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
2258 * Fires when a filter configuration has changed
2259 * @param {Ext.ux.grid.filter.Filter} this The filter object.
2263 Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
2265 this.menu = new Ext.menu.Menu();
2267 if(config && config.value){
2268 this.setValue(config.value);
2269 this.setActive(config.active !== false, true);
2270 delete config.value;
2275 * Destroys this filter by purging any event listeners, and removing any menus.
2277 destroy : function(){
2279 this.menu.destroy();
2281 this.purgeListeners();
2285 * Template method to be implemented by all subclasses that is to
2286 * initialize the filter and install required menu items.
2287 * Defaults to Ext.emptyFn.
2292 * Template method to be implemented by all subclasses that is to
2293 * get and return the value of the filter.
2294 * Defaults to Ext.emptyFn.
2295 * @return {Object} The 'serialized' form of this filter
2296 * @methodOf Ext.ux.grid.filter.Filter
2298 getValue : Ext.emptyFn,
2301 * Template method to be implemented by all subclasses that is to
2302 * set the value of the filter and fire the 'update' event.
2303 * Defaults to Ext.emptyFn.
2304 * @param {Object} data The value to set the filter
2305 * @methodOf Ext.ux.grid.filter.Filter
2307 setValue : Ext.emptyFn,
2310 * Template method to be implemented by all subclasses that is to
2311 * return <tt>true</tt> if the filter has enough configuration information to be activated.
2312 * Defaults to <tt>return true</tt>.
2315 isActivatable : function(){
2320 * Template method to be implemented by all subclasses that is to
2321 * get and return serialized filter data for transmission to the server.
2322 * Defaults to Ext.emptyFn.
2324 getSerialArgs : Ext.emptyFn,
2327 * Template method to be implemented by all subclasses that is to
2328 * validates the provided Ext.data.Record against the filters configuration.
2329 * Defaults to <tt>return true</tt>.
2330 * @param {Ext.data.Record} record The record to validate
2331 * @return {Boolean} true if the record is valid within the bounds
2332 * of the filter, false otherwise.
2334 validateRecord : function(){
2339 * Returns the serialized filter data for transmission to the server
2340 * and fires the 'serialize' event.
2341 * @return {Object/Array} An object or collection of objects containing
2342 * key value pairs representing the current configuration of the filter.
2343 * @methodOf Ext.ux.grid.filter.Filter
2345 serialize : function(){
2346 var args = this.getSerialArgs();
2347 this.fireEvent('serialize', args, this);
2352 fireUpdate : function(){
2354 this.fireEvent('update', this);
2356 this.setActive(this.isActivatable());
2360 * Sets the status of the filter and fires the appropriate events.
2361 * @param {Boolean} active The new filter state.
2362 * @param {Boolean} suppressEvent True to prevent events from being fired.
2363 * @methodOf Ext.ux.grid.filter.Filter
2365 setActive : function(active, suppressEvent){
2366 if(this.active != active){
2367 this.active = active;
2368 if (suppressEvent !== true) {
2369 this.fireEvent(active ? 'activate' : 'deactivate', this);
2374 * @class Ext.ux.grid.filter.BooleanFilter
2375 * @extends Ext.ux.grid.filter.Filter
2376 * Boolean filters use unique radio group IDs (so you can have more than one!)
2377 * <p><b><u>Example Usage:</u></b></p>
2379 var filters = new Ext.ux.grid.GridFilters({
2384 dataIndex: 'visible'
2387 defaultValue: null, // leave unselected (false selected by default)
2388 yesText: 'Yes', // default
2389 noText: 'No' // default
2394 Ext.ux.grid.filter.BooleanFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2396 * @cfg {Boolean} defaultValue
2397 * Set this to null if you do not want either option to be checked by default. Defaults to false.
2399 defaultValue : false,
2401 * @cfg {String} yesText
2402 * Defaults to 'Yes'.
2406 * @cfg {String} noText
2413 * Template method that is to initialize the filter and install required menu items.
2415 init : function (config) {
2418 new Ext.menu.CheckItem({text: this.yesText, group: gId, checked: this.defaultValue === true}),
2419 new Ext.menu.CheckItem({text: this.noText, group: gId, checked: this.defaultValue === false})];
2421 this.menu.add(this.options[0], this.options[1]);
2423 for(var i=0; i<this.options.length; i++){
2424 this.options[i].on('click', this.fireUpdate, this);
2425 this.options[i].on('checkchange', this.fireUpdate, this);
2431 * Template method that is to get and return the value of the filter.
2432 * @return {String} The value of this filter
2434 getValue : function () {
2435 return this.options[0].checked;
2440 * Template method that is to set the value of the filter.
2441 * @param {Object} value The value to set the filter
2443 setValue : function (value) {
2444 this.options[value ? 0 : 1].setChecked(true);
2449 * Template method that is to get and return serialized filter data for
2450 * transmission to the server.
2451 * @return {Object/Array} An object or collection of objects containing
2452 * key value pairs representing the current configuration of the filter.
2454 getSerialArgs : function () {
2455 var args = {type: 'boolean', value: this.getValue()};
2460 * Template method that is to validate the provided Ext.data.Record
2461 * against the filters configuration.
2462 * @param {Ext.data.Record} record The record to validate
2463 * @return {Boolean} true if the record is valid within the bounds
2464 * of the filter, false otherwise.
2466 validateRecord : function (record) {
2467 return record.get(this.dataIndex) == this.getValue();
2470 * @class Ext.ux.grid.filter.DateFilter
2471 * @extends Ext.ux.grid.filter.Filter
2472 * Filter by a configurable Ext.menu.DateMenu
2473 * <p><b><u>Example Usage:</u></b></p>
2475 var filters = new Ext.ux.grid.GridFilters({
2480 dataIndex: 'dateAdded',
2483 dateFormat: 'm/d/Y', // default
2484 beforeText: 'Before', // default
2485 afterText: 'After', // default
2486 onText: 'On', // default
2488 // any DateMenu configs
2491 active: true // default is false
2496 Ext.ux.grid.filter.DateFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2498 * @cfg {String} afterText
2499 * Defaults to 'After'.
2501 afterText : 'After',
2503 * @cfg {String} beforeText
2504 * Defaults to 'Before'.
2506 beforeText : 'Before',
2508 * @cfg {Object} compareMap
2509 * Map for assigning the comparison values used in serialization.
2517 * @cfg {String} dateFormat
2518 * The date format to return when using getValue.
2519 * Defaults to 'm/d/Y'.
2521 dateFormat : 'm/d/Y',
2524 * @cfg {Date} maxDate
2525 * Allowable date as passed to the Ext.DatePicker
2526 * Defaults to undefined.
2529 * @cfg {Date} minDate
2530 * Allowable date as passed to the Ext.DatePicker
2531 * Defaults to undefined.
2534 * @cfg {Array} menuItems
2535 * The items to be shown in this menu
2537 * menuItems : ['before', 'after', '-', 'on'],
2540 menuItems : ['before', 'after', '-', 'on'],
2543 * @cfg {Object} menuItemCfgs
2544 * Default configuration options for each menu item
2547 selectOnFocus: true,
2552 * @cfg {String} onText
2558 * @cfg {Object} pickerOpts
2559 * Configuration options for the date picker associated with each field.
2565 * Template method that is to initialize the filter and install required menu items.
2567 init : function (config) {
2568 var menuCfg, i, len, item, cfg, Cls;
2570 menuCfg = Ext.apply(this.pickerOpts, {
2571 minDate: this.minDate,
2572 maxDate: this.maxDate,
2573 format: this.dateFormat,
2576 select: this.onMenuSelect
2581 for (i = 0, len = this.menuItems.length; i < len; i++) {
2582 item = this.menuItems[i];
2585 itemId: 'range-' + item,
2586 text: this[item + 'Text'],
2587 menu: new Ext.menu.DateMenu(
2588 Ext.apply(menuCfg, {
2594 checkchange: this.onCheckChange
2597 Cls = Ext.menu.CheckItem;
2598 item = this.fields[item] = new Cls(cfg);
2601 this.menu.add(item);
2605 onCheckChange : function () {
2606 this.setActive(this.isActivatable());
2607 this.fireEvent('update', this);
2612 * Handler method called when there is a keyup event on an input
2613 * item of this menu.
2615 onInputKeyUp : function (field, e) {
2617 if (k == e.RETURN && field.isValid()) {
2619 this.menu.hide(true);
2625 * Handler for when the menu for a field fires the 'select' event
2626 * @param {Object} date
2627 * @param {Object} menuItem
2628 * @param {Object} value
2629 * @param {Object} picker
2631 onMenuSelect : function (menuItem, value, picker) {
2632 var fields = this.fields,
2633 field = this.fields[menuItem.itemId];
2635 field.setChecked(true);
2637 if (field == fields.on) {
2638 fields.before.setChecked(false, true);
2639 fields.after.setChecked(false, true);
2641 fields.on.setChecked(false, true);
2642 if (field == fields.after && fields.before.menu.picker.value < value) {
2643 fields.before.setChecked(false, true);
2644 } else if (field == fields.before && fields.after.menu.picker.value > value) {
2645 fields.after.setChecked(false, true);
2648 this.fireEvent('update', this);
2653 * Template method that is to get and return the value of the filter.
2654 * @return {String} The value of this filter
2656 getValue : function () {
2657 var key, result = {};
2658 for (key in this.fields) {
2659 if (this.fields[key].checked) {
2660 result[key] = this.fields[key].menu.picker.getValue();
2668 * Template method that is to set the value of the filter.
2669 * @param {Object} value The value to set the filter
2670 * @param {Boolean} preserve true to preserve the checked status
2671 * of the other fields. Defaults to false, unchecking the
2674 setValue : function (value, preserve) {
2676 for (key in this.fields) {
2678 this.fields[key].menu.picker.setValue(value[key]);
2679 this.fields[key].setChecked(true);
2680 } else if (!preserve) {
2681 this.fields[key].setChecked(false);
2684 this.fireEvent('update', this);
2689 * Template method that is to return <tt>true</tt> if the filter
2690 * has enough configuration information to be activated.
2693 isActivatable : function () {
2695 for (key in this.fields) {
2696 if (this.fields[key].checked) {
2705 * Template method that is to get and return serialized filter data for
2706 * transmission to the server.
2707 * @return {Object/Array} An object or collection of objects containing
2708 * key value pairs representing the current configuration of the filter.
2710 getSerialArgs : function () {
2712 for (var key in this.fields) {
2713 if(this.fields[key].checked){
2716 comparison: this.compareMap[key],
2717 value: this.getFieldValue(key).format(this.dateFormat)
2725 * Get and return the date menu picker value
2726 * @param {String} item The field identifier ('before', 'after', 'on')
2727 * @return {Date} Gets the current selected value of the date field
2729 getFieldValue : function(item){
2730 return this.fields[item].menu.picker.getValue();
2734 * Gets the menu picker associated with the passed field
2735 * @param {String} item The field identifier ('before', 'after', 'on')
2736 * @return {Object} The menu picker
2738 getPicker : function(item){
2739 return this.fields[item].menu.picker;
2743 * Template method that is to validate the provided Ext.data.Record
2744 * against the filters configuration.
2745 * @param {Ext.data.Record} record The record to validate
2746 * @return {Boolean} true if the record is valid within the bounds
2747 * of the filter, false otherwise.
2749 validateRecord : function (record) {
2752 val = record.get(this.dataIndex);
2754 if(!Ext.isDate(val)){
2757 val = val.clearTime(true).getTime();
2759 for (key in this.fields) {
2760 if (this.fields[key].checked) {
2761 pickerValue = this.getFieldValue(key).clearTime(true).getTime();
2762 if (key == 'before' && pickerValue <= val) {
2765 if (key == 'after' && pickerValue >= val) {
2768 if (key == 'on' && pickerValue != val) {
2776 * @class Ext.ux.grid.filter.ListFilter
2777 * @extends Ext.ux.grid.filter.Filter
2778 * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load
2779 * their options the first time they are shown. ListFilter utilizes the
2780 * {@link Ext.ux.menu.ListMenu} component.</p>
2781 * <p>Although not shown here, this class accepts all configuration options
2782 * for {@link Ext.ux.menu.ListMenu}.</p>
2784 * <p><b><u>Example Usage:</u></b></p>
2786 var filters = new Ext.ux.grid.GridFilters({
2792 // options will be used as data to implicitly creates an ArrayStore
2793 options: ['extra small', 'small', 'medium', 'large', 'extra large']
2799 Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2802 * @cfg {Array} options
2803 * <p><code>data</code> to be used to implicitly create a data store
2804 * to back this list when the data source is <b>local</b>. If the
2805 * data for the list is remote, use the <code>{@link #store}</code>
2806 * config instead.</p>
2807 * <br><p>Each item within the provided array may be in one of the
2808 * following formats:</p>
2809 * <div class="mdetail-params"><ul>
2810 * <li><b>Array</b> :
2813 [11, 'extra small'],
2821 * <li><b>Object</b> :
2823 labelField: 'name', // override default of 'text'
2825 {id: 11, name:'extra small'},
2826 {id: 18, name:'small'},
2827 {id: 22, name:'medium'},
2828 {id: 35, name:'large'},
2829 {id: 44, name:'extra large'}
2833 * <li><b>String</b> :
2835 * options: ['extra small', 'small', 'medium', 'large', 'extra large']
2840 * @cfg {Boolean} phpMode
2841 * <p>Adjust the format of this filter. Defaults to false.</p>
2842 * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>
2844 // phpMode == false (default):
2845 filter[0][data][type] list
2846 filter[0][data][value] value1
2847 filter[0][data][value] value2
2848 filter[0][field] prod
2851 filter[0][data][type] list
2852 filter[0][data][value] value1, value2
2853 filter[0][field] prod
2855 * When GridFilters <code>@cfg encode = true</code>:
2857 // phpMode == false (default):
2858 filter : [{"type":"list","value":["small","medium"],"field":"size"}]
2861 filter : [{"type":"list","value":"small,medium","field":"size"}]
2866 * @cfg {Ext.data.Store} store
2867 * The {@link Ext.data.Store} this list should use as its data source
2868 * when the data source is <b>remote</b>. If the data for the list
2869 * is local, use the <code>{@link #options}</code> config instead.
2874 * Template method that is to initialize the filter and install required menu items.
2875 * @param {Object} config
2877 init : function (config) {
2878 this.dt = new Ext.util.DelayedTask(this.fireUpdate, this);
2880 // if a menu already existed, do clean up first
2882 this.menu.destroy();
2884 this.menu = new Ext.ux.menu.ListMenu(config);
2885 this.menu.on('checkchange', this.onCheckChange, this);
2890 * Template method that is to get and return the value of the filter.
2891 * @return {String} The value of this filter
2893 getValue : function () {
2894 return this.menu.getSelected();
2898 * Template method that is to set the value of the filter.
2899 * @param {Object} value The value to set the filter
2901 setValue : function (value) {
2902 this.menu.setSelected(value);
2903 this.fireEvent('update', this);
2908 * Template method that is to return <tt>true</tt> if the filter
2909 * has enough configuration information to be activated.
2912 isActivatable : function () {
2913 return this.getValue().length > 0;
2918 * Template method that is to get and return serialized filter data for
2919 * transmission to the server.
2920 * @return {Object/Array} An object or collection of objects containing
2921 * key value pairs representing the current configuration of the filter.
2923 getSerialArgs : function () {
2924 var args = {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
2929 onCheckChange : function(){
2930 this.dt.delay(this.updateBuffer);
2935 * Template method that is to validate the provided Ext.data.Record
2936 * against the filters configuration.
2937 * @param {Ext.data.Record} record The record to validate
2938 * @return {Boolean} true if the record is valid within the bounds
2939 * of the filter, false otherwise.
2941 validateRecord : function (record) {
2942 return this.getValue().indexOf(record.get(this.dataIndex)) > -1;
2945 * @class Ext.ux.grid.filter.NumericFilter
2946 * @extends Ext.ux.grid.filter.Filter
2947 * Filters using an Ext.ux.menu.RangeMenu.
2948 * <p><b><u>Example Usage:</u></b></p>
2950 var filters = new Ext.ux.grid.GridFilters({
2959 Ext.ux.grid.filter.NumericFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2962 * @cfg {Object} fieldCls
2963 * The Class to use to construct each field item within this menu
2965 * fieldCls : Ext.form.NumberField
2968 fieldCls : Ext.form.NumberField,
2970 * @cfg {Object} fieldCfg
2971 * The default configuration options for any field item unless superseded
2972 * by the <code>{@link #fields}</code> configuration.
2984 * @cfg {Object} fields
2985 * The field items may be configured individually
2986 * Defaults to <tt>undefined</tt>.
2990 gt: { // override fieldCfg options
2992 fieldCls: Ext.ux.form.CustomNumberField // to override default {@link #fieldCls}
2998 * @cfg {Object} iconCls
2999 * The iconCls to be applied to each comparator field item.
3002 gt : 'ux-rangemenu-gt',
3003 lt : 'ux-rangemenu-lt',
3004 eq : 'ux-rangemenu-eq'
3009 gt : 'ux-rangemenu-gt',
3010 lt : 'ux-rangemenu-lt',
3011 eq : 'ux-rangemenu-eq'
3015 * @cfg {Object} menuItemCfgs
3016 * Default configuration options for each menu item
3019 emptyText: 'Enter Filter Text...',
3020 selectOnFocus: true,
3026 emptyText: 'Enter Filter Text...',
3027 selectOnFocus: true,
3032 * @cfg {Array} menuItems
3033 * The items to be shown in this menu. Items are added to the menu
3034 * according to their position within this array. Defaults to:<pre>
3035 * menuItems : ['lt','gt','-','eq']
3038 menuItems : ['lt', 'gt', '-', 'eq'],
3042 * Template method that is to initialize the filter and install required menu items.
3044 init : function (config) {
3045 // if a menu already existed, do clean up first
3047 this.menu.destroy();
3049 this.menu = new Ext.ux.menu.RangeMenu(Ext.apply(config, {
3050 // pass along filter configs to the menu
3051 fieldCfg : this.fieldCfg || {},
3052 fieldCls : this.fieldCls,
3053 fields : this.fields || {},
3054 iconCls: this.iconCls,
3055 menuItemCfgs: this.menuItemCfgs,
3056 menuItems: this.menuItems,
3057 updateBuffer: this.updateBuffer
3059 // relay the event fired by the menu
3060 this.menu.on('update', this.fireUpdate, this);
3065 * Template method that is to get and return the value of the filter.
3066 * @return {String} The value of this filter
3068 getValue : function () {
3069 return this.menu.getValue();
3074 * Template method that is to set the value of the filter.
3075 * @param {Object} value The value to set the filter
3077 setValue : function (value) {
3078 this.menu.setValue(value);
3083 * Template method that is to return <tt>true</tt> if the filter
3084 * has enough configuration information to be activated.
3087 isActivatable : function () {
3088 var values = this.getValue();
3089 for (key in values) {
3090 if (values[key] !== undefined) {
3099 * Template method that is to get and return serialized filter data for
3100 * transmission to the server.
3101 * @return {Object/Array} An object or collection of objects containing
3102 * key value pairs representing the current configuration of the filter.
3104 getSerialArgs : function () {
3107 values = this.menu.getValue();
3108 for (key in values) {
3119 * Template method that is to validate the provided Ext.data.Record
3120 * against the filters configuration.
3121 * @param {Ext.data.Record} record The record to validate
3122 * @return {Boolean} true if the record is valid within the bounds
3123 * of the filter, false otherwise.
3125 validateRecord : function (record) {
3126 var val = record.get(this.dataIndex),
3127 values = this.getValue();
3128 if (values.eq !== undefined && val != values.eq) {
3131 if (values.lt !== undefined && val >= values.lt) {
3134 if (values.gt !== undefined && val <= values.gt) {
3140 * @class Ext.ux.grid.filter.StringFilter
3141 * @extends Ext.ux.grid.filter.Filter
3142 * Filter by a configurable Ext.form.TextField
3143 * <p><b><u>Example Usage:</u></b></p>
3145 var filters = new Ext.ux.grid.GridFilters({
3154 active: true, // default is false
3155 iconCls: 'ux-gridfilter-text-icon' // default
3156 // any Ext.form.TextField configs accepted
3161 Ext.ux.grid.filter.StringFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
3164 * @cfg {String} iconCls
3165 * The iconCls to be applied to the menu item.
3166 * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
3168 iconCls : 'ux-gridfilter-text-icon',
3170 emptyText: 'Enter Filter Text...',
3171 selectOnFocus: true,
3176 * Template method that is to initialize the filter and install required menu items.
3178 init : function (config) {
3179 Ext.applyIf(config, {
3180 enableKeyEvents: true,
3181 iconCls: this.iconCls,
3184 keyup: this.onInputKeyUp
3188 this.inputItem = new Ext.form.TextField(config);
3189 this.menu.add(this.inputItem);
3190 this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
3195 * Template method that is to get and return the value of the filter.
3196 * @return {String} The value of this filter
3198 getValue : function () {
3199 return this.inputItem.getValue();
3204 * Template method that is to set the value of the filter.
3205 * @param {Object} value The value to set the filter
3207 setValue : function (value) {
3208 this.inputItem.setValue(value);
3209 this.fireEvent('update', this);
3214 * Template method that is to return <tt>true</tt> if the filter
3215 * has enough configuration information to be activated.
3218 isActivatable : function () {
3219 return this.inputItem.getValue().length > 0;
3224 * Template method that is to get and return serialized filter data for
3225 * transmission to the server.
3226 * @return {Object/Array} An object or collection of objects containing
3227 * key value pairs representing the current configuration of the filter.
3229 getSerialArgs : function () {
3230 return {type: 'string', value: this.getValue()};
3234 * Template method that is to validate the provided Ext.data.Record
3235 * against the filters configuration.
3236 * @param {Ext.data.Record} record The record to validate
3237 * @return {Boolean} true if the record is valid within the bounds
3238 * of the filter, false otherwise.
3240 validateRecord : function (record) {
3241 var val = record.get(this.dataIndex);
3243 if(typeof val != 'string') {
3244 return (this.getValue().length === 0);
3247 return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
3252 * Handler method called when there is a keyup event on this.inputItem
3254 onInputKeyUp : function (field, e) {
3256 if (k == e.RETURN && field.isValid()) {
3258 this.menu.hide(true);
3261 // restart the timer
3262 this.updateTask.delay(this.updateBuffer);
3265 Ext.namespace('Ext.ux.menu');
3268 * @class Ext.ux.menu.ListMenu
3269 * @extends Ext.menu.Menu
3270 * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.
3271 * Although not listed as configuration options for this class, this class
3272 * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.
3274 Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
3276 * @cfg {String} labelField
3277 * Defaults to 'text'.
3279 labelField : 'text',
3281 * @cfg {String} paramPrefix
3282 * Defaults to 'Loading...'.
3284 loadingText : 'Loading...',
3286 * @cfg {Boolean} loadOnShow
3291 * @cfg {Boolean} single
3292 * Specify true to group all items in this list into a single-select
3293 * radio button group. Defaults to false.
3297 constructor : function (cfg) {
3301 * @event checkchange
3302 * Fires when there is a change in checked items from this list
3303 * @param {Object} item Ext.menu.CheckItem
3304 * @param {Object} checked The checked value that was set
3309 Ext.ux.menu.ListMenu.superclass.constructor.call(this, cfg = cfg || {});
3311 if(!cfg.store && cfg.options){
3313 for(var i=0, len=cfg.options.length; i<len; i++){
3314 var value = cfg.options[i];
3315 switch(Ext.type(value)){
3316 case 'array': options.push(value); break;
3317 case 'object': options.push([value.id, value[this.labelField]]); break;
3318 case 'string': options.push([value, value]); break;
3322 this.store = new Ext.data.Store({
3323 reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]),
3326 'load': this.onLoad,
3332 this.add({text: this.loadingText, iconCls: 'loading-indicator'});
3333 this.store.on('load', this.onLoad, this);
3337 destroy : function () {
3339 this.store.destroy();
3341 Ext.ux.menu.ListMenu.superclass.destroy.call(this);
3345 * Lists will initially show a 'loading' item while the data is retrieved from the store.
3346 * In some cases the loaded data will result in a list that goes off the screen to the
3347 * right (as placement calculations were done with the loading item). This adapter will
3348 * allow show to be called with no arguments to show with the previous arguments and
3349 * thus recalculate the width and potentially hang the menu from the left.
3351 show : function () {
3352 var lastArgs = null;
3354 if(arguments.length === 0){
3355 Ext.ux.menu.ListMenu.superclass.show.apply(this, lastArgs);
3357 lastArgs = arguments;
3358 if (this.loadOnShow && !this.loaded) {
3361 Ext.ux.menu.ListMenu.superclass.show.apply(this, arguments);
3367 onLoad : function (store, records) {
3368 var visible = this.isVisible();
3371 this.removeAll(true);
3373 var gid = this.single ? Ext.id() : null;
3374 for(var i=0, len=records.length; i<len; i++){
3375 var item = new Ext.menu.CheckItem({
3376 text: records[i].get(this.labelField),
3378 checked: this.selected.indexOf(records[i].id) > -1,
3379 hideOnClick: false});
3381 item.itemId = records[i].id;
3382 item.on('checkchange', this.checkChange, this);
3392 this.fireEvent('load', this, records);
3396 * Get the selected items.
3397 * @return {Array} selected
3399 getSelected : function () {
3400 return this.selected;
3404 setSelected : function (value) {
3405 value = this.selected = [].concat(value);
3408 this.items.each(function(item){
3409 item.setChecked(false, true);
3410 for (var i = 0, len = value.length; i < len; i++) {
3411 if (item.itemId == value[i]) {
3412 item.setChecked(true, true);
3420 * Handler for the 'checkchange' event from an check item in this menu
3421 * @param {Object} item Ext.menu.CheckItem
3422 * @param {Object} checked The checked value that was set
3424 checkChange : function (item, checked) {
3426 this.items.each(function(item){
3428 value.push(item.itemId);
3431 this.selected = value;
3433 this.fireEvent('checkchange', item, checked);
3435 });Ext.ns('Ext.ux.menu');
3438 * @class Ext.ux.menu.RangeMenu
3439 * @extends Ext.menu.Menu
3440 * Custom implementation of Ext.menu.Menu that has preconfigured
3441 * items for gt, lt, eq.
3442 * <p><b><u>Example Usage:</u></b></p>
3447 Ext.ux.menu.RangeMenu = Ext.extend(Ext.menu.Menu, {
3449 constructor : function (config) {
3451 Ext.ux.menu.RangeMenu.superclass.constructor.call(this, config);
3456 * Fires when a filter configuration has changed
3457 * @param {Ext.ux.grid.filter.Filter} this The filter object.
3462 this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
3464 var i, len, item, cfg, Cls;
3466 for (i = 0, len = this.menuItems.length; i < len; i++) {
3467 item = this.menuItems[i];
3471 itemId: 'range-' + item,
3472 enableKeyEvents: true,
3473 iconCls: this.iconCls[item] || 'no-icon',
3476 keyup: this.onInputKeyUp
3482 Ext.applyIf(this.fields[item] || {}, this.fieldCfg[item]),
3483 // configurable defaults
3486 Cls = cfg.fieldCls || this.fieldCls;
3487 item = this.fields[item] = new Cls(cfg);
3495 * called by this.updateTask
3497 fireUpdate : function () {
3498 this.fireEvent('update', this);
3502 * Get and return the value of the filter.
3503 * @return {String} The value of this filter
3505 getValue : function () {
3506 var result = {}, key, field;
3507 for (key in this.fields) {
3508 field = this.fields[key];
3509 if (field.isValid() && String(field.getValue()).length > 0) {
3510 result[key] = field.getValue();
3517 * Set the value of this menu and fires the 'update' event.
3518 * @param {Object} data The data to assign to this menu
3520 setValue : function (data) {
3522 for (key in this.fields) {
3523 this.fields[key].setValue(data[key] !== undefined ? data[key] : '');
3525 this.fireEvent('update', this);
3530 * Handler method called when there is a keyup event on an input
3531 * item of this menu.
3533 onInputKeyUp : function (field, e) {
3535 if (k == e.RETURN && field.isValid()) {
3541 if (field == this.fields.eq) {
3542 if (this.fields.gt) {
3543 this.fields.gt.setValue(null);
3545 if (this.fields.lt) {
3546 this.fields.lt.setValue(null);
3550 this.fields.eq.setValue(null);
3553 // restart the timer
3554 this.updateTask.delay(this.updateBuffer);
3558 * Ext JS Library 3.2.0
3559 * Copyright(c) 2006-2010 Ext JS, Inc.
3560 * licensing@extjs.com
3561 * http://www.extjs.com/license
3563 Ext.ns('Ext.ux.grid');
3566 * @class Ext.ux.grid.GroupSummary
3567 * @extends Ext.util.Observable
3568 * A GridPanel plugin that enables dynamic column calculations and a dynamically
3569 * updated grouped summary row.
3571 Ext.ux.grid.GroupSummary = Ext.extend(Ext.util.Observable, {
3573 * @cfg {Function} summaryRenderer Renderer example:<pre><code>
3574 summaryRenderer: function(v, params, data){
3575 return ((v === 0 || v > 1) ? '(' + v +' Tasks)' : '(1 Task)');
3580 * @cfg {String} summaryType (Optional) The type of
3581 * calculation to be used for the column. For options available see
3582 * {@link #Calculations}.
3585 constructor : function(config){
3586 Ext.apply(this, config);
3587 Ext.ux.grid.GroupSummary.superclass.constructor.call(this);
3589 init : function(grid){
3591 var v = this.view = grid.getView();
3592 v.doGroupEnd = this.doGroupEnd.createDelegate(this);
3594 v.afterMethod('onColumnWidthUpdated', this.doWidth, this);
3595 v.afterMethod('onAllColumnWidthsUpdated', this.doAllWidths, this);
3596 v.afterMethod('onColumnHiddenUpdated', this.doHidden, this);
3597 v.afterMethod('onUpdate', this.doUpdate, this);
3598 v.afterMethod('onRemove', this.doRemove, this);
3601 this.rowTpl = new Ext.Template(
3602 '<div class="x-grid3-summary-row" style="{tstyle}">',
3603 '<table class="x-grid3-summary-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
3604 '<tbody><tr>{cells}</tr></tbody>',
3607 this.rowTpl.disableFormats = true;
3609 this.rowTpl.compile();
3612 this.cellTpl = new Ext.Template(
3613 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
3614 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on">{value}</div>',
3617 this.cellTpl.disableFormats = true;
3619 this.cellTpl.compile();
3623 * Toggle the display of the summary row on/off
3624 * @param {Boolean} visible <tt>true</tt> to show the summary, <tt>false</tt> to hide the summary.
3626 toggleSummaries : function(visible){
3627 var el = this.grid.getGridEl();
3629 if(visible === undefined){
3630 visible = el.hasClass('x-grid-hide-summary');
3632 el[visible ? 'removeClass' : 'addClass']('x-grid-hide-summary');
3636 renderSummary : function(o, cs){
3637 cs = cs || this.view.getColumnData();
3638 var cfg = this.grid.getColumnModel().config,
3639 buf = [], c, p = {}, cf, last = cs.length-1;
3640 for(var i = 0, len = cs.length; i < len; i++){
3645 p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
3646 if(cf.summaryType || cf.summaryRenderer){
3647 p.value = (cf.summaryRenderer || c.renderer)(o.data[c.name], p, o);
3651 if(p.value == undefined || p.value === "") p.value = " ";
3652 buf[buf.length] = this.cellTpl.apply(p);
3655 return this.rowTpl.apply({
3656 tstyle: 'width:'+this.view.getTotalWidth()+';',
3663 * @param {Object} rs
3664 * @param {Object} cs
3666 calculate : function(rs, cs){
3667 var data = {}, r, c, cfg = this.grid.getColumnModel().config, cf;
3668 for(var j = 0, jlen = rs.length; j < jlen; j++){
3670 for(var i = 0, len = cs.length; i < len; i++){
3674 data[c.name] = Ext.ux.grid.GroupSummary.Calculations[cf.summaryType](data[c.name] || 0, r, c.name, data);
3681 doGroupEnd : function(buf, g, cs, ds, colCount){
3682 var data = this.calculate(g.rs, cs);
3683 buf.push('</div>', this.renderSummary({data: data}, cs), '</div>');
3686 doWidth : function(col, w, tw){
3687 if(!this.isGrouped()){
3690 var gs = this.view.getGroups(),
3694 for(; i < len; ++i){
3695 s = gs[i].childNodes[2];
3697 s.firstChild.style.width = tw;
3698 s.firstChild.rows[0].childNodes[col].style.width = w;
3702 doAllWidths : function(ws, tw){
3703 if(!this.isGrouped()){
3706 var gs = this.view.getGroups(),
3714 for(; i < len; i++){
3715 s = gs[i].childNodes[2];
3717 s.firstChild.style.width = tw;
3718 cells = s.firstChild.rows[0].childNodes;
3719 for(j = 0; j < wlen; j++){
3720 cells[j].style.width = ws[j];
3725 doHidden : function(col, hidden, tw){
3726 if(!this.isGrouped()){
3729 var gs = this.view.getGroups(),
3733 display = hidden ? 'none' : '';
3734 for(; i < len; i++){
3735 s = gs[i].childNodes[2];
3737 s.firstChild.style.width = tw;
3738 s.firstChild.rows[0].childNodes[col].style.display = display;
3742 isGrouped : function(){
3743 return !Ext.isEmpty(this.grid.getStore().groupField);
3746 // Note: requires that all (or the first) record in the
3747 // group share the same group value. Returns false if the group
3748 // could not be found.
3749 refreshSummary : function(groupValue){
3750 return this.refreshSummaryById(this.view.getGroupId(groupValue));
3753 getSummaryNode : function(gid){
3754 var g = Ext.fly(gid, '_gsummary');
3756 return g.down('.x-grid3-summary-row', true);
3761 refreshSummaryById : function(gid){
3762 var g = Ext.getDom(gid);
3767 this.grid.getStore().each(function(r){
3768 if(r._groupId == gid){
3772 var cs = this.view.getColumnData(),
3773 data = this.calculate(rs, cs),
3774 markup = this.renderSummary({data: data}, cs),
3775 existing = this.getSummaryNode(gid);
3778 g.removeChild(existing);
3780 Ext.DomHelper.append(g, markup);
3784 doUpdate : function(ds, record){
3785 this.refreshSummaryById(record._groupId);
3788 doRemove : function(ds, record, index, isUpdate){
3790 this.refreshSummaryById(record._groupId);
3795 * Show a message in the summary row.
3797 grid.on('afteredit', function(){
3798 var groupValue = 'Ext Forms: Field Anchoring';
3799 summary.showSummaryMsg(groupValue, 'Updating Summary...');
3802 * @param {String} groupValue
3803 * @param {String} msg Text to use as innerHTML for the summary row.
3805 showSummaryMsg : function(groupValue, msg){
3806 var gid = this.view.getGroupId(groupValue),
3807 node = this.getSummaryNode(gid);
3809 node.innerHTML = '<div class="x-grid3-summary-msg">' + msg + '</div>';
3815 Ext.grid.GroupSummary = Ext.ux.grid.GroupSummary;
3819 * Calculation types for summary row:</p><div class="mdetail-params"><ul>
3820 * <li><b><tt>sum</tt></b> : <div class="sub-desc"></div></li>
3821 * <li><b><tt>count</tt></b> : <div class="sub-desc"></div></li>
3822 * <li><b><tt>max</tt></b> : <div class="sub-desc"></div></li>
3823 * <li><b><tt>min</tt></b> : <div class="sub-desc"></div></li>
3824 * <li><b><tt>average</tt></b> : <div class="sub-desc"></div></li>
3826 * <p>Custom calculations may be implemented. An example of
3827 * custom <code>summaryType=totalCost</code>:</p><pre><code>
3828 // define a custom summary function
3829 Ext.ux.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field){
3830 return v + (record.data.estimate * record.data.rate);
3833 * @property Calculations
3836 Ext.ux.grid.GroupSummary.Calculations = {
3837 'sum' : function(v, record, field){
3838 return v + (record.data[field]||0);
3841 'count' : function(v, record, field, data){
3842 return data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
3845 'max' : function(v, record, field, data){
3846 var v = record.data[field];
3847 var max = data[field+'max'] === undefined ? (data[field+'max'] = v) : data[field+'max'];
3848 return v > max ? (data[field+'max'] = v) : max;
3851 'min' : function(v, record, field, data){
3852 var v = record.data[field];
3853 var min = data[field+'min'] === undefined ? (data[field+'min'] = v) : data[field+'min'];
3854 return v < min ? (data[field+'min'] = v) : min;
3857 'average' : function(v, record, field, data){
3858 var c = data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
3859 var t = (data[field+'total'] = ((data[field+'total']||0) + (record.data[field]||0)));
3860 return t === 0 ? 0 : t / c;
3863 Ext.grid.GroupSummary.Calculations = Ext.ux.grid.GroupSummary.Calculations;
3866 * @class Ext.ux.grid.HybridSummary
3867 * @extends Ext.ux.grid.GroupSummary
3868 * Adds capability to specify the summary data for the group via json as illustrated here:
3873 projectId: 100, project: 'House',
3874 taskId: 112, description: 'Paint',
3875 estimate: 6, rate: 150,
3883 description: 14, estimate: 9,
3884 rate: 99, due: new Date(2009, 6, 29),
3892 Ext.ux.grid.HybridSummary = Ext.extend(Ext.ux.grid.GroupSummary, {
3895 * @param {Object} rs
3896 * @param {Object} cs
3898 calculate : function(rs, cs){
3899 var gcol = this.view.getGroupField(),
3900 gvalue = rs[0].data[gcol],
3901 gdata = this.getSummaryData(gvalue);
3902 return gdata || Ext.ux.grid.HybridSummary.superclass.calculate.call(this, rs, cs);
3907 grid.on('afteredit', function(){
3908 var groupValue = 'Ext Forms: Field Anchoring';
3909 summary.showSummaryMsg(groupValue, 'Updating Summary...');
3910 setTimeout(function(){ // simulate server call
3911 // HybridSummary class implements updateSummaryData
3912 summary.updateSummaryData(groupValue,
3913 // create data object based on configured dataIndex
3914 {description: 22, estimate: 888, rate: 888, due: new Date(), cost: 8});
3918 * @param {String} groupValue
3919 * @param {Object} data data object
3920 * @param {Boolean} skipRefresh (Optional) Defaults to false
3922 updateSummaryData : function(groupValue, data, skipRefresh){
3923 var json = this.grid.getStore().reader.jsonData;
3924 if(!json.summaryData){
3925 json.summaryData = {};
3927 json.summaryData[groupValue] = data;
3929 this.refreshSummary(groupValue);
3934 * Returns the summaryData for the specified groupValue or null.
3935 * @param {String} groupValue
3936 * @return {Object} summaryData
3938 getSummaryData : function(groupValue){
3939 var reader = this.grid.getStore().reader,
3940 json = reader.jsonData,
3941 fields = reader.recordType.prototype.fields,
3944 if(json && json.summaryData){
3945 v = json.summaryData[groupValue];
3947 return reader.extractValues(v, fields.items, fields.length);
3955 Ext.grid.HybridSummary = Ext.ux.grid.HybridSummary;
3956 Ext.ux.GroupTab = Ext.extend(Ext.Container, {
3961 deferredRender: true,
3967 headerAsText: false,
3973 initComponent: function(config){
3974 Ext.apply(this, config);
3977 Ext.ux.GroupTab.superclass.initComponent.call(this);
3979 this.addEvents('activate', 'deactivate', 'changemainitem', 'beforetabchange', 'tabchange');
3981 this.setLayout(new Ext.layout.CardLayout({
3982 deferredRender: this.deferredRender
3986 this.stack = Ext.TabPanel.AccessStack();
3991 this.on('beforerender', function(){
3992 this.groupEl = this.ownerCt.getGroupEl(this);
3995 this.on('add', this.onAdd, this, {
3998 this.on('remove', this.onRemove, this, {
4002 if (this.mainItem !== undefined) {
4003 var item = (typeof this.mainItem == 'object') ? this.mainItem : this.items.get(this.mainItem);
4004 delete this.mainItem;
4005 this.setMainItem(item);
4010 * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which
4011 * can return false to cancel the tab change.
4012 * @param {String/Panel} tab The id or tab Panel to activate
4014 setActiveTab : function(item){
4015 item = this.getComponent(item);
4020 this.activeTab = item;
4023 if(this.activeTab != item && this.fireEvent('beforetabchange', this, item, this.activeTab) !== false){
4024 if(this.activeTab && this.activeTab != this.mainItem){
4025 var oldEl = this.getTabEl(this.activeTab);
4027 Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
4030 var el = this.getTabEl(item);
4031 Ext.fly(el).addClass('x-grouptabs-strip-active');
4032 this.activeTab = item;
4033 this.stack.add(item);
4035 this.layout.setActiveItem(item);
4036 if(this.layoutOnTabChange && item.doLayout){
4040 this.scrollToTab(item, this.animScroll);
4043 this.fireEvent('tabchange', this, item);
4049 getTabEl: function(item){
4050 if (item == this.mainItem) {
4051 return this.groupEl;
4053 return Ext.TabPanel.prototype.getTabEl.call(this, item);
4056 onRender: function(ct, position){
4057 Ext.ux.GroupTab.superclass.onRender.call(this, ct, position);
4059 this.strip = Ext.fly(this.groupEl).createChild({
4061 cls: 'x-grouptabs-sub'
4064 this.tooltip = new Ext.ToolTip({
4065 target: this.groupEl,
4066 delegate: 'a.x-grouptabs-text',
4068 renderTo: document.body,
4070 beforeshow: function(tip) {
4071 var item = (tip.triggerElement.parentNode === this.mainItem.tabEl)
4073 : this.findById(tip.triggerElement.parentNode.id.split(this.idDelimiter)[1]);
4078 tip.body.dom.innerHTML = item.tabTip;
4084 if (!this.itemTpl) {
4085 var tt = new Ext.Template('<li class="{cls}" id="{id}">', '<a onclick="return false;" class="x-grouptabs-text {iconCls}">{text}</a>', '</li>');
4086 tt.disableFormats = true;
4088 Ext.ux.GroupTab.prototype.itemTpl = tt;
4091 this.items.each(this.initTab, this);
4094 afterRender: function(){
4095 Ext.ux.GroupTab.superclass.afterRender.call(this);
4097 if (this.activeTab !== undefined) {
4098 var item = (typeof this.activeTab == 'object') ? this.activeTab : this.items.get(this.activeTab);
4099 delete this.activeTab;
4100 this.setActiveTab(item);
4105 initTab: function(item, index){
4106 var before = this.strip.dom.childNodes[index];
4107 var p = Ext.TabPanel.prototype.getTemplateArgs.call(this, item);
4109 if (item === this.mainItem) {
4110 item.tabEl = this.groupEl;
4111 p.cls += ' x-grouptabs-main-item';
4114 var el = before ? this.itemTpl.insertBefore(before, p) : this.itemTpl.append(this.strip, p);
4116 item.tabEl = item.tabEl || el;
4118 item.on('disable', this.onItemDisabled, this);
4119 item.on('enable', this.onItemEnabled, this);
4120 item.on('titlechange', this.onItemTitleChanged, this);
4121 item.on('iconchange', this.onItemIconChanged, this);
4122 item.on('beforeshow', this.onBeforeShowItem, this);
4125 setMainItem: function(item){
4126 item = this.getComponent(item);
4127 if (!item || this.fireEvent('changemainitem', this, item, this.mainItem) === false) {
4131 this.mainItem = item;
4134 getMainItem: function(){
4135 return this.mainItem || null;
4139 onBeforeShowItem: function(item){
4140 if (item != this.activeTab) {
4141 this.setActiveTab(item);
4147 onAdd: function(gt, item, index){
4148 if (this.rendered) {
4149 this.initTab.call(this, item, index);
4154 onRemove: function(tp, item){
4155 Ext.destroy(Ext.get(this.getTabEl(item)));
4156 this.stack.remove(item);
4157 item.un('disable', this.onItemDisabled, this);
4158 item.un('enable', this.onItemEnabled, this);
4159 item.un('titlechange', this.onItemTitleChanged, this);
4160 item.un('iconchange', this.onItemIconChanged, this);
4161 item.un('beforeshow', this.onBeforeShowItem, this);
4162 if (item == this.activeTab) {
4163 var next = this.stack.next();
4165 this.setActiveTab(next);
4167 else if (this.items.getCount() > 0) {
4168 this.setActiveTab(0);
4171 this.activeTab = null;
4177 onBeforeAdd: function(item){
4178 var existing = item.events ? (this.items.containsKey(item.getItemId()) ? item : null) : this.items.get(item);
4180 this.setActiveTab(item);
4183 Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments);
4184 var es = item.elements;
4185 item.elements = es ? es.replace(',header', '') : es;
4186 item.border = (item.border === true);
4190 onItemDisabled: Ext.TabPanel.prototype.onItemDisabled,
4191 onItemEnabled: Ext.TabPanel.prototype.onItemEnabled,
4194 onItemTitleChanged: function(item){
4195 var el = this.getTabEl(item);
4197 Ext.fly(el).child('a.x-grouptabs-text', true).innerHTML = item.title;
4202 onItemIconChanged: function(item, iconCls, oldCls){
4203 var el = this.getTabEl(item);
4205 Ext.fly(el).child('a.x-grouptabs-text').replaceClass(oldCls, iconCls);
4209 beforeDestroy: function(){
4210 Ext.TabPanel.prototype.beforeDestroy.call(this);
4211 this.tooltip.destroy();
4215 Ext.reg('grouptab', Ext.ux.GroupTab);
4218 Ext.ux.GroupTabPanel = Ext.extend(Ext.TabPanel, {
4219 tabPosition: 'left',
4221 alternateColor: false,
4223 alternateCls: 'x-grouptabs-panel-alt',
4225 defaultType: 'grouptab',
4227 deferredRender: false,
4231 initComponent: function(){
4232 Ext.ux.GroupTabPanel.superclass.initComponent.call(this);
4235 'beforegroupchange',
4238 this.elements = 'body,header';
4239 this.stripTarget = 'header';
4241 this.tabPosition = this.tabPosition == 'right' ? 'right' : 'left';
4243 this.addClass('x-grouptabs-panel');
4245 if (this.tabStyle && this.tabStyle != '') {
4246 this.addClass('x-grouptabs-panel-' + this.tabStyle);
4249 if (this.alternateColor) {
4250 this.addClass(this.alternateCls);
4253 this.on('beforeadd', function(gtp, item, index){
4254 this.initGroup(item, index);
4258 initEvents : function() {
4259 this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
4262 onRender: function(ct, position){
4263 Ext.TabPanel.superclass.onRender.call(this, ct, position);
4265 var pos = this.tabPosition == 'top' ? 'header' : 'footer';
4266 this[pos].addClass('x-tab-panel-'+pos+'-plain');
4269 var st = this[this.stripTarget];
4271 this.stripWrap = st.createChild({cls:'x-tab-strip-wrap ', cn:{
4272 tag:'ul', cls:'x-grouptabs-strip x-grouptabs-tab-strip-'+this.tabPosition}});
4274 var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
4275 this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
4277 this.header.addClass('x-grouptabs-panel-header');
4278 this.bwrap.addClass('x-grouptabs-bwrap');
4279 this.body.addClass('x-tab-panel-body-'+this.tabPosition + ' x-grouptabs-panel-body');
4281 if (!this.groupTpl) {
4282 var tt = new Ext.Template(
4283 '<li class="{cls}" id="{id}">',
4284 '<a class="x-grouptabs-expand" onclick="return false;"></a>',
4285 '<a class="x-grouptabs-text {iconCls}" href="#" onclick="return false;">',
4286 '<span>{text}</span></a>',
4289 tt.disableFormats = true;
4291 Ext.ux.GroupTabPanel.prototype.groupTpl = tt;
4293 this.items.each(this.initGroup, this);
4296 afterRender: function(){
4297 Ext.ux.GroupTabPanel.superclass.afterRender.call(this);
4299 this.tabJoint = Ext.fly(this.body.dom.parentNode).createChild({
4303 this.addClass('x-tab-panel-' + this.tabPosition);
4304 this.header.setWidth(this.tabWidth);
4306 if (this.activeGroup !== undefined) {
4307 var group = (typeof this.activeGroup == 'object') ? this.activeGroup : this.items.get(this.activeGroup);
4308 delete this.activeGroup;
4309 this.setActiveGroup(group);
4310 group.setActiveTab(group.getMainItem());
4314 getGroupEl : Ext.TabPanel.prototype.getTabEl,
4317 findTargets: function(e){
4319 itemEl = e.getTarget('li', this.strip);
4321 item = this.findById(itemEl.id.split(this.idDelimiter)[1]);
4322 if (item.disabled) {
4331 expand: e.getTarget('.x-grouptabs-expand', this.strip),
4332 isGroup: !e.getTarget('ul.x-grouptabs-sub', this.strip),
4339 onStripMouseDown: function(e){
4340 if (e.button != 0) {
4344 var t = this.findTargets(e);
4346 this.toggleGroup(t.el);
4350 t.item.setActiveTab(t.item.getMainItem());
4353 t.item.ownerCt.setActiveTab(t.item);
4358 expandGroup: function(groupEl){
4359 if(groupEl.isXType) {
4360 groupEl = this.getGroupEl(groupEl);
4362 Ext.fly(groupEl).addClass('x-grouptabs-expanded');
4363 this.syncTabJoint();
4366 toggleGroup: function(groupEl){
4367 if(groupEl.isXType) {
4368 groupEl = this.getGroupEl(groupEl);
4370 Ext.fly(groupEl).toggleClass('x-grouptabs-expanded');
4371 this.syncTabJoint();
4374 collapseGroup: function(groupEl){
4375 if(groupEl.isXType) {
4376 groupEl = this.getGroupEl(groupEl);
4378 Ext.fly(groupEl).removeClass('x-grouptabs-expanded');
4379 this.syncTabJoint();
4382 syncTabJoint: function(groupEl){
4383 if (!this.tabJoint) {
4387 groupEl = groupEl || this.getGroupEl(this.activeGroup);
4389 this.tabJoint.setHeight(Ext.fly(groupEl).getHeight() - 2);
4391 var y = Ext.isGecko2 ? 0 : 1;
4392 if (this.tabPosition == 'left'){
4393 this.tabJoint.alignTo(groupEl, 'tl-tr', [-2,y]);
4396 this.tabJoint.alignTo(groupEl, 'tr-tl', [1,y]);
4400 this.tabJoint.hide();
4404 getActiveTab : function() {
4405 if(!this.activeGroup) return null;
4406 return this.activeGroup.getTabEl(this.activeGroup.activeTab) || null;
4409 onResize: function(){
4410 Ext.ux.GroupTabPanel.superclass.onResize.apply(this, arguments);
4411 this.syncTabJoint();
4414 createCorner: function(el, pos){
4415 return Ext.fly(el).createChild({
4416 cls: 'x-grouptabs-corner x-grouptabs-corner-' + pos
4420 initGroup: function(group, index){
4421 var before = this.strip.dom.childNodes[index],
4422 p = this.getTemplateArgs(group);
4424 p.cls += ' x-tab-first';
4426 p.cls += ' x-grouptabs-main';
4427 p.text = group.getMainItem().title;
4429 var el = before ? this.groupTpl.insertBefore(before, p) : this.groupTpl.append(this.strip, p),
4430 tl = this.createCorner(el, 'top-' + this.tabPosition),
4431 bl = this.createCorner(el, 'bottom-' + this.tabPosition);
4434 if (group.expanded) {
4435 this.expandGroup(el);
4438 if (Ext.isIE6 || (Ext.isIE && !Ext.isStrict)){
4439 bl.setLeft('-10px');
4440 bl.setBottom('-5px');
4441 tl.setLeft('-10px');
4447 changemainitem: this.onGroupChangeMainItem,
4448 beforetabchange: this.onGroupBeforeTabChange
4452 setActiveGroup : function(group) {
4453 group = this.getComponent(group);
4458 this.activeGroup = group;
4461 if(this.activeGroup != group && this.fireEvent('beforegroupchange', this, group, this.activeGroup) !== false){
4462 if(this.activeGroup){
4463 this.activeGroup.activeTab = null;
4464 var oldEl = this.getGroupEl(this.activeGroup);
4466 Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
4470 var groupEl = this.getGroupEl(group);
4471 Ext.fly(groupEl).addClass('x-grouptabs-strip-active');
4473 this.activeGroup = group;
4474 this.stack.add(group);
4476 this.layout.setActiveItem(group);
4477 this.syncTabJoint(groupEl);
4479 this.fireEvent('groupchange', this, group);
4485 onGroupBeforeTabChange: function(group, newTab, oldTab){
4486 if(group !== this.activeGroup || newTab !== oldTab) {
4487 this.strip.select('.x-grouptabs-sub > li.x-grouptabs-strip-active', true).removeClass('x-grouptabs-strip-active');
4489 this.expandGroup(this.getGroupEl(group));
4490 if(group !== this.activeGroup) {
4491 return this.setActiveGroup(group);
4495 getFrameHeight: function(){
4496 var h = this.el.getFrameWidth('tb');
4497 h += (this.tbar ? this.tbar.getHeight() : 0) +
4498 (this.bbar ? this.bbar.getHeight() : 0);
4503 adjustBodyWidth: function(w){
4504 return w - this.tabWidth;
4508 Ext.reg('grouptabpanel', Ext.ux.GroupTabPanel);/*
4509 * Note that this control will most likely remain as an example, and not as a core Ext form
4510 * control. However, the API will be changing in a future release and so should not yet be
4511 * treated as a final, stable API at this time.
4515 * @class Ext.ux.form.ItemSelector
4516 * @extends Ext.form.Field
4517 * A control that allows selection of between two Ext.ux.form.MultiSelect controls.
4520 * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
4523 * Create a new ItemSelector
4524 * @param {Object} config Configuration options
4525 * @xtype itemselector
4527 Ext.ux.form.ItemSelector = Ext.extend(Ext.form.Field, {
4531 iconDown:"down2.gif",
4532 iconLeft:"left2.gif",
4533 iconRight:"right2.gif",
4535 iconBottom:"bottom2.gif",
4545 defaultAutoCreate:{tag: "div"},
4547 * @cfg {Array} multiselects An array of {@link Ext.ux.form.MultiSelect} config objects, with at least all required parameters (e.g., store)
4551 initComponent: function(){
4552 Ext.ux.form.ItemSelector.superclass.initComponent.call(this);
4554 'rowdblclick' : true,
4559 onRender: function(ct, position){
4560 Ext.ux.form.ItemSelector.superclass.onRender.call(this, ct, position);
4562 // Internal default configuration for both multiselects
4564 legend: 'Available',
4577 this.fromMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[0], msConfig[0]));
4578 this.fromMultiselect.on('dblclick', this.onRowDblClick, this);
4580 this.toMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[1], msConfig[1]));
4581 this.toMultiselect.on('dblclick', this.onRowDblClick, this);
4583 var p = new Ext.Panel({
4584 bodyStyle:this.bodyStyle,
4587 layoutConfig:{columns:3}
4590 p.add(this.fromMultiselect);
4591 var icons = new Ext.Panel({header:false});
4593 p.add(this.toMultiselect);
4595 icons.el.down('.'+icons.bwrapCls).remove();
4598 if (this.imagePath!="" && this.imagePath.charAt(this.imagePath.length-1)!="/")
4599 this.imagePath+="/";
4600 this.iconUp = this.imagePath + (this.iconUp || 'up2.gif');
4601 this.iconDown = this.imagePath + (this.iconDown || 'down2.gif');
4602 this.iconLeft = this.imagePath + (this.iconLeft || 'left2.gif');
4603 this.iconRight = this.imagePath + (this.iconRight || 'right2.gif');
4604 this.iconTop = this.imagePath + (this.iconTop || 'top2.gif');
4605 this.iconBottom = this.imagePath + (this.iconBottom || 'bottom2.gif');
4606 var el=icons.getEl();
4607 this.toTopIcon = el.createChild({tag:'img', src:this.iconTop, style:{cursor:'pointer', margin:'2px'}});
4608 el.createChild({tag: 'br'});
4609 this.upIcon = el.createChild({tag:'img', src:this.iconUp, style:{cursor:'pointer', margin:'2px'}});
4610 el.createChild({tag: 'br'});
4611 this.addIcon = el.createChild({tag:'img', src:this.iconRight, style:{cursor:'pointer', margin:'2px'}});
4612 el.createChild({tag: 'br'});
4613 this.removeIcon = el.createChild({tag:'img', src:this.iconLeft, style:{cursor:'pointer', margin:'2px'}});
4614 el.createChild({tag: 'br'});
4615 this.downIcon = el.createChild({tag:'img', src:this.iconDown, style:{cursor:'pointer', margin:'2px'}});
4616 el.createChild({tag: 'br'});
4617 this.toBottomIcon = el.createChild({tag:'img', src:this.iconBottom, style:{cursor:'pointer', margin:'2px'}});
4618 this.toTopIcon.on('click', this.toTop, this);
4619 this.upIcon.on('click', this.up, this);
4620 this.downIcon.on('click', this.down, this);
4621 this.toBottomIcon.on('click', this.toBottom, this);
4622 this.addIcon.on('click', this.fromTo, this);
4623 this.removeIcon.on('click', this.toFrom, this);
4624 if (!this.drawUpIcon || this.hideNavIcons) { this.upIcon.dom.style.display='none'; }
4625 if (!this.drawDownIcon || this.hideNavIcons) { this.downIcon.dom.style.display='none'; }
4626 if (!this.drawLeftIcon || this.hideNavIcons) { this.addIcon.dom.style.display='none'; }
4627 if (!this.drawRightIcon || this.hideNavIcons) { this.removeIcon.dom.style.display='none'; }
4628 if (!this.drawTopIcon || this.hideNavIcons) { this.toTopIcon.dom.style.display='none'; }
4629 if (!this.drawBotIcon || this.hideNavIcons) { this.toBottomIcon.dom.style.display='none'; }
4631 var tb = p.body.first();
4632 this.el.setWidth(p.body.first().getWidth());
4633 p.body.removeClass();
4635 this.hiddenName = this.name;
4636 var hiddenTag = {tag: "input", type: "hidden", value: "", name: this.name};
4637 this.hiddenField = this.el.createChild(hiddenTag);
4640 doLayout: function(){
4642 this.fromMultiselect.fs.doLayout();
4643 this.toMultiselect.fs.doLayout();
4647 afterRender: function(){
4648 Ext.ux.form.ItemSelector.superclass.afterRender.call(this);
4650 this.toStore = this.toMultiselect.store;
4651 this.toStore.on('add', this.valueChanged, this);
4652 this.toStore.on('remove', this.valueChanged, this);
4653 this.toStore.on('load', this.valueChanged, this);
4654 this.valueChanged(this.toStore);
4657 toTop : function() {
4658 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4660 if (selectionsArray.length > 0) {
4661 selectionsArray.sort();
4662 for (var i=0; i<selectionsArray.length; i++) {
4663 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4664 records.push(record);
4666 selectionsArray = [];
4667 for (var i=records.length-1; i>-1; i--) {
4668 record = records[i];
4669 this.toMultiselect.view.store.remove(record);
4670 this.toMultiselect.view.store.insert(0, record);
4671 selectionsArray.push(((records.length - 1) - i));
4674 this.toMultiselect.view.refresh();
4675 this.toMultiselect.view.select(selectionsArray);
4678 toBottom : function() {
4679 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4681 if (selectionsArray.length > 0) {
4682 selectionsArray.sort();
4683 for (var i=0; i<selectionsArray.length; i++) {
4684 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4685 records.push(record);
4687 selectionsArray = [];
4688 for (var i=0; i<records.length; i++) {
4689 record = records[i];
4690 this.toMultiselect.view.store.remove(record);
4691 this.toMultiselect.view.store.add(record);
4692 selectionsArray.push((this.toMultiselect.view.store.getCount()) - (records.length - i));
4695 this.toMultiselect.view.refresh();
4696 this.toMultiselect.view.select(selectionsArray);
4701 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4702 selectionsArray.sort();
4703 var newSelectionsArray = [];
4704 if (selectionsArray.length > 0) {
4705 for (var i=0; i<selectionsArray.length; i++) {
4706 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4707 if ((selectionsArray[i] - 1) >= 0) {
4708 this.toMultiselect.view.store.remove(record);
4709 this.toMultiselect.view.store.insert(selectionsArray[i] - 1, record);
4710 newSelectionsArray.push(selectionsArray[i] - 1);
4713 this.toMultiselect.view.refresh();
4714 this.toMultiselect.view.select(newSelectionsArray);
4720 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4721 selectionsArray.sort();
4722 selectionsArray.reverse();
4723 var newSelectionsArray = [];
4724 if (selectionsArray.length > 0) {
4725 for (var i=0; i<selectionsArray.length; i++) {
4726 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4727 if ((selectionsArray[i] + 1) < this.toMultiselect.view.store.getCount()) {
4728 this.toMultiselect.view.store.remove(record);
4729 this.toMultiselect.view.store.insert(selectionsArray[i] + 1, record);
4730 newSelectionsArray.push(selectionsArray[i] + 1);
4733 this.toMultiselect.view.refresh();
4734 this.toMultiselect.view.select(newSelectionsArray);
4738 fromTo : function() {
4739 var selectionsArray = this.fromMultiselect.view.getSelectedIndexes();
4741 if (selectionsArray.length > 0) {
4742 for (var i=0; i<selectionsArray.length; i++) {
4743 record = this.fromMultiselect.view.store.getAt(selectionsArray[i]);
4744 records.push(record);
4746 if(!this.allowDup)selectionsArray = [];
4747 for (var i=0; i<records.length; i++) {
4748 record = records[i];
4750 var x=new Ext.data.Record();
4753 this.toMultiselect.view.store.add(record);
4755 this.fromMultiselect.view.store.remove(record);
4756 this.toMultiselect.view.store.add(record);
4757 selectionsArray.push((this.toMultiselect.view.store.getCount() - 1));
4761 this.toMultiselect.view.refresh();
4762 this.fromMultiselect.view.refresh();
4763 var si = this.toMultiselect.store.sortInfo;
4765 this.toMultiselect.store.sort(si.field, si.direction);
4767 this.toMultiselect.view.select(selectionsArray);
4770 toFrom : function() {
4771 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4773 if (selectionsArray.length > 0) {
4774 for (var i=0; i<selectionsArray.length; i++) {
4775 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4776 records.push(record);
4778 selectionsArray = [];
4779 for (var i=0; i<records.length; i++) {
4780 record = records[i];
4781 this.toMultiselect.view.store.remove(record);
4783 this.fromMultiselect.view.store.add(record);
4784 selectionsArray.push((this.fromMultiselect.view.store.getCount() - 1));
4788 this.fromMultiselect.view.refresh();
4789 this.toMultiselect.view.refresh();
4790 var si = this.fromMultiselect.store.sortInfo;
4792 this.fromMultiselect.store.sort(si.field, si.direction);
4794 this.fromMultiselect.view.select(selectionsArray);
4797 valueChanged: function(store) {
4800 for (var i=0; i<store.getCount(); i++) {
4801 record = store.getAt(i);
4802 values.push(record.get(this.toMultiselect.valueField));
4804 this.hiddenField.dom.value = values.join(this.delimiter);
4805 this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
4808 getValue : function() {
4809 return this.hiddenField.dom.value;
4812 onRowDblClick : function(vw, index, node, e) {
4813 if (vw == this.toMultiselect.view){
4815 } else if (vw == this.fromMultiselect.view) {
4818 return this.fireEvent('rowdblclick', vw, index, node, e);
4822 range = this.toMultiselect.store.getRange();
4823 this.toMultiselect.store.removeAll();
4824 this.fromMultiselect.store.add(range);
4825 var si = this.fromMultiselect.store.sortInfo;
4827 this.fromMultiselect.store.sort(si.field, si.direction);
4829 this.valueChanged(this.toMultiselect.store);
4833 Ext.reg('itemselector', Ext.ux.form.ItemSelector);
4836 Ext.ux.ItemSelector = Ext.ux.form.ItemSelector;
4837 Ext.ns('Ext.ux.grid');
4839 Ext.ux.grid.LockingGridView = Ext.extend(Ext.grid.GridView, {
4841 unlockText : 'Unlock',
4843 lockedBorderWidth : 1,
4846 * This option ensures that height between the rows is synchronized
4847 * between the locked and unlocked sides. This option only needs to be used
4848 * when the row heights aren't predictable.
4852 initTemplates : function(){
4853 var ts = this.templates || {};
4856 ts.master = new Ext.Template(
4857 '<div class="x-grid3" hidefocus="true">',
4858 '<div class="x-grid3-locked">',
4859 '<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>',
4860 '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{lstyle}">{lockedBody}</div><div class="x-grid3-scroll-spacer"></div></div>',
4862 '<div class="x-grid3-viewport x-grid3-unlocked">',
4863 '<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>',
4864 '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
4866 '<div class="x-grid3-resize-marker"> </div>',
4867 '<div class="x-grid3-resize-proxy"> </div>',
4872 this.templates = ts;
4874 Ext.ux.grid.LockingGridView.superclass.initTemplates.call(this);
4877 getEditorParent : function(ed){
4881 initElements : function(){
4882 var E = Ext.Element,
4883 el = this.grid.getGridEl().dom.firstChild,
4886 this.el = new E(el);
4887 this.lockedWrap = new E(cs[0]);
4888 this.lockedHd = new E(this.lockedWrap.dom.firstChild);
4889 this.lockedInnerHd = this.lockedHd.dom.firstChild;
4890 this.lockedScroller = new E(this.lockedWrap.dom.childNodes[1]);
4891 this.lockedBody = new E(this.lockedScroller.dom.firstChild);
4892 this.mainWrap = new E(cs[1]);
4893 this.mainHd = new E(this.mainWrap.dom.firstChild);
4895 if (this.grid.hideHeaders) {
4896 this.lockedHd.setDisplayed(false);
4897 this.mainHd.setDisplayed(false);
4900 this.innerHd = this.mainHd.dom.firstChild;
4901 this.scroller = new E(this.mainWrap.dom.childNodes[1]);
4904 this.scroller.setStyle('overflow-x', 'hidden');
4907 this.mainBody = new E(this.scroller.dom.firstChild);
4908 this.focusEl = new E(this.scroller.dom.childNodes[1]);
4909 this.resizeMarker = new E(cs[2]);
4910 this.resizeProxy = new E(cs[3]);
4912 this.focusEl.swallowEvent('click', true);
4915 getLockedRows : function(){
4916 return this.hasRows() ? this.lockedBody.dom.childNodes : [];
4919 getLockedRow : function(row){
4920 return this.getLockedRows()[row];
4923 getCell : function(row, col){
4924 var llen = this.cm.getLockedCount();
4926 return this.getLockedRow(row).getElementsByTagName('td')[col];
4928 return Ext.ux.grid.LockingGridView.superclass.getCell.call(this, row, col - llen);
4931 getHeaderCell : function(index){
4932 var llen = this.cm.getLockedCount();
4934 return this.lockedHd.dom.getElementsByTagName('td')[index];
4936 return Ext.ux.grid.LockingGridView.superclass.getHeaderCell.call(this, index - llen);
4939 addRowClass : function(row, cls){
4940 var r = this.getLockedRow(row);
4942 this.fly(r).addClass(cls);
4944 Ext.ux.grid.LockingGridView.superclass.addRowClass.call(this, row, cls);
4947 removeRowClass : function(row, cls){
4948 var r = this.getLockedRow(row);
4950 this.fly(r).removeClass(cls);
4952 Ext.ux.grid.LockingGridView.superclass.removeRowClass.call(this, row, cls);
4955 removeRow : function(row) {
4956 Ext.removeNode(this.getLockedRow(row));
4957 Ext.ux.grid.LockingGridView.superclass.removeRow.call(this, row);
4960 removeRows : function(firstRow, lastRow){
4961 var bd = this.lockedBody.dom;
4962 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
4963 Ext.removeNode(bd.childNodes[firstRow]);
4965 Ext.ux.grid.LockingGridView.superclass.removeRows.call(this, firstRow, lastRow);
4968 syncScroll : function(e){
4969 var mb = this.scroller.dom;
4970 this.lockedScroller.dom.scrollTop = mb.scrollTop;
4971 Ext.ux.grid.LockingGridView.superclass.syncScroll.call(this, e);
4974 updateSortIcon : function(col, dir){
4975 var sc = this.sortClasses,
4976 lhds = this.lockedHd.select('td').removeClass(sc),
4977 hds = this.mainHd.select('td').removeClass(sc),
4978 llen = this.cm.getLockedCount(),
4979 cls = sc[dir == 'DESC' ? 1 : 0];
4981 lhds.item(col).addClass(cls);
4983 hds.item(col - llen).addClass(cls);
4987 updateAllColumnWidths : function(){
4988 var tw = this.getTotalWidth(),
4989 clen = this.cm.getColumnCount(),
4990 lw = this.getLockedWidth(),
4991 llen = this.cm.getLockedCount(),
4993 this.updateLockedWidth();
4994 for(i = 0; i < clen; i++){
4995 ws[i] = this.getColumnWidth(i);
4996 var hd = this.getHeaderCell(i);
4997 hd.style.width = ws[i];
4999 var lns = this.getLockedRows(), ns = this.getRows(), row, trow, j;
5000 for(i = 0, len = ns.length; i < len; i++){
5002 row.style.width = lw;
5004 row.firstChild.style.width = lw;
5005 trow = row.firstChild.rows[0];
5006 for (j = 0; j < llen; j++) {
5007 trow.childNodes[j].style.width = ws[j];
5011 row.style.width = tw;
5013 row.firstChild.style.width = tw;
5014 trow = row.firstChild.rows[0];
5015 for (j = llen; j < clen; j++) {
5016 trow.childNodes[j - llen].style.width = ws[j];
5020 this.onAllColumnWidthsUpdated(ws, tw);
5021 this.syncHeaderHeight();
5024 updateColumnWidth : function(col, width){
5025 var w = this.getColumnWidth(col),
5026 llen = this.cm.getLockedCount(),
5028 this.updateLockedWidth();
5030 ns = this.getLockedRows();
5031 rw = this.getLockedWidth();
5034 ns = this.getRows();
5035 rw = this.getTotalWidth();
5038 var hd = this.getHeaderCell(col);
5040 for(var i = 0, len = ns.length; i < len; i++){
5042 row.style.width = rw;
5044 row.firstChild.style.width = rw;
5045 row.firstChild.rows[0].childNodes[c].style.width = w;
5048 this.onColumnWidthUpdated(col, w, this.getTotalWidth());
5049 this.syncHeaderHeight();
5052 updateColumnHidden : function(col, hidden){
5053 var llen = this.cm.getLockedCount(),
5055 display = hidden ? 'none' : '';
5056 this.updateLockedWidth();
5058 ns = this.getLockedRows();
5059 rw = this.getLockedWidth();
5062 ns = this.getRows();
5063 rw = this.getTotalWidth();
5066 var hd = this.getHeaderCell(col);
5067 hd.style.display = display;
5068 for(var i = 0, len = ns.length; i < len; i++){
5070 row.style.width = rw;
5072 row.firstChild.style.width = rw;
5073 row.firstChild.rows[0].childNodes[c].style.display = display;
5076 this.onColumnHiddenUpdated(col, hidden, this.getTotalWidth());
5077 delete this.lastViewWidth;
5081 doRender : function(cs, rs, ds, startRow, colCount, stripe){
5082 var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1,
5083 tstyle = 'width:'+this.getTotalWidth()+';',
5084 lstyle = 'width:'+this.getLockedWidth()+';',
5085 buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r;
5086 for(var j = 0, len = rs.length; j < len; j++){
5087 r = rs[j]; cb = []; lcb = [];
5088 var rowIndex = (j+startRow);
5089 for(var i = 0; i < colCount; i++){
5092 p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
5093 (this.cm.config[i].cellCls ? ' ' + this.cm.config[i].cellCls : '');
5094 p.attr = p.cellAttr = '';
5095 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
5097 if(Ext.isEmpty(p.value)){
5100 if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
5101 p.css += ' x-grid3-dirty-cell';
5104 lcb[lcb.length] = ct.apply(p);
5106 cb[cb.length] = ct.apply(p);
5110 if(stripe && ((rowIndex+1) % 2 === 0)){
5111 alt[0] = 'x-grid3-row-alt';
5114 alt[1] = ' x-grid3-dirty-row';
5117 if(this.getRowClass){
5118 alt[2] = this.getRowClass(r, rowIndex, rp, ds);
5120 rp.alt = alt.join(' ');
5121 rp.cells = cb.join('');
5123 buf[buf.length] = rt.apply(rp);
5124 rp.cells = lcb.join('');
5126 lbuf[lbuf.length] = rt.apply(rp);
5128 return [buf.join(''), lbuf.join('')];
5130 processRows : function(startRow, skipStripe){
5131 if(!this.ds || this.ds.getCount() < 1){
5134 var rows = this.getRows(),
5135 lrows = this.getLockedRows(),
5137 skipStripe = skipStripe || !this.grid.stripeRows;
5138 startRow = startRow || 0;
5139 for(var i = 0, len = rows.length; i < len; ++i){
5145 row.className = row.className.replace(this.rowClsRe, ' ');
5146 lrow.className = lrow.className.replace(this.rowClsRe, ' ');
5147 if ((i + 1) % 2 === 0){
5148 row.className += ' x-grid3-row-alt';
5149 lrow.className += ' x-grid3-row-alt';
5152 if(this.syncHeights){
5153 var el1 = Ext.get(row),
5154 el2 = Ext.get(lrow),
5155 h1 = el1.getHeight(),
5156 h2 = el2.getHeight();
5166 Ext.fly(rows[0]).addClass(this.firstRowCls);
5167 Ext.fly(lrows[0]).addClass(this.firstRowCls);
5169 Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
5170 Ext.fly(lrows[lrows.length - 1]).addClass(this.lastRowCls);
5173 afterRender : function(){
5174 if(!this.ds || !this.cm){
5177 var bd = this.renderRows() || [' ', ' '];
5178 this.mainBody.dom.innerHTML = bd[0];
5179 this.lockedBody.dom.innerHTML = bd[1];
5180 this.processRows(0, true);
5181 if(this.deferEmptyText !== true){
5182 this.applyEmptyText();
5186 renderUI : function(){
5187 var header = this.renderHeaders();
5188 var body = this.templates.body.apply({rows:' '});
5189 var html = this.templates.master.apply({
5192 ostyle: 'width:'+this.getOffsetWidth()+';',
5193 bstyle: 'width:'+this.getTotalWidth()+';',
5195 lockedHeader: header[1],
5196 lstyle: 'width:'+this.getLockedWidth()+';'
5199 g.getGridEl().dom.innerHTML = html;
5200 this.initElements();
5201 Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
5202 Ext.fly(this.lockedInnerHd).on('click', this.handleHdDown, this);
5205 mouseover: this.handleHdOver,
5206 mouseout: this.handleHdOut,
5207 mousemove: this.handleHdMove
5211 mouseover: this.handleHdOver,
5212 mouseout: this.handleHdOut,
5213 mousemove: this.handleHdMove
5215 this.scroller.on('scroll', this.syncScroll, this);
5216 if(g.enableColumnResize !== false){
5217 this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
5218 this.splitZone.setOuterHandleElId(Ext.id(this.lockedHd.dom));
5219 this.splitZone.setOuterHandleElId(Ext.id(this.mainHd.dom));
5221 if(g.enableColumnMove){
5222 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
5223 this.columnDrag.setOuterHandleElId(Ext.id(this.lockedInnerHd));
5224 this.columnDrag.setOuterHandleElId(Ext.id(this.innerHd));
5225 this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
5227 if(g.enableHdMenu !== false){
5228 this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
5230 {itemId: 'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
5231 {itemId: 'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
5233 if(this.grid.enableColLock !== false){
5235 {itemId: 'lock', text: this.lockText, cls: 'xg-hmenu-lock'},
5236 {itemId: 'unlock', text: this.unlockText, cls: 'xg-hmenu-unlock'}
5239 if(g.enableColumnHide !== false){
5240 this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
5243 beforeshow: this.beforeColMenuShow,
5244 itemclick: this.handleHdMenuClick
5246 this.hmenu.add('-', {
5249 text: this.columnsText,
5251 iconCls: 'x-cols-icon'
5254 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
5256 if(g.trackMouseOver){
5259 mouseover: this.onRowOver,
5260 mouseout: this.onRowOut
5262 this.lockedBody.on({
5264 mouseover: this.onRowOver,
5265 mouseout: this.onRowOut
5269 if(g.enableDragDrop || g.enableDrag){
5270 this.dragZone = new Ext.grid.GridDragZone(g, {
5271 ddGroup : g.ddGroup || 'GridDD'
5274 this.updateHeaderSortState();
5277 layout : function(){
5282 var c = g.getGridEl();
5283 var csize = c.getSize(true);
5284 var vw = csize.width;
5285 if(!g.hideHeaders && (vw < 20 || csize.height < 20)){
5288 this.syncHeaderHeight();
5290 this.scroller.dom.style.overflow = 'visible';
5291 this.lockedScroller.dom.style.overflow = 'visible';
5293 this.scroller.dom.style.position = 'static';
5294 this.lockedScroller.dom.style.position = 'static';
5297 this.el.setSize(csize.width, csize.height);
5298 var hdHeight = this.mainHd.getHeight();
5299 var vh = csize.height - (hdHeight);
5301 this.updateLockedWidth();
5303 if(this.lastViewWidth != vw){
5304 this.fitColumns(false, false);
5305 this.lastViewWidth = vw;
5309 this.syncHeaderScroll();
5311 this.onLayout(vw, vh);
5314 getOffsetWidth : function() {
5315 return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth() + this.getScrollOffset()) + 'px';
5318 renderHeaders : function(){
5320 ts = this.templates,
5324 len = cm.getColumnCount(),
5326 for(var i = 0; i < len; i++){
5327 p.id = cm.getColumnId(i);
5328 p.value = cm.getColumnHeader(i) || '';
5329 p.style = this.getColumnStyle(i, true);
5330 p.tooltip = this.getColumnTooltip(i);
5331 p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
5332 (cm.config[i].headerCls ? ' ' + cm.config[i].headerCls : '');
5333 if(cm.config[i].align == 'right'){
5334 p.istyle = 'padding-right:16px';
5339 lcb[lcb.length] = ct.apply(p);
5341 cb[cb.length] = ct.apply(p);
5344 return [ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'}),
5345 ts.header.apply({cells: lcb.join(''), tstyle:'width:'+this.getLockedWidth()+';'})];
5348 updateHeaders : function(){
5349 var hd = this.renderHeaders();
5350 this.innerHd.firstChild.innerHTML = hd[0];
5351 this.innerHd.firstChild.style.width = this.getOffsetWidth();
5352 this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
5353 this.lockedInnerHd.firstChild.innerHTML = hd[1];
5354 var lw = this.getLockedWidth();
5355 this.lockedInnerHd.firstChild.style.width = lw;
5356 this.lockedInnerHd.firstChild.firstChild.style.width = lw;
5359 getResolvedXY : function(resolved){
5363 var c = resolved.cell, r = resolved.row;
5364 return c ? Ext.fly(c).getXY() : [this.scroller.getX(), Ext.fly(r).getY()];
5367 syncFocusEl : function(row, col, hscroll){
5368 Ext.ux.grid.LockingGridView.superclass.syncFocusEl.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
5371 ensureVisible : function(row, col, hscroll){
5372 return Ext.ux.grid.LockingGridView.superclass.ensureVisible.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
5375 insertRows : function(dm, firstRow, lastRow, isUpdate){
5376 var last = dm.getCount() - 1;
5377 if(!isUpdate && firstRow === 0 && lastRow >= last){
5381 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
5383 var html = this.renderRows(firstRow, lastRow),
5384 before = this.getRow(firstRow);
5387 this.removeRowClass(0, this.firstRowCls);
5389 Ext.DomHelper.insertHtml('beforeBegin', before, html[0]);
5390 before = this.getLockedRow(firstRow);
5391 Ext.DomHelper.insertHtml('beforeBegin', before, html[1]);
5393 this.removeRowClass(last - 1, this.lastRowCls);
5394 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html[0]);
5395 Ext.DomHelper.insertHtml('beforeEnd', this.lockedBody.dom, html[1]);
5398 this.fireEvent('rowsinserted', this, firstRow, lastRow);
5399 this.processRows(firstRow);
5400 }else if(firstRow === 0 || firstRow >= last){
5401 this.addRowClass(firstRow, firstRow === 0 ? this.firstRowCls : this.lastRowCls);
5404 this.syncFocusEl(firstRow);
5407 getColumnStyle : function(col, isHeader){
5408 var style = !isHeader ? this.cm.config[col].cellStyle || this.cm.config[col].css || '' : this.cm.config[col].headerStyle || '';
5409 style += 'width:'+this.getColumnWidth(col)+';';
5410 if(this.cm.isHidden(col)){
5411 style += 'display:none;';
5413 var align = this.cm.config[col].align;
5415 style += 'text-align:'+align+';';
5420 getLockedWidth : function() {
5421 return this.cm.getTotalLockedWidth() + 'px';
5424 getTotalWidth : function() {
5425 return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth()) + 'px';
5428 getColumnData : function(){
5429 var cs = [], cm = this.cm, colCount = cm.getColumnCount();
5430 for(var i = 0; i < colCount; i++){
5431 var name = cm.getDataIndex(i);
5433 name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
5434 renderer : cm.getRenderer(i),
5435 id : cm.getColumnId(i),
5436 style : this.getColumnStyle(i),
5437 locked : cm.isLocked(i)
5443 renderBody : function(){
5444 var markup = this.renderRows() || [' ', ' '];
5445 return [this.templates.body.apply({rows: markup[0]}), this.templates.body.apply({rows: markup[1]})];
5448 refreshRow : function(record){
5449 Ext.ux.grid.LockingGridView.superclass.refreshRow.call(this, record);
5450 var index = Ext.isNumber(record) ? record : this.ds.indexOf(record);
5451 this.getLockedRow(index).rowIndex = index;
5454 refresh : function(headersToo){
5455 this.fireEvent('beforerefresh', this);
5456 this.grid.stopEditing(true);
5457 var result = this.renderBody();
5458 this.mainBody.update(result[0]).setWidth(this.getTotalWidth());
5459 this.lockedBody.update(result[1]).setWidth(this.getLockedWidth());
5460 if(headersToo === true){
5461 this.updateHeaders();
5462 this.updateHeaderSortState();
5464 this.processRows(0, true);
5466 this.applyEmptyText();
5467 this.fireEvent('refresh', this);
5470 onDenyColumnLock : function(){
5474 initData : function(ds, cm){
5476 this.cm.un('columnlockchange', this.onColumnLock, this);
5478 Ext.ux.grid.LockingGridView.superclass.initData.call(this, ds, cm);
5480 this.cm.on('columnlockchange', this.onColumnLock, this);
5484 onColumnLock : function(){
5488 handleHdMenuClick : function(item){
5489 var index = this.hdCtxIndex,
5491 id = item.getItemId(),
5492 llen = cm.getLockedCount();
5495 if(cm.getColumnCount(true) <= llen + 1){
5496 this.onDenyColumnLock();
5500 cm.setLocked(index, true, true);
5501 cm.moveColumn(index, llen);
5502 this.grid.fireEvent('columnmove', index, llen);
5504 cm.setLocked(index, true);
5508 if(llen - 1 != index){
5509 cm.setLocked(index, false, true);
5510 cm.moveColumn(index, llen - 1);
5511 this.grid.fireEvent('columnmove', index, llen - 1);
5513 cm.setLocked(index, false);
5517 return Ext.ux.grid.LockingGridView.superclass.handleHdMenuClick.call(this, item);
5522 handleHdDown : function(e, t){
5523 Ext.ux.grid.LockingGridView.superclass.handleHdDown.call(this, e, t);
5524 if(this.grid.enableColLock !== false){
5525 if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
5526 var hd = this.findHeaderCell(t),
5527 index = this.getCellIndex(hd),
5528 ms = this.hmenu.items, cm = this.cm;
5529 ms.get('lock').setDisabled(cm.isLocked(index));
5530 ms.get('unlock').setDisabled(!cm.isLocked(index));
5535 syncHeaderHeight: function(){
5536 this.innerHd.firstChild.firstChild.style.height = 'auto';
5537 this.lockedInnerHd.firstChild.firstChild.style.height = 'auto';
5538 var hd = this.innerHd.firstChild.firstChild.offsetHeight,
5539 lhd = this.lockedInnerHd.firstChild.firstChild.offsetHeight,
5540 height = (lhd > hd ? lhd : hd) + 'px';
5541 this.innerHd.firstChild.firstChild.style.height = height;
5542 this.lockedInnerHd.firstChild.firstChild.style.height = height;
5545 updateLockedWidth: function(){
5546 var lw = this.cm.getTotalLockedWidth(),
5547 tw = this.cm.getTotalWidth() - lw,
5548 csize = this.grid.getGridEl().getSize(true),
5549 lp = Ext.isBorderBox ? 0 : this.lockedBorderWidth,
5550 rp = Ext.isBorderBox ? 0 : this.rowBorderWidth,
5551 vw = (csize.width - lw - lp - rp) + 'px',
5552 so = this.getScrollOffset();
5553 if(!this.grid.autoHeight){
5554 var vh = (csize.height - this.mainHd.getHeight()) + 'px';
5555 this.lockedScroller.dom.style.height = vh;
5556 this.scroller.dom.style.height = vh;
5558 this.lockedWrap.dom.style.width = (lw + rp) + 'px';
5559 this.scroller.dom.style.width = vw;
5560 this.mainWrap.dom.style.left = (lw + lp + rp) + 'px';
5562 this.lockedInnerHd.firstChild.style.width = lw + 'px';
5563 this.lockedInnerHd.firstChild.firstChild.style.width = lw + 'px';
5564 this.innerHd.style.width = vw;
5565 this.innerHd.firstChild.style.width = (tw + rp + so) + 'px';
5566 this.innerHd.firstChild.firstChild.style.width = tw + 'px';
5569 this.lockedBody.dom.style.width = (lw + rp) + 'px';
5570 this.mainBody.dom.style.width = (tw + rp) + 'px';
5575 Ext.ux.grid.LockingColumnModel = Ext.extend(Ext.grid.ColumnModel, {
5577 * Returns true if the given column index is currently locked
5578 * @param {Number} colIndex The column index
5579 * @return {Boolean} True if the column is locked
5581 isLocked : function(colIndex){
5582 return this.config[colIndex].locked === true;
5586 * Locks or unlocks a given column
5587 * @param {Number} colIndex The column index
5588 * @param {Boolean} value True to lock, false to unlock
5589 * @param {Boolean} suppressEvent Pass false to cause the columnlockchange event not to fire
5591 setLocked : function(colIndex, value, suppressEvent){
5592 if (this.isLocked(colIndex) == value) {
5595 this.config[colIndex].locked = value;
5596 if (!suppressEvent) {
5597 this.fireEvent('columnlockchange', this, colIndex, value);
5602 * Returns the total width of all locked columns
5603 * @return {Number} The width of all locked columns
5605 getTotalLockedWidth : function(){
5607 for (var i = 0, len = this.config.length; i < len; i++) {
5608 if (this.isLocked(i) && !this.isHidden(i)) {
5609 totalWidth += this.getColumnWidth(i);
5617 * Returns the total number of locked columns
5618 * @return {Number} The number of locked columns
5620 getLockedCount : function() {
5621 var len = this.config.length;
5623 for (var i = 0; i < len; i++) {
5624 if (!this.isLocked(i)) {
5629 //if we get to this point all of the columns are locked so we return the total
5634 * Moves a column from one position to another
5635 * @param {Number} oldIndex The current column index
5636 * @param {Number} newIndex The destination column index
5638 moveColumn : function(oldIndex, newIndex){
5639 var oldLocked = this.isLocked(oldIndex),
5640 newLocked = this.isLocked(newIndex);
5642 if (oldIndex < newIndex && oldLocked && !newLocked) {
5643 this.setLocked(oldIndex, false, true);
5644 } else if (oldIndex > newIndex && !oldLocked && newLocked) {
5645 this.setLocked(oldIndex, true, true);
5648 Ext.ux.grid.LockingColumnModel.superclass.moveColumn.apply(this, arguments);
5651 Ext.ns('Ext.ux.form');
5654 * @class Ext.ux.form.MultiSelect
5655 * @extends Ext.form.Field
5656 * A control that allows selection and form submission of multiple list items.
5659 * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
5660 * 2008-06-19 bpm Docs and demo code clean up
5663 * Create a new MultiSelect
5664 * @param {Object} config Configuration options
5665 * @xtype multiselect
5667 Ext.ux.form.MultiSelect = Ext.extend(Ext.form.Field, {
5669 * @cfg {String} legend Wraps the object with a fieldset and specified legend.
5672 * @cfg {Ext.ListView} view The {@link Ext.ListView} used to render the multiselect list.
5675 * @cfg {String/Array} dragGroup The ddgroup name(s) for the MultiSelect DragZone (defaults to undefined).
5678 * @cfg {String/Array} dropGroup The ddgroup name(s) for the MultiSelect DropZone (defaults to undefined).
5681 * @cfg {Boolean} ddReorder Whether the items in the MultiSelect list are drag/drop reorderable (defaults to false).
5685 * @cfg {Object/Array} tbar The top toolbar of the control. This can be a {@link Ext.Toolbar} object, a
5686 * toolbar config, or an array of buttons/button configs to be added to the toolbar.
5689 * @cfg {String} appendOnly True if the list should only allow append drops when drag/drop is enabled
5690 * (use for lists which are sorted, defaults to false).
5694 * @cfg {Number} width Width in pixels of the control (defaults to 100).
5698 * @cfg {Number} height Height in pixels of the control (defaults to 100).
5702 * @cfg {String/Number} displayField Name/Index of the desired display field in the dataset (defaults to 0).
5706 * @cfg {String/Number} valueField Name/Index of the desired value field in the dataset (defaults to 1).
5710 * @cfg {Boolean} allowBlank False to require at least one item in the list to be selected, true to allow no
5711 * selection (defaults to true).
5715 * @cfg {Number} minSelections Minimum number of selections allowed (defaults to 0).
5719 * @cfg {Number} maxSelections Maximum number of selections allowed (defaults to Number.MAX_VALUE).
5721 maxSelections:Number.MAX_VALUE,
5723 * @cfg {String} blankText Default text displayed when the control contains no items (defaults to the same value as
5724 * {@link Ext.form.TextField#blankText}.
5726 blankText:Ext.form.TextField.prototype.blankText,
5728 * @cfg {String} minSelectionsText Validation message displayed when {@link #minSelections} is not met (defaults to 'Minimum {0}
5729 * item(s) required'). The {0} token will be replaced by the value of {@link #minSelections}.
5731 minSelectionsText:'Minimum {0} item(s) required',
5733 * @cfg {String} maxSelectionsText Validation message displayed when {@link #maxSelections} is not met (defaults to 'Maximum {0}
5734 * item(s) allowed'). The {0} token will be replaced by the value of {@link #maxSelections}.
5736 maxSelectionsText:'Maximum {0} item(s) allowed',
5738 * @cfg {String} delimiter The string used to delimit between items when set or returned as a string of values
5739 * (defaults to ',').
5743 * @cfg {Ext.data.Store/Array} store The data source to which this MultiSelect is bound (defaults to <tt>undefined</tt>).
5744 * Acceptable values for this property are:
5745 * <div class="mdetail-params"><ul>
5746 * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
5747 * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally.
5748 * <div class="mdetail-params"><ul>
5749 * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
5750 * A 1-dimensional array will automatically be expanded (each array item will be the combo
5751 * {@link #valueField value} and {@link #displayField text})</div></li>
5752 * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
5753 * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
5754 * {@link #valueField value}, while the value at index 1 is assumed to be the combo {@link #displayField text}.
5755 * </div></li></ul></div></li></ul></div>
5759 defaultAutoCreate : {tag: "div"},
5762 initComponent: function(){
5763 Ext.ux.form.MultiSelect.superclass.initComponent.call(this);
5765 if(Ext.isArray(this.store)){
5766 if (Ext.isArray(this.store[0])){
5767 this.store = new Ext.data.ArrayStore({
5768 fields: ['value','text'],
5771 this.valueField = 'value';
5773 this.store = new Ext.data.ArrayStore({
5778 this.valueField = 'text';
5780 this.displayField = 'text';
5782 this.store = Ext.StoreMgr.lookup(this.store);
5794 onRender: function(ct, position){
5795 Ext.ux.form.MultiSelect.superclass.onRender.call(this, ct, position);
5797 var fs = this.fs = new Ext.form.FieldSet({
5800 height: this.height,
5802 style: "padding:0;",
5805 fs.body.addClass('ux-mselect');
5807 this.view = new Ext.ListView({
5810 columns: [{ header: 'Value', width: 1, dataIndex: this.displayField }],
5816 this.view.on('click', this.onViewClick, this);
5817 this.view.on('beforeclick', this.onViewBeforeClick, this);
5818 this.view.on('dblclick', this.onViewDblClick, this);
5820 this.hiddenName = this.name || Ext.id();
5821 var hiddenTag = { tag: "input", type: "hidden", value: "", name: this.hiddenName };
5822 this.hiddenField = this.el.createChild(hiddenTag);
5823 this.hiddenField.dom.disabled = this.hiddenName != this.name;
5828 afterRender: function(){
5829 Ext.ux.form.MultiSelect.superclass.afterRender.call(this);
5831 if (this.ddReorder && !this.dragGroup && !this.dropGroup){
5832 this.dragGroup = this.dropGroup = 'MultiselectDD-' + Ext.id();
5835 if (this.draggable || this.dragGroup){
5836 this.dragZone = new Ext.ux.form.MultiSelect.DragZone(this, {
5837 ddGroup: this.dragGroup
5840 if (this.droppable || this.dropGroup){
5841 this.dropZone = new Ext.ux.form.MultiSelect.DropZone(this, {
5842 ddGroup: this.dropGroup
5848 onViewClick: function(vw, index, node, e) {
5849 this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
5850 this.hiddenField.dom.value = this.getValue();
5851 this.fireEvent('click', this, e);
5856 onViewBeforeClick: function(vw, index, node, e) {
5857 if (this.disabled) {return false;}
5861 onViewDblClick : function(vw, index, node, e) {
5862 return this.fireEvent('dblclick', vw, index, node, e);
5866 * Returns an array of data values for the selected items in the list. The values will be separated
5867 * by {@link #delimiter}.
5868 * @return {Array} value An array of string data values
5870 getValue: function(valueField){
5871 var returnArray = [];
5872 var selectionsArray = this.view.getSelectedIndexes();
5873 if (selectionsArray.length == 0) {return '';}
5874 for (var i=0; i<selectionsArray.length; i++) {
5875 returnArray.push(this.store.getAt(selectionsArray[i]).get((valueField != null) ? valueField : this.valueField));
5877 return returnArray.join(this.delimiter);
5881 * Sets a delimited string (using {@link #delimiter}) or array of data values into the list.
5882 * @param {String/Array} values The values to set
5884 setValue: function(values) {
5886 var selections = [];
5887 this.view.clearSelections();
5888 this.hiddenField.dom.value = '';
5890 if (!values || (values == '')) { return; }
5892 if (!Ext.isArray(values)) { values = values.split(this.delimiter); }
5893 for (var i=0; i<values.length; i++) {
5894 index = this.view.store.indexOf(this.view.store.query(this.valueField,
5895 new RegExp('^' + values[i] + '$', "i")).itemAt(0));
5896 selections.push(index);
5898 this.view.select(selections);
5899 this.hiddenField.dom.value = this.getValue();
5904 reset : function() {
5909 getRawValue: function(valueField) {
5910 var tmp = this.getValue(valueField);
5912 tmp = tmp.split(this.delimiter);
5921 setRawValue: function(values){
5926 validateValue : function(value){
5927 if (value.length < 1) { // if it has no value
5928 if (this.allowBlank) {
5929 this.clearInvalid();
5932 this.markInvalid(this.blankText);
5936 if (value.length < this.minSelections) {
5937 this.markInvalid(String.format(this.minSelectionsText, this.minSelections));
5940 if (value.length > this.maxSelections) {
5941 this.markInvalid(String.format(this.maxSelectionsText, this.maxSelections));
5948 disable: function(){
5949 this.disabled = true;
5950 this.hiddenField.dom.disabled = true;
5956 this.disabled = false;
5957 this.hiddenField.dom.disabled = false;
5962 destroy: function(){
5963 Ext.destroy(this.fs, this.dragZone, this.dropZone);
5964 Ext.ux.form.MultiSelect.superclass.destroy.call(this);
5969 Ext.reg('multiselect', Ext.ux.form.MultiSelect);
5972 Ext.ux.Multiselect = Ext.ux.form.MultiSelect;
5975 Ext.ux.form.MultiSelect.DragZone = function(ms, config){
5977 this.view = ms.view;
5978 var ddGroup = config.ddGroup || 'MultiselectDD';
5980 if (Ext.isArray(ddGroup)){
5981 dd = ddGroup.shift();
5986 Ext.ux.form.MultiSelect.DragZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
5987 this.setDraggable(ddGroup);
5990 Ext.extend(Ext.ux.form.MultiSelect.DragZone, Ext.dd.DragZone, {
5991 onInitDrag : function(x, y){
5992 var el = Ext.get(this.dragData.ddel.cloneNode(true));
5993 this.proxy.update(el.dom);
5994 el.setWidth(el.child('em').getWidth());
5995 this.onStartDrag(x, y);
6000 collectSelection: function(data) {
6001 data.repairXY = Ext.fly(this.view.getSelectedNodes()[0]).getXY();
6003 this.view.store.each(function(rec){
6004 if (this.view.isSelected(i)) {
6005 var n = this.view.getNode(i);
6006 var dragNode = n.cloneNode(true);
6007 dragNode.id = Ext.id();
6008 data.ddel.appendChild(dragNode);
6009 data.records.push(this.view.store.getAt(i));
6010 data.viewNodes.push(n);
6017 onEndDrag: function(data, e) {
6018 var d = Ext.get(this.dragData.ddel);
6019 if (d && d.hasClass("multi-proxy")) {
6025 getDragData: function(e){
6026 var target = this.view.findItemFromChild(e.getTarget());
6028 if (!this.view.isSelected(target) && !e.ctrlKey && !e.shiftKey) {
6029 this.view.select(target);
6030 this.ms.setValue(this.ms.getValue());
6032 if (this.view.getSelectionCount() == 0 || e.ctrlKey || e.shiftKey) return false;
6034 sourceView: this.view,
6038 if (this.view.getSelectionCount() == 1) {
6039 var i = this.view.getSelectedIndexes()[0];
6040 var n = this.view.getNode(i);
6041 dragData.viewNodes.push(dragData.ddel = n);
6042 dragData.records.push(this.view.store.getAt(i));
6043 dragData.repairXY = Ext.fly(n).getXY();
6045 dragData.ddel = document.createElement('div');
6046 dragData.ddel.className = 'multi-proxy';
6047 this.collectSelection(dragData);
6054 // override the default repairXY.
6055 getRepairXY : function(e){
6056 return this.dragData.repairXY;
6060 setDraggable: function(ddGroup){
6061 if (!ddGroup) return;
6062 if (Ext.isArray(ddGroup)) {
6063 Ext.each(ddGroup, this.setDraggable, this);
6066 this.addToGroup(ddGroup);
6070 Ext.ux.form.MultiSelect.DropZone = function(ms, config){
6072 this.view = ms.view;
6073 var ddGroup = config.ddGroup || 'MultiselectDD';
6075 if (Ext.isArray(ddGroup)){
6076 dd = ddGroup.shift();
6081 Ext.ux.form.MultiSelect.DropZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
6082 this.setDroppable(ddGroup);
6085 Ext.extend(Ext.ux.form.MultiSelect.DropZone, Ext.dd.DropZone, {
6087 * Part of the Ext.dd.DropZone interface. If no target node is found, the
6088 * whole Element becomes the target, and this causes the drop gesture to append.
6090 getTargetFromEvent : function(e) {
6091 var target = e.getTarget();
6096 getDropPoint : function(e, n, dd){
6097 if (n == this.ms.fs.body.dom) { return "below"; }
6098 var t = Ext.lib.Dom.getY(n), b = t + n.offsetHeight;
6099 var c = t + (b - t) / 2;
6100 var y = Ext.lib.Event.getPageY(e);
6109 isValidDropPoint: function(pt, n, data) {
6110 if (!data.viewNodes || (data.viewNodes.length != 1)) {
6113 var d = data.viewNodes[0];
6117 if ((pt == "below") && (n.nextSibling == d)) {
6120 if ((pt == "above") && (n.previousSibling == d)) {
6127 onNodeEnter : function(n, dd, e, data){
6132 onNodeOver : function(n, dd, e, data){
6133 var dragElClass = this.dropNotAllowed;
6134 var pt = this.getDropPoint(e, n, dd);
6135 if (this.isValidDropPoint(pt, n, data)) {
6136 if (this.ms.appendOnly) {
6137 return "x-tree-drop-ok-below";
6140 // set the insert point style on the target node
6144 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
6145 targetElClass = "x-view-drag-insert-above";
6147 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
6148 targetElClass = "x-view-drag-insert-below";
6150 if (this.lastInsertClass != targetElClass){
6151 Ext.fly(n).replaceClass(this.lastInsertClass, targetElClass);
6152 this.lastInsertClass = targetElClass;
6160 onNodeOut : function(n, dd, e, data){
6161 this.removeDropIndicators(n);
6165 onNodeDrop : function(n, dd, e, data){
6166 if (this.ms.fireEvent("drop", this, n, dd, e, data) === false) {
6169 var pt = this.getDropPoint(e, n, dd);
6170 if (n != this.ms.fs.body.dom)
6171 n = this.view.findItemFromChild(n);
6173 if(this.ms.appendOnly) {
6174 insertAt = this.view.store.getCount();
6176 insertAt = n == this.ms.fs.body.dom ? this.view.store.getCount() - 1 : this.view.indexOf(n);
6177 if (pt == "below") {
6184 // Validate if dragging within the same MultiSelect
6185 if (data.sourceView == this.view) {
6186 // If the first element to be inserted below is the target node, remove it
6187 if (pt == "below") {
6188 if (data.viewNodes[0] == n) {
6189 data.viewNodes.shift();
6191 } else { // If the last element to be inserted above is the target node, remove it
6192 if (data.viewNodes[data.viewNodes.length - 1] == n) {
6193 data.viewNodes.pop();
6197 // Nothing to drop...
6198 if (!data.viewNodes.length) {
6202 // If we are moving DOWN, then because a store.remove() takes place first,
6203 // the insertAt must be decremented.
6204 if (insertAt > this.view.store.indexOf(data.records[0])) {
6210 for (var i = 0; i < data.records.length; i++) {
6211 var r = data.records[i];
6212 if (data.sourceView) {
6213 data.sourceView.store.remove(r);
6215 this.view.store.insert(dir == 'down' ? insertAt : insertAt++, r);
6216 var si = this.view.store.sortInfo;
6218 this.view.store.sort(si.field, si.direction);
6225 removeDropIndicators : function(n){
6227 Ext.fly(n).removeClass([
6228 "x-view-drag-insert-above",
6229 "x-view-drag-insert-left",
6230 "x-view-drag-insert-right",
6231 "x-view-drag-insert-below"]);
6232 this.lastInsertClass = "_noclass";
6237 setDroppable: function(ddGroup){
6238 if (!ddGroup) return;
6239 if (Ext.isArray(ddGroup)) {
6240 Ext.each(ddGroup, this.setDroppable, this);
6243 this.addToGroup(ddGroup);
6247 /* Fix for Opera, which does not seem to include the map function on Array's */
6248 if (!Array.prototype.map) {
6249 Array.prototype.map = function(fun){
6250 var len = this.length;
6251 if (typeof fun != 'function') {
6252 throw new TypeError();
6254 var res = new Array(len);
6255 var thisp = arguments[1];
6256 for (var i = 0; i < len; i++) {
6258 res[i] = fun.call(thisp, this[i], i, this);
6265 Ext.ns('Ext.ux.data');
6268 * @class Ext.ux.data.PagingMemoryProxy
6269 * @extends Ext.data.MemoryProxy
6270 * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
6272 Ext.ux.data.PagingMemoryProxy = Ext.extend(Ext.data.MemoryProxy, {
6273 constructor : function(data){
6274 Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);
6277 doRequest : function(action, rs, params, reader, callback, scope, options){
6282 result = reader.readRecords(this.data);
6285 this.fireEvent('loadexception', this, options, null, e);
6286 callback.call(scope, null, options, false);
6291 if (params.filter !== undefined) {
6292 result.records = result.records.filter(function(el){
6293 if (typeof(el) == 'object') {
6294 var att = params.filterCol || 0;
6295 return String(el.data[att]).match(params.filter) ? true : false;
6298 return String(el).match(params.filter) ? true : false;
6301 result.totalRecords = result.records.length;
6305 if (params.sort !== undefined) {
6306 // use integer as params.sort to specify column, since arrays are not named
6307 // params.sort=0; would also match a array without columns
6308 var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
6309 var fn = function(v1, v2){
6310 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
6312 result.records.sort(function(a, b){
6314 if (typeof(a) == 'object') {
6315 v = fn(a.data[params.sort], b.data[params.sort]) * dir;
6321 v = (a.index < b.index ? -1 : 1);
6326 // paging (use undefined cause start can also be 0 (thus false))
6327 if (params.start !== undefined && params.limit !== undefined) {
6328 result.records = result.records.slice(params.start, params.start + params.limit);
6330 callback.call(scope, result, options, true);
6335 Ext.data.PagingMemoryProxy = Ext.ux.data.PagingMemoryProxy;
6336 Ext.ux.PanelResizer = Ext.extend(Ext.util.Observable, {
6340 constructor: function(config){
6341 Ext.apply(this, config);
6343 Ext.ux.PanelResizer.superclass.constructor.call(this, config);
6349 if(this.panel.elements.indexOf('footer')==-1){
6350 p.elements += ',footer';
6352 p.on('render', this.onRender, this);
6355 onRender : function(p){
6356 this.handle = p.footer.createChild({cls:'x-panel-resize'});
6358 this.tracker = new Ext.dd.DragTracker({
6359 onStart: this.onDragStart.createDelegate(this),
6360 onDrag: this.onDrag.createDelegate(this),
6361 onEnd: this.onDragEnd.createDelegate(this),
6365 this.tracker.initEl(this.handle);
6366 p.on('beforedestroy', this.tracker.destroy, this.tracker);
6370 onDragStart: function(e){
6371 this.dragging = true;
6372 this.startHeight = this.panel.el.getHeight();
6373 this.fireEvent('dragstart', this, e);
6377 onDrag: function(e){
6378 this.panel.setHeight((this.startHeight-this.tracker.getOffset()[1]).constrain(this.minHeight, this.maxHeight));
6379 this.fireEvent('drag', this, e);
6383 onDragEnd: function(e){
6384 this.dragging = false;
6385 this.fireEvent('dragend', this, e);
6388 Ext.preg('panelresizer', Ext.ux.PanelResizer);Ext.ux.Portal = Ext.extend(Ext.Panel, {
6392 defaultType : 'portalcolumn',
6394 initComponent : function(){
6395 Ext.ux.Portal.superclass.initComponent.call(this);
6398 beforedragover:true,
6405 initEvents : function(){
6406 Ext.ux.Portal.superclass.initEvents.call(this);
6407 this.dd = new Ext.ux.Portal.DropZone(this, this.dropConfig);
6410 beforeDestroy : function() {
6414 Ext.ux.Portal.superclass.beforeDestroy.call(this);
6418 Ext.reg('portal', Ext.ux.Portal);
6421 Ext.ux.Portal.DropZone = function(portal, cfg){
6422 this.portal = portal;
6423 Ext.dd.ScrollManager.register(portal.body);
6424 Ext.ux.Portal.DropZone.superclass.constructor.call(this, portal.bwrap.dom, cfg);
6425 portal.body.ddScrollConfig = this.ddScrollConfig;
6428 Ext.extend(Ext.ux.Portal.DropZone, Ext.dd.DropTarget, {
6436 createEvent : function(dd, e, data, col, c, pos){
6438 portal: this.portal,
6446 status: this.dropAllowed
6450 notifyOver : function(dd, e, data){
6451 var xy = e.getXY(), portal = this.portal, px = dd.proxy;
6453 // case column widths
6455 this.grid = this.getGrid();
6458 // handle case scroll where scrollbars appear during drag
6459 var cw = portal.body.dom.clientWidth;
6462 }else if(this.lastCW != cw){
6465 this.grid = this.getGrid();
6469 var col = 0, xs = this.grid.columnX, cmatch = false;
6470 for(var len = xs.length; col < len; col++){
6471 if(xy[0] < (xs[col].x + xs[col].w)){
6476 // no match, fix last index
6481 // find insert position
6482 var p, match = false, pos = 0,
6483 c = portal.items.itemAt(col),
6484 items = c.items.items, overSelf = false;
6486 for(var len = items.length; pos < len; pos++){
6488 var h = p.el.getHeight();
6492 else if((p.el.getY()+(h/2)) > xy[1]){
6498 pos = (match && p ? pos : c.items.getCount()) + (overSelf ? -1 : 0);
6499 var overEvent = this.createEvent(dd, e, data, col, c, pos);
6501 if(portal.fireEvent('validatedrop', overEvent) !== false &&
6502 portal.fireEvent('beforedragover', overEvent) !== false){
6504 // make sure proxy width is fluid
6505 px.getProxy().setWidth('auto');
6508 px.moveProxy(p.el.dom.parentNode, match ? p.el.dom : null);
6510 px.moveProxy(c.el.dom, null);
6513 this.lastPos = {c: c, col: col, p: overSelf || (match && p) ? pos : false};
6514 this.scrollPos = portal.body.getScroll();
6516 portal.fireEvent('dragover', overEvent);
6518 return overEvent.status;
6520 return overEvent.status;
6525 notifyOut : function(){
6529 notifyDrop : function(dd, e, data){
6534 var c = this.lastPos.c, col = this.lastPos.col, pos = this.lastPos.p;
6536 var dropEvent = this.createEvent(dd, e, data, col, c,
6537 pos !== false ? pos : c.items.getCount());
6539 if(this.portal.fireEvent('validatedrop', dropEvent) !== false &&
6540 this.portal.fireEvent('beforedrop', dropEvent) !== false){
6542 dd.proxy.getProxy().remove();
6543 dd.panel.el.dom.parentNode.removeChild(dd.panel.el.dom);
6546 if(c == dd.panel.ownerCt && (c.items.items.indexOf(dd.panel) <= pos)){
6549 c.insert(pos, dd.panel);
6556 this.portal.fireEvent('drop', dropEvent);
6558 // scroll position is lost on drop, fix it
6559 var st = this.scrollPos.top;
6561 var d = this.portal.body.dom;
6562 setTimeout(function(){
6568 delete this.lastPos;
6571 // internal cache of body and column coords
6572 getGrid : function(){
6573 var box = this.portal.bwrap.getBox();
6575 this.portal.items.each(function(c){
6576 box.columnX.push({x: c.el.getX(), w: c.el.getWidth()});
6581 // unregister the dropzone from ScrollManager
6583 //Ext.dd.ScrollManager.unregister(this.portal.body);
6584 Ext.ux.Portal.DropZone.superclass.unreg.call(this);
6587 Ext.ux.PortalColumn = Ext.extend(Ext.Container, {
6589 //autoEl : 'div',//already defined by Ext.Component
6590 defaultType : 'portlet',
6591 cls : 'x-portal-column'
6594 Ext.reg('portalcolumn', Ext.ux.PortalColumn);
6595 Ext.ux.Portlet = Ext.extend(Ext.Panel, {
6603 Ext.reg('portlet', Ext.ux.Portlet);
6605 * @class Ext.ux.ProgressBarPager
6607 * Plugin (ptype = 'tabclosemenu') for displaying a progressbar inside of a paging toolbar instead of plain text
6609 * @ptype progressbarpager
6611 * Create a new ItemSelector
6612 * @param {Object} config Configuration options
6613 * @xtype itemselector
6615 Ext.ux.ProgressBarPager = Ext.extend(Object, {
6617 * @cfg {Integer} progBarWidth
6618 * <p>The default progress bar width. Default is 225.</p>
6622 * @cfg {String} defaultText
6623 * <p>The text to display while the store is loading. Default is 'Loading...'</p>
6625 defaultText : 'Loading...',
6627 * @cfg {Object} defaultAnimCfg
6628 * <p>A {@link Ext.Fx Ext.Fx} configuration object. Default is { duration : 1, easing : 'bounceOut' }.</p>
6632 easing : 'bounceOut'
6634 constructor : function(config) {
6636 Ext.apply(this, config);
6640 init : function (parent) {
6642 if(parent.displayInfo){
6643 this.parent = parent;
6644 var ind = parent.items.indexOf(parent.displayItem);
6645 parent.remove(parent.displayItem, true);
6646 this.progressBar = new Ext.ProgressBar({
6647 text : this.defaultText,
6648 width : this.progBarWidth,
6649 animate : this.defaultAnimCfg
6652 parent.displayItem = this.progressBar;
6654 parent.add(parent.displayItem);
6656 Ext.apply(parent, this.parentOverrides);
6658 this.progressBar.on('render', function(pb) {
6659 pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
6660 }, this, {single: true});
6666 // This method handles the click for the progress bar
6667 handleProgressBarClick : function(e){
6668 var parent = this.parent,
6669 displayItem = parent.displayItem,
6670 box = this.progressBar.getBox(),
6672 position = xy[0]-box.x,
6673 pages = Math.ceil(parent.store.getTotalCount()/parent.pageSize),
6674 newpage = Math.ceil(position/(displayItem.width/pages));
6676 parent.changePage(newpage);
6679 // private, overriddes
6682 // This method updates the information via the progress bar.
6683 updateInfo : function(){
6684 if(this.displayItem){
6685 var count = this.store.getCount(),
6686 pgData = this.getPageData(),
6687 pageNum = this.readPage(pgData),
6692 this.cursor+1, this.cursor+count, this.store.getTotalCount()
6695 pageNum = pgData.activePage; ;
6697 var pct = pageNum / pgData.pages;
6699 this.displayItem.updateProgress(pct, msg, this.animate || this.defaultAnimConfig);
6704 Ext.preg('progressbarpager', Ext.ux.ProgressBarPager);
6706 Ext.ns('Ext.ux.grid');
6709 * @class Ext.ux.grid.RowEditor
6710 * @extends Ext.Panel
6711 * Plugin (ptype = 'roweditor') that adds the ability to rapidly edit full rows in a grid.
6712 * A validation mode may be enabled which uses AnchorTips to notify the user of all
6713 * validation errors at once.
6717 Ext.ux.grid.RowEditor = Ext.extend(Ext.Panel, {
6721 cls: 'x-small-editor',
6722 buttonAlign: 'center',
6723 baseCls: 'x-row-editor',
6724 elements: 'header,footer,body',
6727 clicksToEdit: 'auto',
6733 cancelText: 'Cancel',
6734 commitChangesText: 'You need to commit or cancel your changes',
6735 errorText: 'Errors',
6741 initComponent: function(){
6742 Ext.ux.grid.RowEditor.superclass.initComponent.call(this);
6746 * Fired before the row editor is activated.
6747 * If the listener returns <tt>false</tt> the editor will not be activated.
6748 * @param {Ext.ux.grid.RowEditor} roweditor This object
6749 * @param {Number} rowIndex The rowIndex of the row just edited
6754 * Fired when the editor is cancelled.
6755 * @param {Ext.ux.grid.RowEditor} roweditor This object
6756 * @param {Boolean} forced True if the cancel button is pressed, false is the editor was invalid.
6760 * @event validateedit
6761 * Fired after a row is edited and passes validation.
6762 * If the listener returns <tt>false</tt> changes to the record will not be set.
6763 * @param {Ext.ux.grid.RowEditor} roweditor This object
6764 * @param {Object} changes Object with changes made to the record.
6765 * @param {Ext.data.Record} r The Record that was edited.
6766 * @param {Number} rowIndex The rowIndex of the row just edited
6771 * Fired after a row is edited and passes validation. This event is fired
6772 * after the store's update event is fired with this edit.
6773 * @param {Ext.ux.grid.RowEditor} roweditor This object
6774 * @param {Object} changes Object with changes made to the record.
6775 * @param {Ext.data.Record} r The Record that was edited.
6776 * @param {Number} rowIndex The rowIndex of the row just edited
6782 init: function(grid){
6784 this.ownerCt = grid;
6785 if(this.clicksToEdit === 2){
6786 grid.on('rowdblclick', this.onRowDblClick, this);
6788 grid.on('rowclick', this.onRowClick, this);
6790 grid.on('rowdblclick', this.onRowDblClick, this);
6794 // stopEditing without saving when a record is removed from Store.
6795 grid.getStore().on('remove', function() {
6796 this.stopEditing(false);
6801 keydown: this.onGridKey,
6802 columnresize: this.verifyLayout,
6803 columnmove: this.refreshFields,
6804 reconfigure: this.refreshFields,
6805 beforedestroy : this.beforedestroy,
6806 destroy : this.destroy,
6809 fn: this.positionButtons
6812 grid.getColumnModel().on('hiddenchange', this.verifyLayout, this, {delay:1});
6813 grid.getView().on('refresh', this.stopEditing.createDelegate(this, []));
6816 beforedestroy: function() {
6817 this.stopMonitoring();
6818 this.grid.getStore().un('remove', this.onStoreRemove, this);
6819 this.stopEditing(false);
6820 Ext.destroy(this.btns, this.tooltip);
6823 refreshFields: function(){
6825 this.verifyLayout();
6828 isDirty: function(){
6830 this.items.each(function(f){
6831 if(String(this.values[f.id]) !== String(f.getValue())){
6839 startEditing: function(rowIndex, doFocus){
6840 if(this.editing && this.isDirty()){
6841 this.showTooltip(this.commitChangesText);
6844 if(Ext.isObject(rowIndex)){
6845 rowIndex = this.grid.getStore().indexOf(rowIndex);
6847 if(this.fireEvent('beforeedit', this, rowIndex) !== false){
6848 this.editing = true;
6849 var g = this.grid, view = g.getView(),
6850 row = view.getRow(rowIndex),
6851 record = g.store.getAt(rowIndex);
6853 this.record = record;
6854 this.rowIndex = rowIndex;
6857 this.render(view.getEditorParent());
6859 var w = Ext.fly(row).getWidth();
6861 if(!this.initialized){
6864 var cm = g.getColumnModel(), fields = this.items.items, f, val;
6865 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6866 val = this.preEditValue(record, cm.getDataIndex(i));
6869 this.values[f.id] = Ext.isEmpty(val) ? '' : val;
6871 this.verifyLayout(true);
6872 if(!this.isVisible()){
6873 this.setPagePosition(Ext.fly(row).getXY());
6875 this.el.setXY(Ext.fly(row).getXY(), {duration:0.15});
6877 if(!this.isVisible()){
6878 this.show().doLayout();
6880 if(doFocus !== false){
6881 this.doFocus.defer(this.focusDelay, this);
6886 stopEditing : function(saveChanges){
6887 this.editing = false;
6888 if(!this.isVisible()){
6891 if(saveChanges === false || !this.isValid()){
6893 this.fireEvent('canceledit', this, saveChanges === false);
6899 cm = this.grid.colModel,
6900 fields = this.items.items;
6901 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6902 if(!cm.isHidden(i)){
6903 var dindex = cm.getDataIndex(i);
6904 if(!Ext.isEmpty(dindex)){
6905 var oldValue = r.data[dindex],
6906 value = this.postEditValue(fields[i].getValue(), oldValue, r, dindex);
6907 if(String(oldValue) !== String(value)){
6908 changes[dindex] = value;
6914 if(hasChange && this.fireEvent('validateedit', this, changes, r, this.rowIndex) !== false){
6916 Ext.iterate(changes, function(name, value){
6920 this.fireEvent('afteredit', this, changes, r, this.rowIndex);
6925 verifyLayout: function(force){
6926 if(this.el && (this.isVisible() || force === true)){
6927 var row = this.grid.getView().getRow(this.rowIndex);
6928 this.setSize(Ext.fly(row).getWidth(), Ext.isIE ? Ext.fly(row).getHeight() + 9 : undefined);
6929 var cm = this.grid.colModel, fields = this.items.items;
6930 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6931 if(!cm.isHidden(i)){
6933 if(i === (len - 1)){
6934 adjust += 3; // outer padding
6939 fields[i].setWidth(cm.getColumnWidth(i) - adjust);
6945 this.positionButtons();
6949 slideHide : function(){
6953 initFields: function(){
6954 var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
6955 this.removeAll(false);
6956 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6957 var c = cm.getColumnAt(i),
6960 ed = c.displayEditor || new Ext.form.DisplayField();
6963 ed.margins = pm('0 1 2 1');
6964 } else if(i == len - 1){
6965 ed.margins = pm('0 0 2 1');
6967 ed.margins = pm('0 1 2');
6969 ed.setWidth(cm.getColumnWidth(i));
6971 if(ed.ownerCt !== this){
6972 ed.on('focus', this.ensureVisible, this);
6973 ed.on('specialkey', this.onKey, this);
6977 this.initialized = true;
6980 onKey: function(f, e){
6981 if(e.getKey() === e.ENTER){
6982 this.stopEditing(true);
6983 e.stopPropagation();
6987 onGridKey: function(e){
6988 if(e.getKey() === e.ENTER && !this.isVisible()){
6989 var r = this.grid.getSelectionModel().getSelected();
6991 var index = this.grid.store.indexOf(r);
6992 this.startEditing(index);
6993 e.stopPropagation();
6998 ensureVisible: function(editor){
6999 if(this.isVisible()){
7000 this.grid.getView().ensureVisible(this.rowIndex, this.grid.colModel.getIndexById(editor.column.id), true);
7004 onRowClick: function(g, rowIndex, e){
7005 if(this.clicksToEdit == 'auto'){
7006 var li = this.lastClickIndex;
7007 this.lastClickIndex = rowIndex;
7008 if(li != rowIndex && !this.isVisible()){
7012 this.startEditing(rowIndex, false);
7013 this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
7016 onRowDblClick: function(g, rowIndex, e){
7017 this.startEditing(rowIndex, false);
7018 this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
7021 onRender: function(){
7022 Ext.ux.grid.RowEditor.superclass.onRender.apply(this, arguments);
7023 this.el.swallowEvent(['keydown', 'keyup', 'keypress']);
7024 this.btns = new Ext.Panel({
7029 width: (this.minButtonWidth * 2) + (this.frameWidth * 2) + (this.buttonPad * 4), // width must be specified for IE
7034 text: this.saveText,
7035 width: this.minButtonWidth,
7036 handler: this.stopEditing.createDelegate(this, [true])
7039 text: this.cancelText,
7040 width: this.minButtonWidth,
7041 handler: this.stopEditing.createDelegate(this, [false])
7044 this.btns.render(this.bwrap);
7047 afterRender: function(){
7048 Ext.ux.grid.RowEditor.superclass.afterRender.apply(this, arguments);
7049 this.positionButtons();
7050 if(this.monitorValid){
7051 this.startMonitoring();
7056 if(this.monitorValid){
7057 this.startMonitoring();
7059 Ext.ux.grid.RowEditor.superclass.onShow.apply(this, arguments);
7063 Ext.ux.grid.RowEditor.superclass.onHide.apply(this, arguments);
7064 this.stopMonitoring();
7065 this.grid.getView().focusRow(this.rowIndex);
7068 positionButtons: function(){
7071 h = this.el.dom.clientHeight,
7073 scroll = view.scroller.dom.scrollLeft,
7074 bw = this.btns.getWidth(),
7075 width = Math.min(g.getWidth(), g.getColumnModel().getTotalWidth());
7077 this.btns.el.shift({left: (width/2)-(bw/2)+scroll, top: h - 2, stopFx: true, duration:0.2});
7082 preEditValue : function(r, field){
7083 var value = r.data[field];
7084 return this.autoEncode && typeof value === 'string' ? Ext.util.Format.htmlDecode(value) : value;
7088 postEditValue : function(value, originalValue, r, field){
7089 return this.autoEncode && typeof value == 'string' ? Ext.util.Format.htmlEncode(value) : value;
7092 doFocus: function(pt){
7093 if(this.isVisible()){
7095 cm = this.grid.getColumnModel(),
7098 index = this.getTargetColumnIndex(pt);
7100 for(var i = index||0, len = cm.getColumnCount(); i < len; i++){
7101 c = cm.getColumnAt(i);
7102 if(!c.hidden && c.getEditor()){
7103 c.getEditor().focus();
7110 getTargetColumnIndex: function(pt){
7111 var grid = this.grid,
7114 cms = grid.colModel.config,
7117 for(var len = cms.length, c; c = cms[i]; i++){
7119 if(Ext.fly(v.getHeaderCell(i)).getRegion().right >= x){
7128 startMonitoring : function(){
7129 if(!this.bound && this.monitorValid){
7132 run : this.bindHandler,
7133 interval : this.monitorPoll || 200,
7139 stopMonitoring : function(){
7142 this.tooltip.hide();
7146 isValid: function(){
7148 this.items.each(function(f){
7149 if(!f.isValid(true)){
7158 bindHandler : function(){
7160 return false; // stops binding
7162 var valid = this.isValid();
7163 if(!valid && this.errorSummary){
7164 this.showTooltip(this.getErrorText().join(''));
7166 this.btns.saveBtn.setDisabled(!valid);
7167 this.fireEvent('validation', this, valid);
7170 showTooltip: function(msg){
7171 var t = this.tooltip;
7173 t = this.tooltip = new Ext.ToolTip({
7177 title: this.errorText,
7180 anchorToTarget: true,
7184 var v = this.grid.getView(),
7185 top = parseInt(this.el.dom.style.top, 10),
7186 scroll = v.scroller.dom.scrollTop,
7187 h = this.el.getHeight();
7189 if(top + h >= scroll){
7190 t.initTarget(this.items.last().getEl());
7198 }else if(t.rendered){
7203 getErrorText: function(){
7204 var data = ['<ul>'];
7205 this.items.each(function(f){
7206 if(!f.isValid(true)){
7207 data.push('<li>', f.getActiveError(), '</li>');
7214 Ext.preg('roweditor', Ext.ux.grid.RowEditor);
7215 Ext.ns('Ext.ux.grid');
7218 * @class Ext.ux.grid.RowExpander
7219 * @extends Ext.util.Observable
7220 * Plugin (ptype = 'rowexpander') that adds the ability to have a Column in a grid which enables
7221 * a second row body which expands/contracts. The expand/contract behavior is configurable to react
7222 * on clicking of the column, double click of the row, and/or hitting enter while a row is selected.
7224 * @ptype rowexpander
7226 Ext.ux.grid.RowExpander = Ext.extend(Ext.util.Observable, {
7228 * @cfg {Boolean} expandOnEnter
7229 * <tt>true</tt> to toggle selected row(s) between expanded/collapsed when the enter
7230 * key is pressed (defaults to <tt>true</tt>).
7232 expandOnEnter : true,
7234 * @cfg {Boolean} expandOnDblClick
7235 * <tt>true</tt> to toggle a row between expanded/collapsed when double clicked
7236 * (defaults to <tt>true</tt>).
7238 expandOnDblClick : true,
7245 menuDisabled : true,
7249 enableCaching : true,
7251 constructor: function(config){
7252 Ext.apply(this, config);
7256 * @event beforeexpand
7257 * Fires before the row expands. Have the listener return false to prevent the row from expanding.
7258 * @param {Object} this RowExpander object.
7259 * @param {Object} Ext.data.Record Record for the selected row.
7260 * @param {Object} body body element for the secondary row.
7261 * @param {Number} rowIndex The current row index.
7266 * Fires after the row expands.
7267 * @param {Object} this RowExpander object.
7268 * @param {Object} Ext.data.Record Record for the selected row.
7269 * @param {Object} body body element for the secondary row.
7270 * @param {Number} rowIndex The current row index.
7274 * @event beforecollapse
7275 * Fires before the row collapses. Have the listener return false to prevent the row from collapsing.
7276 * @param {Object} this RowExpander object.
7277 * @param {Object} Ext.data.Record Record for the selected row.
7278 * @param {Object} body body element for the secondary row.
7279 * @param {Number} rowIndex The current row index.
7281 beforecollapse: true,
7284 * Fires after the row collapses.
7285 * @param {Object} this RowExpander object.
7286 * @param {Object} Ext.data.Record Record for the selected row.
7287 * @param {Object} body body element for the secondary row.
7288 * @param {Number} rowIndex The current row index.
7293 Ext.ux.grid.RowExpander.superclass.constructor.call(this);
7296 if(typeof this.tpl == 'string'){
7297 this.tpl = new Ext.Template(this.tpl);
7303 this.bodyContent = {};
7306 getRowClass : function(record, rowIndex, p, ds){
7308 var content = this.bodyContent[record.id];
7309 if(!content && !this.lazyRender){
7310 content = this.getBodyContent(record, rowIndex);
7315 return this.state[record.id] ? 'x-grid3-row-expanded' : 'x-grid3-row-collapsed';
7318 init : function(grid){
7321 var view = grid.getView();
7322 view.getRowClass = this.getRowClass.createDelegate(this);
7324 view.enableRowBody = true;
7327 grid.on('render', this.onRender, this);
7328 grid.on('destroy', this.onDestroy, this);
7332 onRender: function() {
7333 var grid = this.grid;
7334 var mainBody = grid.getView().mainBody;
7335 mainBody.on('mousedown', this.onMouseDown, this, {delegate: '.x-grid3-row-expander'});
7336 if (this.expandOnEnter) {
7337 this.keyNav = new Ext.KeyNav(this.grid.getGridEl(), {
7338 'enter' : this.onEnter,
7342 if (this.expandOnDblClick) {
7343 grid.on('rowdblclick', this.onRowDblClick, this);
7348 onDestroy: function() {
7350 this.keyNav.disable();
7354 * A majority of the time, the plugin will be destroyed along with the grid,
7355 * which means the mainBody won't be available. On the off chance that the plugin
7356 * isn't destroyed with the grid, take care of removing the listener.
7358 var mainBody = this.grid.getView().mainBody;
7360 mainBody.un('mousedown', this.onMouseDown, this);
7364 onRowDblClick: function(grid, rowIdx, e) {
7365 this.toggleRow(rowIdx);
7368 onEnter: function(e) {
7370 var sm = g.getSelectionModel();
7371 var sels = sm.getSelections();
7372 for (var i = 0, len = sels.length; i < len; i++) {
7373 var rowIdx = g.getStore().indexOf(sels[i]);
7374 this.toggleRow(rowIdx);
7378 getBodyContent : function(record, index){
7379 if(!this.enableCaching){
7380 return this.tpl.apply(record.data);
7382 var content = this.bodyContent[record.id];
7384 content = this.tpl.apply(record.data);
7385 this.bodyContent[record.id] = content;
7390 onMouseDown : function(e, t){
7392 var row = e.getTarget('.x-grid3-row');
7393 this.toggleRow(row);
7396 renderer : function(v, p, record){
7397 p.cellAttr = 'rowspan="2"';
7398 return '<div class="x-grid3-row-expander"> </div>';
7401 beforeExpand : function(record, body, rowIndex){
7402 if(this.fireEvent('beforeexpand', this, record, body, rowIndex) !== false){
7403 if(this.tpl && this.lazyRender){
7404 body.innerHTML = this.getBodyContent(record, rowIndex);
7412 toggleRow : function(row){
7413 if(typeof row == 'number'){
7414 row = this.grid.view.getRow(row);
7416 this[Ext.fly(row).hasClass('x-grid3-row-collapsed') ? 'expandRow' : 'collapseRow'](row);
7419 expandRow : function(row){
7420 if(typeof row == 'number'){
7421 row = this.grid.view.getRow(row);
7423 var record = this.grid.store.getAt(row.rowIndex);
7424 var body = Ext.DomQuery.selectNode('tr:nth(2) div.x-grid3-row-body', row);
7425 if(this.beforeExpand(record, body, row.rowIndex)){
7426 this.state[record.id] = true;
7427 Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
7428 this.fireEvent('expand', this, record, body, row.rowIndex);
7432 collapseRow : function(row){
7433 if(typeof row == 'number'){
7434 row = this.grid.view.getRow(row);
7436 var record = this.grid.store.getAt(row.rowIndex);
7437 var body = Ext.fly(row).child('tr:nth(1) div.x-grid3-row-body', true);
7438 if(this.fireEvent('beforecollapse', this, record, body, row.rowIndex) !== false){
7439 this.state[record.id] = false;
7440 Ext.fly(row).replaceClass('x-grid3-row-expanded', 'x-grid3-row-collapsed');
7441 this.fireEvent('collapse', this, record, body, row.rowIndex);
7446 Ext.preg('rowexpander', Ext.ux.grid.RowExpander);
7449 Ext.grid.RowExpander = Ext.ux.grid.RowExpander;// We are adding these custom layouts to a namespace that does not
7450 // exist by default in Ext, so we have to add the namespace first:
7451 Ext.ns('Ext.ux.layout');
7454 * @class Ext.ux.layout.RowLayout
7455 * @extends Ext.layout.ContainerLayout
7456 * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of
7457 * each row can be specified as a percentage or fixed height. Row widths can also be fixed, percentage or auto.
7458 * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config,
7459 * and should generally not need to be created directly via the new keyword.</p>
7460 * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a
7461 * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it. The
7462 * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel.
7463 * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p>
7464 * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1.
7465 * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and
7466 * less than 1 (e.g., .25).</p>
7467 * <p>The basic rules for specifying row heights are pretty simple. The logic makes two passes through the
7468 * set of contained panels. During the first layout pass, all panels that either have a fixed height or none
7469 * specified (auto) are skipped, but their heights are subtracted from the overall container height. During the second
7470 * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on
7471 * the total <b>remaining</b> container height. In other words, percentage height panels are designed to fill the space
7472 * left over by all the fixed-height and/or auto-height panels. Because of this, while you can specify any number of rows
7473 * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your
7474 * layout may not render as expected. Example usage:</p>
7476 // All rows are percentages -- they must add up to 1
7477 var p = new Ext.Panel({
7478 title: 'Row Layout - Percentage Only',
7492 // Mix of height and rowHeight -- all rowHeight values must add
7493 // up to 1. The first row will take up exactly 120px, and the last two
7494 // rows will fill the remaining container height.
7495 var p = new Ext.Panel({
7496 title: 'Row Layout - Mixed',
7501 // standard panel widths are still supported too:
7502 width: '50%' // or 200
7514 Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
7521 allowContainerRemove: false,
7524 isValidParent : function(c, target){
7525 return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
7528 getLayoutTargetSize : function() {
7529 var target = this.container.getLayoutTarget(), ret;
7531 ret = target.getViewSize();
7533 // IE in strict mode will return a height of 0 on the 1st pass of getViewSize.
7534 // Use getStyleSize to verify the 0 height, the adjustment pass will then work properly
7536 if (Ext.isIE && Ext.isStrict && ret.height == 0){
7537 ret = target.getStyleSize();
7540 ret.width -= target.getPadding('lr');
7541 ret.height -= target.getPadding('tb');
7546 renderAll : function(ct, target) {
7548 // the innerCt prevents wrapping and shuffling while
7549 // the container is resizing
7550 this.innerCt = target.createChild({cls:'x-column-inner'});
7551 this.innerCt.createChild({cls:'x-clear'});
7553 Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
7557 onLayout : function(ct, target){
7558 var rs = ct.items.items,
7565 this.renderAll(ct, target);
7567 var size = this.getLayoutTargetSize();
7569 if(size.width < 1 && size.height < 1){ // display none?
7573 var h = size.height,
7576 this.innerCt.setSize({height:h});
7578 // some rows can be percentages while others are fixed
7579 // so we need to make 2 passes
7581 for(i = 0; i < len; i++){
7583 m = r.getPositionEl().getMargins('tb');
7586 ph -= (r.getHeight() + m);
7590 ph = ph < 0 ? 0 : ph;
7592 for(i = 0; i < len; i++){
7596 r.setSize({height: Math.floor(r.rowHeight*ph) - m});
7600 // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
7601 // spaces were accounted for properly. If not, re-layout.
7603 if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
7604 var ts = this.getLayoutTargetSize();
7605 if (ts.width != size.width){
7606 this.adjustmentPass = true;
7607 this.onLayout(ct, target);
7611 delete this.adjustmentPass;
7615 * @property activeItem
7620 Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;
7621 Ext.ns('Ext.ux.form');
7623 Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
7624 initComponent : function(){
7625 Ext.ux.form.SearchField.superclass.initComponent.call(this);
7626 this.on('specialkey', function(f, e){
7627 if(e.getKey() == e.ENTER){
7628 this.onTrigger2Click();
7633 validationEvent:false,
7634 validateOnBlur:false,
7635 trigger1Class:'x-form-clear-trigger',
7636 trigger2Class:'x-form-search-trigger',
7640 paramName : 'query',
7642 onTrigger1Click : function(){
7644 this.el.dom.value = '';
7646 this.store.baseParams = this.store.baseParams || {};
7647 this.store.baseParams[this.paramName] = '';
7648 this.store.reload({params:o});
7649 this.triggers[0].hide();
7650 this.hasSearch = false;
7654 onTrigger2Click : function(){
7655 var v = this.getRawValue();
7657 this.onTrigger1Click();
7661 this.store.baseParams = this.store.baseParams || {};
7662 this.store.baseParams[this.paramName] = v;
7663 this.store.reload({params:o});
7664 this.hasSearch = true;
7665 this.triggers[0].show();
7667 });Ext.ns('Ext.ux.form');
7670 * @class Ext.ux.form.SelectBox
7671 * @extends Ext.form.ComboBox
7672 * <p>Makes a ComboBox more closely mimic an HTML SELECT. Supports clicking and dragging
7673 * through the list, with item selection occurring when the mouse button is released.
7674 * When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}
7675 * on inner elements. Re-enabling editable after calling this will NOT work.</p>
7676 * @author Corey Gilmore http://extjs.com/forum/showthread.php?t=6392
7677 * @history 2007-07-08 jvs
7678 * Slight mods for Ext 2.0
7681 Ext.ux.form.SelectBox = Ext.extend(Ext.form.ComboBox, {
7682 constructor: function(config){
7683 this.searchResetDelay = 1000;
7684 config = config || {};
7685 config = Ext.apply(config || {}, {
7687 forceSelection: true,
7689 lastSearchTerm: false,
7690 triggerAction: 'all',
7694 Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);
7696 this.lastSelectedIndex = this.selectedIndex || 0;
7699 initEvents : function(){
7700 Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);
7701 // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE
7702 this.el.on('keydown', this.keySearch, this, true);
7703 this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);
7706 keySearch : function(e, target, options) {
7707 var raw = e.getKey();
7708 var key = String.fromCharCode(raw);
7711 if( !this.store.getCount() ) {
7716 case Ext.EventObject.HOME:
7721 case Ext.EventObject.END:
7726 case Ext.EventObject.PAGEDOWN:
7727 this.selectNextPage();
7731 case Ext.EventObject.PAGEUP:
7732 this.selectPrevPage();
7737 // skip special keys other than the shift key
7738 if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {
7741 if( this.lastSearchTerm == key ) {
7742 startIndex = this.lastSelectedIndex;
7744 this.search(this.displayField, key, startIndex);
7745 this.cshTask.delay(this.searchResetDelay);
7748 onRender : function(ct, position) {
7749 this.store.on('load', this.calcRowsPerPage, this);
7750 Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);
7751 if( this.mode == 'local' ) {
7753 this.calcRowsPerPage();
7757 onSelect : function(record, index, skipCollapse){
7758 if(this.fireEvent('beforeselect', this, record, index) !== false){
7759 this.setValue(record.data[this.valueField || this.displayField]);
7760 if( !skipCollapse ) {
7763 this.lastSelectedIndex = index + 1;
7764 this.fireEvent('select', this, record, index);
7768 afterRender : function() {
7769 Ext.ux.form.SelectBox.superclass.afterRender.apply(this, arguments);
7771 this.el.swallowEvent('mousedown', true);
7773 this.el.unselectable();
7774 this.innerList.unselectable();
7775 this.trigger.unselectable();
7776 this.innerList.on('mouseup', function(e, target, options) {
7777 if( target.id && target.id == this.innerList.id ) {
7783 this.innerList.on('mouseover', function(e, target, options) {
7784 if( target.id && target.id == this.innerList.id ) {
7787 this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;
7788 this.cshTask.delay(this.searchResetDelay);
7791 this.trigger.un('click', this.onTriggerClick, this);
7792 this.trigger.on('mousedown', function(e, target, options) {
7794 this.onTriggerClick();
7797 this.on('collapse', function(e, target, options) {
7798 Ext.getDoc().un('mouseup', this.collapseIf, this);
7801 this.on('expand', function(e, target, options) {
7802 Ext.getDoc().on('mouseup', this.collapseIf, this);
7806 clearSearchHistory : function() {
7807 this.lastSelectedIndex = 0;
7808 this.lastSearchTerm = false;
7811 selectFirst : function() {
7812 this.focusAndSelect(this.store.data.first());
7815 selectLast : function() {
7816 this.focusAndSelect(this.store.data.last());
7819 selectPrevPage : function() {
7820 if( !this.rowHeight ) {
7823 var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);
7824 this.focusAndSelect(this.store.getAt(index));
7827 selectNextPage : function() {
7828 if( !this.rowHeight ) {
7831 var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);
7832 this.focusAndSelect(this.store.getAt(index));
7835 search : function(field, value, startIndex) {
7836 field = field || this.displayField;
7837 this.lastSearchTerm = value;
7838 var index = this.store.find.apply(this.store, arguments);
7839 if( index !== -1 ) {
7840 this.focusAndSelect(index);
7844 focusAndSelect : function(record) {
7845 var index = Ext.isNumber(record) ? record : this.store.indexOf(record);
7846 this.select(index, this.isExpanded());
7847 this.onSelect(this.store.getAt(index), index, this.isExpanded());
7850 calcRowsPerPage : function() {
7851 if( this.store.getCount() ) {
7852 this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();
7853 this.rowsPerPage = this.maxHeight / this.rowHeight;
7855 this.rowHeight = false;
7861 Ext.reg('selectbox', Ext.ux.form.SelectBox);
7864 Ext.ux.SelectBox = Ext.ux.form.SelectBox;
7866 * Plugin for PagingToolbar which replaces the textfield input with a slider
7868 Ext.ux.SlidingPager = Ext.extend(Object, {
7869 init : function(pbar){
7870 var idx = pbar.items.indexOf(pbar.inputItem);
7871 Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
7874 var slider = new Ext.Slider({
7878 plugins: new Ext.slider.Tip({
7879 getText : function(thumb) {
7880 return String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
7884 changecomplete: function(s, v){
7889 pbar.insert(idx + 1, slider);
7891 change: function(pb, data){
7892 slider.setMaxValue(data.pages);
7893 slider.setValue(data.activePage);
7897 });Ext.ns('Ext.ux.form');
7900 * @class Ext.ux.form.SpinnerField
7901 * @extends Ext.form.NumberField
7902 * Creates a field utilizing Ext.ux.Spinner
7903 * @xtype spinnerfield
7905 Ext.ux.form.SpinnerField = Ext.extend(Ext.form.NumberField, {
7908 autoSize: Ext.emptyFn,
7909 onBlur: Ext.emptyFn,
7910 adjustSize: Ext.BoxComponent.prototype.adjustSize,
7912 constructor: function(config) {
7913 var spinnerConfig = Ext.copyTo({}, config, 'incrementValue,alternateIncrementValue,accelerate,defaultValue,triggerClass,splitterClass');
7915 var spl = this.spinner = new Ext.ux.Spinner(spinnerConfig);
7917 var plugins = config.plugins
7918 ? (Ext.isArray(config.plugins)
7919 ? config.plugins.push(spl)
7920 : [config.plugins, spl])
7923 Ext.ux.form.SpinnerField.superclass.constructor.call(this, Ext.apply(config, {plugins: plugins}));
7927 getResizeEl: function(){
7932 getPositionEl: function(){
7937 alignErrorIcon: function(){
7939 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
7943 validateBlur: function(){
7948 Ext.reg('spinnerfield', Ext.ux.form.SpinnerField);
7951 Ext.form.SpinnerField = Ext.ux.form.SpinnerField;
7953 * @class Ext.ux.Spinner
7954 * @extends Ext.util.Observable
7955 * Creates a Spinner control utilized by Ext.ux.form.SpinnerField
7957 Ext.ux.Spinner = Ext.extend(Ext.util.Observable, {
7959 alternateIncrementValue: 5,
7960 triggerClass: 'x-form-spinner-trigger',
7961 splitterClass: 'x-form-spinner-splitter',
7962 alternateKey: Ext.EventObject.shiftKey,
7966 constructor: function(config){
7967 Ext.ux.Spinner.superclass.constructor.call(this, config);
7968 Ext.apply(this, config);
7969 this.mimicing = false;
7972 init: function(field){
7975 field.afterMethod('onRender', this.doRender, this);
7976 field.afterMethod('onEnable', this.doEnable, this);
7977 field.afterMethod('onDisable', this.doDisable, this);
7978 field.afterMethod('afterRender', this.doAfterRender, this);
7979 field.afterMethod('onResize', this.doResize, this);
7980 field.afterMethod('onFocus', this.doFocus, this);
7981 field.beforeMethod('onDestroy', this.doDestroy, this);
7984 doRender: function(ct, position){
7985 var el = this.el = this.field.getEl();
7989 f.wrap = this.wrap = el.wrap({
7990 cls: "x-form-field-wrap"
7994 this.wrap = f.wrap.addClass('x-form-field-wrap');
7997 this.trigger = this.wrap.createChild({
7999 src: Ext.BLANK_IMAGE_URL,
8000 cls: "x-form-trigger " + this.triggerClass
8004 this.wrap.setWidth(el.getWidth() + this.trigger.getWidth());
8007 this.splitter = this.wrap.createChild({
8009 cls: this.splitterClass,
8010 style: 'width:13px; height:2px;'
8012 this.splitter.setRight((Ext.isIE) ? 1 : 2).setTop(10).show();
8014 this.proxy = this.trigger.createProxy('', this.splitter, true);
8015 this.proxy.addClass("x-form-spinner-proxy");
8016 this.proxy.setStyle('left', '0px');
8017 this.proxy.setSize(14, 1);
8019 this.dd = new Ext.dd.DDProxy(this.splitter.dom.id, "SpinnerDrag", {
8020 dragElId: this.proxy.id
8027 doAfterRender: function(){
8029 if (Ext.isIE && this.el.getY() != (y = this.trigger.getY())) {
8035 doEnable: function(){
8037 this.wrap.removeClass(this.field.disabledClass);
8041 doDisable: function(){
8043 this.wrap.addClass(this.field.disabledClass);
8044 this.el.removeClass(this.field.disabledClass);
8048 doResize: function(w, h){
8049 if (typeof w == 'number') {
8050 this.el.setWidth(w - this.trigger.getWidth());
8052 this.wrap.setWidth(this.el.getWidth() + this.trigger.getWidth());
8055 doFocus: function(){
8056 if (!this.mimicing) {
8057 this.wrap.addClass('x-trigger-wrap-focus');
8058 this.mimicing = true;
8059 Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {
8062 this.el.on('keydown', this.checkTab, this);
8067 checkTab: function(e){
8068 if (e.getKey() == e.TAB) {
8074 mimicBlur: function(e){
8075 if (!this.wrap.contains(e.target) && this.field.validateBlur(e)) {
8081 triggerBlur: function(){
8082 this.mimicing = false;
8083 Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
8084 this.el.un("keydown", this.checkTab, this);
8085 this.field.beforeBlur();
8086 this.wrap.removeClass('x-trigger-wrap-focus');
8087 this.field.onBlur.call(this.field);
8090 initTrigger: function(){
8091 this.trigger.addClassOnOver('x-form-trigger-over');
8092 this.trigger.addClassOnClick('x-form-trigger-click');
8095 initSpinner: function(){
8096 this.field.addEvents({
8102 this.keyNav = new Ext.KeyNav(this.el, {
8108 "down": function(e){
8113 "pageUp": function(e){
8115 this.onSpinUpAlternate();
8118 "pageDown": function(e){
8120 this.onSpinDownAlternate();
8126 this.repeater = new Ext.util.ClickRepeater(this.trigger, {
8127 accelerate: this.accelerate
8129 this.field.mon(this.repeater, "click", this.onTriggerClick, this, {
8130 preventDefault: true
8133 this.field.mon(this.trigger, {
8134 mouseover: this.onMouseOver,
8135 mouseout: this.onMouseOut,
8136 mousemove: this.onMouseMove,
8137 mousedown: this.onMouseDown,
8138 mouseup: this.onMouseUp,
8140 preventDefault: true
8143 this.field.mon(this.wrap, "mousewheel", this.handleMouseWheel, this);
8145 this.dd.setXConstraint(0, 0, 10)
8146 this.dd.setYConstraint(1500, 1500, 10);
8147 this.dd.endDrag = this.endDrag.createDelegate(this);
8148 this.dd.startDrag = this.startDrag.createDelegate(this);
8149 this.dd.onDrag = this.onDrag.createDelegate(this);
8152 onMouseOver: function(){
8153 if (this.disabled) {
8156 var middle = this.getMiddle();
8157 this.tmpHoverClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-overup' : 'x-form-spinner-overdown';
8158 this.trigger.addClass(this.tmpHoverClass);
8162 onMouseOut: function(){
8163 this.trigger.removeClass(this.tmpHoverClass);
8167 onMouseMove: function(){
8168 if (this.disabled) {
8171 var middle = this.getMiddle();
8172 if (((Ext.EventObject.getPageY() > middle) && this.tmpHoverClass == "x-form-spinner-overup") ||
8173 ((Ext.EventObject.getPageY() < middle) && this.tmpHoverClass == "x-form-spinner-overdown")) {
8178 onMouseDown: function(){
8179 if (this.disabled) {
8182 var middle = this.getMiddle();
8183 this.tmpClickClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-clickup' : 'x-form-spinner-clickdown';
8184 this.trigger.addClass(this.tmpClickClass);
8188 onMouseUp: function(){
8189 this.trigger.removeClass(this.tmpClickClass);
8193 onTriggerClick: function(){
8194 if (this.disabled || this.el.dom.readOnly) {
8197 var middle = this.getMiddle();
8198 var ud = (Ext.EventObject.getPageY() < middle) ? 'Up' : 'Down';
8199 this['onSpin' + ud]();
8203 getMiddle: function(){
8204 var t = this.trigger.getTop();
8205 var h = this.trigger.getHeight();
8206 var middle = t + (h / 2);
8211 //checks if control is allowed to spin
8212 isSpinnable: function(){
8213 if (this.disabled || this.el.dom.readOnly) {
8214 Ext.EventObject.preventDefault(); //prevent scrolling when disabled/readonly
8220 handleMouseWheel: function(e){
8221 //disable scrolling when not focused
8222 if (this.wrap.hasClass('x-trigger-wrap-focus') == false) {
8226 var delta = e.getWheelDelta();
8239 startDrag: function(){
8241 this._previousY = Ext.fly(this.dd.getDragEl()).getTop();
8245 endDrag: function(){
8251 if (this.disabled) {
8254 var y = Ext.fly(this.dd.getDragEl()).getTop();
8257 if (this._previousY > y) {
8260 if (this._previousY < y) {
8264 this['onSpin' + ud]();
8267 this._previousY = y;
8271 onSpinUp: function(){
8272 if (this.isSpinnable() == false) {
8275 if (Ext.EventObject.shiftKey == true) {
8276 this.onSpinUpAlternate();
8280 this.spin(false, false);
8282 this.field.fireEvent("spin", this);
8283 this.field.fireEvent("spinup", this);
8287 onSpinDown: function(){
8288 if (this.isSpinnable() == false) {
8291 if (Ext.EventObject.shiftKey == true) {
8292 this.onSpinDownAlternate();
8296 this.spin(true, false);
8298 this.field.fireEvent("spin", this);
8299 this.field.fireEvent("spindown", this);
8303 onSpinUpAlternate: function(){
8304 if (this.isSpinnable() == false) {
8307 this.spin(false, true);
8308 this.field.fireEvent("spin", this);
8309 this.field.fireEvent("spinup", this);
8313 onSpinDownAlternate: function(){
8314 if (this.isSpinnable() == false) {
8317 this.spin(true, true);
8318 this.field.fireEvent("spin", this);
8319 this.field.fireEvent("spindown", this);
8322 spin: function(down, alternate){
8323 var v = parseFloat(this.field.getValue());
8324 var incr = (alternate == true) ? this.alternateIncrementValue : this.incrementValue;
8325 (down == true) ? v -= incr : v += incr;
8327 v = (isNaN(v)) ? this.defaultValue : v;
8328 v = this.fixBoundries(v);
8329 this.field.setRawValue(v);
8332 fixBoundries: function(value){
8335 if (this.field.minValue != undefined && v < this.field.minValue) {
8336 v = this.field.minValue;
8338 if (this.field.maxValue != undefined && v > this.field.maxValue) {
8339 v = this.field.maxValue;
8342 return this.fixPrecision(v);
8346 fixPrecision: function(value){
8347 var nan = isNaN(value);
8348 if (!this.field.allowDecimals || this.field.decimalPrecision == -1 || nan || !value) {
8349 return nan ? '' : value;
8351 return parseFloat(parseFloat(value).toFixed(this.field.decimalPrecision));
8354 doDestroy: function(){
8356 this.trigger.remove();
8360 delete this.field.wrap;
8363 if (this.splitter) {
8364 this.splitter.remove();
8373 this.proxy.remove();
8376 if (this.repeater) {
8377 this.repeater.purgeListeners();
8383 Ext.form.Spinner = Ext.ux.Spinner;Ext.ux.Spotlight = function(config){
8384 Ext.apply(this, config);
8386 Ext.ux.Spotlight.prototype = {
8395 createElements : function(){
8396 var bd = Ext.getBody();
8398 this.right = bd.createChild({cls:'x-spotlight'});
8399 this.left = bd.createChild({cls:'x-spotlight'});
8400 this.top = bd.createChild({cls:'x-spotlight'});
8401 this.bottom = bd.createChild({cls:'x-spotlight'});
8403 this.all = new Ext.CompositeElement([this.right, this.left, this.top, this.bottom]);
8406 show : function(el, callback, scope){
8408 this.show.defer(50, this, [el, callback, scope]);
8411 this.el = Ext.get(el);
8413 this.createElements();
8416 this.all.setDisplayed('');
8417 this.applyBounds(true, false);
8419 Ext.EventManager.onWindowResize(this.syncSize, this);
8420 this.applyBounds(false, this.animate, false, callback, scope);
8422 this.applyBounds(false, false, false, callback, scope); // all these booleans look hideous
8426 hide : function(callback, scope){
8428 this.hide.defer(50, this, [callback, scope]);
8431 Ext.EventManager.removeResizeListener(this.syncSize, this);
8432 this.applyBounds(true, this.animate, true, callback, scope);
8435 doHide : function(){
8436 this.active = false;
8437 this.all.setDisplayed(false);
8440 syncSize : function(){
8441 this.applyBounds(false, false);
8444 applyBounds : function(basePts, anim, doHide, callback, scope){
8446 var rg = this.el.getRegion();
8448 var dw = Ext.lib.Dom.getViewWidth(true);
8449 var dh = Ext.lib.Dom.getViewHeight(true);
8451 var c = 0, cb = false;
8454 callback: function(){
8457 this.animated = false;
8461 Ext.callback(callback, scope, [this]);
8465 duration: this.duration,
8468 this.animated = true;
8471 this.right.setBounds(
8473 basePts ? dh : rg.top,
8475 basePts ? 0 : (dh - rg.top),
8478 this.left.setBounds(
8482 basePts ? 0 : rg.bottom,
8486 basePts ? dw : rg.left,
8488 basePts ? 0 : dw - rg.left,
8492 this.bottom.setBounds(
8495 basePts ? 0 : rg.right,
8504 Ext.callback(callback, scope, [this]);
8509 destroy : function(){
8522 Ext.Spotlight = Ext.ux.Spotlight;/**
8523 * @class Ext.ux.StatusBar
8524 * <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to
8525 * supporting the standard {@link Ext.Toolbar} interface for adding buttons, menus and other items, the StatusBar
8526 * provides a greedy status element that can be aligned to either side and has convenient methods for setting the
8527 * status text and icon. You can also indicate that something is processing using the {@link #showBusy} method.</p>
8532 bbar: new Ext.ux.StatusBar({
8535 // defaults to use when the status is cleared:
8536 defaultText: 'Default status text',
8537 defaultIconCls: 'default-icon',
8539 // values to set initially:
8541 iconCls: 'ready-icon',
8543 // any standard Toolbar items:
8546 }, '-', 'Plain Text']
8550 // Update the status bar later in code:
8551 var sb = Ext.getCmp('my-status');
8555 clear: true // auto-clear after a set interval
8558 // Set the status bar to show that something is processing:
8563 sb.clearStatus(); // once completeed
8565 * @extends Ext.Toolbar
8567 * Creates a new StatusBar
8568 * @param {Object/Array} config A config object
8570 Ext.ux.StatusBar = Ext.extend(Ext.Toolbar, {
8572 * @cfg {String} statusAlign
8573 * The alignment of the status element within the overall StatusBar layout. When the StatusBar is rendered,
8574 * it creates an internal div containing the status text and icon. Any additional Toolbar items added in the
8575 * StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be
8576 * rendered, in added order, to the opposite side. The status element is greedy, so it will automatically
8577 * expand to take up all sapce left over by any other items. Example usage:
8579 // Create a left-aligned status bar containing a button,
8580 // separator and text item that will be right-aligned (default):
8584 bbar: new Ext.ux.StatusBar({
8585 defaultText: 'Default status text',
8589 }, '-', 'Plain Text']
8593 // By adding the statusAlign config, this will create the
8594 // exact same toolbar, except the status and toolbar item
8595 // layout will be reversed from the previous example:
8599 bbar: new Ext.ux.StatusBar({
8600 defaultText: 'Default status text',
8602 statusAlign: 'right',
8605 }, '-', 'Plain Text']
8611 * @cfg {String} defaultText
8612 * The default {@link #text} value. This will be used anytime the status bar is cleared with the
8613 * <tt>useDefaults:true</tt> option (defaults to '').
8616 * @cfg {String} defaultIconCls
8617 * The default {@link #iconCls} value (see the iconCls docs for additional details about customizing the icon).
8618 * This will be used anytime the status bar is cleared with the <tt>useDefaults:true</tt> option (defaults to '').
8621 * @cfg {String} text
8622 * A string that will be <b>initially</b> set as the status message. This string
8623 * will be set as innerHTML (html tags are accepted) for the toolbar item.
8624 * If not specified, the value set for <code>{@link #defaultText}</code>
8628 * @cfg {String} iconCls
8629 * A CSS class that will be <b>initially</b> set as the status bar icon and is
8630 * expected to provide a background image (defaults to '').
8631 * Example usage:<pre><code>
8632 // Example CSS rule:
8633 .x-statusbar .x-status-custom {
8635 background: transparent url(images/custom-icon.gif) no-repeat 3px 2px;
8638 // Setting a default icon:
8639 var sb = new Ext.ux.StatusBar({
8640 defaultIconCls: 'x-status-custom'
8643 // Changing the icon:
8646 iconCls: 'x-status-custom'
8653 * The base class applied to the containing element for this component on render (defaults to 'x-statusbar')
8655 cls : 'x-statusbar',
8657 * @cfg {String} busyIconCls
8658 * The default <code>{@link #iconCls}</code> applied when calling
8659 * <code>{@link #showBusy}</code> (defaults to <tt>'x-status-busy'</tt>).
8660 * It can be overridden at any time by passing the <code>iconCls</code>
8661 * argument into <code>{@link #showBusy}</code>.
8663 busyIconCls : 'x-status-busy',
8665 * @cfg {String} busyText
8666 * The default <code>{@link #text}</code> applied when calling
8667 * <code>{@link #showBusy}</code> (defaults to <tt>'Loading...'</tt>).
8668 * It can be overridden at any time by passing the <code>text</code>
8669 * argument into <code>{@link #showBusy}</code>.
8671 busyText : 'Loading...',
8673 * @cfg {Number} autoClear
8674 * The number of milliseconds to wait after setting the status via
8675 * <code>{@link #setStatus}</code> before automatically clearing the status
8676 * text and icon (defaults to <tt>5000</tt>). Note that this only applies
8677 * when passing the <tt>clear</tt> argument to <code>{@link #setStatus}</code>
8678 * since that is the only way to defer clearing the status. This can
8679 * be overridden by specifying a different <tt>wait</tt> value in
8680 * <code>{@link #setStatus}</code>. Calls to <code>{@link #clearStatus}</code>
8681 * always clear the status bar immediately and ignore this value.
8686 * @cfg {String} emptyText
8687 * The text string to use if no text has been set. Defaults to
8688 * <tt>' '</tt>). If there are no other items in the toolbar using
8689 * an empty string (<tt>''</tt>) for this value would end up in the toolbar
8690 * height collapsing since the empty string will not maintain the toolbar
8691 * height. Use <tt>''</tt> if the toolbar should collapse in height
8692 * vertically when no text is specified and there are no other items in
8695 emptyText : ' ',
8701 initComponent : function(){
8702 if(this.statusAlign=='right'){
8703 this.cls += ' x-status-right';
8705 Ext.ux.StatusBar.superclass.initComponent.call(this);
8709 afterRender : function(){
8710 Ext.ux.StatusBar.superclass.afterRender.call(this);
8712 var right = this.statusAlign == 'right';
8713 this.currIconCls = this.iconCls || this.defaultIconCls;
8714 this.statusEl = new Ext.Toolbar.TextItem({
8715 cls: 'x-status-text ' + (this.currIconCls || ''),
8716 text: this.text || this.defaultText || ''
8721 this.add(this.statusEl);
8723 this.insert(0, this.statusEl);
8724 this.insert(1, '->');
8730 * Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the
8731 * status that was set after a specified interval.
8732 * @param {Object/String} config A config object specifying what status to set, or a string assumed
8733 * to be the status text (and all other options are defaulted as explained below). A config
8734 * object containing any or all of the following properties can be passed:<ul>
8735 * <li><tt>text</tt> {String} : (optional) The status text to display. If not specified, any current
8736 * status text will remain unchanged.</li>
8737 * <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see
8738 * {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>
8739 * <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will
8740 * automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not
8741 * specified, the new status will not be auto-cleared and will stay until updated again or cleared using
8742 * {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},
8743 * {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,
8744 * it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.
8745 * All other options will be defaulted as with the boolean option. To customize any other options,
8746 * you can pass an object in the format:<ul>
8747 * <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing
8748 * (defaults to {@link #autoClear}).</li>
8749 * <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback
8750 * executes (defaults to true which fades the status out).</li>
8751 * <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls
8752 * (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>
8754 * Example usage:<pre><code>
8755 // Simple call to update the text
8756 statusBar.setStatus('New status');
8758 // Set the status and icon, auto-clearing with default options:
8759 statusBar.setStatus({
8761 iconCls: 'x-status-custom',
8765 // Auto-clear with custom options:
8766 statusBar.setStatus({
8768 iconCls: 'x-status-custom',
8776 * @return {Ext.ux.StatusBar} this
8778 setStatus : function(o){
8781 if(typeof o == 'string'){
8784 if(o.text !== undefined){
8785 this.setText(o.text);
8787 if(o.iconCls !== undefined){
8788 this.setIcon(o.iconCls);
8793 wait = this.autoClear,
8794 defaults = {useDefaults: true, anim: true};
8796 if(typeof c == 'object'){
8797 c = Ext.applyIf(c, defaults);
8801 }else if(typeof c == 'number'){
8804 }else if(typeof c == 'boolean'){
8808 c.threadId = this.activeThreadId;
8809 this.clearStatus.defer(wait, this, [c]);
8815 * Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.
8816 * @param {Object} config (optional) A config object containing any or all of the following properties. If this
8817 * object is not specified the status will be cleared using the defaults below:<ul>
8818 * <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults
8819 * to false which clears immediately).</li>
8820 * <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and
8821 * {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>
8823 * @return {Ext.ux.StatusBar} this
8825 clearStatus : function(o){
8828 if(o.threadId && o.threadId !== this.activeThreadId){
8829 // this means the current call was made internally, but a newer
8830 // thread has set a message since this call was deferred. Since
8831 // we don't want to overwrite a newer message just ignore.
8835 var text = o.useDefaults ? this.defaultText : this.emptyText,
8836 iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';
8839 // animate the statusEl Ext.Element
8840 this.statusEl.el.fadeOut({
8844 callback: function(){
8850 this.statusEl.el.show();
8854 // hide/show the el to avoid jumpy text or icon
8855 this.statusEl.hide();
8860 this.statusEl.show();
8866 * Convenience method for setting the status text directly. For more flexible options see {@link #setStatus}.
8867 * @param {String} text (optional) The text to set (defaults to '')
8868 * @return {Ext.ux.StatusBar} this
8870 setText : function(text){
8871 this.activeThreadId++;
8872 this.text = text || '';
8874 this.statusEl.setText(this.text);
8880 * Returns the current status text.
8881 * @return {String} The status text
8883 getText : function(){
8888 * Convenience method for setting the status icon directly. For more flexible options see {@link #setStatus}.
8889 * See {@link #iconCls} for complete details about customizing the icon.
8890 * @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)
8891 * @return {Ext.ux.StatusBar} this
8893 setIcon : function(cls){
8894 this.activeThreadId++;
8898 if(this.currIconCls){
8899 this.statusEl.removeClass(this.currIconCls);
8900 this.currIconCls = null;
8903 this.statusEl.addClass(cls);
8904 this.currIconCls = cls;
8907 this.currIconCls = cls;
8913 * Convenience method for setting the status text and icon to special values that are pre-configured to indicate
8914 * a "busy" state, usually for loading or processing activities.
8915 * @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a
8916 * string to use as the status text (in which case all other options for setStatus will be defaulted). Use the
8917 * <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}
8918 * and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and
8919 * {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.
8920 * @return {Ext.ux.StatusBar} this
8922 showBusy : function(o){
8923 if(typeof o == 'string'){
8926 o = Ext.applyIf(o || {}, {
8927 text: this.busyText,
8928 iconCls: this.busyIconCls
8930 return this.setStatus(o);
8933 Ext.reg('statusbar', Ext.ux.StatusBar);
8935 * @class Ext.ux.TabCloseMenu
8937 * Plugin (ptype = 'tabclosemenu') for adding a close context menu to tabs. Note that the menu respects
8938 * the closable configuration on the tab. As such, commands like remove others and remove all will not
8939 * remove items that are not closable.
8942 * @param {Object} config The configuration options
8943 * @ptype tabclosemenu
8945 Ext.ux.TabCloseMenu = Ext.extend(Object, {
8947 * @cfg {String} closeTabText
8948 * The text for closing the current tab. Defaults to <tt>'Close Tab'</tt>.
8950 closeTabText: 'Close Tab',
8953 * @cfg {String} closeOtherTabsText
8954 * The text for closing all tabs except the current one. Defaults to <tt>'Close Other Tabs'</tt>.
8956 closeOtherTabsText: 'Close Other Tabs',
8959 * @cfg {Boolean} showCloseAll
8960 * Indicates whether to show the 'Close All' option. Defaults to <tt>true</tt>.
8965 * @cfg {String} closeAllTabsText
8966 * <p>The text for closing all tabs. Defaults to <tt>'Close All Tabs'</tt>.
8968 closeAllTabsText: 'Close All Tabs',
8970 constructor : function(config){
8971 Ext.apply(this, config || {});
8975 init : function(tabs){
8979 contextmenu: this.onContextMenu,
8980 destroy: this.destroy
8984 destroy : function(){
8985 Ext.destroy(this.menu);
8992 onContextMenu : function(tabs, item, e){
8994 var m = this.createMenu(),
8996 disableOthers = true,
8997 closeAll = m.getComponent('closeall');
8999 m.getComponent('close').setDisabled(!item.closable);
9000 tabs.items.each(function(){
9004 disableOthers = false;
9009 m.getComponent('closeothers').setDisabled(disableOthers);
9011 closeAll.setDisabled(disableAll);
9015 m.showAt(e.getPoint());
9018 createMenu : function(){
9022 text: this.closeTabText,
9024 handler: this.onClose
9026 if(this.showCloseAll){
9030 itemId: 'closeothers',
9031 text: this.closeOtherTabsText,
9033 handler: this.onCloseOthers
9035 if(this.showCloseAll){
9038 text: this.closeAllTabsText,
9040 handler: this.onCloseAll
9043 this.menu = new Ext.menu.Menu({
9050 onClose : function(){
9051 this.tabs.remove(this.active);
9054 onCloseOthers : function(){
9058 onCloseAll : function(){
9059 this.doClose(false);
9062 doClose : function(excludeActive){
9064 this.tabs.items.each(function(item){
9066 if(!excludeActive || item != this.active){
9071 Ext.each(items, function(item){
9072 this.tabs.remove(item);
9077 Ext.preg('tabclosemenu', Ext.ux.TabCloseMenu);Ext.ns('Ext.ux.grid');
9080 * @class Ext.ux.grid.TableGrid
9081 * @extends Ext.grid.GridPanel
9082 * A Grid which creates itself from an existing HTML table element.
9084 * 2007-03-01 Original version by Nige "Animal" White
9085 * 2007-03-10 jvs Slightly refactored to reuse existing classes * @constructor
9086 * @param {String/HTMLElement/Ext.Element} table The table element from which this grid will be created -
9087 * The table MUST have some type of size defined for the grid to fill. The container will be
9088 * automatically set to position relative if it isn't already.
9089 * @param {Object} config A config object that sets properties on this grid and has two additional (optional)
9090 * properties: fields and columns which allow for customizing data fields and columns for this grid.
9092 Ext.ux.grid.TableGrid = function(table, config){
9095 Ext.apply(this, config);
9096 var cf = config.fields || [], ch = config.columns || [];
9097 table = Ext.get(table);
9099 var ct = table.insertSibling();
9101 var fields = [], cols = [];
9102 var headers = table.query("thead th");
9103 for (var i = 0, h; h = headers[i]; i++) {
9104 var text = h.innerHTML;
9105 var name = 'tcol-' + i;
9107 fields.push(Ext.applyIf(cf[i] ||
9110 mapping: 'td:nth(' + (i + 1) + ')/@innerHTML'
9113 cols.push(Ext.applyIf(ch[i] ||
9117 'width': h.offsetWidth,
9123 var ds = new Ext.data.Store({
9124 reader: new Ext.data.XmlReader({
9129 ds.loadData(table.dom);
9131 var cm = new Ext.grid.ColumnModel(cols);
9133 if (config.width || config.height) {
9134 ct.setSize(config.width || 'auto', config.height || 'auto');
9137 ct.setWidth(table.getWidth());
9140 if (config.remove !== false) {
9147 'sm': new Ext.grid.RowSelectionModel(),
9151 Ext.ux.grid.TableGrid.superclass.constructor.call(this, ct, {});
9154 Ext.extend(Ext.ux.grid.TableGrid, Ext.grid.GridPanel);
9157 Ext.grid.TableGrid = Ext.ux.grid.TableGrid;
9160 * @class Ext.ux.TabScrollerMenu
9162 * Plugin (ptype = 'tabscrollermenu') for adding a tab scroller menu to tabs.
9164 * @param {Object} config Configuration options
9165 * @ptype tabscrollermenu
9167 Ext.ux.TabScrollerMenu = Ext.extend(Object, {
9169 * @cfg {Number} pageSize How many items to allow per submenu.
9173 * @cfg {Number} maxText How long should the title of each {@link Ext.menu.Item} be.
9177 * @cfg {String} menuPrefixText Text to prefix the submenus.
9179 menuPrefixText : 'Items',
9180 constructor : function(config) {
9181 config = config || {};
9182 Ext.apply(this, config);
9185 init : function(tabPanel) {
9186 Ext.apply(tabPanel, this.parentOverrides);
9188 tabPanel.tabScrollerMenu = this;
9196 var newFn = tabPanel.createScrollers.createSequence(thisRef.createPanelsMenu, this);
9197 tabPanel.createScrollers = newFn;
9202 // private && sequeneced
9203 createPanelsMenu : function() {
9204 var h = this.stripWrap.dom.offsetHeight;
9206 //move the right menu item to the left 18px
9207 var rtScrBtn = this.header.dom.firstChild;
9208 Ext.fly(rtScrBtn).applyStyles({
9212 var stripWrap = Ext.get(this.strip.dom.parentNode);
9213 stripWrap.applyStyles({
9214 'margin-right' : '36px'
9217 // Add the new righthand menu
9218 var scrollMenu = this.header.insertFirst({
9219 cls:'x-tab-tabmenu-right'
9221 scrollMenu.setHeight(h);
9222 scrollMenu.addClassOnOver('x-tab-tabmenu-over');
9223 scrollMenu.on('click', this.showTabsMenu, this);
9225 this.scrollLeft.show = this.scrollLeft.show.createSequence(function() {
9229 this.scrollLeft.hide = this.scrollLeft.hide.createSequence(function() {
9235 * Returns an the current page size (this.pageSize);
9236 * @return {Number} this.pageSize The current page size.
9238 getPageSize : function() {
9239 return this.pageSize;
9242 * Sets the number of menu items per submenu "page size".
9243 * @param {Number} pageSize The page size
9245 setPageSize : function(pageSize) {
9246 this.pageSize = pageSize;
9249 * Returns the current maxText length;
9250 * @return {Number} this.maxText The current max text length.
9252 getMaxText : function() {
9253 return this.maxText;
9256 * Sets the maximum text size for each menu item.
9257 * @param {Number} t The max text per each menu item.
9259 setMaxText : function(t) {
9263 * Returns the current menu prefix text String.;
9264 * @return {String} this.menuPrefixText The current menu prefix text.
9266 getMenuPrefixText : function() {
9267 return this.menuPrefixText;
9270 * Sets the menu prefix text String.
9271 * @param {String} t The menu prefix text.
9273 setMenuPrefixText : function(t) {
9274 this.menuPrefixText = t;
9276 // private && applied to the tab panel itself.
9278 // all execute within the scope of the tab panel
9280 showTabsMenu : function(e) {
9281 if (this.tabsMenu) {
9282 this.tabsMenu.destroy();
9283 this.un('destroy', this.tabsMenu.destroy, this.tabsMenu);
9284 this.tabsMenu = null;
9286 this.tabsMenu = new Ext.menu.Menu();
9287 this.on('destroy', this.tabsMenu.destroy, this.tabsMenu);
9289 this.generateTabMenuItems();
9291 var target = Ext.get(e.getTarget());
9292 var xy = target.getXY();
9294 //Y param + 24 pixels
9297 this.tabsMenu.showAt(xy);
9300 generateTabMenuItems : function() {
9301 var curActive = this.getActiveTab();
9302 var totalItems = this.items.getCount();
9303 var pageSize = this.tabScrollerMenu.getPageSize();
9306 if (totalItems > pageSize) {
9307 var numSubMenus = Math.floor(totalItems / pageSize);
9308 var remainder = totalItems % pageSize;
9310 // Loop through all of the items and create submenus in chunks of 10
9311 for (var i = 0 ; i < numSubMenus; i++) {
9312 var curPage = (i + 1) * pageSize;
9316 for (var x = 0; x < pageSize; x++) {
9317 index = x + curPage - pageSize;
9318 var item = this.items.get(index);
9319 menuItems.push(this.autoGenMenuItem(item));
9323 text : this.tabScrollerMenu.getMenuPrefixText() + ' ' + (curPage - pageSize + 1) + ' - ' + curPage,
9329 if (remainder > 0) {
9330 var start = numSubMenus * pageSize;
9332 for (var i = start ; i < totalItems; i ++ ) {
9333 var item = this.items.get(i);
9334 menuItems.push(this.autoGenMenuItem(item));
9338 text : this.tabScrollerMenu.menuPrefixText + ' ' + (start + 1) + ' - ' + (start + menuItems.length),
9345 this.items.each(function(item) {
9346 if (item.id != curActive.id && ! item.hidden) {
9347 menuItems.push(this.autoGenMenuItem(item));
9353 autoGenMenuItem : function(item) {
9354 var maxText = this.tabScrollerMenu.getMaxText();
9355 var text = Ext.util.Format.ellipsis(item.title, maxText);
9359 handler : this.showTabFromMenu,
9361 disabled : item.disabled,
9363 iconCls : item.iconCls
9368 showTabFromMenu : function(menuItem) {
9369 this.setActiveTab(menuItem.tabToShow);
9374 Ext.reg('tabscrollermenu', Ext.ux.TabScrollerMenu);
9375 Ext.ns('Ext.ux.tree');
9378 * @class Ext.ux.tree.XmlTreeLoader
9379 * @extends Ext.tree.TreeLoader
9380 * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
9381 * Any text value included as a text node in the XML will be added to the parent node as an attribute
9382 * called <tt>innerText</tt>. Also, the tag name of each XML node will be added to the tree node as
9383 * an attribute called <tt>tagName</tt>.</p>
9384 * <p>By default, this class expects that your source XML will provide the necessary attributes on each
9385 * node as expected by the {@link Ext.tree.TreePanel} to display and load properly. However, you can
9386 * provide your own custom processing of node attributes by overriding the {@link #processNode} method
9387 * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
9389 * Creates a new XmlTreeloader.
9390 * @param {Object} config A config object containing config properties.
9392 Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
9394 * @property XML_NODE_ELEMENT
9395 * XML element node (value 1, read-only)
9398 XML_NODE_ELEMENT : 1,
9400 * @property XML_NODE_TEXT
9401 * XML text node (value 3, read-only)
9407 processResponse : function(response, node, callback){
9408 var xmlData = response.responseXML;
9409 var root = xmlData.documentElement || xmlData;
9413 node.appendChild(this.parseXml(root));
9416 if(typeof callback == "function"){
9417 callback(this, node);
9420 this.handleFailure(response);
9425 parseXml : function(node) {
9427 Ext.each(node.childNodes, function(n){
9428 if(n.nodeType == this.XML_NODE_ELEMENT){
9429 var treeNode = this.createNode(n);
9430 if(n.childNodes.length > 0){
9431 var child = this.parseXml(n);
9432 if(typeof child == 'string'){
9433 treeNode.attributes.innerText = child;
9435 treeNode.appendChild(child);
9438 nodes.push(treeNode);
9440 else if(n.nodeType == this.XML_NODE_TEXT){
9441 var text = n.nodeValue.trim();
9442 if(text.length > 0){
9443 return nodes = text;
9452 createNode : function(node){
9454 tagName: node.tagName
9457 Ext.each(node.attributes, function(a){
9458 attr[a.nodeName] = a.nodeValue;
9461 this.processAttributes(attr);
9463 return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
9467 * Template method intended to be overridden by subclasses that need to provide
9468 * custom attribute processing prior to the creation of each TreeNode. This method
9469 * will be passed a config object containing existing TreeNode attribute name/value
9470 * pairs which can be modified as needed directly (no need to return the object).
9472 processAttributes: Ext.emptyFn
9476 Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;
9478 * @class Ext.ux.ValidationStatus
9479 * A {@link Ext.StatusBar} plugin that provides automatic error notification when the
9480 * associated form contains validation errors.
9481 * @extends Ext.Component
9483 * Creates a new ValiationStatus plugin
9484 * @param {Object} config A config object
9486 Ext.ux.ValidationStatus = Ext.extend(Ext.Component, {
9488 * @cfg {String} errorIconCls
9489 * The {@link #iconCls} value to be applied to the status message when there is a
9490 * validation error. Defaults to <tt>'x-status-error'</tt>.
9492 errorIconCls : 'x-status-error',
9494 * @cfg {String} errorListCls
9495 * The css class to be used for the error list when there are validation errors.
9496 * Defaults to <tt>'x-status-error-list'</tt>.
9498 errorListCls : 'x-status-error-list',
9500 * @cfg {String} validIconCls
9501 * The {@link #iconCls} value to be applied to the status message when the form
9502 * validates. Defaults to <tt>'x-status-valid'</tt>.
9504 validIconCls : 'x-status-valid',
9507 * @cfg {String} showText
9508 * The {@link #text} value to be applied when there is a form validation error.
9509 * Defaults to <tt>'The form has errors (click for details...)'</tt>.
9511 showText : 'The form has errors (click for details...)',
9513 * @cfg {String} showText
9514 * The {@link #text} value to display when the error list is displayed.
9515 * Defaults to <tt>'Click again to hide the error list'</tt>.
9517 hideText : 'Click again to hide the error list',
9519 * @cfg {String} submitText
9520 * The {@link #text} value to be applied when the form is being submitted.
9521 * Defaults to <tt>'Saving...'</tt>.
9523 submitText : 'Saving...',
9526 init : function(sb){
9527 sb.on('render', function(){
9528 this.statusBar = sb;
9529 this.monitor = true;
9530 this.errors = new Ext.util.MixedCollection();
9531 this.listAlign = (sb.statusAlign=='right' ? 'br-tr?' : 'bl-tl?');
9534 this.form = Ext.getCmp(this.form).getForm();
9535 this.startMonitoring();
9536 this.form.on('beforeaction', function(f, action){
9537 if(action.type == 'submit'){
9538 // Ignore monitoring while submitting otherwise the field validation
9539 // events cause the status message to reset too early
9540 this.monitor = false;
9543 var startMonitor = function(){
9544 this.monitor = true;
9546 this.form.on('actioncomplete', startMonitor, this);
9547 this.form.on('actionfailed', startMonitor, this);
9549 }, this, {single:true});
9555 // Grab the statusEl after the first layout.
9556 sb.statusEl.getEl().on('click', this.onStatusClick, this, {buffer:200});
9567 startMonitoring : function(){
9568 this.form.items.each(function(f){
9569 f.on('invalid', this.onFieldValidation, this);
9570 f.on('valid', this.onFieldValidation, this);
9575 stopMonitoring : function(){
9576 this.form.items.each(function(f){
9577 f.un('invalid', this.onFieldValidation, this);
9578 f.un('valid', this.onFieldValidation, this);
9583 onDestroy : function(){
9584 this.stopMonitoring();
9585 this.statusBar.statusEl.un('click', this.onStatusClick, this);
9586 Ext.ux.ValidationStatus.superclass.onDestroy.call(this);
9590 onFieldValidation : function(f, msg){
9595 this.errors.add(f.id, {field:f, msg:msg});
9597 this.errors.removeKey(f.id);
9599 this.updateErrorList();
9600 if(this.errors.getCount() > 0){
9601 if(this.statusBar.getText() != this.showText){
9602 this.statusBar.setStatus({text:this.showText, iconCls:this.errorIconCls});
9605 this.statusBar.clearStatus().setIcon(this.validIconCls);
9610 updateErrorList : function(){
9611 if(this.errors.getCount() > 0){
9613 this.errors.each(function(err){
9614 msg += ('<li id="x-err-'+ err.field.id +'"><a href="#">' + err.msg + '</a></li>');
9616 this.getMsgEl().update(msg+'</ul>');
9618 this.getMsgEl().update('');
9623 getMsgEl : function(){
9625 this.msgEl = Ext.DomHelper.append(Ext.getBody(), {
9626 cls: this.errorListCls+' x-hide-offsets'
9629 this.msgEl.on('click', function(e){
9630 var t = e.getTarget('li', 10, true);
9632 Ext.getCmp(t.id.split('x-err-')[1]).focus();
9635 }, this, {stopEvent:true}); // prevent anchor click navigation
9641 showErrors : function(){
9642 this.updateErrorList();
9643 this.getMsgEl().alignTo(this.statusBar.getEl(), this.listAlign).slideIn('b', {duration:0.3, easing:'easeOut'});
9644 this.statusBar.setText(this.hideText);
9645 this.form.getEl().on('click', this.hideErrors, this, {single:true}); // hide if the user clicks directly into the form
9649 hideErrors : function(){
9650 var el = this.getMsgEl();
9652 el.slideOut('b', {duration:0.2, easing:'easeIn'});
9653 this.statusBar.setText(this.showText);
9655 this.form.getEl().un('click', this.hideErrors, this);
9659 onStatusClick : function(){
9660 if(this.getMsgEl().isVisible()){
9662 }else if(this.errors.getCount() > 0){
9667 Ext.override(Ext.list.Column, {
9669 var types = Ext.data.Types,
9673 if(Ext.isString(this.type)){
9674 this.type = Ext.data.Types[this.type.toUpperCase()] || types.AUTO;
9677 this.type = types.AUTO;
9680 // named sortTypes are supported, here we look them up
9681 if(Ext.isString(st)){
9682 this.sortType = Ext.data.SortTypes[st];
9683 }else if(Ext.isEmpty(st)){
9684 this.sortType = this.type.sortType;
9689 Ext.tree.Column = Ext.extend(Ext.list.Column, {});
9690 Ext.tree.NumberColumn = Ext.extend(Ext.list.NumberColumn, {});
9691 Ext.tree.DateColumn = Ext.extend(Ext.list.DateColumn, {});
9692 Ext.tree.BooleanColumn = Ext.extend(Ext.list.BooleanColumn, {});
9694 Ext.reg('tgcolumn', Ext.tree.Column);
9695 Ext.reg('tgnumbercolumn', Ext.tree.NumberColumn);
9696 Ext.reg('tgdatecolumn', Ext.tree.DateColumn);
9697 Ext.reg('tgbooleancolumn', Ext.tree.BooleanColumn);
9700 * @class Ext.ux.tree.TreeGridNodeUI
9701 * @extends Ext.tree.TreeNodeUI
9703 Ext.ux.tree.TreeGridNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
9704 isTreeGridNodeUI: true,
9706 renderElements : function(n, a, targetNode, bulkRender){
9707 var t = n.getOwnerTree(),
9712 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
9715 '<tbody class="x-tree-node">',
9716 '<tr ext:tree-node-id="', n.id ,'" class="x-tree-node-el x-tree-node-leaf ', a.cls, '">',
9717 '<td class="x-treegrid-col">',
9718 '<span class="x-tree-node-indent">', this.indentMarkup, "</span>",
9719 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
9720 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon', (a.icon ? " x-tree-node-inline-icon" : ""), (a.iconCls ? " "+a.iconCls : ""), '" unselectable="on">',
9721 '<a hidefocus="on" class="x-tree-node-anchor" href="', a.href ? a.href : '#', '" tabIndex="1" ',
9722 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : '', '>',
9723 '<span unselectable="on">', (c.tpl ? c.tpl.apply(a) : a[c.dataIndex] || c.text), '</span></a>',
9727 for(i = 1, len = cols.length; i < len; i++){
9730 '<td class="x-treegrid-col ', (c.cls ? c.cls : ''), '">',
9731 '<div unselectable="on" class="x-treegrid-text"', (c.align ? ' style="text-align: ' + c.align + ';"' : ''), '>',
9732 (c.tpl ? c.tpl.apply(a) : a[c.dataIndex]),
9739 '</tr><tr class="x-tree-node-ct"><td colspan="', cols.length, '">',
9740 '<table class="x-treegrid-node-ct-table" cellpadding="0" cellspacing="0" style="table-layout: fixed; display: none; width: ', t.innerCt.getWidth() ,'px;"><colgroup>'
9742 for(i = 0, len = cols.length; i<len; i++) {
9743 buf.push('<col style="width: ', (cols[i].hidden ? 0 : cols[i].width) ,'px;" />');
9745 buf.push('</colgroup></table></td></tr></tbody>');
9747 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
9748 this.wrap = Ext.DomHelper.insertHtml("beforeBegin", n.nextSibling.ui.getEl(), buf.join(''));
9750 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(''));
9753 this.elNode = this.wrap.childNodes[0];
9754 this.ctNode = this.wrap.childNodes[1].firstChild.firstChild;
9755 var cs = this.elNode.firstChild.childNodes;
9756 this.indentNode = cs[0];
9757 this.ecNode = cs[1];
9758 this.iconNode = cs[2];
9759 this.anchor = cs[3];
9760 this.textNode = cs[3].firstChild;
9764 animExpand : function(cb){
9765 this.ctNode.style.display = "";
9766 Ext.ux.tree.TreeGridNodeUI.superclass.animExpand.call(this, cb);
9770 Ext.ux.tree.TreeGridRootNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
9771 isTreeGridNodeUI: true,
9774 render : function(){
9776 this.wrap = this.ctNode = this.node.ownerTree.innerCt.dom;
9777 this.node.expanded = true;
9781 // weird table-layout: fixed issue in webkit
9782 var ct = this.ctNode;
9783 ct.style.tableLayout = null;
9785 ct.style.tableLayout = 'fixed';
9790 destroy : function(){
9792 Ext.dd.Registry.unregister(this.elNode.id);
9797 collapse : Ext.emptyFn,
9798 expand : Ext.emptyFn
9800 * @class Ext.tree.ColumnResizer
9801 * @extends Ext.util.Observable
9803 Ext.tree.ColumnResizer = Ext.extend(Ext.util.Observable, {
9805 * @cfg {Number} minWidth The minimum width the column can be dragged to.
9806 * Defaults to <tt>14</tt>.
9810 constructor: function(config){
9811 Ext.apply(this, config);
9812 Ext.tree.ColumnResizer.superclass.constructor.call(this);
9815 init : function(tree){
9817 tree.on('render', this.initEvents, this);
9820 initEvents : function(tree){
9821 tree.mon(tree.innerHd, 'mousemove', this.handleHdMove, this);
9822 this.tracker = new Ext.dd.DragTracker({
9823 onBeforeStart: this.onBeforeStart.createDelegate(this),
9824 onStart: this.onStart.createDelegate(this),
9825 onDrag: this.onDrag.createDelegate(this),
9826 onEnd: this.onEnd.createDelegate(this),
9830 this.tracker.initEl(tree.innerHd);
9831 tree.on('beforedestroy', this.tracker.destroy, this.tracker);
9834 handleHdMove : function(e, t){
9837 hd = e.getTarget('.x-treegrid-hd', 3, true);
9840 var r = hd.getRegion(),
9842 pn = hd.dom.parentNode;
9844 if(x - r.left <= hw && hd.dom !== pn.firstChild) {
9845 var ps = hd.dom.previousSibling;
9846 while(ps && Ext.fly(ps).hasClass('x-treegrid-hd-hidden')) {
9847 ps = ps.previousSibling;
9850 this.activeHd = Ext.get(ps);
9851 ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
9853 } else if(r.right - x <= hw) {
9855 while(ns && Ext.fly(ns).hasClass('x-treegrid-hd-hidden')) {
9856 ns = ns.previousSibling;
9859 this.activeHd = Ext.get(ns);
9860 ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';
9863 delete this.activeHd;
9869 onBeforeStart : function(e){
9870 this.dragHd = this.activeHd;
9871 return !!this.dragHd;
9874 onStart : function(e){
9875 this.tree.headersDisabled = true;
9876 this.proxy = this.tree.body.createChild({cls:'x-treegrid-resizer'});
9877 this.proxy.setHeight(this.tree.body.getHeight());
9879 var x = this.tracker.getXY()[0];
9881 this.hdX = this.dragHd.getX();
9882 this.hdIndex = this.tree.findHeaderIndex(this.dragHd);
9884 this.proxy.setX(this.hdX);
9885 this.proxy.setWidth(x-this.hdX);
9887 this.maxWidth = this.tree.outerCt.getWidth() - this.tree.innerBody.translatePoints(this.hdX).left;
9890 onDrag : function(e){
9891 var cursorX = this.tracker.getXY()[0];
9892 this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));
9895 onEnd : function(e){
9896 var nw = this.proxy.getWidth(),
9899 this.proxy.remove();
9902 tree.columns[this.hdIndex].width = nw;
9903 tree.updateColumnWidths();
9905 setTimeout(function(){
9906 tree.headersDisabled = false;
9909 });Ext.ns('Ext.ux.tree');
9912 * @class Ext.ux.tree.TreeGridSorter
9913 * @extends Ext.tree.TreeSorter
9914 * Provides sorting of nodes in a {@link Ext.ux.tree.TreeGrid}. The TreeGridSorter automatically monitors events on the
9915 * associated TreeGrid that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
9916 * Example usage:<br />
9918 new Ext.ux.tree.TreeGridSorter(myTreeGrid, {
9921 sortType: function(node) {
9922 // sort by a custom, typed attribute:
9923 return parseInt(node.id, 10);
9928 * @param {TreeGrid} tree
9929 * @param {Object} config
9931 Ext.ux.tree.TreeGridSorter = Ext.extend(Ext.tree.TreeSorter, {
9933 * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
9935 sortClasses : ['sort-asc', 'sort-desc'],
9937 * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
9939 sortAscText : 'Sort Ascending',
9941 * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
9943 sortDescText : 'Sort Descending',
9945 constructor : function(tree, config) {
9946 if(!Ext.isObject(config)) {
9948 property: tree.columns[0].dataIndex || 'text',
9953 Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this, arguments);
9956 tree.on('headerclick', this.onHeaderClick, this);
9957 tree.ddAppendOnly = true;
9960 this.defaultSortFn = function(n1, n2){
9962 var dsc = me.dir && me.dir.toLowerCase() == 'desc';
9963 var p = me.property || 'text';
9964 var sortType = me.sortType;
9965 var fs = me.folderSort;
9966 var cs = me.caseSensitive === true;
9967 var leafAttr = me.leafAttr || 'leaf';
9970 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
9973 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
9977 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
9978 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
9980 return dsc ? +1 : -1;
9982 return dsc ? -1 : +1;
9988 tree.on('afterrender', this.onAfterTreeRender, this, {single: true});
9989 tree.on('headermenuclick', this.onHeaderMenuClick, this);
9992 onAfterTreeRender : function() {
9993 if(this.tree.hmenu){
9994 this.tree.hmenu.insert(0,
9995 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
9996 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
9999 this.updateSortIcon(0, 'asc');
10002 onHeaderMenuClick : function(c, id, index) {
10003 if(id === 'asc' || id === 'desc') {
10004 this.onHeaderClick(c, null, index);
10009 onHeaderClick : function(c, el, i) {
10010 if(c && !this.tree.headersDisabled){
10013 me.property = c.dataIndex;
10014 me.dir = c.dir = (c.dir === 'desc' ? 'asc' : 'desc');
10015 me.sortType = c.sortType;
10016 me.caseSensitive === Ext.isBoolean(c.caseSensitive) ? c.caseSensitive : this.caseSensitive;
10017 me.sortFn = c.sortFn || this.defaultSortFn;
10019 this.tree.root.cascade(function(n) {
10021 me.updateSort(me.tree, n);
10025 this.updateSortIcon(i, c.dir);
10030 updateSortIcon : function(col, dir){
10031 var sc = this.sortClasses;
10032 var hds = this.tree.innerHd.select('td').removeClass(sc);
10033 hds.item(col).addClass(sc[dir == 'desc' ? 1 : 0]);
10036 * @class Ext.ux.tree.TreeGridLoader
10037 * @extends Ext.tree.TreeLoader
10039 Ext.ux.tree.TreeGridLoader = Ext.extend(Ext.tree.TreeLoader, {
10040 createNode : function(attr) {
10041 if (!attr.uiProvider) {
10042 attr.uiProvider = Ext.ux.tree.TreeGridNodeUI;
10044 return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
10047 * @class Ext.ux.tree.TreeGrid
10048 * @extends Ext.tree.TreePanel
10052 Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, {
10053 rootVisible : false,
10056 borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
10057 cls : 'x-treegrid',
10059 columnResize : true,
10061 reserveScrollOffset : true,
10062 enableHdMenu : true,
10064 columnsText : 'Columns',
10066 initComponent : function() {
10068 this.root = new Ext.tree.AsyncTreeNode({text: 'Root'});
10071 // initialize the loader
10072 var l = this.loader;
10074 l = new Ext.ux.tree.TreeGridLoader({
10075 dataUrl: this.dataUrl,
10076 requestMethod: this.requestMethod,
10079 }else if(Ext.isObject(l) && !l.load){
10080 l = new Ext.ux.tree.TreeGridLoader(l);
10083 l.createNode = function(attr) {
10084 if (!attr.uiProvider) {
10085 attr.uiProvider = Ext.ux.tree.TreeGridNodeUI;
10087 return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
10092 Ext.ux.tree.TreeGrid.superclass.initComponent.call(this);
10094 this.initColumns();
10096 if(this.enableSort) {
10097 this.treeGridSorter = new Ext.ux.tree.TreeGridSorter(this, this.enableSort);
10100 if(this.columnResize){
10101 this.colResizer = new Ext.tree.ColumnResizer(this.columnResize);
10102 this.colResizer.init(this);
10105 var c = this.columns;
10106 if(!this.internalTpl){
10107 this.internalTpl = new Ext.XTemplate(
10108 '<div class="x-grid3-header">',
10109 '<div class="x-treegrid-header-inner">',
10110 '<div class="x-grid3-header-offset">',
10111 '<table cellspacing="0" cellpadding="0" border="0"><colgroup><tpl for="columns"><col /></tpl></colgroup>',
10112 '<thead><tr class="x-grid3-hd-row">',
10113 '<tpl for="columns">',
10114 '<td class="x-grid3-hd x-grid3-cell x-treegrid-hd" style="text-align: {align};" id="', this.id, '-xlhd-{#}">',
10115 '<div class="x-grid3-hd-inner x-treegrid-hd-inner" unselectable="on">',
10116 this.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
10117 '{header}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
10124 '<div class="x-treegrid-root-node">',
10125 '<table class="x-treegrid-root-table" cellpadding="0" cellspacing="0" style="table-layout: fixed;"></table>',
10130 if(!this.colgroupTpl) {
10131 this.colgroupTpl = new Ext.XTemplate(
10132 '<colgroup><tpl for="columns"><col style="width: {width}px"/></tpl></colgroup>'
10137 initColumns : function() {
10138 var cs = this.columns,
10143 for(i = 0; i < len; i++){
10146 c.xtype = c.xtype ? (/^tg/.test(c.xtype) ? c.xtype : 'tg' + c.xtype) : 'tgcolumn';
10152 if(this.enableSort !== false && c.sortable !== false) {
10154 this.enableSort = true;
10158 this.columns = columns;
10161 onRender : function(){
10162 Ext.tree.TreePanel.superclass.onRender.apply(this, arguments);
10164 this.el.addClass('x-treegrid');
10166 this.outerCt = this.body.createChild({
10167 cls:'x-tree-root-ct x-treegrid-ct ' + (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')
10170 this.internalTpl.overwrite(this.outerCt, {columns: this.columns});
10172 this.mainHd = Ext.get(this.outerCt.dom.firstChild);
10173 this.innerHd = Ext.get(this.mainHd.dom.firstChild);
10174 this.innerBody = Ext.get(this.outerCt.dom.lastChild);
10175 this.innerCt = Ext.get(this.innerBody.dom.firstChild);
10177 this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
10179 if(this.hideHeaders){
10180 this.header.dom.style.display = 'none';
10182 else if(this.enableHdMenu !== false){
10183 this.hmenu = new Ext.menu.Menu({id: this.id + '-hctx'});
10184 if(this.enableColumnHide !== false){
10185 this.colMenu = new Ext.menu.Menu({id: this.id + '-hcols-menu'});
10188 beforeshow: this.beforeColMenuShow,
10189 itemclick: this.handleHdMenuClick
10193 hideOnClick: false,
10194 text: this.columnsText,
10195 menu: this.colMenu,
10196 iconCls: 'x-cols-icon'
10199 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
10203 setRootNode : function(node){
10204 node.attributes.uiProvider = Ext.ux.tree.TreeGridRootNodeUI;
10205 node = Ext.ux.tree.TreeGrid.superclass.setRootNode.call(this, node);
10207 this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
10212 clearInnerCt : function(){
10214 var dom = this.innerCt.dom;
10215 while(dom.firstChild){
10216 dom.removeChild(dom.firstChild);
10219 Ext.ux.tree.TreeGrid.superclass.clearInnerCt.call(this);
10223 initEvents : function() {
10224 Ext.ux.tree.TreeGrid.superclass.initEvents.apply(this, arguments);
10226 this.mon(this.innerBody, 'scroll', this.syncScroll, this);
10227 this.mon(this.innerHd, 'click', this.handleHdDown, this);
10228 this.mon(this.mainHd, {
10230 mouseover: this.handleHdOver,
10231 mouseout: this.handleHdOut
10235 onResize : function(w, h) {
10236 Ext.ux.tree.TreeGrid.superclass.onResize.apply(this, arguments);
10238 var bd = this.innerBody.dom;
10239 var hd = this.innerHd.dom;
10245 if(Ext.isNumber(h)){
10246 bd.style.height = this.body.getHeight(true) - hd.offsetHeight + 'px';
10249 if(Ext.isNumber(w)){
10250 var sw = Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
10251 if(this.reserveScrollOffset || ((bd.offsetWidth - bd.clientWidth) > 10)){
10252 this.setScrollOffset(sw);
10255 setTimeout(function(){
10256 me.setScrollOffset(bd.offsetWidth - bd.clientWidth > 10 ? sw : 0);
10262 updateColumnWidths : function() {
10263 var cols = this.columns,
10264 colCount = cols.length,
10265 groups = this.outerCt.query('colgroup'),
10266 groupCount = groups.length,
10269 for(i = 0; i<colCount; i++) {
10271 for(j = 0; j<groupCount; j++) {
10273 g.childNodes[i].style.width = (c.hidden ? 0 : c.width) + 'px';
10277 for(i = 0, groups = this.innerHd.query('td'), len = groups.length; i<len; i++) {
10278 c = Ext.fly(groups[i]);
10279 if(cols[i] && cols[i].hidden) {
10280 c.addClass('x-treegrid-hd-hidden');
10283 c.removeClass('x-treegrid-hd-hidden');
10287 var tcw = this.getTotalColumnWidth();
10288 Ext.fly(this.innerHd.dom.firstChild).setWidth(tcw + (this.scrollOffset || 0));
10289 this.outerCt.select('table').setWidth(tcw);
10290 this.syncHeaderScroll();
10293 getVisibleColumns : function() {
10299 for(i = 0; i<len; i++) {
10300 if(!cs[i].hidden) {
10301 columns.push(cs[i]);
10307 getTotalColumnWidth : function() {
10309 for(var i = 0, cs = this.getVisibleColumns(), len = cs.length; i<len; i++) {
10310 total += cs[i].width;
10315 setScrollOffset : function(scrollOffset) {
10316 this.scrollOffset = scrollOffset;
10317 this.updateColumnWidths();
10321 handleHdDown : function(e, t){
10322 var hd = e.getTarget('.x-treegrid-hd');
10324 if(hd && Ext.fly(t).hasClass('x-grid3-hd-btn')){
10325 var ms = this.hmenu.items,
10327 index = this.findHeaderIndex(hd),
10332 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
10333 this.hdCtxIndex = index;
10335 this.fireEvent('headerbuttonclick', ms, c, hd, index);
10337 this.hmenu.on('hide', function(){
10338 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
10339 }, this, {single:true});
10341 this.hmenu.show(t, 'tl-bl?');
10344 var index = this.findHeaderIndex(hd);
10345 this.fireEvent('headerclick', this.columns[index], hd, index);
10350 handleHdOver : function(e, t){
10351 var hd = e.getTarget('.x-treegrid-hd');
10352 if(hd && !this.headersDisabled){
10353 index = this.findHeaderIndex(hd);
10354 this.activeHdRef = t;
10355 this.activeHdIndex = index;
10356 var el = Ext.get(hd);
10357 this.activeHdRegion = el.getRegion();
10358 el.addClass('x-grid3-hd-over');
10359 this.activeHdBtn = el.child('.x-grid3-hd-btn');
10360 if(this.activeHdBtn){
10361 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
10367 handleHdOut : function(e, t){
10368 var hd = e.getTarget('.x-treegrid-hd');
10369 if(hd && (!Ext.isIE || !e.within(hd, true))){
10370 this.activeHdRef = null;
10371 Ext.fly(hd).removeClass('x-grid3-hd-over');
10372 hd.style.cursor = '';
10376 findHeaderIndex : function(hd){
10378 var cs = hd.parentNode.childNodes;
10379 for(var i = 0, c; c = cs[i]; i++){
10388 beforeColMenuShow : function(){
10389 var cols = this.columns,
10390 colCount = cols.length,
10392 this.colMenu.removeAll();
10393 for(i = 1; i < colCount; i++){
10395 if(c.hideable !== false){
10396 this.colMenu.add(new Ext.menu.CheckItem({
10397 itemId: 'col-' + i,
10399 checked: !c.hidden,
10401 disabled: c.hideable === false
10408 handleHdMenuClick : function(item){
10409 var index = this.hdCtxIndex,
10410 id = item.getItemId();
10412 if(this.fireEvent('headermenuclick', this.columns[index], id, index) !== false) {
10413 index = id.substr(4);
10414 if(index > 0 && this.columns[index]) {
10415 this.setColumnVisible(index, !item.checked);
10422 setColumnVisible : function(index, visible) {
10423 this.columns[index].hidden = !visible;
10424 this.updateColumnWidths();
10428 * Scrolls the grid to the top
10430 scrollToTop : function(){
10431 this.innerBody.dom.scrollTop = 0;
10432 this.innerBody.dom.scrollLeft = 0;
10436 syncScroll : function(){
10437 this.syncHeaderScroll();
10438 var mb = this.innerBody.dom;
10439 this.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
10443 syncHeaderScroll : function(){
10444 var mb = this.innerBody.dom;
10445 this.innerHd.dom.scrollLeft = mb.scrollLeft;
10446 this.innerHd.dom.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
10449 registerNode : function(n) {
10450 Ext.ux.tree.TreeGrid.superclass.registerNode.call(this, n);
10451 if(!n.uiProvider && !n.isRoot && !n.ui.isTreeGridNodeUI) {
10452 n.ui = new Ext.ux.tree.TreeGridNodeUI(n);
10457 Ext.reg('treegrid', Ext.ux.tree.TreeGrid);