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 visibleHeight = this.scroller.dom.clientHeight;
80 return (visibleHeight < 1) ? 0 : Math.ceil(visibleHeight / rh);
83 getVisibleRows: function(){
84 var count = this.getVisibleRowCount(),
85 sc = this.scroller.dom.scrollTop,
86 start = (sc === 0 ? 0 : Math.floor(sc/this.getCalculatedRowHeight())-1);
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,
99 rh = this.getStyleRowHeight(),
100 vr = this.getVisibleRows(),
101 tstyle = 'width:'+this.getTotalWidth()+';height:'+rh+'px;',
107 rp = {tstyle: tstyle},
109 for (var j = 0, len = rs.length; j < len; j++) {
111 var rowIndex = (j+startRow),
112 visible = rowIndex >= vr.first && rowIndex <= vr.last;
114 for (var i = 0; i < colCount; i++) {
117 p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
118 p.attr = p.cellAttr = "";
119 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
121 if (p.value === undefined || p.value === "") {
124 if (r.dirty && typeof r.modified[c.name] !== 'undefined') {
125 p.css += ' x-grid3-dirty-cell';
127 cb[cb.length] = ct.apply(p);
131 if(stripe && ((rowIndex+1) % 2 === 0)){
132 alt[0] = "x-grid3-row-alt";
135 alt[1] = " x-grid3-dirty-row";
138 if(this.getRowClass){
139 alt[2] = this.getRowClass(r, rowIndex, rp, ds);
141 rp.alt = alt.join(" ");
142 rp.cells = cb.join("");
143 buf[buf.length] = !visible ? ts.rowHolder.apply(rp) : (onlyBody ? rb.apply(rp) : rt.apply(rp));
148 isRowRendered: function(index){
149 var row = this.getRow(index);
150 return row && row.childNodes.length > 0;
153 syncScroll: function(){
154 Ext.ux.grid.BufferView.superclass.syncScroll.apply(this, arguments);
158 // a (optionally) buffered method to update contents of gridview
160 if (this.scrollDelay) {
161 if (!this.renderTask) {
162 this.renderTask = new Ext.util.DelayedTask(this.doUpdate, this);
164 this.renderTask.delay(this.scrollDelay);
170 onRemove : function(ds, record, index, isUpdate){
171 Ext.ux.grid.BufferView.superclass.onRemove.apply(this, arguments);
172 if(isUpdate !== true){
177 doUpdate: function(){
178 if (this.getVisibleRowCount() > 0) {
182 cs = this.getColumnData(),
183 vr = this.getVisibleRows(),
185 for (var i = vr.first; i <= vr.last; i++) {
186 // if row is NOT rendered and is visible, render it
187 if(!this.isRowRendered(i) && (row = this.getRow(i))){
188 var html = this.doRender(cs, [ds.getAt(i)], ds, i, cm.getColumnCount(), g.stripeRows, true);
189 row.innerHTML = html;
196 // a buffered method to clean rows
199 this.cleanTask = new Ext.util.DelayedTask(this.doClean, this);
201 this.cleanTask.delay(this.cleanDelay);
205 if (this.getVisibleRowCount() > 0) {
206 var vr = this.getVisibleRows();
207 vr.first -= this.cacheSize;
208 vr.last += this.cacheSize;
210 var i = 0, rows = this.getRows();
211 // if first is less than 0, all rows have been rendered
212 // so lets clean the end...
216 for(var len = this.ds.getCount(); i < len; i++){
217 // if current row is outside of first and last and
218 // has content, update the innerHTML to nothing
219 if ((i < vr.first || i > vr.last) && rows[i].innerHTML) {
220 rows[i].innerHTML = '';
226 removeTask: function(name){
227 var task = this[name];
228 if(task && task.cancel){
234 destroy : function(){
235 this.removeTask('cleanTask');
236 this.removeTask('renderTask');
237 Ext.ux.grid.BufferView.superclass.destroy.call(this);
241 Ext.ux.grid.BufferView.superclass.layout.call(this);
244 });// We are adding these custom layouts to a namespace that does not
245 // exist by default in Ext, so we have to add the namespace first:
246 Ext.ns('Ext.ux.layout');
249 * @class Ext.ux.layout.CenterLayout
250 * @extends Ext.layout.FitLayout
251 * <p>This is a very simple layout style used to center contents within a container. This layout works within
252 * nested containers and can also be used as expected as a Viewport layout to center the page layout.</p>
253 * <p>As a subclass of FitLayout, CenterLayout expects to have a single child panel of the container that uses
254 * the layout. The layout does not require any config options, although the child panel contained within the
255 * layout must provide a fixed or percentage width. The child panel's height will fit to the container by
256 * default, but you can specify <tt>autoHeight:true</tt> to allow it to autosize based on its content height.
259 // The content panel is centered in the container
260 var p = new Ext.Panel({
261 title: 'Center Layout',
264 title: 'Centered Content',
270 // If you leave the title blank and specify no border
271 // you'll create a non-visual, structural panel just
272 // for centering the contents in the main container.
273 var p = new Ext.Panel({
277 title: 'Centered Content',
285 Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.FitLayout, {
287 setItemSize : function(item, size){
288 this.container.addClass('ux-layout-center');
289 item.addClass('ux-layout-center-item');
290 if(item && size.height > 0){
292 size.width = item.width;
299 Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout;
300 Ext.ns('Ext.ux.grid');
303 * @class Ext.ux.grid.CheckColumn
305 * GridPanel plugin to add a column with check boxes to a grid.
306 * <p>Example usage:</p>
309 var checkColumn = new Ext.grid.CheckColumn({
316 // add the column to the column model
317 var cm = new Ext.grid.ColumnModel([{
325 var grid = new Ext.grid.EditorGridPanel({
328 plugins: [checkColumn], // include plugin
332 * In addition to storing a Boolean value within the record data, this
333 * class toggles a css class between <tt>'x-grid3-check-col'</tt> and
334 * <tt>'x-grid3-check-col-on'</tt> to alter the background image used for
337 Ext.ux.grid.CheckColumn = function(config){
338 Ext.apply(this, config);
342 this.renderer = this.renderer.createDelegate(this);
345 Ext.ux.grid.CheckColumn.prototype ={
346 init : function(grid){
348 this.grid.on('render', function(){
349 var view = this.grid.getView();
350 view.mainBody.on('mousedown', this.onMouseDown, this);
354 onMouseDown : function(e, t){
355 if(Ext.fly(t).hasClass(this.createId())){
357 var index = this.grid.getView().findRowIndex(t);
358 var record = this.grid.store.getAt(index);
359 record.set(this.dataIndex, !record.data[this.dataIndex]);
363 renderer : function(v, p, record){
364 p.css += ' x-grid3-check-col-td';
365 return String.format('<div class="x-grid3-check-col{0} {1}"> </div>', v ? '-on' : '', this.createId());
368 createId : function(){
369 return 'x-grid3-cc-' + this.id;
374 Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn);
377 Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn;Ext.ns('Ext.ux.grid');
379 Ext.ux.grid.ColumnHeaderGroup = Ext.extend(Ext.util.Observable, {
381 constructor: function(config){
382 this.config = config;
385 init: function(grid){
386 Ext.applyIf(grid.colModel, this.config);
387 Ext.apply(grid.getView(), this.viewConfig);
391 initTemplates: function(){
392 this.constructor.prototype.initTemplates.apply(this, arguments);
393 var ts = this.templates || {};
395 ts.gcell = new Ext.XTemplate('<td class="x-grid3-hd x-grid3-gcell x-grid3-td-{id} ux-grid-hd-group-row-{row} {cls}" style="{style}">', '<div {tooltip} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '', '{value}</div></td>');
398 this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", "");
401 renderHeaders: function(){
402 var ts = this.templates, headers = [], cm = this.cm, rows = cm.rows, tstyle = 'width:' + this.getTotalWidth() + ';';
404 for(var row = 0, rlen = rows.length; row < rlen; row++){
405 var r = rows[row], cells = [];
406 for(var i = 0, gcol = 0, len = r.length; i < len; i++){
408 group.colspan = group.colspan || 1;
409 var id = this.getColumnId(group.dataIndex ? cm.findColumnIndex(group.dataIndex) : gcol), gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
410 cells[i] = ts.gcell.apply({
411 cls: 'ux-grid-hd-group-cell',
414 style: 'width:' + gs.width + ';' + (gs.hidden ? 'display:none;' : '') + (group.align ? 'text-align:' + group.align + ';' : ''),
415 tooltip: group.tooltip ? (Ext.QuickTips.isEnabled() ? 'ext:qtip' : 'title') + '="' + group.tooltip + '"' : '',
416 istyle: group.align == 'right' ? 'padding-right:16px' : '',
417 btn: this.grid.enableHdMenu && group.header,
418 value: group.header || ' '
420 gcol += group.colspan;
422 headers[row] = ts.header.apply({
424 cells: cells.join('')
427 headers.push(this.constructor.prototype.renderHeaders.apply(this, arguments));
428 return headers.join('');
431 onColumnWidthUpdated: function(){
432 this.constructor.prototype.onColumnWidthUpdated.apply(this, arguments);
433 Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
436 onAllColumnWidthsUpdated: function(){
437 this.constructor.prototype.onAllColumnWidthsUpdated.apply(this, arguments);
438 Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
441 onColumnHiddenUpdated: function(){
442 this.constructor.prototype.onColumnHiddenUpdated.apply(this, arguments);
443 Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
446 getHeaderCell: function(index){
447 return this.mainHd.query(this.cellSelector)[index];
450 findHeaderCell: function(el){
451 return el ? this.fly(el).findParent('td.x-grid3-hd', this.cellSelectorDepth) : false;
454 findHeaderIndex: function(el){
455 var cell = this.findHeaderCell(el);
456 return cell ? this.getCellIndex(cell) : false;
459 updateSortIcon: function(col, dir){
460 var sc = this.sortClasses, hds = this.mainHd.select(this.cellSelector).removeClass(sc);
461 hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
464 handleHdDown: function(e, t){
466 if(el.hasClass('x-grid3-hd-btn')){
468 var hd = this.findHeaderCell(t);
469 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
470 var index = this.getCellIndex(hd);
471 this.hdCtxIndex = index;
472 var ms = this.hmenu.items, cm = this.cm;
473 ms.get('asc').setDisabled(!cm.isSortable(index));
474 ms.get('desc').setDisabled(!cm.isSortable(index));
475 this.hmenu.on('hide', function(){
476 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
480 this.hmenu.show(t, 'tl-bl?');
481 }else if(el.hasClass('ux-grid-hd-group-cell') || Ext.fly(t).up('.ux-grid-hd-group-cell')){
486 handleHdMove: function(e, t){
487 var hd = this.findHeaderCell(this.activeHdRef);
488 if(hd && !this.headersDisabled && !Ext.fly(hd).hasClass('ux-grid-hd-group-cell')){
489 var hw = this.splitHandleWidth || 5, r = this.activeHdRegion, x = e.getPageX(), ss = hd.style, cur = '';
490 if(this.grid.enableColumnResize !== false){
491 if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex - 1)){
492 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize
496 }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
497 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
504 handleHdOver: function(e, t){
505 var hd = this.findHeaderCell(t);
506 if(hd && !this.headersDisabled){
507 this.activeHdRef = t;
508 this.activeHdIndex = this.getCellIndex(hd);
509 var fly = this.fly(hd);
510 this.activeHdRegion = fly.getRegion();
511 if(!(this.cm.isMenuDisabled(this.activeHdIndex) || fly.hasClass('ux-grid-hd-group-cell'))){
512 fly.addClass('x-grid3-hd-over');
513 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
514 if(this.activeHdBtn){
515 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight - 1) + 'px';
521 handleHdOut: function(e, t){
522 var hd = this.findHeaderCell(t);
523 if(hd && (!Ext.isIE || !e.within(hd, true))){
524 this.activeHdRef = null;
525 this.fly(hd).removeClass('x-grid3-hd-over');
526 hd.style.cursor = '';
530 handleHdMenuClick: function(item){
531 var index = this.hdCtxIndex, cm = this.cm, ds = this.ds, id = item.getItemId();
534 ds.sort(cm.getDataIndex(index), 'ASC');
537 ds.sort(cm.getDataIndex(index), 'DESC');
540 if(id.substr(0, 5) == 'group'){
541 var i = id.split('-'), row = parseInt(i[1], 10), col = parseInt(i[2], 10), r = this.cm.rows[row], group, gcol = 0;
542 for(var i = 0, len = r.length; i < len; i++){
544 if(col >= gcol && col < gcol + group.colspan){
547 gcol += group.colspan;
550 var max = cm.getColumnsBy(this.isHideableColumn, this).length;
551 for(var i = gcol, len = gcol + group.colspan; i < len; i++){
557 this.onDenyColumnHide();
561 for(var i = gcol, len = gcol + group.colspan; i < len; i++){
562 if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
563 cm.setHidden(i, item.checked);
567 index = cm.getIndexById(id.substr(4));
569 if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
570 this.onDenyColumnHide();
573 cm.setHidden(index, item.checked);
576 item.checked = !item.checked;
578 var updateChildren = function(menu){
579 menu.items.each(function(childItem){
580 if(!childItem.disabled){
581 childItem.setChecked(item.checked, false);
583 updateChildren(childItem.menu);
588 updateChildren(item.menu);
590 var parentMenu = item, parentItem;
591 while(parentMenu = parentMenu.parentMenu){
592 if(!parentMenu.parentMenu || !(parentItem = parentMenu.parentMenu.items.get(parentMenu.getItemId())) || !parentItem.setChecked){
595 var checked = parentMenu.items.findIndexBy(function(m){
598 parentItem.setChecked(checked, true);
600 item.checked = !item.checked;
605 beforeColMenuShow: function(){
606 var cm = this.cm, rows = this.cm.rows;
607 this.colMenu.removeAll();
608 for(var col = 0, clen = cm.getColumnCount(); col < clen; col++){
609 var menu = this.colMenu, title = cm.getColumnHeader(col), text = [];
610 if(cm.config[col].fixed !== true && cm.config[col].hideable !== false){
611 for(var row = 0, rlen = rows.length; row < rlen; row++){
612 var r = rows[row], group, gcol = 0;
613 for(var i = 0, len = r.length; i < len; i++){
615 if(col >= gcol && col < gcol + group.colspan){
618 gcol += group.colspan;
620 if(group && group.header){
621 if(cm.hierarchicalColMenu){
622 var gid = 'group-' + row + '-' + gcol;
623 var item = menu.items.item(gid);
624 var submenu = item ? item.menu : null;
626 submenu = new Ext.menu.Menu({
629 submenu.on("itemclick", this.handleHdMenuClick, this);
630 var checked = false, disabled = true;
631 for(var c = gcol, lc = gcol + group.colspan; c < lc; c++){
635 if(cm.config[c].hideable !== false){
650 text.push(group.header);
655 menu.add(new Ext.menu.CheckItem({
656 itemId: "col-" + cm.getColumnId(col),
657 text: text.join(' '),
658 checked: !cm.isHidden(col),
660 disabled: cm.config[col].hideable === false
666 renderUI: function(){
667 this.constructor.prototype.renderUI.apply(this, arguments);
668 Ext.apply(this.columnDrop, Ext.ux.grid.ColumnHeaderGroup.prototype.columnDropConfig);
669 Ext.apply(this.splitZone, Ext.ux.grid.ColumnHeaderGroup.prototype.splitZoneConfig);
674 allowHeaderDrag: function(e){
675 return !e.getTarget(null, null, true).hasClass('ux-grid-hd-group-cell');
680 getTargetFromEvent: function(e){
681 var t = Ext.lib.Event.getTarget(e);
682 return this.view.findHeaderCell(t);
685 positionIndicator: function(h, n, e){
686 var data = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
690 var px = data.px + this.proxyOffsets[0];
691 this.proxyTop.setLeftTop(px, data.r.top + this.proxyOffsets[1]);
692 this.proxyTop.show();
693 this.proxyBottom.setLeftTop(px, data.r.bottom);
694 this.proxyBottom.show();
698 onNodeDrop: function(n, dd, e, data){
701 var d = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
705 var cm = this.grid.colModel, right = d.oldIndex < d.newIndex, rows = cm.rows;
706 for(var row = d.row, rlen = rows.length; row < rlen; row++){
707 var r = rows[row], len = r.length, fromIx = 0, span = 1, toIx = len;
708 for(var i = 0, gcol = 0; i < len; i++){
710 if(d.oldIndex >= gcol && d.oldIndex < gcol + group.colspan){
713 if(d.oldIndex + d.colspan - 1 >= gcol && d.oldIndex + d.colspan - 1 < gcol + group.colspan){
714 span = i - fromIx + 1;
716 if(d.newIndex >= gcol && d.newIndex < gcol + group.colspan){
719 gcol += group.colspan;
721 var groups = r.splice(fromIx, span);
722 rows[row] = r.splice(0, toIx - (right ? span : 0)).concat(groups).concat(r);
724 for(var c = 0; c < d.colspan; c++){
725 var oldIx = d.oldIndex + (right ? 0 : c), newIx = d.newIndex + (right ? -1 : c);
726 cm.moveColumn(oldIx, newIx);
727 this.grid.fireEvent("columnmove", oldIx, newIx);
735 getGroupStyle: function(group, gcol){
736 var width = 0, hidden = true;
737 for(var i = gcol, len = gcol + group.colspan; i < len; i++){
738 if(!this.cm.isHidden(i)){
739 var cw = this.cm.getColumnWidth(i);
740 if(typeof cw == 'number'){
747 width: (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? width : Math.max(width - this.borderWidth, 0)) + 'px',
752 updateGroupStyles: function(col){
753 var tables = this.mainHd.query('.x-grid3-header-offset > table'), tw = this.getTotalWidth(), rows = this.cm.rows;
754 for(var row = 0; row < tables.length; row++){
755 tables[row].style.width = tw;
756 if(row < rows.length){
757 var cells = tables[row].firstChild.firstChild.childNodes;
758 for(var i = 0, gcol = 0; i < cells.length; i++){
759 var group = rows[row][i];
760 if((typeof col != 'number') || (col >= gcol && col < gcol + group.colspan)){
761 var gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
762 cells[i].style.width = gs.width;
763 cells[i].style.display = gs.hidden ? 'none' : '';
765 gcol += group.colspan;
771 getGroupRowIndex: function(el){
773 var m = el.className.match(this.hrowRe);
775 return parseInt(m[1], 10);
778 return this.cm.rows.length;
781 getGroupSpan: function(row, col){
785 colspan: this.cm.getColumnCount()
788 var r = this.cm.rows[row];
790 for(var i = 0, gcol = 0, len = r.length; i < len; i++){
792 if(col >= gcol && col < gcol + group.colspan){
795 colspan: group.colspan
798 gcol += group.colspan;
811 getDragDropData: function(h, n, e){
812 if(h.parentNode != n.parentNode){
815 var cm = this.grid.colModel, x = Ext.lib.Event.getPageX(e), r = Ext.lib.Dom.getRegion(n.firstChild), px, pt;
816 if((r.right - x) <= (r.right - r.left) / 2){
817 px = r.right + this.view.borderWidth;
823 var oldIndex = this.view.getCellIndex(h), newIndex = this.view.getCellIndex(n);
824 if(cm.isFixed(newIndex)){
827 var row = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupRowIndex.call(this.view, h),
828 oldGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, oldIndex),
829 newGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, newIndex),
830 oldIndex = oldGroup.col;
831 newIndex = newGroup.col + (pt == "after" ? newGroup.colspan : 0);
832 if(newIndex >= oldGroup.col && newIndex <= oldGroup.col + oldGroup.colspan){
835 var parentGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row - 1, oldIndex);
836 if(newIndex < parentGroup.col || newIndex > parentGroup.col + parentGroup.colspan){
846 colspan: oldGroup.colspan
849 });Ext.ns('Ext.ux.tree');
852 * @class Ext.ux.tree.ColumnTree
853 * @extends Ext.tree.TreePanel
857 Ext.ux.tree.ColumnTree = Ext.extend(Ext.tree.TreePanel, {
859 borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
860 cls : 'x-column-tree',
862 onRender : function(){
863 Ext.tree.ColumnTree.superclass.onRender.apply(this, arguments);
864 this.headers = this.header.createChild({cls:'x-tree-headers'});
866 var cols = this.columns, c;
868 var scrollOffset = 19; // similar to Ext.grid.GridView default
870 for(var i = 0, len = cols.length; i < len; i++){
872 totalWidth += c.width;
873 this.headers.createChild({
874 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
876 cls:'x-tree-hd-text',
879 style:'width:'+(c.width-this.borderWidth)+'px;'
882 this.headers.createChild({cls:'x-clear'});
883 // prevent floats from wrapping when clipped
884 this.headers.setWidth(totalWidth+scrollOffset);
885 this.innerCt.setWidth(totalWidth);
889 Ext.reg('columntree', Ext.ux.tree.ColumnTree);
892 Ext.tree.ColumnTree = Ext.ux.tree.ColumnTree;
896 * @class Ext.ux.tree.ColumnNodeUI
897 * @extends Ext.tree.TreeNodeUI
899 Ext.ux.tree.ColumnNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
900 focus: Ext.emptyFn, // prevent odd scrolling behavior
902 renderElements : function(n, a, targetNode, bulkRender){
903 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
905 var t = n.getOwnerTree();
906 var cols = t.columns;
907 var bw = t.borderWidth;
911 '<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf ', a.cls,'">',
912 '<div class="x-tree-col" style="width:',c.width-bw,'px;">',
913 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
914 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
915 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on">',
916 '<a hidefocus="on" class="x-tree-node-anchor" href="',a.href ? a.href : "#",'" tabIndex="1" ',
917 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '>',
918 '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</span></a>",
920 for(var i = 1, len = cols.length; i < len; i++){
923 buf.push('<div class="x-tree-col ',(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
924 '<div class="x-tree-col-text">',(c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</div>",
928 '<div class="x-clear"></div></div>',
929 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
932 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
933 this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
934 n.nextSibling.ui.getEl(), buf.join(""));
936 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
939 this.elNode = this.wrap.childNodes[0];
940 this.ctNode = this.wrap.childNodes[1];
941 var cs = this.elNode.firstChild.childNodes;
942 this.indentNode = cs[0];
944 this.iconNode = cs[2];
946 this.textNode = cs[3].firstChild;
951 Ext.tree.ColumnNodeUI = Ext.ux.tree.ColumnNodeUI;
953 * @class Ext.DataView.LabelEditor
954 * @extends Ext.Editor
957 Ext.DataView.LabelEditor = Ext.extend(Ext.Editor, {
960 cls: "x-small-editor",
962 completeOnEnter: true,
964 labelSelector: 'span.x-editable',
966 constructor: function(cfg, field){
967 Ext.DataView.LabelEditor.superclass.constructor.call(this,
968 field || new Ext.form.TextField({
978 init : function(view){
980 view.on('render', this.initEditor, this);
981 this.on('complete', this.onSave, this);
984 initEditor : function(){
987 containerclick: this.doBlur,
990 this.view.getEl().on('mousedown', this.onMouseDown, this, {delegate: this.labelSelector});
999 onMouseDown : function(e, target){
1000 if(!e.ctrlKey && !e.shiftKey){
1001 var item = this.view.findItemFromChild(target);
1003 var record = this.view.store.getAt(this.view.indexOf(item));
1004 this.startEdit(target, record.data[this.dataIndex]);
1005 this.activeRecord = record;
1011 onSave : function(ed, value){
1012 this.activeRecord.set(this.dataIndex, value);
1017 Ext.DataView.DragSelector = function(cfg){
1019 var view, proxy, tracker;
1020 var rs, bodyRegion, dragRegion = new Ext.lib.Region(0,0,0,0);
1021 var dragSafe = cfg.dragSafe === true;
1023 this.init = function(dataView){
1025 view.on('render', onRender);
1028 function fillRegions(){
1030 view.all.each(function(el){
1031 rs[rs.length] = el.getRegion();
1033 bodyRegion = view.el.getRegion();
1036 function cancelClick(){
1040 function onBeforeStart(e){
1041 return !dragSafe || e.target == view.el.dom;
1044 function onStart(e){
1045 view.on('containerclick', cancelClick, view, {single:true});
1047 proxy = view.el.createChild({cls:'x-view-selector'});
1049 if(proxy.dom.parentNode !== view.el.dom){
1050 view.el.dom.appendChild(proxy.dom);
1052 proxy.setDisplayed('block');
1055 view.clearSelections();
1059 var startXY = tracker.startXY;
1060 var xy = tracker.getXY();
1062 var x = Math.min(startXY[0], xy[0]);
1063 var y = Math.min(startXY[1], xy[1]);
1064 var w = Math.abs(startXY[0] - xy[0]);
1065 var h = Math.abs(startXY[1] - xy[1]);
1067 dragRegion.left = x;
1069 dragRegion.right = x+w;
1070 dragRegion.bottom = y+h;
1072 dragRegion.constrainTo(bodyRegion);
1073 proxy.setRegion(dragRegion);
1075 for(var i = 0, len = rs.length; i < len; i++){
1076 var r = rs[i], sel = dragRegion.intersect(r);
1077 if(sel && !r.selected){
1079 view.select(i, true);
1080 }else if(!sel && r.selected){
1089 view.un('containerclick', cancelClick, view);
1092 proxy.setDisplayed(false);
1096 function onRender(view){
1097 tracker = new Ext.dd.DragTracker({
1098 onBeforeStart: onBeforeStart,
1103 tracker.initEl(view.el);
1105 };Ext.ns('Ext.ux.form');
1108 * @class Ext.ux.form.FileUploadField
1109 * @extends Ext.form.TextField
1110 * Creates a file upload field.
1111 * @xtype fileuploadfield
1113 Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField, {
1115 * @cfg {String} buttonText The button text to display on the upload button (defaults to
1116 * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
1117 * value will be used instead if available.
1119 buttonText: 'Browse...',
1121 * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
1122 * text field (defaults to false). If true, all inherited TextField members will still be available.
1126 * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
1127 * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
1131 * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
1141 autoSize: Ext.emptyFn,
1144 initComponent: function(){
1145 Ext.ux.form.FileUploadField.superclass.initComponent.call(this);
1149 * @event fileselected
1150 * Fires when the underlying file input field's value has changed from the user
1151 * selecting a new file from the system file selection dialog.
1152 * @param {Ext.ux.form.FileUploadField} this
1153 * @param {String} value The file value returned by the underlying file input field
1160 onRender : function(ct, position){
1161 Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct, position);
1163 this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
1164 this.el.addClass('x-form-file-text');
1165 this.el.dom.removeAttribute('name');
1166 this.createFileInput();
1168 var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
1169 text: this.buttonText
1171 this.button = new Ext.Button(Ext.apply(btnCfg, {
1172 renderTo: this.wrap,
1173 cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
1176 if(this.buttonOnly){
1178 this.wrap.setWidth(this.button.getEl().getWidth());
1181 this.bindListeners();
1182 this.resizeEl = this.positionEl = this.wrap;
1185 bindListeners: function(){
1188 mouseenter: function() {
1189 this.button.addClass(['x-btn-over','x-btn-focus'])
1191 mouseleave: function(){
1192 this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
1194 mousedown: function(){
1195 this.button.addClass('x-btn-click')
1197 mouseup: function(){
1198 this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
1201 var v = this.fileInput.dom.value;
1203 this.fireEvent('fileselected', this, v);
1208 createFileInput : function() {
1209 this.fileInput = this.wrap.createChild({
1210 id: this.getFileInputId(),
1211 name: this.name||this.getId(),
1220 this.fileInput.remove();
1221 this.createFileInput();
1222 this.bindListeners();
1223 Ext.ux.form.FileUploadField.superclass.reset.call(this);
1227 getFileInputId: function(){
1228 return this.id + '-file';
1232 onResize : function(w, h){
1233 Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
1235 this.wrap.setWidth(w);
1237 if(!this.buttonOnly){
1238 var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
1239 this.el.setWidth(w);
1244 onDestroy: function(){
1245 Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
1246 Ext.destroy(this.fileInput, this.button, this.wrap);
1249 onDisable: function(){
1250 Ext.ux.form.FileUploadField.superclass.onDisable.call(this);
1251 this.doDisable(true);
1254 onEnable: function(){
1255 Ext.ux.form.FileUploadField.superclass.onEnable.call(this);
1256 this.doDisable(false);
1261 doDisable: function(disabled){
1262 this.fileInput.dom.disabled = disabled;
1263 this.button.setDisabled(disabled);
1268 preFocus : Ext.emptyFn,
1271 alignErrorIcon : function(){
1272 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
1277 Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
1280 Ext.form.FileUploadField = Ext.ux.form.FileUploadField;
1282 * @class Ext.ux.GMapPanel
1283 * @extends Ext.Panel
1284 * @author Shea Frederick
1286 Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
1287 initComponent : function(){
1299 Ext.applyIf(this,defConfig);
1301 Ext.ux.GMapPanel.superclass.initComponent.call(this);
1304 afterRender : function(){
1306 var wh = this.ownerCt.getSize();
1307 Ext.applyIf(this, wh);
1309 Ext.ux.GMapPanel.superclass.afterRender.call(this);
1311 if (this.gmapType === 'map'){
1312 this.gmap = new GMap2(this.body.dom);
1315 if (this.gmapType === 'panorama'){
1316 this.gmap = new GStreetviewPanorama(this.body.dom);
1319 if (typeof this.addControl == 'object' && this.gmapType === 'map') {
1320 this.gmap.addControl(this.addControl);
1323 if (typeof this.setCenter === 'object') {
1324 if (typeof this.setCenter.geoCodeAddr === 'string'){
1325 this.geoCodeLookup(this.setCenter.geoCodeAddr);
1327 if (this.gmapType === 'map'){
1328 var point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
1329 this.gmap.setCenter(point, this.zoomLevel);
1331 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
1332 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
1335 if (this.gmapType === 'panorama'){
1336 this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
1340 GEvent.bind(this.gmap, 'load', this, function(){
1345 onMapReady : function(){
1346 this.addMarkers(this.markers);
1347 this.addMapControls();
1350 onResize : function(w, h){
1352 if (typeof this.getMap() == 'object') {
1353 this.gmap.checkResize();
1356 Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);
1359 setSize : function(width, height, animate){
1361 if (typeof this.getMap() == 'object') {
1362 this.gmap.checkResize();
1365 Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
1368 getMap : function(){
1373 getCenter : function(){
1375 return this.getMap().getCenter();
1378 getCenterLatLng : function(){
1380 var ll = this.getCenter();
1381 return {lat: ll.lat(), lng: ll.lng()};
1384 addMarkers : function(markers) {
1386 if (Ext.isArray(markers)){
1387 for (var i = 0; i < markers.length; i++) {
1388 var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
1389 this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
1394 addMarker : function(point, marker, clear, center, listeners){
1396 Ext.applyIf(marker,G_DEFAULT_ICON);
1398 if (clear === true){
1399 this.getMap().clearOverlays();
1401 if (center === true) {
1402 this.getMap().setCenter(point, this.zoomLevel);
1405 var mark = new GMarker(point,marker);
1406 if (typeof listeners === 'object'){
1407 for (evt in listeners) {
1408 GEvent.bind(mark, evt, this, listeners[evt]);
1411 this.getMap().addOverlay(mark);
1414 addMapControls : function(){
1416 if (this.gmapType === 'map') {
1417 if (Ext.isArray(this.mapControls)) {
1418 for(i=0;i<this.mapControls.length;i++){
1419 this.addMapControl(this.mapControls[i]);
1421 }else if(typeof this.mapControls === 'string'){
1422 this.addMapControl(this.mapControls);
1423 }else if(typeof this.mapControls === 'object'){
1424 this.getMap().addControl(this.mapControls);
1429 addMapControl : function(mc){
1431 var mcf = window[mc];
1432 if (typeof mcf === 'function') {
1433 this.getMap().addControl(new mcf());
1437 addOptions : function(){
1439 if (Ext.isArray(this.mapConfOpts)) {
1441 for(i=0;i<this.mapConfOpts.length;i++){
1442 this.addOption(this.mapConfOpts[i]);
1444 }else if(typeof this.mapConfOpts === 'string'){
1445 this.addOption(this.mapConfOpts);
1449 addOption : function(mc){
1451 var mcf = this.getMap()[mc];
1452 if (typeof mcf === 'function') {
1453 this.getMap()[mc]();
1457 geoCodeLookup : function(addr) {
1459 this.geocoder = new GClientGeocoder();
1460 this.geocoder.getLocations(addr, this.addAddressToMap.createDelegate(this));
1463 addAddressToMap : function(response) {
1465 if (!response || response.Status.code != 200) {
1466 Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
1468 place = response.Placemark[0];
1469 addressinfo = place.AddressDetails;
1470 accuracy = addressinfo.Accuracy;
1471 if (accuracy === 0) {
1472 Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
1475 Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
1477 point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
1478 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
1479 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);
1489 Ext.reg('gmappanel', Ext.ux.GMapPanel); Ext.namespace('Ext.ux.grid');
1492 * @class Ext.ux.grid.GridFilters
1493 * @extends Ext.util.Observable
1494 * <p>GridFilter is a plugin (<code>ptype='gridfilters'</code>) for grids that
1495 * allow for a slightly more robust representation of filtering than what is
1496 * provided by the default store.</p>
1497 * <p>Filtering is adjusted by the user using the grid's column header menu
1498 * (this menu can be disabled through configuration). Through this menu users
1499 * can configure, enable, and disable filters for each column.</p>
1500 * <p><b><u>Features:</u></b></p>
1501 * <div class="mdetail-params"><ul>
1502 * <li><b>Filtering implementations</b> :
1503 * <div class="sub-desc">
1504 * Default filtering for Strings, Numeric Ranges, Date Ranges, Lists (which can
1505 * be backed by a Ext.data.Store), and Boolean. Additional custom filter types
1506 * and menus are easily created by extending Ext.ux.grid.filter.Filter.
1508 * <li><b>Graphical indicators</b> :
1509 * <div class="sub-desc">
1510 * Columns that are filtered have {@link #filterCls a configurable css class}
1511 * applied to the column headers.
1513 * <li><b>Paging</b> :
1514 * <div class="sub-desc">
1515 * If specified as a plugin to the grid's configured PagingToolbar, the current page
1516 * will be reset to page 1 whenever you update the filters.
1518 * <li><b>Automatic Reconfiguration</b> :
1519 * <div class="sub-desc">
1520 * Filters automatically reconfigure when the grid 'reconfigure' event fires.
1522 * <li><b>Stateful</b> :
1523 * Filter information will be persisted across page loads by specifying a
1524 * <code>stateId</code> in the Grid configuration.
1525 * <div class="sub-desc">
1526 * The filter collection binds to the
1527 * <code>{@link Ext.grid.GridPanel#beforestaterestore beforestaterestore}</code>
1528 * and <code>{@link Ext.grid.GridPanel#beforestatesave beforestatesave}</code>
1529 * events in order to be stateful.
1531 * <li><b>Grid Changes</b> :
1532 * <div class="sub-desc"><ul>
1533 * <li>A <code>filters</code> <i>property</i> is added to the grid pointing to
1535 * <li>A <code>filterupdate</code> <i>event</i> is added to the grid and is
1536 * fired upon onStateChange completion.</li>
1538 * <li><b>Server side code examples</b> :
1539 * <div class="sub-desc"><ul>
1540 * <li><a href="http://www.vinylfox.com/extjs/grid-filter-php-backend-code.php">PHP</a> - (Thanks VinylFox)</li>
1541 * <li><a href="http://extjs.com/forum/showthread.php?p=77326#post77326">Ruby on Rails</a> - (Thanks Zyclops)</li>
1542 * <li><a href="http://extjs.com/forum/showthread.php?p=176596#post176596">Ruby on Rails</a> - (Thanks Rotomaul)</li>
1543 * <li><a href="http://www.debatablybeta.com/posts/using-extjss-grid-filtering-with-django/">Python</a> - (Thanks Matt)</li>
1544 * <li><a href="http://mcantrell.wordpress.com/2008/08/22/extjs-grids-and-grails/">Grails</a> - (Thanks Mike)</li>
1547 * <p><b><u>Example usage:</u></b></p>
1549 var store = new Ext.data.GroupingStore({
1553 var filters = new Ext.ux.grid.GridFilters({
1554 autoReload: false, //don't reload automatically
1555 local: true, //only filter locally
1556 // filters may be configured through the plugin,
1557 // or in the column definition within the column model configuration
1569 dataIndex: 'dateAdded'
1573 options: ['extra small', 'small', 'medium', 'large', 'extra large'],
1577 dataIndex: 'visible'
1580 var cm = new Ext.grid.ColumnModel([{
1584 var grid = new Ext.grid.GridPanel({
1587 view: new Ext.grid.GroupingView(),
1591 bbar: new Ext.PagingToolbar({
1594 plugins: [filters] //reset page to page 1 if filters change
1598 store.load({params: {start: 0, limit: 15}});
1600 // a filters property is added to the grid
1604 Ext.ux.grid.GridFilters = Ext.extend(Ext.util.Observable, {
1606 * @cfg {Boolean} autoReload
1607 * Defaults to true, reloading the datasource when a filter change happens.
1608 * Set this to false to prevent the datastore from being reloaded if there
1609 * are changes to the filters. See <code>{@link updateBuffer}</code>.
1613 * @cfg {Boolean} encode
1614 * Specify true for {@link #buildQuery} to use Ext.util.JSON.encode to
1615 * encode the filter query parameter sent with a remote request.
1616 * Defaults to false.
1619 * @cfg {Array} filters
1620 * An Array of filters config objects. Refer to each filter type class for
1621 * configuration details specific to each filter type. Filters for Strings,
1622 * Numeric Ranges, Date Ranges, Lists, and Boolean are the standard filters
1626 * @cfg {String} filterCls
1627 * The css class to be applied to column headers with active filters.
1628 * Defaults to <tt>'ux-filterd-column'</tt>.
1630 filterCls : 'ux-filtered-column',
1632 * @cfg {Boolean} local
1633 * <tt>true</tt> to use Ext.data.Store filter functions (local filtering)
1634 * instead of the default (<tt>false</tt>) server side filtering.
1638 * @cfg {String} menuFilterText
1639 * defaults to <tt>'Filters'</tt>.
1641 menuFilterText : 'Filters',
1643 * @cfg {String} paramPrefix
1644 * The url parameter prefix for the filters.
1645 * Defaults to <tt>'filter'</tt>.
1647 paramPrefix : 'filter',
1649 * @cfg {Boolean} showMenu
1650 * Defaults to true, including a filter submenu in the default header menu.
1654 * @cfg {String} stateId
1655 * Name of the value to be used to store state information.
1657 stateId : undefined,
1659 * @cfg {Integer} updateBuffer
1660 * Number of milliseconds to defer store updates since the last filter change.
1665 constructor : function (config) {
1666 config = config || {};
1667 this.deferredUpdate = new Ext.util.DelayedTask(this.reload, this);
1668 this.filters = new Ext.util.MixedCollection();
1669 this.filters.getKey = function (o) {
1670 return o ? o.dataIndex : null;
1672 this.addFilters(config.filters);
1673 delete config.filters;
1674 Ext.apply(this, config);
1678 init : function (grid) {
1679 if (grid instanceof Ext.grid.GridPanel) {
1682 this.bindStore(this.grid.getStore(), true);
1683 // assumes no filters were passed in the constructor, so try and use ones from the colModel
1684 if(this.filters.getCount() == 0){
1685 this.addFilters(this.grid.getColumnModel());
1688 this.grid.filters = this;
1690 this.grid.addEvents({'filterupdate': true});
1694 beforestaterestore: this.applyState,
1695 beforestatesave: this.saveState,
1696 beforedestroy: this.destroy,
1697 reconfigure: this.onReconfigure
1706 render: this.onRender
1710 } else if (grid instanceof Ext.PagingToolbar) {
1711 this.toolbar = grid;
1717 * Handler for the grid's beforestaterestore event (fires before the state of the
1718 * grid is restored).
1719 * @param {Object} grid The grid object
1720 * @param {Object} state The hash of state values returned from the StateProvider.
1722 applyState : function (grid, state) {
1724 this.applyingState = true;
1725 this.clearFilters();
1726 if (state.filters) {
1727 for (key in state.filters) {
1728 filter = this.filters.get(key);
1730 filter.setValue(state.filters[key]);
1731 filter.setActive(true);
1735 this.deferredUpdate.cancel();
1739 delete this.applyingState;
1740 delete state.filters;
1744 * Saves the state of all active filters
1745 * @param {Object} grid
1746 * @param {Object} state
1749 saveState : function (grid, state) {
1751 this.filters.each(function (filter) {
1752 if (filter.active) {
1753 filters[filter.dataIndex] = filter.getValue();
1756 return (state.filters = filters);
1761 * Handler called when the grid is rendered
1763 onRender : function () {
1764 this.grid.getView().on('refresh', this.onRefresh, this);
1770 * Handler called by the grid 'beforedestroy' event
1772 destroy : function () {
1774 this.purgeListeners();
1776 if(this.filterMenu){
1777 Ext.menu.MenuMgr.unregister(this.filterMenu);
1778 this.filterMenu.destroy();
1779 this.filterMenu = this.menu.menu = null;
1784 * Remove all filters, permanently destroying them.
1786 removeAll : function () {
1788 Ext.destroy.apply(Ext, this.filters.items);
1789 // remove all items from the collection
1790 this.filters.clear();
1796 * Changes the data store bound to this view and refreshes it.
1797 * @param {Store} store The store to bind to this view
1799 bindStore : function(store, initial){
1800 if(!initial && this.store){
1802 store.un('load', this.onLoad, this);
1804 store.un('beforeload', this.onBeforeLoad, this);
1809 store.on('load', this.onLoad, this);
1811 store.on('beforeload', this.onBeforeLoad, this);
1819 * Handler called when the grid reconfigure event fires
1821 onReconfigure : function () {
1822 this.bindStore(this.grid.getStore());
1823 this.store.clearFilter();
1825 this.addFilters(this.grid.getColumnModel());
1826 this.updateColumnHeadings();
1829 createMenu : function () {
1830 var view = this.grid.getView(),
1833 if (this.showMenu && hmenu) {
1835 this.sep = hmenu.addSeparator();
1836 this.filterMenu = new Ext.menu.Menu({
1837 id: this.grid.id + '-filters-menu'
1839 this.menu = hmenu.add({
1842 text: this.menuFilterText,
1843 menu: this.filterMenu
1848 checkchange: this.onCheckChange,
1849 beforecheckchange: this.onBeforeCheck
1851 hmenu.on('beforeshow', this.onMenu, this);
1853 this.updateColumnHeadings();
1858 * Get the filter menu from the filters MixedCollection based on the clicked header
1860 getMenuFilter : function () {
1861 var view = this.grid.getView();
1862 if (!view || view.hdCtxIndex === undefined) {
1865 return this.filters.get(
1866 view.cm.config[view.hdCtxIndex].dataIndex
1872 * Handler called by the grid's hmenu beforeshow event
1874 onMenu : function (filterMenu) {
1875 var filter = this.getMenuFilter();
1879 TODO: lazy rendering
1881 filter.menu = filter.createMenu();
1884 this.menu.menu = filter.menu;
1885 this.menu.setChecked(filter.active, false);
1886 // disable the menu if filter.disabled explicitly set to true
1887 this.menu.setDisabled(filter.disabled === true);
1890 this.menu.setVisible(filter !== undefined);
1891 this.sep.setVisible(filter !== undefined);
1895 onCheckChange : function (item, value) {
1896 this.getMenuFilter().setActive(value);
1900 onBeforeCheck : function (check, value) {
1901 return !value || this.getMenuFilter().isActivatable();
1906 * Handler for all events on filters.
1907 * @param {String} event Event name
1908 * @param {Object} filter Standard signature of the event before the event is fired
1910 onStateChange : function (event, filter) {
1911 if (event === 'serialize') {
1915 if (filter == this.getMenuFilter()) {
1916 this.menu.setChecked(filter.active, false);
1919 if ((this.autoReload || this.local) && !this.applyingState) {
1920 this.deferredUpdate.delay(this.updateBuffer);
1922 this.updateColumnHeadings();
1924 if (!this.applyingState) {
1925 this.grid.saveState();
1927 this.grid.fireEvent('filterupdate', this, filter);
1932 * Handler for store's beforeload event when configured for remote filtering
1933 * @param {Object} store
1934 * @param {Object} options
1936 onBeforeLoad : function (store, options) {
1937 options.params = options.params || {};
1938 this.cleanParams(options.params);
1939 var params = this.buildQuery(this.getFilterData());
1940 Ext.apply(options.params, params);
1945 * Handler for store's load event when configured for local filtering
1946 * @param {Object} store
1947 * @param {Object} options
1949 onLoad : function (store, options) {
1950 store.filterBy(this.getRecordFilter());
1955 * Handler called when the grid's view is refreshed
1957 onRefresh : function () {
1958 this.updateColumnHeadings();
1962 * Update the styles for the header row based on the active filters
1964 updateColumnHeadings : function () {
1965 var view = this.grid.getView(),
1968 for (i = 0, len = view.cm.config.length; i < len; i++) {
1969 filter = this.getFilter(view.cm.config[i].dataIndex);
1970 Ext.fly(view.getHeaderCell(i))[filter && filter.active ? 'addClass' : 'removeClass'](this.filterCls);
1976 reload : function () {
1978 this.grid.store.clearFilter(true);
1979 this.grid.store.filterBy(this.getRecordFilter());
1982 store = this.grid.store;
1983 this.deferredUpdate.cancel();
1985 start = store.paramNames.start;
1986 if (store.lastOptions && store.lastOptions.params && store.lastOptions.params[start]) {
1987 store.lastOptions.params[start] = 0;
1995 * Method factory that generates a record validator for the filters active at the time
1999 getRecordFilter : function () {
2001 this.filters.each(function (filter) {
2002 if (filter.active) {
2008 return function (record) {
2009 for (i = 0; i < len; i++) {
2010 if (!f[i].validateRecord(record)) {
2019 * Adds a filter to the collection and observes it for state change.
2020 * @param {Object/Ext.ux.grid.filter.Filter} config A filter configuration or a filter object.
2021 * @return {Ext.ux.grid.filter.Filter} The existing or newly created filter object.
2023 addFilter : function (config) {
2024 var Cls = this.getFilterClass(config.type),
2025 filter = config.menu ? config : (new Cls(config));
2026 this.filters.add(filter);
2028 Ext.util.Observable.capture(filter, this.onStateChange, this);
2033 * Adds filters to the collection.
2034 * @param {Array/Ext.grid.ColumnModel} filters Either an Array of
2035 * filter configuration objects or an Ext.grid.ColumnModel. The columns
2036 * of a passed Ext.grid.ColumnModel will be examined for a <code>filter</code>
2037 * property and, if present, will be used as the filter configuration object.
2039 addFilters : function (filters) {
2041 var i, len, filter, cm = false, dI;
2042 if (filters instanceof Ext.grid.ColumnModel) {
2043 filters = filters.config;
2046 for (i = 0, len = filters.length; i < len; i++) {
2049 dI = filters[i].dataIndex;
2050 filter = filters[i].filter || filters[i].filterable;
2052 filter = (filter === true) ? {} : filter;
2053 Ext.apply(filter, {dataIndex:dI});
2054 // filter type is specified in order of preference:
2055 // filter type specified in config
2056 // type specified in store's field's type config
2057 filter.type = filter.type || this.store.fields.get(dI).type.type;
2060 filter = filters[i];
2062 // if filter config found add filter for the column
2064 this.addFilter(filter);
2071 * Returns a filter for the given dataIndex, if one exists.
2072 * @param {String} dataIndex The dataIndex of the desired filter object.
2073 * @return {Ext.ux.grid.filter.Filter}
2075 getFilter : function (dataIndex) {
2076 return this.filters.get(dataIndex);
2080 * Turns all filters off. This does not clear the configuration information
2081 * (see {@link #removeAll}).
2083 clearFilters : function () {
2084 this.filters.each(function (filter) {
2085 filter.setActive(false);
2090 * Returns an Array of the currently active filters.
2091 * @return {Array} filters Array of the currently active filters.
2093 getFilterData : function () {
2094 var filters = [], i, len;
2096 this.filters.each(function (f) {
2098 var d = [].concat(f.serialize());
2099 for (i = 0, len = d.length; i < len; i++) {
2111 * Function to take the active filters data and build it into a query.
2112 * The format of the query depends on the <code>{@link #encode}</code>
2114 * <div class="mdetail-params"><ul>
2116 * <li><b><tt>false</tt></b> : <i>Default</i>
2117 * <div class="sub-desc">
2118 * Flatten into query string of the form (assuming <code>{@link #paramPrefix}='filters'</code>:
2120 filters[0][field]="someDataIndex"&
2121 filters[0][data][comparison]="someValue1"&
2122 filters[0][data][type]="someValue2"&
2123 filters[0][data][value]="someValue3"&
2126 * <li><b><tt>true</tt></b> :
2127 * <div class="sub-desc">
2128 * JSON encode the filter data
2130 filters[0][field]="someDataIndex"&
2131 filters[0][data][comparison]="someValue1"&
2132 filters[0][data][type]="someValue2"&
2133 filters[0][data][value]="someValue3"&
2137 * Override this method to customize the format of the filter query for remote requests.
2138 * @param {Array} filters A collection of objects representing active filters and their configuration.
2139 * Each element will take the form of {field: dataIndex, data: filterConf}. dataIndex is not assured
2140 * to be unique as any one filter may be a composite of more basic filters for the same dataIndex.
2141 * @return {Object} Query keys and values
2143 buildQuery : function (filters) {
2144 var p = {}, i, f, root, dataPrefix, key, tmp,
2145 len = filters.length;
2148 for (i = 0; i < len; i++) {
2150 root = [this.paramPrefix, '[', i, ']'].join('');
2151 p[root + '[field]'] = f.field;
2153 dataPrefix = root + '[data]';
2154 for (key in f.data) {
2155 p[[dataPrefix, '[', key, ']'].join('')] = f.data[key];
2160 for (i = 0; i < len; i++) {
2168 // only build if there is active filter
2169 if (tmp.length > 0){
2170 p[this.paramPrefix] = Ext.util.JSON.encode(tmp);
2177 * Removes filter related query parameters from the provided object.
2178 * @param {Object} p Query parameters that may contain filter related fields.
2180 cleanParams : function (p) {
2181 // if encoding just delete the property
2183 delete p[this.paramPrefix];
2184 // otherwise scrub the object of filter data
2187 regex = new RegExp('^' + this.paramPrefix + '\[[0-9]+\]');
2189 if (regex.test(key)) {
2197 * Function for locating filter classes, overwrite this with your favorite
2198 * loader to provide dynamic filter loading.
2199 * @param {String} type The type of filter to load ('Filter' is automatically
2200 * appended to the passed type; eg, 'string' becomes 'StringFilter').
2201 * @return {Class} The Ext.ux.grid.filter.Class
2203 getFilterClass : function (type) {
2204 // map the supported Ext.data.Field type values into a supported filter
2214 return Ext.ux.grid.filter[type.substr(0, 1).toUpperCase() + type.substr(1) + 'Filter'];
2219 Ext.preg('gridfilters', Ext.ux.grid.GridFilters);
2220 Ext.namespace('Ext.ux.grid.filter');
2223 * @class Ext.ux.grid.filter.Filter
2224 * @extends Ext.util.Observable
2225 * Abstract base class for filter implementations.
2227 Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {
2229 * @cfg {Boolean} active
2230 * Indicates the initial status of the filter (defaults to false).
2234 * True if this filter is active. Use setActive() to alter after configuration.
2239 * @cfg {String} dataIndex
2240 * The {@link Ext.data.Store} dataIndex of the field this filter represents.
2241 * The dataIndex does not actually have to exist in the store.
2245 * The filter configuration menu that will be installed into the filter submenu of a column menu.
2246 * @type Ext.menu.Menu
2251 * @cfg {Number} updateBuffer
2252 * Number of milliseconds to wait after user interaction to fire an update. Only supported
2253 * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
2257 constructor : function (config) {
2258 Ext.apply(this, config);
2263 * Fires when an inactive filter becomes active
2264 * @param {Ext.ux.grid.filter.Filter} this
2269 * Fires when an active filter becomes inactive
2270 * @param {Ext.ux.grid.filter.Filter} this
2275 * Fires after the serialization process. Use this to attach additional parameters to serialization
2276 * data before it is encoded and sent to the server.
2277 * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
2278 * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
2283 * Fires when a filter configuration has changed
2284 * @param {Ext.ux.grid.filter.Filter} this The filter object.
2288 Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
2290 this.menu = new Ext.menu.Menu();
2292 if(config && config.value){
2293 this.setValue(config.value);
2294 this.setActive(config.active !== false, true);
2295 delete config.value;
2300 * Destroys this filter by purging any event listeners, and removing any menus.
2302 destroy : function(){
2304 this.menu.destroy();
2306 this.purgeListeners();
2310 * Template method to be implemented by all subclasses that is to
2311 * initialize the filter and install required menu items.
2312 * Defaults to Ext.emptyFn.
2317 * Template method to be implemented by all subclasses that is to
2318 * get and return the value of the filter.
2319 * Defaults to Ext.emptyFn.
2320 * @return {Object} The 'serialized' form of this filter
2321 * @methodOf Ext.ux.grid.filter.Filter
2323 getValue : Ext.emptyFn,
2326 * Template method to be implemented by all subclasses that is to
2327 * set the value of the filter and fire the 'update' event.
2328 * Defaults to Ext.emptyFn.
2329 * @param {Object} data The value to set the filter
2330 * @methodOf Ext.ux.grid.filter.Filter
2332 setValue : Ext.emptyFn,
2335 * Template method to be implemented by all subclasses that is to
2336 * return <tt>true</tt> if the filter has enough configuration information to be activated.
2337 * Defaults to <tt>return true</tt>.
2340 isActivatable : function(){
2345 * Template method to be implemented by all subclasses that is to
2346 * get and return serialized filter data for transmission to the server.
2347 * Defaults to Ext.emptyFn.
2349 getSerialArgs : Ext.emptyFn,
2352 * Template method to be implemented by all subclasses that is to
2353 * validates the provided Ext.data.Record against the filters configuration.
2354 * Defaults to <tt>return true</tt>.
2355 * @param {Ext.data.Record} record The record to validate
2356 * @return {Boolean} true if the record is valid within the bounds
2357 * of the filter, false otherwise.
2359 validateRecord : function(){
2364 * Returns the serialized filter data for transmission to the server
2365 * and fires the 'serialize' event.
2366 * @return {Object/Array} An object or collection of objects containing
2367 * key value pairs representing the current configuration of the filter.
2368 * @methodOf Ext.ux.grid.filter.Filter
2370 serialize : function(){
2371 var args = this.getSerialArgs();
2372 this.fireEvent('serialize', args, this);
2377 fireUpdate : function(){
2379 this.fireEvent('update', this);
2381 this.setActive(this.isActivatable());
2385 * Sets the status of the filter and fires the appropriate events.
2386 * @param {Boolean} active The new filter state.
2387 * @param {Boolean} suppressEvent True to prevent events from being fired.
2388 * @methodOf Ext.ux.grid.filter.Filter
2390 setActive : function(active, suppressEvent){
2391 if(this.active != active){
2392 this.active = active;
2393 if (suppressEvent !== true) {
2394 this.fireEvent(active ? 'activate' : 'deactivate', this);
2399 * @class Ext.ux.grid.filter.BooleanFilter
2400 * @extends Ext.ux.grid.filter.Filter
2401 * Boolean filters use unique radio group IDs (so you can have more than one!)
2402 * <p><b><u>Example Usage:</u></b></p>
2404 var filters = new Ext.ux.grid.GridFilters({
2409 dataIndex: 'visible'
2412 defaultValue: null, // leave unselected (false selected by default)
2413 yesText: 'Yes', // default
2414 noText: 'No' // default
2419 Ext.ux.grid.filter.BooleanFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2421 * @cfg {Boolean} defaultValue
2422 * Set this to null if you do not want either option to be checked by default. Defaults to false.
2424 defaultValue : false,
2426 * @cfg {String} yesText
2427 * Defaults to 'Yes'.
2431 * @cfg {String} noText
2438 * Template method that is to initialize the filter and install required menu items.
2440 init : function (config) {
2443 new Ext.menu.CheckItem({text: this.yesText, group: gId, checked: this.defaultValue === true}),
2444 new Ext.menu.CheckItem({text: this.noText, group: gId, checked: this.defaultValue === false})];
2446 this.menu.add(this.options[0], this.options[1]);
2448 for(var i=0; i<this.options.length; i++){
2449 this.options[i].on('click', this.fireUpdate, this);
2450 this.options[i].on('checkchange', this.fireUpdate, this);
2456 * Template method that is to get and return the value of the filter.
2457 * @return {String} The value of this filter
2459 getValue : function () {
2460 return this.options[0].checked;
2465 * Template method that is to set the value of the filter.
2466 * @param {Object} value The value to set the filter
2468 setValue : function (value) {
2469 this.options[value ? 0 : 1].setChecked(true);
2474 * Template method that is to get and return serialized filter data for
2475 * transmission to the server.
2476 * @return {Object/Array} An object or collection of objects containing
2477 * key value pairs representing the current configuration of the filter.
2479 getSerialArgs : function () {
2480 var args = {type: 'boolean', value: this.getValue()};
2485 * Template method that is to validate the provided Ext.data.Record
2486 * against the filters configuration.
2487 * @param {Ext.data.Record} record The record to validate
2488 * @return {Boolean} true if the record is valid within the bounds
2489 * of the filter, false otherwise.
2491 validateRecord : function (record) {
2492 return record.get(this.dataIndex) == this.getValue();
2495 * @class Ext.ux.grid.filter.DateFilter
2496 * @extends Ext.ux.grid.filter.Filter
2497 * Filter by a configurable Ext.menu.DateMenu
2498 * <p><b><u>Example Usage:</u></b></p>
2500 var filters = new Ext.ux.grid.GridFilters({
2505 dataIndex: 'dateAdded',
2508 dateFormat: 'm/d/Y', // default
2509 beforeText: 'Before', // default
2510 afterText: 'After', // default
2511 onText: 'On', // default
2513 // any DateMenu configs
2516 active: true // default is false
2521 Ext.ux.grid.filter.DateFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2523 * @cfg {String} afterText
2524 * Defaults to 'After'.
2526 afterText : 'After',
2528 * @cfg {String} beforeText
2529 * Defaults to 'Before'.
2531 beforeText : 'Before',
2533 * @cfg {Object} compareMap
2534 * Map for assigning the comparison values used in serialization.
2542 * @cfg {String} dateFormat
2543 * The date format to return when using getValue.
2544 * Defaults to 'm/d/Y'.
2546 dateFormat : 'm/d/Y',
2549 * @cfg {Date} maxDate
2550 * Allowable date as passed to the Ext.DatePicker
2551 * Defaults to undefined.
2554 * @cfg {Date} minDate
2555 * Allowable date as passed to the Ext.DatePicker
2556 * Defaults to undefined.
2559 * @cfg {Array} menuItems
2560 * The items to be shown in this menu
2562 * menuItems : ['before', 'after', '-', 'on'],
2565 menuItems : ['before', 'after', '-', 'on'],
2568 * @cfg {Object} menuItemCfgs
2569 * Default configuration options for each menu item
2572 selectOnFocus: true,
2577 * @cfg {String} onText
2583 * @cfg {Object} pickerOpts
2584 * Configuration options for the date picker associated with each field.
2590 * Template method that is to initialize the filter and install required menu items.
2592 init : function (config) {
2593 var menuCfg, i, len, item, cfg, Cls;
2595 menuCfg = Ext.apply(this.pickerOpts, {
2596 minDate: this.minDate,
2597 maxDate: this.maxDate,
2598 format: this.dateFormat,
2601 select: this.onMenuSelect
2606 for (i = 0, len = this.menuItems.length; i < len; i++) {
2607 item = this.menuItems[i];
2610 itemId: 'range-' + item,
2611 text: this[item + 'Text'],
2612 menu: new Ext.menu.DateMenu(
2613 Ext.apply(menuCfg, {
2619 checkchange: this.onCheckChange
2622 Cls = Ext.menu.CheckItem;
2623 item = this.fields[item] = new Cls(cfg);
2626 this.menu.add(item);
2630 onCheckChange : function () {
2631 this.setActive(this.isActivatable());
2632 this.fireEvent('update', this);
2637 * Handler method called when there is a keyup event on an input
2638 * item of this menu.
2640 onInputKeyUp : function (field, e) {
2642 if (k == e.RETURN && field.isValid()) {
2644 this.menu.hide(true);
2650 * Handler for when the menu for a field fires the 'select' event
2651 * @param {Object} date
2652 * @param {Object} menuItem
2653 * @param {Object} value
2654 * @param {Object} picker
2656 onMenuSelect : function (menuItem, value, picker) {
2657 var fields = this.fields,
2658 field = this.fields[menuItem.itemId];
2660 field.setChecked(true);
2662 if (field == fields.on) {
2663 fields.before.setChecked(false, true);
2664 fields.after.setChecked(false, true);
2666 fields.on.setChecked(false, true);
2667 if (field == fields.after && fields.before.menu.picker.value < value) {
2668 fields.before.setChecked(false, true);
2669 } else if (field == fields.before && fields.after.menu.picker.value > value) {
2670 fields.after.setChecked(false, true);
2673 this.fireEvent('update', this);
2678 * Template method that is to get and return the value of the filter.
2679 * @return {String} The value of this filter
2681 getValue : function () {
2682 var key, result = {};
2683 for (key in this.fields) {
2684 if (this.fields[key].checked) {
2685 result[key] = this.fields[key].menu.picker.getValue();
2693 * Template method that is to set the value of the filter.
2694 * @param {Object} value The value to set the filter
2695 * @param {Boolean} preserve true to preserve the checked status
2696 * of the other fields. Defaults to false, unchecking the
2699 setValue : function (value, preserve) {
2701 for (key in this.fields) {
2703 this.fields[key].menu.picker.setValue(value[key]);
2704 this.fields[key].setChecked(true);
2705 } else if (!preserve) {
2706 this.fields[key].setChecked(false);
2709 this.fireEvent('update', this);
2714 * Template method that is to return <tt>true</tt> if the filter
2715 * has enough configuration information to be activated.
2718 isActivatable : function () {
2720 for (key in this.fields) {
2721 if (this.fields[key].checked) {
2730 * Template method that is to get and return serialized filter data for
2731 * transmission to the server.
2732 * @return {Object/Array} An object or collection of objects containing
2733 * key value pairs representing the current configuration of the filter.
2735 getSerialArgs : function () {
2737 for (var key in this.fields) {
2738 if(this.fields[key].checked){
2741 comparison: this.compareMap[key],
2742 value: this.getFieldValue(key).format(this.dateFormat)
2750 * Get and return the date menu picker value
2751 * @param {String} item The field identifier ('before', 'after', 'on')
2752 * @return {Date} Gets the current selected value of the date field
2754 getFieldValue : function(item){
2755 return this.fields[item].menu.picker.getValue();
2759 * Gets the menu picker associated with the passed field
2760 * @param {String} item The field identifier ('before', 'after', 'on')
2761 * @return {Object} The menu picker
2763 getPicker : function(item){
2764 return this.fields[item].menu.picker;
2768 * Template method that is to validate the provided Ext.data.Record
2769 * against the filters configuration.
2770 * @param {Ext.data.Record} record The record to validate
2771 * @return {Boolean} true if the record is valid within the bounds
2772 * of the filter, false otherwise.
2774 validateRecord : function (record) {
2777 val = record.get(this.dataIndex);
2779 if(!Ext.isDate(val)){
2782 val = val.clearTime(true).getTime();
2784 for (key in this.fields) {
2785 if (this.fields[key].checked) {
2786 pickerValue = this.getFieldValue(key).clearTime(true).getTime();
2787 if (key == 'before' && pickerValue <= val) {
2790 if (key == 'after' && pickerValue >= val) {
2793 if (key == 'on' && pickerValue != val) {
2801 * @class Ext.ux.grid.filter.ListFilter
2802 * @extends Ext.ux.grid.filter.Filter
2803 * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load
2804 * their options the first time they are shown. ListFilter utilizes the
2805 * {@link Ext.ux.menu.ListMenu} component.</p>
2806 * <p>Although not shown here, this class accepts all configuration options
2807 * for {@link Ext.ux.menu.ListMenu}.</p>
2809 * <p><b><u>Example Usage:</u></b></p>
2811 var filters = new Ext.ux.grid.GridFilters({
2817 // options will be used as data to implicitly creates an ArrayStore
2818 options: ['extra small', 'small', 'medium', 'large', 'extra large']
2824 Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2827 * @cfg {Array} options
2828 * <p><code>data</code> to be used to implicitly create a data store
2829 * to back this list when the data source is <b>local</b>. If the
2830 * data for the list is remote, use the <code>{@link #store}</code>
2831 * config instead.</p>
2832 * <br><p>Each item within the provided array may be in one of the
2833 * following formats:</p>
2834 * <div class="mdetail-params"><ul>
2835 * <li><b>Array</b> :
2838 [11, 'extra small'],
2846 * <li><b>Object</b> :
2848 labelField: 'name', // override default of 'text'
2850 {id: 11, name:'extra small'},
2851 {id: 18, name:'small'},
2852 {id: 22, name:'medium'},
2853 {id: 35, name:'large'},
2854 {id: 44, name:'extra large'}
2858 * <li><b>String</b> :
2860 * options: ['extra small', 'small', 'medium', 'large', 'extra large']
2865 * @cfg {Boolean} phpMode
2866 * <p>Adjust the format of this filter. Defaults to false.</p>
2867 * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>
2869 // phpMode == false (default):
2870 filter[0][data][type] list
2871 filter[0][data][value] value1
2872 filter[0][data][value] value2
2873 filter[0][field] prod
2876 filter[0][data][type] list
2877 filter[0][data][value] value1, value2
2878 filter[0][field] prod
2880 * When GridFilters <code>@cfg encode = true</code>:
2882 // phpMode == false (default):
2883 filter : [{"type":"list","value":["small","medium"],"field":"size"}]
2886 filter : [{"type":"list","value":"small,medium","field":"size"}]
2891 * @cfg {Ext.data.Store} store
2892 * The {@link Ext.data.Store} this list should use as its data source
2893 * when the data source is <b>remote</b>. If the data for the list
2894 * is local, use the <code>{@link #options}</code> config instead.
2899 * Template method that is to initialize the filter and install required menu items.
2900 * @param {Object} config
2902 init : function (config) {
2903 this.dt = new Ext.util.DelayedTask(this.fireUpdate, this);
2905 // if a menu already existed, do clean up first
2907 this.menu.destroy();
2909 this.menu = new Ext.ux.menu.ListMenu(config);
2910 this.menu.on('checkchange', this.onCheckChange, this);
2915 * Template method that is to get and return the value of the filter.
2916 * @return {String} The value of this filter
2918 getValue : function () {
2919 return this.menu.getSelected();
2923 * Template method that is to set the value of the filter.
2924 * @param {Object} value The value to set the filter
2926 setValue : function (value) {
2927 this.menu.setSelected(value);
2928 this.fireEvent('update', this);
2933 * Template method that is to return <tt>true</tt> if the filter
2934 * has enough configuration information to be activated.
2937 isActivatable : function () {
2938 return this.getValue().length > 0;
2943 * Template method that is to get and return serialized filter data for
2944 * transmission to the server.
2945 * @return {Object/Array} An object or collection of objects containing
2946 * key value pairs representing the current configuration of the filter.
2948 getSerialArgs : function () {
2949 var args = {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
2954 onCheckChange : function(){
2955 this.dt.delay(this.updateBuffer);
2960 * Template method that is to validate the provided Ext.data.Record
2961 * against the filters configuration.
2962 * @param {Ext.data.Record} record The record to validate
2963 * @return {Boolean} true if the record is valid within the bounds
2964 * of the filter, false otherwise.
2966 validateRecord : function (record) {
2967 return this.getValue().indexOf(record.get(this.dataIndex)) > -1;
2970 * @class Ext.ux.grid.filter.NumericFilter
2971 * @extends Ext.ux.grid.filter.Filter
2972 * Filters using an Ext.ux.menu.RangeMenu.
2973 * <p><b><u>Example Usage:</u></b></p>
2975 var filters = new Ext.ux.grid.GridFilters({
2984 Ext.ux.grid.filter.NumericFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
2987 * @cfg {Object} fieldCls
2988 * The Class to use to construct each field item within this menu
2990 * fieldCls : Ext.form.NumberField
2993 fieldCls : Ext.form.NumberField,
2995 * @cfg {Object} fieldCfg
2996 * The default configuration options for any field item unless superseded
2997 * by the <code>{@link #fields}</code> configuration.
3009 * @cfg {Object} fields
3010 * The field items may be configured individually
3011 * Defaults to <tt>undefined</tt>.
3015 gt: { // override fieldCfg options
3017 fieldCls: Ext.ux.form.CustomNumberField // to override default {@link #fieldCls}
3023 * @cfg {Object} iconCls
3024 * The iconCls to be applied to each comparator field item.
3027 gt : 'ux-rangemenu-gt',
3028 lt : 'ux-rangemenu-lt',
3029 eq : 'ux-rangemenu-eq'
3034 gt : 'ux-rangemenu-gt',
3035 lt : 'ux-rangemenu-lt',
3036 eq : 'ux-rangemenu-eq'
3040 * @cfg {Object} menuItemCfgs
3041 * Default configuration options for each menu item
3044 emptyText: 'Enter Filter Text...',
3045 selectOnFocus: true,
3051 emptyText: 'Enter Filter Text...',
3052 selectOnFocus: true,
3057 * @cfg {Array} menuItems
3058 * The items to be shown in this menu. Items are added to the menu
3059 * according to their position within this array. Defaults to:<pre>
3060 * menuItems : ['lt','gt','-','eq']
3063 menuItems : ['lt', 'gt', '-', 'eq'],
3067 * Template method that is to initialize the filter and install required menu items.
3069 init : function (config) {
3070 // if a menu already existed, do clean up first
3072 this.menu.destroy();
3074 this.menu = new Ext.ux.menu.RangeMenu(Ext.apply(config, {
3075 // pass along filter configs to the menu
3076 fieldCfg : this.fieldCfg || {},
3077 fieldCls : this.fieldCls,
3078 fields : this.fields || {},
3079 iconCls: this.iconCls,
3080 menuItemCfgs: this.menuItemCfgs,
3081 menuItems: this.menuItems,
3082 updateBuffer: this.updateBuffer
3084 // relay the event fired by the menu
3085 this.menu.on('update', this.fireUpdate, this);
3090 * Template method that is to get and return the value of the filter.
3091 * @return {String} The value of this filter
3093 getValue : function () {
3094 return this.menu.getValue();
3099 * Template method that is to set the value of the filter.
3100 * @param {Object} value The value to set the filter
3102 setValue : function (value) {
3103 this.menu.setValue(value);
3108 * Template method that is to return <tt>true</tt> if the filter
3109 * has enough configuration information to be activated.
3112 isActivatable : function () {
3113 var values = this.getValue();
3114 for (key in values) {
3115 if (values[key] !== undefined) {
3124 * Template method that is to get and return serialized filter data for
3125 * transmission to the server.
3126 * @return {Object/Array} An object or collection of objects containing
3127 * key value pairs representing the current configuration of the filter.
3129 getSerialArgs : function () {
3132 values = this.menu.getValue();
3133 for (key in values) {
3144 * Template method that is to validate the provided Ext.data.Record
3145 * against the filters configuration.
3146 * @param {Ext.data.Record} record The record to validate
3147 * @return {Boolean} true if the record is valid within the bounds
3148 * of the filter, false otherwise.
3150 validateRecord : function (record) {
3151 var val = record.get(this.dataIndex),
3152 values = this.getValue();
3153 if (values.eq !== undefined && val != values.eq) {
3156 if (values.lt !== undefined && val >= values.lt) {
3159 if (values.gt !== undefined && val <= values.gt) {
3165 * @class Ext.ux.grid.filter.StringFilter
3166 * @extends Ext.ux.grid.filter.Filter
3167 * Filter by a configurable Ext.form.TextField
3168 * <p><b><u>Example Usage:</u></b></p>
3170 var filters = new Ext.ux.grid.GridFilters({
3179 active: true, // default is false
3180 iconCls: 'ux-gridfilter-text-icon' // default
3181 // any Ext.form.TextField configs accepted
3186 Ext.ux.grid.filter.StringFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
3189 * @cfg {String} iconCls
3190 * The iconCls to be applied to the menu item.
3191 * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
3193 iconCls : 'ux-gridfilter-text-icon',
3195 emptyText: 'Enter Filter Text...',
3196 selectOnFocus: true,
3201 * Template method that is to initialize the filter and install required menu items.
3203 init : function (config) {
3204 Ext.applyIf(config, {
3205 enableKeyEvents: true,
3206 iconCls: this.iconCls,
3209 keyup: this.onInputKeyUp
3213 this.inputItem = new Ext.form.TextField(config);
3214 this.menu.add(this.inputItem);
3215 this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
3220 * Template method that is to get and return the value of the filter.
3221 * @return {String} The value of this filter
3223 getValue : function () {
3224 return this.inputItem.getValue();
3229 * Template method that is to set the value of the filter.
3230 * @param {Object} value The value to set the filter
3232 setValue : function (value) {
3233 this.inputItem.setValue(value);
3234 this.fireEvent('update', this);
3239 * Template method that is to return <tt>true</tt> if the filter
3240 * has enough configuration information to be activated.
3243 isActivatable : function () {
3244 return this.inputItem.getValue().length > 0;
3249 * Template method that is to get and return serialized filter data for
3250 * transmission to the server.
3251 * @return {Object/Array} An object or collection of objects containing
3252 * key value pairs representing the current configuration of the filter.
3254 getSerialArgs : function () {
3255 return {type: 'string', value: this.getValue()};
3259 * Template method that is to validate the provided Ext.data.Record
3260 * against the filters configuration.
3261 * @param {Ext.data.Record} record The record to validate
3262 * @return {Boolean} true if the record is valid within the bounds
3263 * of the filter, false otherwise.
3265 validateRecord : function (record) {
3266 var val = record.get(this.dataIndex);
3268 if(typeof val != 'string') {
3269 return (this.getValue().length === 0);
3272 return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
3277 * Handler method called when there is a keyup event on this.inputItem
3279 onInputKeyUp : function (field, e) {
3281 if (k == e.RETURN && field.isValid()) {
3283 this.menu.hide(true);
3286 // restart the timer
3287 this.updateTask.delay(this.updateBuffer);
3290 Ext.namespace('Ext.ux.menu');
3293 * @class Ext.ux.menu.ListMenu
3294 * @extends Ext.menu.Menu
3295 * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.
3296 * Although not listed as configuration options for this class, this class
3297 * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.
3299 Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
3301 * @cfg {String} labelField
3302 * Defaults to 'text'.
3304 labelField : 'text',
3306 * @cfg {String} paramPrefix
3307 * Defaults to 'Loading...'.
3309 loadingText : 'Loading...',
3311 * @cfg {Boolean} loadOnShow
3316 * @cfg {Boolean} single
3317 * Specify true to group all items in this list into a single-select
3318 * radio button group. Defaults to false.
3322 constructor : function (cfg) {
3326 * @event checkchange
3327 * Fires when there is a change in checked items from this list
3328 * @param {Object} item Ext.menu.CheckItem
3329 * @param {Object} checked The checked value that was set
3334 Ext.ux.menu.ListMenu.superclass.constructor.call(this, cfg = cfg || {});
3336 if(!cfg.store && cfg.options){
3338 for(var i=0, len=cfg.options.length; i<len; i++){
3339 var value = cfg.options[i];
3340 switch(Ext.type(value)){
3341 case 'array': options.push(value); break;
3342 case 'object': options.push([value.id, value[this.labelField]]); break;
3343 case 'string': options.push([value, value]); break;
3347 this.store = new Ext.data.Store({
3348 reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]),
3351 'load': this.onLoad,
3357 this.add({text: this.loadingText, iconCls: 'loading-indicator'});
3358 this.store.on('load', this.onLoad, this);
3362 destroy : function () {
3364 this.store.destroy();
3366 Ext.ux.menu.ListMenu.superclass.destroy.call(this);
3370 * Lists will initially show a 'loading' item while the data is retrieved from the store.
3371 * In some cases the loaded data will result in a list that goes off the screen to the
3372 * right (as placement calculations were done with the loading item). This adapter will
3373 * allow show to be called with no arguments to show with the previous arguments and
3374 * thus recalculate the width and potentially hang the menu from the left.
3376 show : function () {
3377 var lastArgs = null;
3379 if(arguments.length === 0){
3380 Ext.ux.menu.ListMenu.superclass.show.apply(this, lastArgs);
3382 lastArgs = arguments;
3383 if (this.loadOnShow && !this.loaded) {
3386 Ext.ux.menu.ListMenu.superclass.show.apply(this, arguments);
3392 onLoad : function (store, records) {
3393 var visible = this.isVisible();
3396 this.removeAll(true);
3398 var gid = this.single ? Ext.id() : null;
3399 for(var i=0, len=records.length; i<len; i++){
3400 var item = new Ext.menu.CheckItem({
3401 text: records[i].get(this.labelField),
3403 checked: this.selected.indexOf(records[i].id) > -1,
3404 hideOnClick: false});
3406 item.itemId = records[i].id;
3407 item.on('checkchange', this.checkChange, this);
3417 this.fireEvent('load', this, records);
3421 * Get the selected items.
3422 * @return {Array} selected
3424 getSelected : function () {
3425 return this.selected;
3429 setSelected : function (value) {
3430 value = this.selected = [].concat(value);
3433 this.items.each(function(item){
3434 item.setChecked(false, true);
3435 for (var i = 0, len = value.length; i < len; i++) {
3436 if (item.itemId == value[i]) {
3437 item.setChecked(true, true);
3445 * Handler for the 'checkchange' event from an check item in this menu
3446 * @param {Object} item Ext.menu.CheckItem
3447 * @param {Object} checked The checked value that was set
3449 checkChange : function (item, checked) {
3451 this.items.each(function(item){
3453 value.push(item.itemId);
3456 this.selected = value;
3458 this.fireEvent('checkchange', item, checked);
3460 });Ext.ns('Ext.ux.menu');
3463 * @class Ext.ux.menu.RangeMenu
3464 * @extends Ext.menu.Menu
3465 * Custom implementation of Ext.menu.Menu that has preconfigured
3466 * items for gt, lt, eq.
3467 * <p><b><u>Example Usage:</u></b></p>
3472 Ext.ux.menu.RangeMenu = Ext.extend(Ext.menu.Menu, {
3474 constructor : function (config) {
3476 Ext.ux.menu.RangeMenu.superclass.constructor.call(this, config);
3481 * Fires when a filter configuration has changed
3482 * @param {Ext.ux.grid.filter.Filter} this The filter object.
3487 this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
3489 var i, len, item, cfg, Cls;
3491 for (i = 0, len = this.menuItems.length; i < len; i++) {
3492 item = this.menuItems[i];
3496 itemId: 'range-' + item,
3497 enableKeyEvents: true,
3498 iconCls: this.iconCls[item] || 'no-icon',
3501 keyup: this.onInputKeyUp
3507 Ext.applyIf(this.fields[item] || {}, this.fieldCfg[item]),
3508 // configurable defaults
3511 Cls = cfg.fieldCls || this.fieldCls;
3512 item = this.fields[item] = new Cls(cfg);
3520 * called by this.updateTask
3522 fireUpdate : function () {
3523 this.fireEvent('update', this);
3527 * Get and return the value of the filter.
3528 * @return {String} The value of this filter
3530 getValue : function () {
3531 var result = {}, key, field;
3532 for (key in this.fields) {
3533 field = this.fields[key];
3534 if (field.isValid() && String(field.getValue()).length > 0) {
3535 result[key] = field.getValue();
3542 * Set the value of this menu and fires the 'update' event.
3543 * @param {Object} data The data to assign to this menu
3545 setValue : function (data) {
3547 for (key in this.fields) {
3548 this.fields[key].setValue(data[key] !== undefined ? data[key] : '');
3550 this.fireEvent('update', this);
3555 * Handler method called when there is a keyup event on an input
3556 * item of this menu.
3558 onInputKeyUp : function (field, e) {
3560 if (k == e.RETURN && field.isValid()) {
3566 if (field == this.fields.eq) {
3567 if (this.fields.gt) {
3568 this.fields.gt.setValue(null);
3570 if (this.fields.lt) {
3571 this.fields.lt.setValue(null);
3575 this.fields.eq.setValue(null);
3578 // restart the timer
3579 this.updateTask.delay(this.updateBuffer);
3583 * Ext JS Library 3.2.0
3584 * Copyright(c) 2006-2010 Ext JS, Inc.
3585 * licensing@extjs.com
3586 * http://www.extjs.com/license
3588 Ext.ns('Ext.ux.grid');
3591 * @class Ext.ux.grid.GroupSummary
3592 * @extends Ext.util.Observable
3593 * A GridPanel plugin that enables dynamic column calculations and a dynamically
3594 * updated grouped summary row.
3596 Ext.ux.grid.GroupSummary = Ext.extend(Ext.util.Observable, {
3598 * @cfg {Function} summaryRenderer Renderer example:<pre><code>
3599 summaryRenderer: function(v, params, data){
3600 return ((v === 0 || v > 1) ? '(' + v +' Tasks)' : '(1 Task)');
3605 * @cfg {String} summaryType (Optional) The type of
3606 * calculation to be used for the column. For options available see
3607 * {@link #Calculations}.
3610 constructor : function(config){
3611 Ext.apply(this, config);
3612 Ext.ux.grid.GroupSummary.superclass.constructor.call(this);
3614 init : function(grid){
3616 var v = this.view = grid.getView();
3617 v.doGroupEnd = this.doGroupEnd.createDelegate(this);
3619 v.afterMethod('onColumnWidthUpdated', this.doWidth, this);
3620 v.afterMethod('onAllColumnWidthsUpdated', this.doAllWidths, this);
3621 v.afterMethod('onColumnHiddenUpdated', this.doHidden, this);
3622 v.afterMethod('onUpdate', this.doUpdate, this);
3623 v.afterMethod('onRemove', this.doRemove, this);
3626 this.rowTpl = new Ext.Template(
3627 '<div class="x-grid3-summary-row" style="{tstyle}">',
3628 '<table class="x-grid3-summary-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
3629 '<tbody><tr>{cells}</tr></tbody>',
3632 this.rowTpl.disableFormats = true;
3634 this.rowTpl.compile();
3637 this.cellTpl = new Ext.Template(
3638 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
3639 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on">{value}</div>',
3642 this.cellTpl.disableFormats = true;
3644 this.cellTpl.compile();
3648 * Toggle the display of the summary row on/off
3649 * @param {Boolean} visible <tt>true</tt> to show the summary, <tt>false</tt> to hide the summary.
3651 toggleSummaries : function(visible){
3652 var el = this.grid.getGridEl();
3654 if(visible === undefined){
3655 visible = el.hasClass('x-grid-hide-summary');
3657 el[visible ? 'removeClass' : 'addClass']('x-grid-hide-summary');
3661 renderSummary : function(o, cs){
3662 cs = cs || this.view.getColumnData();
3663 var cfg = this.grid.getColumnModel().config,
3664 buf = [], c, p = {}, cf, last = cs.length-1;
3665 for(var i = 0, len = cs.length; i < len; i++){
3670 p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
3671 if(cf.summaryType || cf.summaryRenderer){
3672 p.value = (cf.summaryRenderer || c.renderer)(o.data[c.name], p, o);
3676 if(p.value == undefined || p.value === "") p.value = " ";
3677 buf[buf.length] = this.cellTpl.apply(p);
3680 return this.rowTpl.apply({
3681 tstyle: 'width:'+this.view.getTotalWidth()+';',
3688 * @param {Object} rs
3689 * @param {Object} cs
3691 calculate : function(rs, cs){
3692 var data = {}, r, c, cfg = this.grid.getColumnModel().config, cf;
3693 for(var j = 0, jlen = rs.length; j < jlen; j++){
3695 for(var i = 0, len = cs.length; i < len; i++){
3699 data[c.name] = Ext.ux.grid.GroupSummary.Calculations[cf.summaryType](data[c.name] || 0, r, c.name, data);
3706 doGroupEnd : function(buf, g, cs, ds, colCount){
3707 var data = this.calculate(g.rs, cs);
3708 buf.push('</div>', this.renderSummary({data: data}, cs), '</div>');
3711 doWidth : function(col, w, tw){
3712 if(!this.isGrouped()){
3715 var gs = this.view.getGroups(),
3719 for(; i < len; ++i){
3720 s = gs[i].childNodes[2];
3722 s.firstChild.style.width = tw;
3723 s.firstChild.rows[0].childNodes[col].style.width = w;
3727 doAllWidths : function(ws, tw){
3728 if(!this.isGrouped()){
3731 var gs = this.view.getGroups(),
3739 for(; i < len; i++){
3740 s = gs[i].childNodes[2];
3742 s.firstChild.style.width = tw;
3743 cells = s.firstChild.rows[0].childNodes;
3744 for(j = 0; j < wlen; j++){
3745 cells[j].style.width = ws[j];
3750 doHidden : function(col, hidden, tw){
3751 if(!this.isGrouped()){
3754 var gs = this.view.getGroups(),
3758 display = hidden ? 'none' : '';
3759 for(; i < len; i++){
3760 s = gs[i].childNodes[2];
3762 s.firstChild.style.width = tw;
3763 s.firstChild.rows[0].childNodes[col].style.display = display;
3767 isGrouped : function(){
3768 return !Ext.isEmpty(this.grid.getStore().groupField);
3771 // Note: requires that all (or the first) record in the
3772 // group share the same group value. Returns false if the group
3773 // could not be found.
3774 refreshSummary : function(groupValue){
3775 return this.refreshSummaryById(this.view.getGroupId(groupValue));
3778 getSummaryNode : function(gid){
3779 var g = Ext.fly(gid, '_gsummary');
3781 return g.down('.x-grid3-summary-row', true);
3786 refreshSummaryById : function(gid){
3787 var g = Ext.getDom(gid);
3792 this.grid.getStore().each(function(r){
3793 if(r._groupId == gid){
3797 var cs = this.view.getColumnData(),
3798 data = this.calculate(rs, cs),
3799 markup = this.renderSummary({data: data}, cs),
3800 existing = this.getSummaryNode(gid);
3803 g.removeChild(existing);
3805 Ext.DomHelper.append(g, markup);
3809 doUpdate : function(ds, record){
3810 this.refreshSummaryById(record._groupId);
3813 doRemove : function(ds, record, index, isUpdate){
3815 this.refreshSummaryById(record._groupId);
3820 * Show a message in the summary row.
3822 grid.on('afteredit', function(){
3823 var groupValue = 'Ext Forms: Field Anchoring';
3824 summary.showSummaryMsg(groupValue, 'Updating Summary...');
3827 * @param {String} groupValue
3828 * @param {String} msg Text to use as innerHTML for the summary row.
3830 showSummaryMsg : function(groupValue, msg){
3831 var gid = this.view.getGroupId(groupValue),
3832 node = this.getSummaryNode(gid);
3834 node.innerHTML = '<div class="x-grid3-summary-msg">' + msg + '</div>';
3840 Ext.grid.GroupSummary = Ext.ux.grid.GroupSummary;
3844 * Calculation types for summary row:</p><div class="mdetail-params"><ul>
3845 * <li><b><tt>sum</tt></b> : <div class="sub-desc"></div></li>
3846 * <li><b><tt>count</tt></b> : <div class="sub-desc"></div></li>
3847 * <li><b><tt>max</tt></b> : <div class="sub-desc"></div></li>
3848 * <li><b><tt>min</tt></b> : <div class="sub-desc"></div></li>
3849 * <li><b><tt>average</tt></b> : <div class="sub-desc"></div></li>
3851 * <p>Custom calculations may be implemented. An example of
3852 * custom <code>summaryType=totalCost</code>:</p><pre><code>
3853 // define a custom summary function
3854 Ext.ux.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field){
3855 return v + (record.data.estimate * record.data.rate);
3858 * @property Calculations
3861 Ext.ux.grid.GroupSummary.Calculations = {
3862 'sum' : function(v, record, field){
3863 return v + (record.data[field]||0);
3866 'count' : function(v, record, field, data){
3867 return data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
3870 'max' : function(v, record, field, data){
3871 var v = record.data[field];
3872 var max = data[field+'max'] === undefined ? (data[field+'max'] = v) : data[field+'max'];
3873 return v > max ? (data[field+'max'] = v) : max;
3876 'min' : function(v, record, field, data){
3877 var v = record.data[field];
3878 var min = data[field+'min'] === undefined ? (data[field+'min'] = v) : data[field+'min'];
3879 return v < min ? (data[field+'min'] = v) : min;
3882 'average' : function(v, record, field, data){
3883 var c = data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
3884 var t = (data[field+'total'] = ((data[field+'total']||0) + (record.data[field]||0)));
3885 return t === 0 ? 0 : t / c;
3888 Ext.grid.GroupSummary.Calculations = Ext.ux.grid.GroupSummary.Calculations;
3891 * @class Ext.ux.grid.HybridSummary
3892 * @extends Ext.ux.grid.GroupSummary
3893 * Adds capability to specify the summary data for the group via json as illustrated here:
3898 projectId: 100, project: 'House',
3899 taskId: 112, description: 'Paint',
3900 estimate: 6, rate: 150,
3908 description: 14, estimate: 9,
3909 rate: 99, due: new Date(2009, 6, 29),
3917 Ext.ux.grid.HybridSummary = Ext.extend(Ext.ux.grid.GroupSummary, {
3920 * @param {Object} rs
3921 * @param {Object} cs
3923 calculate : function(rs, cs){
3924 var gcol = this.view.getGroupField(),
3925 gvalue = rs[0].data[gcol],
3926 gdata = this.getSummaryData(gvalue);
3927 return gdata || Ext.ux.grid.HybridSummary.superclass.calculate.call(this, rs, cs);
3932 grid.on('afteredit', function(){
3933 var groupValue = 'Ext Forms: Field Anchoring';
3934 summary.showSummaryMsg(groupValue, 'Updating Summary...');
3935 setTimeout(function(){ // simulate server call
3936 // HybridSummary class implements updateSummaryData
3937 summary.updateSummaryData(groupValue,
3938 // create data object based on configured dataIndex
3939 {description: 22, estimate: 888, rate: 888, due: new Date(), cost: 8});
3943 * @param {String} groupValue
3944 * @param {Object} data data object
3945 * @param {Boolean} skipRefresh (Optional) Defaults to false
3947 updateSummaryData : function(groupValue, data, skipRefresh){
3948 var json = this.grid.getStore().reader.jsonData;
3949 if(!json.summaryData){
3950 json.summaryData = {};
3952 json.summaryData[groupValue] = data;
3954 this.refreshSummary(groupValue);
3959 * Returns the summaryData for the specified groupValue or null.
3960 * @param {String} groupValue
3961 * @return {Object} summaryData
3963 getSummaryData : function(groupValue){
3964 var reader = this.grid.getStore().reader,
3965 json = reader.jsonData,
3966 fields = reader.recordType.prototype.fields,
3969 if(json && json.summaryData){
3970 v = json.summaryData[groupValue];
3972 return reader.extractValues(v, fields.items, fields.length);
3980 Ext.grid.HybridSummary = Ext.ux.grid.HybridSummary;
3981 Ext.ux.GroupTab = Ext.extend(Ext.Container, {
3986 deferredRender: true,
3992 headerAsText: false,
3998 initComponent: function(config){
3999 Ext.apply(this, config);
4002 Ext.ux.GroupTab.superclass.initComponent.call(this);
4004 this.addEvents('activate', 'deactivate', 'changemainitem', 'beforetabchange', 'tabchange');
4006 this.setLayout(new Ext.layout.CardLayout({
4007 deferredRender: this.deferredRender
4011 this.stack = Ext.TabPanel.AccessStack();
4016 this.on('beforerender', function(){
4017 this.groupEl = this.ownerCt.getGroupEl(this);
4020 this.on('add', this.onAdd, this, {
4023 this.on('remove', this.onRemove, this, {
4027 if (this.mainItem !== undefined) {
4028 var item = (typeof this.mainItem == 'object') ? this.mainItem : this.items.get(this.mainItem);
4029 delete this.mainItem;
4030 this.setMainItem(item);
4035 * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which
4036 * can return false to cancel the tab change.
4037 * @param {String/Panel} tab The id or tab Panel to activate
4039 setActiveTab : function(item){
4040 item = this.getComponent(item);
4045 this.activeTab = item;
4048 if(this.activeTab != item && this.fireEvent('beforetabchange', this, item, this.activeTab) !== false){
4049 if(this.activeTab && this.activeTab != this.mainItem){
4050 var oldEl = this.getTabEl(this.activeTab);
4052 Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
4055 var el = this.getTabEl(item);
4056 Ext.fly(el).addClass('x-grouptabs-strip-active');
4057 this.activeTab = item;
4058 this.stack.add(item);
4060 this.layout.setActiveItem(item);
4061 if(this.layoutOnTabChange && item.doLayout){
4065 this.scrollToTab(item, this.animScroll);
4068 this.fireEvent('tabchange', this, item);
4074 getTabEl: function(item){
4075 if (item == this.mainItem) {
4076 return this.groupEl;
4078 return Ext.TabPanel.prototype.getTabEl.call(this, item);
4081 onRender: function(ct, position){
4082 Ext.ux.GroupTab.superclass.onRender.call(this, ct, position);
4084 this.strip = Ext.fly(this.groupEl).createChild({
4086 cls: 'x-grouptabs-sub'
4089 this.tooltip = new Ext.ToolTip({
4090 target: this.groupEl,
4091 delegate: 'a.x-grouptabs-text',
4093 renderTo: document.body,
4095 beforeshow: function(tip) {
4096 var item = (tip.triggerElement.parentNode === this.mainItem.tabEl)
4098 : this.findById(tip.triggerElement.parentNode.id.split(this.idDelimiter)[1]);
4103 tip.body.dom.innerHTML = item.tabTip;
4109 if (!this.itemTpl) {
4110 var tt = new Ext.Template('<li class="{cls}" id="{id}">', '<a onclick="return false;" class="x-grouptabs-text {iconCls}">{text}</a>', '</li>');
4111 tt.disableFormats = true;
4113 Ext.ux.GroupTab.prototype.itemTpl = tt;
4116 this.items.each(this.initTab, this);
4119 afterRender: function(){
4120 Ext.ux.GroupTab.superclass.afterRender.call(this);
4122 if (this.activeTab !== undefined) {
4123 var item = (typeof this.activeTab == 'object') ? this.activeTab : this.items.get(this.activeTab);
4124 delete this.activeTab;
4125 this.setActiveTab(item);
4130 initTab: function(item, index){
4131 var before = this.strip.dom.childNodes[index];
4132 var p = Ext.TabPanel.prototype.getTemplateArgs.call(this, item);
4134 if (item === this.mainItem) {
4135 item.tabEl = this.groupEl;
4136 p.cls += ' x-grouptabs-main-item';
4139 var el = before ? this.itemTpl.insertBefore(before, p) : this.itemTpl.append(this.strip, p);
4141 item.tabEl = item.tabEl || el;
4143 item.on('disable', this.onItemDisabled, this);
4144 item.on('enable', this.onItemEnabled, this);
4145 item.on('titlechange', this.onItemTitleChanged, this);
4146 item.on('iconchange', this.onItemIconChanged, this);
4147 item.on('beforeshow', this.onBeforeShowItem, this);
4150 setMainItem: function(item){
4151 item = this.getComponent(item);
4152 if (!item || this.fireEvent('changemainitem', this, item, this.mainItem) === false) {
4156 this.mainItem = item;
4159 getMainItem: function(){
4160 return this.mainItem || null;
4164 onBeforeShowItem: function(item){
4165 if (item != this.activeTab) {
4166 this.setActiveTab(item);
4172 onAdd: function(gt, item, index){
4173 if (this.rendered) {
4174 this.initTab.call(this, item, index);
4179 onRemove: function(tp, item){
4180 Ext.destroy(Ext.get(this.getTabEl(item)));
4181 this.stack.remove(item);
4182 item.un('disable', this.onItemDisabled, this);
4183 item.un('enable', this.onItemEnabled, this);
4184 item.un('titlechange', this.onItemTitleChanged, this);
4185 item.un('iconchange', this.onItemIconChanged, this);
4186 item.un('beforeshow', this.onBeforeShowItem, this);
4187 if (item == this.activeTab) {
4188 var next = this.stack.next();
4190 this.setActiveTab(next);
4192 else if (this.items.getCount() > 0) {
4193 this.setActiveTab(0);
4196 this.activeTab = null;
4202 onBeforeAdd: function(item){
4203 var existing = item.events ? (this.items.containsKey(item.getItemId()) ? item : null) : this.items.get(item);
4205 this.setActiveTab(item);
4208 Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments);
4209 var es = item.elements;
4210 item.elements = es ? es.replace(',header', '') : es;
4211 item.border = (item.border === true);
4215 onItemDisabled: Ext.TabPanel.prototype.onItemDisabled,
4216 onItemEnabled: Ext.TabPanel.prototype.onItemEnabled,
4219 onItemTitleChanged: function(item){
4220 var el = this.getTabEl(item);
4222 Ext.fly(el).child('a.x-grouptabs-text', true).innerHTML = item.title;
4227 onItemIconChanged: function(item, iconCls, oldCls){
4228 var el = this.getTabEl(item);
4230 Ext.fly(el).child('a.x-grouptabs-text').replaceClass(oldCls, iconCls);
4234 beforeDestroy: function(){
4235 Ext.TabPanel.prototype.beforeDestroy.call(this);
4236 this.tooltip.destroy();
4240 Ext.reg('grouptab', Ext.ux.GroupTab);
4243 Ext.ux.GroupTabPanel = Ext.extend(Ext.TabPanel, {
4244 tabPosition: 'left',
4246 alternateColor: false,
4248 alternateCls: 'x-grouptabs-panel-alt',
4250 defaultType: 'grouptab',
4252 deferredRender: false,
4256 initComponent: function(){
4257 Ext.ux.GroupTabPanel.superclass.initComponent.call(this);
4260 'beforegroupchange',
4263 this.elements = 'body,header';
4264 this.stripTarget = 'header';
4266 this.tabPosition = this.tabPosition == 'right' ? 'right' : 'left';
4268 this.addClass('x-grouptabs-panel');
4270 if (this.tabStyle && this.tabStyle != '') {
4271 this.addClass('x-grouptabs-panel-' + this.tabStyle);
4274 if (this.alternateColor) {
4275 this.addClass(this.alternateCls);
4278 this.on('beforeadd', function(gtp, item, index){
4279 this.initGroup(item, index);
4281 this.items.each(function(item){
4282 item.on('tabchange',function(item){
4283 this.fireEvent('tabchange', this, item.activeTab);
4288 initEvents : function() {
4289 this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
4292 onRender: function(ct, position){
4293 Ext.TabPanel.superclass.onRender.call(this, ct, position);
4295 var pos = this.tabPosition == 'top' ? 'header' : 'footer';
4296 this[pos].addClass('x-tab-panel-'+pos+'-plain');
4299 var st = this[this.stripTarget];
4301 this.stripWrap = st.createChild({cls:'x-tab-strip-wrap ', cn:{
4302 tag:'ul', cls:'x-grouptabs-strip x-grouptabs-tab-strip-'+this.tabPosition}});
4304 var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
4305 this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
4307 this.header.addClass('x-grouptabs-panel-header');
4308 this.bwrap.addClass('x-grouptabs-bwrap');
4309 this.body.addClass('x-tab-panel-body-'+this.tabPosition + ' x-grouptabs-panel-body');
4311 if (!this.groupTpl) {
4312 var tt = new Ext.Template(
4313 '<li class="{cls}" id="{id}">',
4314 '<a class="x-grouptabs-expand" onclick="return false;"></a>',
4315 '<a class="x-grouptabs-text {iconCls}" href="#" onclick="return false;">',
4316 '<span>{text}</span></a>',
4319 tt.disableFormats = true;
4321 Ext.ux.GroupTabPanel.prototype.groupTpl = tt;
4323 this.items.each(this.initGroup, this);
4326 afterRender: function(){
4327 Ext.ux.GroupTabPanel.superclass.afterRender.call(this);
4329 this.tabJoint = Ext.fly(this.body.dom.parentNode).createChild({
4333 this.addClass('x-tab-panel-' + this.tabPosition);
4334 this.header.setWidth(this.tabWidth);
4336 if (this.activeGroup !== undefined) {
4337 var group = (typeof this.activeGroup == 'object') ? this.activeGroup : this.items.get(this.activeGroup);
4338 delete this.activeGroup;
4339 this.setActiveGroup(group);
4340 group.setActiveTab(group.getMainItem());
4344 getGroupEl : Ext.TabPanel.prototype.getTabEl,
4347 findTargets: function(e){
4349 itemEl = e.getTarget('li', this.strip);
4351 item = this.findById(itemEl.id.split(this.idDelimiter)[1]);
4352 if (item.disabled) {
4361 expand: e.getTarget('.x-grouptabs-expand', this.strip),
4362 isGroup: !e.getTarget('ul.x-grouptabs-sub', this.strip),
4369 onStripMouseDown: function(e){
4370 if (e.button != 0) {
4374 var t = this.findTargets(e);
4376 this.toggleGroup(t.el);
4380 t.item.setActiveTab(t.item.getMainItem());
4383 t.item.ownerCt.setActiveTab(t.item);
4388 expandGroup: function(groupEl){
4389 if(groupEl.isXType) {
4390 groupEl = this.getGroupEl(groupEl);
4392 Ext.fly(groupEl).addClass('x-grouptabs-expanded');
4393 this.syncTabJoint();
4396 toggleGroup: function(groupEl){
4397 if(groupEl.isXType) {
4398 groupEl = this.getGroupEl(groupEl);
4400 Ext.fly(groupEl).toggleClass('x-grouptabs-expanded');
4401 this.syncTabJoint();
4404 collapseGroup: function(groupEl){
4405 if(groupEl.isXType) {
4406 groupEl = this.getGroupEl(groupEl);
4408 Ext.fly(groupEl).removeClass('x-grouptabs-expanded');
4409 this.syncTabJoint();
4412 syncTabJoint: function(groupEl){
4413 if (!this.tabJoint) {
4417 groupEl = groupEl || this.getGroupEl(this.activeGroup);
4419 this.tabJoint.setHeight(Ext.fly(groupEl).getHeight() - 2);
4421 var y = Ext.isGecko2 ? 0 : 1;
4422 if (this.tabPosition == 'left'){
4423 this.tabJoint.alignTo(groupEl, 'tl-tr', [-2,y]);
4426 this.tabJoint.alignTo(groupEl, 'tr-tl', [1,y]);
4430 this.tabJoint.hide();
4434 getActiveTab : function() {
4435 if(!this.activeGroup) return null;
4436 return this.activeGroup.getTabEl(this.activeGroup.activeTab) || null;
4439 onResize: function(){
4440 Ext.ux.GroupTabPanel.superclass.onResize.apply(this, arguments);
4441 this.syncTabJoint();
4444 createCorner: function(el, pos){
4445 return Ext.fly(el).createChild({
4446 cls: 'x-grouptabs-corner x-grouptabs-corner-' + pos
4450 initGroup: function(group, index){
4451 var before = this.strip.dom.childNodes[index],
4452 p = this.getTemplateArgs(group);
4454 p.cls += ' x-tab-first';
4456 p.cls += ' x-grouptabs-main';
4457 p.text = group.getMainItem().title;
4459 var el = before ? this.groupTpl.insertBefore(before, p) : this.groupTpl.append(this.strip, p),
4460 tl = this.createCorner(el, 'top-' + this.tabPosition),
4461 bl = this.createCorner(el, 'bottom-' + this.tabPosition);
4464 if (group.expanded) {
4465 this.expandGroup(el);
4468 if (Ext.isIE6 || (Ext.isIE && !Ext.isStrict)){
4469 bl.setLeft('-10px');
4470 bl.setBottom('-5px');
4471 tl.setLeft('-10px');
4477 changemainitem: this.onGroupChangeMainItem,
4478 beforetabchange: this.onGroupBeforeTabChange
4482 setActiveGroup : function(group) {
4483 group = this.getComponent(group);
4488 this.activeGroup = group;
4491 if(this.activeGroup != group && this.fireEvent('beforegroupchange', this, group, this.activeGroup) !== false){
4492 if(this.activeGroup){
4493 this.activeGroup.activeTab = null;
4494 var oldEl = this.getGroupEl(this.activeGroup);
4496 Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
4500 var groupEl = this.getGroupEl(group);
4501 Ext.fly(groupEl).addClass('x-grouptabs-strip-active');
4503 this.activeGroup = group;
4504 this.stack.add(group);
4506 this.layout.setActiveItem(group);
4507 this.syncTabJoint(groupEl);
4509 this.fireEvent('groupchange', this, group);
4515 onGroupBeforeTabChange: function(group, newTab, oldTab){
4516 if(group !== this.activeGroup || newTab !== oldTab) {
4517 this.strip.select('.x-grouptabs-sub > li.x-grouptabs-strip-active', true).removeClass('x-grouptabs-strip-active');
4519 this.expandGroup(this.getGroupEl(group));
4520 if(group !== this.activeGroup) {
4521 return this.setActiveGroup(group);
4525 getFrameHeight: function(){
4526 var h = this.el.getFrameWidth('tb');
4527 h += (this.tbar ? this.tbar.getHeight() : 0) +
4528 (this.bbar ? this.bbar.getHeight() : 0);
4533 adjustBodyWidth: function(w){
4534 return w - this.tabWidth;
4538 Ext.reg('grouptabpanel', Ext.ux.GroupTabPanel);
4540 * Note that this control will most likely remain as an example, and not as a core Ext form
4541 * control. However, the API will be changing in a future release and so should not yet be
4542 * treated as a final, stable API at this time.
4546 * @class Ext.ux.form.ItemSelector
4547 * @extends Ext.form.Field
4548 * A control that allows selection of between two Ext.ux.form.MultiSelect controls.
4551 * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
4554 * Create a new ItemSelector
4555 * @param {Object} config Configuration options
4556 * @xtype itemselector
4558 Ext.ux.form.ItemSelector = Ext.extend(Ext.form.Field, {
4562 iconDown:"down2.gif",
4563 iconLeft:"left2.gif",
4564 iconRight:"right2.gif",
4566 iconBottom:"bottom2.gif",
4576 defaultAutoCreate:{tag: "div"},
4578 * @cfg {Array} multiselects An array of {@link Ext.ux.form.MultiSelect} config objects, with at least all required parameters (e.g., store)
4582 initComponent: function(){
4583 Ext.ux.form.ItemSelector.superclass.initComponent.call(this);
4585 'rowdblclick' : true,
4590 onRender: function(ct, position){
4591 Ext.ux.form.ItemSelector.superclass.onRender.call(this, ct, position);
4593 // Internal default configuration for both multiselects
4595 legend: 'Available',
4608 this.fromMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[0], msConfig[0]));
4609 this.fromMultiselect.on('dblclick', this.onRowDblClick, this);
4611 this.toMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[1], msConfig[1]));
4612 this.toMultiselect.on('dblclick', this.onRowDblClick, this);
4614 var p = new Ext.Panel({
4615 bodyStyle:this.bodyStyle,
4618 layoutConfig:{columns:3}
4621 p.add(this.fromMultiselect);
4622 var icons = new Ext.Panel({header:false});
4624 p.add(this.toMultiselect);
4626 icons.el.down('.'+icons.bwrapCls).remove();
4629 if (this.imagePath!="" && this.imagePath.charAt(this.imagePath.length-1)!="/")
4630 this.imagePath+="/";
4631 this.iconUp = this.imagePath + (this.iconUp || 'up2.gif');
4632 this.iconDown = this.imagePath + (this.iconDown || 'down2.gif');
4633 this.iconLeft = this.imagePath + (this.iconLeft || 'left2.gif');
4634 this.iconRight = this.imagePath + (this.iconRight || 'right2.gif');
4635 this.iconTop = this.imagePath + (this.iconTop || 'top2.gif');
4636 this.iconBottom = this.imagePath + (this.iconBottom || 'bottom2.gif');
4637 var el=icons.getEl();
4638 this.toTopIcon = el.createChild({tag:'img', src:this.iconTop, style:{cursor:'pointer', margin:'2px'}});
4639 el.createChild({tag: 'br'});
4640 this.upIcon = el.createChild({tag:'img', src:this.iconUp, style:{cursor:'pointer', margin:'2px'}});
4641 el.createChild({tag: 'br'});
4642 this.addIcon = el.createChild({tag:'img', src:this.iconRight, style:{cursor:'pointer', margin:'2px'}});
4643 el.createChild({tag: 'br'});
4644 this.removeIcon = el.createChild({tag:'img', src:this.iconLeft, style:{cursor:'pointer', margin:'2px'}});
4645 el.createChild({tag: 'br'});
4646 this.downIcon = el.createChild({tag:'img', src:this.iconDown, style:{cursor:'pointer', margin:'2px'}});
4647 el.createChild({tag: 'br'});
4648 this.toBottomIcon = el.createChild({tag:'img', src:this.iconBottom, style:{cursor:'pointer', margin:'2px'}});
4649 this.toTopIcon.on('click', this.toTop, this);
4650 this.upIcon.on('click', this.up, this);
4651 this.downIcon.on('click', this.down, this);
4652 this.toBottomIcon.on('click', this.toBottom, this);
4653 this.addIcon.on('click', this.fromTo, this);
4654 this.removeIcon.on('click', this.toFrom, this);
4655 if (!this.drawUpIcon || this.hideNavIcons) { this.upIcon.dom.style.display='none'; }
4656 if (!this.drawDownIcon || this.hideNavIcons) { this.downIcon.dom.style.display='none'; }
4657 if (!this.drawLeftIcon || this.hideNavIcons) { this.addIcon.dom.style.display='none'; }
4658 if (!this.drawRightIcon || this.hideNavIcons) { this.removeIcon.dom.style.display='none'; }
4659 if (!this.drawTopIcon || this.hideNavIcons) { this.toTopIcon.dom.style.display='none'; }
4660 if (!this.drawBotIcon || this.hideNavIcons) { this.toBottomIcon.dom.style.display='none'; }
4662 var tb = p.body.first();
4663 this.el.setWidth(p.body.first().getWidth());
4664 p.body.removeClass();
4666 this.hiddenName = this.name;
4667 var hiddenTag = {tag: "input", type: "hidden", value: "", name: this.name};
4668 this.hiddenField = this.el.createChild(hiddenTag);
4671 doLayout: function(){
4673 this.fromMultiselect.fs.doLayout();
4674 this.toMultiselect.fs.doLayout();
4678 afterRender: function(){
4679 Ext.ux.form.ItemSelector.superclass.afterRender.call(this);
4681 this.toStore = this.toMultiselect.store;
4682 this.toStore.on('add', this.valueChanged, this);
4683 this.toStore.on('remove', this.valueChanged, this);
4684 this.toStore.on('load', this.valueChanged, this);
4685 this.valueChanged(this.toStore);
4688 toTop : function() {
4689 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4691 if (selectionsArray.length > 0) {
4692 selectionsArray.sort();
4693 for (var i=0; i<selectionsArray.length; i++) {
4694 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4695 records.push(record);
4697 selectionsArray = [];
4698 for (var i=records.length-1; i>-1; i--) {
4699 record = records[i];
4700 this.toMultiselect.view.store.remove(record);
4701 this.toMultiselect.view.store.insert(0, record);
4702 selectionsArray.push(((records.length - 1) - i));
4705 this.toMultiselect.view.refresh();
4706 this.toMultiselect.view.select(selectionsArray);
4709 toBottom : function() {
4710 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4712 if (selectionsArray.length > 0) {
4713 selectionsArray.sort();
4714 for (var i=0; i<selectionsArray.length; i++) {
4715 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4716 records.push(record);
4718 selectionsArray = [];
4719 for (var i=0; i<records.length; i++) {
4720 record = records[i];
4721 this.toMultiselect.view.store.remove(record);
4722 this.toMultiselect.view.store.add(record);
4723 selectionsArray.push((this.toMultiselect.view.store.getCount()) - (records.length - i));
4726 this.toMultiselect.view.refresh();
4727 this.toMultiselect.view.select(selectionsArray);
4732 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4733 selectionsArray.sort();
4734 var newSelectionsArray = [];
4735 if (selectionsArray.length > 0) {
4736 for (var i=0; i<selectionsArray.length; i++) {
4737 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4738 if ((selectionsArray[i] - 1) >= 0) {
4739 this.toMultiselect.view.store.remove(record);
4740 this.toMultiselect.view.store.insert(selectionsArray[i] - 1, record);
4741 newSelectionsArray.push(selectionsArray[i] - 1);
4744 this.toMultiselect.view.refresh();
4745 this.toMultiselect.view.select(newSelectionsArray);
4751 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4752 selectionsArray.sort();
4753 selectionsArray.reverse();
4754 var newSelectionsArray = [];
4755 if (selectionsArray.length > 0) {
4756 for (var i=0; i<selectionsArray.length; i++) {
4757 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4758 if ((selectionsArray[i] + 1) < this.toMultiselect.view.store.getCount()) {
4759 this.toMultiselect.view.store.remove(record);
4760 this.toMultiselect.view.store.insert(selectionsArray[i] + 1, record);
4761 newSelectionsArray.push(selectionsArray[i] + 1);
4764 this.toMultiselect.view.refresh();
4765 this.toMultiselect.view.select(newSelectionsArray);
4769 fromTo : function() {
4770 var selectionsArray = this.fromMultiselect.view.getSelectedIndexes();
4772 if (selectionsArray.length > 0) {
4773 for (var i=0; i<selectionsArray.length; i++) {
4774 record = this.fromMultiselect.view.store.getAt(selectionsArray[i]);
4775 records.push(record);
4777 if(!this.allowDup)selectionsArray = [];
4778 for (var i=0; i<records.length; i++) {
4779 record = records[i];
4781 var x=new Ext.data.Record();
4784 this.toMultiselect.view.store.add(record);
4786 this.fromMultiselect.view.store.remove(record);
4787 this.toMultiselect.view.store.add(record);
4788 selectionsArray.push((this.toMultiselect.view.store.getCount() - 1));
4792 this.toMultiselect.view.refresh();
4793 this.fromMultiselect.view.refresh();
4794 var si = this.toMultiselect.store.sortInfo;
4796 this.toMultiselect.store.sort(si.field, si.direction);
4798 this.toMultiselect.view.select(selectionsArray);
4801 toFrom : function() {
4802 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
4804 if (selectionsArray.length > 0) {
4805 for (var i=0; i<selectionsArray.length; i++) {
4806 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
4807 records.push(record);
4809 selectionsArray = [];
4810 for (var i=0; i<records.length; i++) {
4811 record = records[i];
4812 this.toMultiselect.view.store.remove(record);
4814 this.fromMultiselect.view.store.add(record);
4815 selectionsArray.push((this.fromMultiselect.view.store.getCount() - 1));
4819 this.fromMultiselect.view.refresh();
4820 this.toMultiselect.view.refresh();
4821 var si = this.fromMultiselect.store.sortInfo;
4823 this.fromMultiselect.store.sort(si.field, si.direction);
4825 this.fromMultiselect.view.select(selectionsArray);
4828 valueChanged: function(store) {
4831 for (var i=0; i<store.getCount(); i++) {
4832 record = store.getAt(i);
4833 values.push(record.get(this.toMultiselect.valueField));
4835 this.hiddenField.dom.value = values.join(this.delimiter);
4836 this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
4839 getValue : function() {
4840 return this.hiddenField.dom.value;
4843 onRowDblClick : function(vw, index, node, e) {
4844 if (vw == this.toMultiselect.view){
4846 } else if (vw == this.fromMultiselect.view) {
4849 return this.fireEvent('rowdblclick', vw, index, node, e);
4853 range = this.toMultiselect.store.getRange();
4854 this.toMultiselect.store.removeAll();
4855 this.fromMultiselect.store.add(range);
4856 var si = this.fromMultiselect.store.sortInfo;
4858 this.fromMultiselect.store.sort(si.field, si.direction);
4860 this.valueChanged(this.toMultiselect.store);
4864 Ext.reg('itemselector', Ext.ux.form.ItemSelector);
4867 Ext.ux.ItemSelector = Ext.ux.form.ItemSelector;
4868 Ext.ns('Ext.ux.grid');
4870 Ext.ux.grid.LockingGridView = Ext.extend(Ext.grid.GridView, {
4872 unlockText : 'Unlock',
4874 lockedBorderWidth : 1,
4877 * This option ensures that height between the rows is synchronized
4878 * between the locked and unlocked sides. This option only needs to be used
4879 * when the row heights aren't predictable.
4883 initTemplates : function(){
4884 var ts = this.templates || {};
4887 ts.master = new Ext.Template(
4888 '<div class="x-grid3" hidefocus="true">',
4889 '<div class="x-grid3-locked">',
4890 '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{lstyle}">{lockedHeader}</div></div><div class="x-clear"></div></div>',
4891 '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{lstyle}">{lockedBody}</div><div class="x-grid3-scroll-spacer"></div></div>',
4893 '<div class="x-grid3-viewport x-grid3-unlocked">',
4894 '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
4895 '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
4897 '<div class="x-grid3-resize-marker"> </div>',
4898 '<div class="x-grid3-resize-proxy"> </div>',
4903 this.templates = ts;
4905 Ext.ux.grid.LockingGridView.superclass.initTemplates.call(this);
4908 getEditorParent : function(ed){
4912 initElements : function(){
4913 var E = Ext.Element,
4914 el = this.grid.getGridEl().dom.firstChild,
4917 this.el = new E(el);
4918 this.lockedWrap = new E(cs[0]);
4919 this.lockedHd = new E(this.lockedWrap.dom.firstChild);
4920 this.lockedInnerHd = this.lockedHd.dom.firstChild;
4921 this.lockedScroller = new E(this.lockedWrap.dom.childNodes[1]);
4922 this.lockedBody = new E(this.lockedScroller.dom.firstChild);
4923 this.mainWrap = new E(cs[1]);
4924 this.mainHd = new E(this.mainWrap.dom.firstChild);
4926 if (this.grid.hideHeaders) {
4927 this.lockedHd.setDisplayed(false);
4928 this.mainHd.setDisplayed(false);
4931 this.innerHd = this.mainHd.dom.firstChild;
4932 this.scroller = new E(this.mainWrap.dom.childNodes[1]);
4935 this.scroller.setStyle('overflow-x', 'hidden');
4938 this.mainBody = new E(this.scroller.dom.firstChild);
4939 this.focusEl = new E(this.scroller.dom.childNodes[1]);
4940 this.resizeMarker = new E(cs[2]);
4941 this.resizeProxy = new E(cs[3]);
4943 this.focusEl.swallowEvent('click', true);
4946 getLockedRows : function(){
4947 return this.hasRows() ? this.lockedBody.dom.childNodes : [];
4950 getLockedRow : function(row){
4951 return this.getLockedRows()[row];
4954 getCell : function(row, col){
4955 var llen = this.cm.getLockedCount();
4957 return this.getLockedRow(row).getElementsByTagName('td')[col];
4959 return Ext.ux.grid.LockingGridView.superclass.getCell.call(this, row, col - llen);
4962 getHeaderCell : function(index){
4963 var llen = this.cm.getLockedCount();
4965 return this.lockedHd.dom.getElementsByTagName('td')[index];
4967 return Ext.ux.grid.LockingGridView.superclass.getHeaderCell.call(this, index - llen);
4970 addRowClass : function(row, cls){
4971 var r = this.getLockedRow(row);
4973 this.fly(r).addClass(cls);
4975 Ext.ux.grid.LockingGridView.superclass.addRowClass.call(this, row, cls);
4978 removeRowClass : function(row, cls){
4979 var r = this.getLockedRow(row);
4981 this.fly(r).removeClass(cls);
4983 Ext.ux.grid.LockingGridView.superclass.removeRowClass.call(this, row, cls);
4986 removeRow : function(row) {
4987 Ext.removeNode(this.getLockedRow(row));
4988 Ext.ux.grid.LockingGridView.superclass.removeRow.call(this, row);
4991 removeRows : function(firstRow, lastRow){
4992 var bd = this.lockedBody.dom;
4993 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
4994 Ext.removeNode(bd.childNodes[firstRow]);
4996 Ext.ux.grid.LockingGridView.superclass.removeRows.call(this, firstRow, lastRow);
4999 syncScroll : function(e){
5000 var mb = this.scroller.dom;
5001 this.lockedScroller.dom.scrollTop = mb.scrollTop;
5002 Ext.ux.grid.LockingGridView.superclass.syncScroll.call(this, e);
5005 updateSortIcon : function(col, dir){
5006 var sc = this.sortClasses,
5007 lhds = this.lockedHd.select('td').removeClass(sc),
5008 hds = this.mainHd.select('td').removeClass(sc),
5009 llen = this.cm.getLockedCount(),
5010 cls = sc[dir == 'DESC' ? 1 : 0];
5012 lhds.item(col).addClass(cls);
5014 hds.item(col - llen).addClass(cls);
5018 updateAllColumnWidths : function(){
5019 var tw = this.getTotalWidth(),
5020 clen = this.cm.getColumnCount(),
5021 lw = this.getLockedWidth(),
5022 llen = this.cm.getLockedCount(),
5024 this.updateLockedWidth();
5025 for(i = 0; i < clen; i++){
5026 ws[i] = this.getColumnWidth(i);
5027 var hd = this.getHeaderCell(i);
5028 hd.style.width = ws[i];
5030 var lns = this.getLockedRows(), ns = this.getRows(), row, trow, j;
5031 for(i = 0, len = ns.length; i < len; i++){
5033 row.style.width = lw;
5035 row.firstChild.style.width = lw;
5036 trow = row.firstChild.rows[0];
5037 for (j = 0; j < llen; j++) {
5038 trow.childNodes[j].style.width = ws[j];
5042 row.style.width = tw;
5044 row.firstChild.style.width = tw;
5045 trow = row.firstChild.rows[0];
5046 for (j = llen; j < clen; j++) {
5047 trow.childNodes[j - llen].style.width = ws[j];
5051 this.onAllColumnWidthsUpdated(ws, tw);
5052 this.syncHeaderHeight();
5055 updateColumnWidth : function(col, width){
5056 var w = this.getColumnWidth(col),
5057 llen = this.cm.getLockedCount(),
5059 this.updateLockedWidth();
5061 ns = this.getLockedRows();
5062 rw = this.getLockedWidth();
5065 ns = this.getRows();
5066 rw = this.getTotalWidth();
5069 var hd = this.getHeaderCell(col);
5071 for(var i = 0, len = ns.length; i < len; i++){
5073 row.style.width = rw;
5075 row.firstChild.style.width = rw;
5076 row.firstChild.rows[0].childNodes[c].style.width = w;
5079 this.onColumnWidthUpdated(col, w, this.getTotalWidth());
5080 this.syncHeaderHeight();
5083 updateColumnHidden : function(col, hidden){
5084 var llen = this.cm.getLockedCount(),
5086 display = hidden ? 'none' : '';
5087 this.updateLockedWidth();
5089 ns = this.getLockedRows();
5090 rw = this.getLockedWidth();
5093 ns = this.getRows();
5094 rw = this.getTotalWidth();
5097 var hd = this.getHeaderCell(col);
5098 hd.style.display = display;
5099 for(var i = 0, len = ns.length; i < len; i++){
5101 row.style.width = rw;
5103 row.firstChild.style.width = rw;
5104 row.firstChild.rows[0].childNodes[c].style.display = display;
5107 this.onColumnHiddenUpdated(col, hidden, this.getTotalWidth());
5108 delete this.lastViewWidth;
5112 doRender : function(cs, rs, ds, startRow, colCount, stripe){
5113 var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1,
5114 tstyle = 'width:'+this.getTotalWidth()+';',
5115 lstyle = 'width:'+this.getLockedWidth()+';',
5116 buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r;
5117 for(var j = 0, len = rs.length; j < len; j++){
5118 r = rs[j]; cb = []; lcb = [];
5119 var rowIndex = (j+startRow);
5120 for(var i = 0; i < colCount; i++){
5123 p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
5124 (this.cm.config[i].cellCls ? ' ' + this.cm.config[i].cellCls : '');
5125 p.attr = p.cellAttr = '';
5126 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
5128 if(Ext.isEmpty(p.value)){
5131 if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
5132 p.css += ' x-grid3-dirty-cell';
5135 lcb[lcb.length] = ct.apply(p);
5137 cb[cb.length] = ct.apply(p);
5141 if(stripe && ((rowIndex+1) % 2 === 0)){
5142 alt[0] = 'x-grid3-row-alt';
5145 alt[1] = ' x-grid3-dirty-row';
5148 if(this.getRowClass){
5149 alt[2] = this.getRowClass(r, rowIndex, rp, ds);
5151 rp.alt = alt.join(' ');
5152 rp.cells = cb.join('');
5154 buf[buf.length] = rt.apply(rp);
5155 rp.cells = lcb.join('');
5157 lbuf[lbuf.length] = rt.apply(rp);
5159 return [buf.join(''), lbuf.join('')];
5161 processRows : function(startRow, skipStripe){
5162 if(!this.ds || this.ds.getCount() < 1){
5165 var rows = this.getRows(),
5166 lrows = this.getLockedRows(),
5168 skipStripe = skipStripe || !this.grid.stripeRows;
5169 startRow = startRow || 0;
5170 for(var i = 0, len = rows.length; i < len; ++i){
5176 row.className = row.className.replace(this.rowClsRe, ' ');
5177 lrow.className = lrow.className.replace(this.rowClsRe, ' ');
5178 if ((i + 1) % 2 === 0){
5179 row.className += ' x-grid3-row-alt';
5180 lrow.className += ' x-grid3-row-alt';
5183 if(this.syncHeights){
5184 var el1 = Ext.get(row),
5185 el2 = Ext.get(lrow),
5186 h1 = el1.getHeight(),
5187 h2 = el2.getHeight();
5197 Ext.fly(rows[0]).addClass(this.firstRowCls);
5198 Ext.fly(lrows[0]).addClass(this.firstRowCls);
5200 Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
5201 Ext.fly(lrows[lrows.length - 1]).addClass(this.lastRowCls);
5204 afterRender : function(){
5205 if(!this.ds || !this.cm){
5208 var bd = this.renderRows() || [' ', ' '];
5209 this.mainBody.dom.innerHTML = bd[0];
5210 this.lockedBody.dom.innerHTML = bd[1];
5211 this.processRows(0, true);
5212 if(this.deferEmptyText !== true){
5213 this.applyEmptyText();
5215 this.grid.fireEvent('viewready', this.grid);
5218 renderUI : function(){
5219 var header = this.renderHeaders();
5220 var body = this.templates.body.apply({rows:' '});
5221 var html = this.templates.master.apply({
5224 ostyle: 'width:'+this.getOffsetWidth()+';',
5225 bstyle: 'width:'+this.getTotalWidth()+';',
5227 lockedHeader: header[1],
5228 lstyle: 'width:'+this.getLockedWidth()+';'
5231 g.getGridEl().dom.innerHTML = html;
5232 this.initElements();
5233 Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
5234 Ext.fly(this.lockedInnerHd).on('click', this.handleHdDown, this);
5237 mouseover: this.handleHdOver,
5238 mouseout: this.handleHdOut,
5239 mousemove: this.handleHdMove
5243 mouseover: this.handleHdOver,
5244 mouseout: this.handleHdOut,
5245 mousemove: this.handleHdMove
5247 this.scroller.on('scroll', this.syncScroll, this);
5248 if(g.enableColumnResize !== false){
5249 this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
5250 this.splitZone.setOuterHandleElId(Ext.id(this.lockedHd.dom));
5251 this.splitZone.setOuterHandleElId(Ext.id(this.mainHd.dom));
5253 if(g.enableColumnMove){
5254 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
5255 this.columnDrag.setOuterHandleElId(Ext.id(this.lockedInnerHd));
5256 this.columnDrag.setOuterHandleElId(Ext.id(this.innerHd));
5257 this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
5259 if(g.enableHdMenu !== false){
5260 this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
5262 {itemId: 'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
5263 {itemId: 'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
5265 if(this.grid.enableColLock !== false){
5267 {itemId: 'lock', text: this.lockText, cls: 'xg-hmenu-lock'},
5268 {itemId: 'unlock', text: this.unlockText, cls: 'xg-hmenu-unlock'}
5271 if(g.enableColumnHide !== false){
5272 this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
5275 beforeshow: this.beforeColMenuShow,
5276 itemclick: this.handleHdMenuClick
5278 this.hmenu.add('-', {
5281 text: this.columnsText,
5283 iconCls: 'x-cols-icon'
5286 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
5288 if(g.trackMouseOver){
5291 mouseover: this.onRowOver,
5292 mouseout: this.onRowOut
5294 this.lockedBody.on({
5296 mouseover: this.onRowOver,
5297 mouseout: this.onRowOut
5301 if(g.enableDragDrop || g.enableDrag){
5302 this.dragZone = new Ext.grid.GridDragZone(g, {
5303 ddGroup : g.ddGroup || 'GridDD'
5306 this.updateHeaderSortState();
5309 layout : function(){
5314 var c = g.getGridEl();
5315 var csize = c.getSize(true);
5316 var vw = csize.width;
5317 if(!g.hideHeaders && (vw < 20 || csize.height < 20)){
5320 this.syncHeaderHeight();
5322 this.scroller.dom.style.overflow = 'visible';
5323 this.lockedScroller.dom.style.overflow = 'visible';
5325 this.scroller.dom.style.position = 'static';
5326 this.lockedScroller.dom.style.position = 'static';
5329 this.el.setSize(csize.width, csize.height);
5330 var hdHeight = this.mainHd.getHeight();
5331 var vh = csize.height - (hdHeight);
5333 this.updateLockedWidth();
5335 if(this.lastViewWidth != vw){
5336 this.fitColumns(false, false);
5337 this.lastViewWidth = vw;
5341 this.syncHeaderScroll();
5343 this.onLayout(vw, vh);
5346 getOffsetWidth : function() {
5347 return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth() + this.getScrollOffset()) + 'px';
5350 renderHeaders : function(){
5352 ts = this.templates,
5356 len = cm.getColumnCount(),
5358 for(var i = 0; i < len; i++){
5359 p.id = cm.getColumnId(i);
5360 p.value = cm.getColumnHeader(i) || '';
5361 p.style = this.getColumnStyle(i, true);
5362 p.tooltip = this.getColumnTooltip(i);
5363 p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
5364 (cm.config[i].headerCls ? ' ' + cm.config[i].headerCls : '');
5365 if(cm.config[i].align == 'right'){
5366 p.istyle = 'padding-right:16px';
5371 lcb[lcb.length] = ct.apply(p);
5373 cb[cb.length] = ct.apply(p);
5376 return [ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'}),
5377 ts.header.apply({cells: lcb.join(''), tstyle:'width:'+this.getLockedWidth()+';'})];
5380 updateHeaders : function(){
5381 var hd = this.renderHeaders();
5382 this.innerHd.firstChild.innerHTML = hd[0];
5383 this.innerHd.firstChild.style.width = this.getOffsetWidth();
5384 this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
5385 this.lockedInnerHd.firstChild.innerHTML = hd[1];
5386 var lw = this.getLockedWidth();
5387 this.lockedInnerHd.firstChild.style.width = lw;
5388 this.lockedInnerHd.firstChild.firstChild.style.width = lw;
5391 getResolvedXY : function(resolved){
5395 var c = resolved.cell, r = resolved.row;
5396 return c ? Ext.fly(c).getXY() : [this.scroller.getX(), Ext.fly(r).getY()];
5399 syncFocusEl : function(row, col, hscroll){
5400 Ext.ux.grid.LockingGridView.superclass.syncFocusEl.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
5403 ensureVisible : function(row, col, hscroll){
5404 return Ext.ux.grid.LockingGridView.superclass.ensureVisible.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
5407 insertRows : function(dm, firstRow, lastRow, isUpdate){
5408 var last = dm.getCount() - 1;
5409 if(!isUpdate && firstRow === 0 && lastRow >= last){
5413 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
5415 var html = this.renderRows(firstRow, lastRow),
5416 before = this.getRow(firstRow);
5419 this.removeRowClass(0, this.firstRowCls);
5421 Ext.DomHelper.insertHtml('beforeBegin', before, html[0]);
5422 before = this.getLockedRow(firstRow);
5423 Ext.DomHelper.insertHtml('beforeBegin', before, html[1]);
5425 this.removeRowClass(last - 1, this.lastRowCls);
5426 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html[0]);
5427 Ext.DomHelper.insertHtml('beforeEnd', this.lockedBody.dom, html[1]);
5430 this.fireEvent('rowsinserted', this, firstRow, lastRow);
5431 this.processRows(firstRow);
5432 }else if(firstRow === 0 || firstRow >= last){
5433 this.addRowClass(firstRow, firstRow === 0 ? this.firstRowCls : this.lastRowCls);
5436 this.syncFocusEl(firstRow);
5439 getColumnStyle : function(col, isHeader){
5440 var style = !isHeader ? this.cm.config[col].cellStyle || this.cm.config[col].css || '' : this.cm.config[col].headerStyle || '';
5441 style += 'width:'+this.getColumnWidth(col)+';';
5442 if(this.cm.isHidden(col)){
5443 style += 'display:none;';
5445 var align = this.cm.config[col].align;
5447 style += 'text-align:'+align+';';
5452 getLockedWidth : function() {
5453 return this.cm.getTotalLockedWidth() + 'px';
5456 getTotalWidth : function() {
5457 return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth()) + 'px';
5460 getColumnData : function(){
5461 var cs = [], cm = this.cm, colCount = cm.getColumnCount();
5462 for(var i = 0; i < colCount; i++){
5463 var name = cm.getDataIndex(i);
5465 name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
5466 renderer : cm.getRenderer(i),
5467 id : cm.getColumnId(i),
5468 style : this.getColumnStyle(i),
5469 locked : cm.isLocked(i)
5475 renderBody : function(){
5476 var markup = this.renderRows() || [' ', ' '];
5477 return [this.templates.body.apply({rows: markup[0]}), this.templates.body.apply({rows: markup[1]})];
5480 refreshRow : function(record){
5481 Ext.ux.grid.LockingGridView.superclass.refreshRow.call(this, record);
5482 var index = Ext.isNumber(record) ? record : this.ds.indexOf(record);
5483 this.getLockedRow(index).rowIndex = index;
5486 refresh : function(headersToo){
5487 this.fireEvent('beforerefresh', this);
5488 this.grid.stopEditing(true);
5489 var result = this.renderBody();
5490 this.mainBody.update(result[0]).setWidth(this.getTotalWidth());
5491 this.lockedBody.update(result[1]).setWidth(this.getLockedWidth());
5492 if(headersToo === true){
5493 this.updateHeaders();
5494 this.updateHeaderSortState();
5496 this.processRows(0, true);
5498 this.applyEmptyText();
5499 this.fireEvent('refresh', this);
5502 onDenyColumnLock : function(){
5506 initData : function(ds, cm){
5508 this.cm.un('columnlockchange', this.onColumnLock, this);
5510 Ext.ux.grid.LockingGridView.superclass.initData.call(this, ds, cm);
5512 this.cm.on('columnlockchange', this.onColumnLock, this);
5516 onColumnLock : function(){
5520 handleHdMenuClick : function(item){
5521 var index = this.hdCtxIndex,
5523 id = item.getItemId(),
5524 llen = cm.getLockedCount();
5527 if(cm.getColumnCount(true) <= llen + 1){
5528 this.onDenyColumnLock();
5531 cm.setLocked(index, true);
5533 cm.moveColumn(index, llen);
5534 this.grid.fireEvent('columnmove', index, llen);
5538 if(llen - 1 != index){
5539 cm.setLocked(index, false, true);
5540 cm.moveColumn(index, llen - 1);
5541 this.grid.fireEvent('columnmove', index, llen - 1);
5543 cm.setLocked(index, false);
5547 return Ext.ux.grid.LockingGridView.superclass.handleHdMenuClick.call(this, item);
5552 handleHdDown : function(e, t){
5553 Ext.ux.grid.LockingGridView.superclass.handleHdDown.call(this, e, t);
5554 if(this.grid.enableColLock !== false){
5555 if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
5556 var hd = this.findHeaderCell(t),
5557 index = this.getCellIndex(hd),
5558 ms = this.hmenu.items, cm = this.cm;
5559 ms.get('lock').setDisabled(cm.isLocked(index));
5560 ms.get('unlock').setDisabled(!cm.isLocked(index));
5565 syncHeaderHeight: function(){
5566 this.innerHd.firstChild.firstChild.style.height = 'auto';
5567 this.lockedInnerHd.firstChild.firstChild.style.height = 'auto';
5568 var hd = this.innerHd.firstChild.firstChild.offsetHeight,
5569 lhd = this.lockedInnerHd.firstChild.firstChild.offsetHeight,
5570 height = (lhd > hd ? lhd : hd) + 'px';
5571 this.innerHd.firstChild.firstChild.style.height = height;
5572 this.lockedInnerHd.firstChild.firstChild.style.height = height;
5575 updateLockedWidth: function(){
5576 var lw = this.cm.getTotalLockedWidth(),
5577 tw = this.cm.getTotalWidth() - lw,
5578 csize = this.grid.getGridEl().getSize(true),
5579 lp = Ext.isBorderBox ? 0 : this.lockedBorderWidth,
5580 rp = Ext.isBorderBox ? 0 : this.rowBorderWidth,
5581 vw = (csize.width - lw - lp - rp) + 'px',
5582 so = this.getScrollOffset();
5583 if(!this.grid.autoHeight){
5584 var vh = (csize.height - this.mainHd.getHeight()) + 'px';
5585 this.lockedScroller.dom.style.height = vh;
5586 this.scroller.dom.style.height = vh;
5588 this.lockedWrap.dom.style.width = (lw + rp) + 'px';
5589 this.scroller.dom.style.width = vw;
5590 this.mainWrap.dom.style.left = (lw + lp + rp) + 'px';
5592 this.lockedInnerHd.firstChild.style.width = lw + 'px';
5593 this.lockedInnerHd.firstChild.firstChild.style.width = lw + 'px';
5594 this.innerHd.style.width = vw;
5595 this.innerHd.firstChild.style.width = (tw + rp + so) + 'px';
5596 this.innerHd.firstChild.firstChild.style.width = tw + 'px';
5599 this.lockedBody.dom.style.width = (lw + rp) + 'px';
5600 this.mainBody.dom.style.width = (tw + rp) + 'px';
5605 Ext.ux.grid.LockingColumnModel = Ext.extend(Ext.grid.ColumnModel, {
5607 * Returns true if the given column index is currently locked
5608 * @param {Number} colIndex The column index
5609 * @return {Boolean} True if the column is locked
5611 isLocked : function(colIndex){
5612 return this.config[colIndex].locked === true;
5616 * Locks or unlocks a given column
5617 * @param {Number} colIndex The column index
5618 * @param {Boolean} value True to lock, false to unlock
5619 * @param {Boolean} suppressEvent Pass false to cause the columnlockchange event not to fire
5621 setLocked : function(colIndex, value, suppressEvent){
5622 if (this.isLocked(colIndex) == value) {
5625 this.config[colIndex].locked = value;
5626 if (!suppressEvent) {
5627 this.fireEvent('columnlockchange', this, colIndex, value);
5632 * Returns the total width of all locked columns
5633 * @return {Number} The width of all locked columns
5635 getTotalLockedWidth : function(){
5637 for (var i = 0, len = this.config.length; i < len; i++) {
5638 if (this.isLocked(i) && !this.isHidden(i)) {
5639 totalWidth += this.getColumnWidth(i);
5647 * Returns the total number of locked columns
5648 * @return {Number} The number of locked columns
5650 getLockedCount : function() {
5651 var len = this.config.length;
5653 for (var i = 0; i < len; i++) {
5654 if (!this.isLocked(i)) {
5659 //if we get to this point all of the columns are locked so we return the total
5664 * Moves a column from one position to another
5665 * @param {Number} oldIndex The current column index
5666 * @param {Number} newIndex The destination column index
5668 moveColumn : function(oldIndex, newIndex){
5669 var oldLocked = this.isLocked(oldIndex),
5670 newLocked = this.isLocked(newIndex);
5672 if (oldIndex < newIndex && oldLocked && !newLocked) {
5673 this.setLocked(oldIndex, false, true);
5674 } else if (oldIndex > newIndex && !oldLocked && newLocked) {
5675 this.setLocked(oldIndex, true, true);
5678 Ext.ux.grid.LockingColumnModel.superclass.moveColumn.apply(this, arguments);
5681 Ext.ns('Ext.ux.form');
5684 * @class Ext.ux.form.MultiSelect
5685 * @extends Ext.form.Field
5686 * A control that allows selection and form submission of multiple list items.
5689 * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
5690 * 2008-06-19 bpm Docs and demo code clean up
5693 * Create a new MultiSelect
5694 * @param {Object} config Configuration options
5695 * @xtype multiselect
5697 Ext.ux.form.MultiSelect = Ext.extend(Ext.form.Field, {
5699 * @cfg {String} legend Wraps the object with a fieldset and specified legend.
5702 * @cfg {Ext.ListView} view The {@link Ext.ListView} used to render the multiselect list.
5705 * @cfg {String/Array} dragGroup The ddgroup name(s) for the MultiSelect DragZone (defaults to undefined).
5708 * @cfg {String/Array} dropGroup The ddgroup name(s) for the MultiSelect DropZone (defaults to undefined).
5711 * @cfg {Boolean} ddReorder Whether the items in the MultiSelect list are drag/drop reorderable (defaults to false).
5715 * @cfg {Object/Array} tbar The top toolbar of the control. This can be a {@link Ext.Toolbar} object, a
5716 * toolbar config, or an array of buttons/button configs to be added to the toolbar.
5719 * @cfg {String} appendOnly True if the list should only allow append drops when drag/drop is enabled
5720 * (use for lists which are sorted, defaults to false).
5724 * @cfg {Number} width Width in pixels of the control (defaults to 100).
5728 * @cfg {Number} height Height in pixels of the control (defaults to 100).
5732 * @cfg {String/Number} displayField Name/Index of the desired display field in the dataset (defaults to 0).
5736 * @cfg {String/Number} valueField Name/Index of the desired value field in the dataset (defaults to 1).
5740 * @cfg {Boolean} allowBlank False to require at least one item in the list to be selected, true to allow no
5741 * selection (defaults to true).
5745 * @cfg {Number} minSelections Minimum number of selections allowed (defaults to 0).
5749 * @cfg {Number} maxSelections Maximum number of selections allowed (defaults to Number.MAX_VALUE).
5751 maxSelections:Number.MAX_VALUE,
5753 * @cfg {String} blankText Default text displayed when the control contains no items (defaults to the same value as
5754 * {@link Ext.form.TextField#blankText}.
5756 blankText:Ext.form.TextField.prototype.blankText,
5758 * @cfg {String} minSelectionsText Validation message displayed when {@link #minSelections} is not met (defaults to 'Minimum {0}
5759 * item(s) required'). The {0} token will be replaced by the value of {@link #minSelections}.
5761 minSelectionsText:'Minimum {0} item(s) required',
5763 * @cfg {String} maxSelectionsText Validation message displayed when {@link #maxSelections} is not met (defaults to 'Maximum {0}
5764 * item(s) allowed'). The {0} token will be replaced by the value of {@link #maxSelections}.
5766 maxSelectionsText:'Maximum {0} item(s) allowed',
5768 * @cfg {String} delimiter The string used to delimit between items when set or returned as a string of values
5769 * (defaults to ',').
5773 * @cfg {Ext.data.Store/Array} store The data source to which this MultiSelect is bound (defaults to <tt>undefined</tt>).
5774 * Acceptable values for this property are:
5775 * <div class="mdetail-params"><ul>
5776 * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
5777 * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally.
5778 * <div class="mdetail-params"><ul>
5779 * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
5780 * A 1-dimensional array will automatically be expanded (each array item will be the combo
5781 * {@link #valueField value} and {@link #displayField text})</div></li>
5782 * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
5783 * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
5784 * {@link #valueField value}, while the value at index 1 is assumed to be the combo {@link #displayField text}.
5785 * </div></li></ul></div></li></ul></div>
5789 defaultAutoCreate : {tag: "div"},
5792 initComponent: function(){
5793 Ext.ux.form.MultiSelect.superclass.initComponent.call(this);
5795 if(Ext.isArray(this.store)){
5796 if (Ext.isArray(this.store[0])){
5797 this.store = new Ext.data.ArrayStore({
5798 fields: ['value','text'],
5801 this.valueField = 'value';
5803 this.store = new Ext.data.ArrayStore({
5808 this.valueField = 'text';
5810 this.displayField = 'text';
5812 this.store = Ext.StoreMgr.lookup(this.store);
5824 onRender: function(ct, position){
5825 Ext.ux.form.MultiSelect.superclass.onRender.call(this, ct, position);
5827 var fs = this.fs = new Ext.form.FieldSet({
5830 height: this.height,
5832 style: "padding:0;",
5835 fs.body.addClass('ux-mselect');
5837 this.view = new Ext.ListView({
5840 columns: [{ header: 'Value', width: 1, dataIndex: this.displayField }],
5846 this.view.on('click', this.onViewClick, this);
5847 this.view.on('beforeclick', this.onViewBeforeClick, this);
5848 this.view.on('dblclick', this.onViewDblClick, this);
5850 this.hiddenName = this.name || Ext.id();
5851 var hiddenTag = { tag: "input", type: "hidden", value: "", name: this.hiddenName };
5852 this.hiddenField = this.el.createChild(hiddenTag);
5853 this.hiddenField.dom.disabled = this.hiddenName != this.name;
5858 afterRender: function(){
5859 Ext.ux.form.MultiSelect.superclass.afterRender.call(this);
5861 if (this.ddReorder && !this.dragGroup && !this.dropGroup){
5862 this.dragGroup = this.dropGroup = 'MultiselectDD-' + Ext.id();
5865 if (this.draggable || this.dragGroup){
5866 this.dragZone = new Ext.ux.form.MultiSelect.DragZone(this, {
5867 ddGroup: this.dragGroup
5870 if (this.droppable || this.dropGroup){
5871 this.dropZone = new Ext.ux.form.MultiSelect.DropZone(this, {
5872 ddGroup: this.dropGroup
5878 onViewClick: function(vw, index, node, e) {
5879 this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
5880 this.hiddenField.dom.value = this.getValue();
5881 this.fireEvent('click', this, e);
5886 onViewBeforeClick: function(vw, index, node, e) {
5887 if (this.disabled || this.readOnly) {
5893 onViewDblClick : function(vw, index, node, e) {
5894 return this.fireEvent('dblclick', vw, index, node, e);
5898 * Returns an array of data values for the selected items in the list. The values will be separated
5899 * by {@link #delimiter}.
5900 * @return {Array} value An array of string data values
5902 getValue: function(valueField){
5903 var returnArray = [];
5904 var selectionsArray = this.view.getSelectedIndexes();
5905 if (selectionsArray.length == 0) {return '';}
5906 for (var i=0; i<selectionsArray.length; i++) {
5907 returnArray.push(this.store.getAt(selectionsArray[i]).get((valueField != null) ? valueField : this.valueField));
5909 return returnArray.join(this.delimiter);
5913 * Sets a delimited string (using {@link #delimiter}) or array of data values into the list.
5914 * @param {String/Array} values The values to set
5916 setValue: function(values) {
5918 var selections = [];
5919 this.view.clearSelections();
5920 this.hiddenField.dom.value = '';
5922 if (!values || (values == '')) { return; }
5924 if (!Ext.isArray(values)) { values = values.split(this.delimiter); }
5925 for (var i=0; i<values.length; i++) {
5926 index = this.view.store.indexOf(this.view.store.query(this.valueField,
5927 new RegExp('^' + values[i] + '$', "i")).itemAt(0));
5928 selections.push(index);
5930 this.view.select(selections);
5931 this.hiddenField.dom.value = this.getValue();
5936 reset : function() {
5941 getRawValue: function(valueField) {
5942 var tmp = this.getValue(valueField);
5944 tmp = tmp.split(this.delimiter);
5953 setRawValue: function(values){
5958 validateValue : function(value){
5959 if (value.length < 1) { // if it has no value
5960 if (this.allowBlank) {
5961 this.clearInvalid();
5964 this.markInvalid(this.blankText);
5968 if (value.length < this.minSelections) {
5969 this.markInvalid(String.format(this.minSelectionsText, this.minSelections));
5972 if (value.length > this.maxSelections) {
5973 this.markInvalid(String.format(this.maxSelectionsText, this.maxSelections));
5980 disable: function(){
5981 this.disabled = true;
5982 this.hiddenField.dom.disabled = true;
5988 this.disabled = false;
5989 this.hiddenField.dom.disabled = false;
5994 destroy: function(){
5995 Ext.destroy(this.fs, this.dragZone, this.dropZone);
5996 Ext.ux.form.MultiSelect.superclass.destroy.call(this);
6001 Ext.reg('multiselect', Ext.ux.form.MultiSelect);
6004 Ext.ux.Multiselect = Ext.ux.form.MultiSelect;
6007 Ext.ux.form.MultiSelect.DragZone = function(ms, config){
6009 this.view = ms.view;
6010 var ddGroup = config.ddGroup || 'MultiselectDD';
6012 if (Ext.isArray(ddGroup)){
6013 dd = ddGroup.shift();
6018 Ext.ux.form.MultiSelect.DragZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
6019 this.setDraggable(ddGroup);
6022 Ext.extend(Ext.ux.form.MultiSelect.DragZone, Ext.dd.DragZone, {
6023 onInitDrag : function(x, y){
6024 var el = Ext.get(this.dragData.ddel.cloneNode(true));
6025 this.proxy.update(el.dom);
6026 el.setWidth(el.child('em').getWidth());
6027 this.onStartDrag(x, y);
6032 collectSelection: function(data) {
6033 data.repairXY = Ext.fly(this.view.getSelectedNodes()[0]).getXY();
6035 this.view.store.each(function(rec){
6036 if (this.view.isSelected(i)) {
6037 var n = this.view.getNode(i);
6038 var dragNode = n.cloneNode(true);
6039 dragNode.id = Ext.id();
6040 data.ddel.appendChild(dragNode);
6041 data.records.push(this.view.store.getAt(i));
6042 data.viewNodes.push(n);
6049 onEndDrag: function(data, e) {
6050 var d = Ext.get(this.dragData.ddel);
6051 if (d && d.hasClass("multi-proxy")) {
6057 getDragData: function(e){
6058 var target = this.view.findItemFromChild(e.getTarget());
6060 if (!this.view.isSelected(target) && !e.ctrlKey && !e.shiftKey) {
6061 this.view.select(target);
6062 this.ms.setValue(this.ms.getValue());
6064 if (this.view.getSelectionCount() == 0 || e.ctrlKey || e.shiftKey) return false;
6066 sourceView: this.view,
6070 if (this.view.getSelectionCount() == 1) {
6071 var i = this.view.getSelectedIndexes()[0];
6072 var n = this.view.getNode(i);
6073 dragData.viewNodes.push(dragData.ddel = n);
6074 dragData.records.push(this.view.store.getAt(i));
6075 dragData.repairXY = Ext.fly(n).getXY();
6077 dragData.ddel = document.createElement('div');
6078 dragData.ddel.className = 'multi-proxy';
6079 this.collectSelection(dragData);
6086 // override the default repairXY.
6087 getRepairXY : function(e){
6088 return this.dragData.repairXY;
6092 setDraggable: function(ddGroup){
6093 if (!ddGroup) return;
6094 if (Ext.isArray(ddGroup)) {
6095 Ext.each(ddGroup, this.setDraggable, this);
6098 this.addToGroup(ddGroup);
6102 Ext.ux.form.MultiSelect.DropZone = function(ms, config){
6104 this.view = ms.view;
6105 var ddGroup = config.ddGroup || 'MultiselectDD';
6107 if (Ext.isArray(ddGroup)){
6108 dd = ddGroup.shift();
6113 Ext.ux.form.MultiSelect.DropZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
6114 this.setDroppable(ddGroup);
6117 Ext.extend(Ext.ux.form.MultiSelect.DropZone, Ext.dd.DropZone, {
6119 * Part of the Ext.dd.DropZone interface. If no target node is found, the
6120 * whole Element becomes the target, and this causes the drop gesture to append.
6122 getTargetFromEvent : function(e) {
6123 var target = e.getTarget();
6128 getDropPoint : function(e, n, dd){
6129 if (n == this.ms.fs.body.dom) { return "below"; }
6130 var t = Ext.lib.Dom.getY(n), b = t + n.offsetHeight;
6131 var c = t + (b - t) / 2;
6132 var y = Ext.lib.Event.getPageY(e);
6141 isValidDropPoint: function(pt, n, data) {
6142 if (!data.viewNodes || (data.viewNodes.length != 1)) {
6145 var d = data.viewNodes[0];
6149 if ((pt == "below") && (n.nextSibling == d)) {
6152 if ((pt == "above") && (n.previousSibling == d)) {
6159 onNodeEnter : function(n, dd, e, data){
6164 onNodeOver : function(n, dd, e, data){
6165 var dragElClass = this.dropNotAllowed;
6166 var pt = this.getDropPoint(e, n, dd);
6167 if (this.isValidDropPoint(pt, n, data)) {
6168 if (this.ms.appendOnly) {
6169 return "x-tree-drop-ok-below";
6172 // set the insert point style on the target node
6176 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
6177 targetElClass = "x-view-drag-insert-above";
6179 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
6180 targetElClass = "x-view-drag-insert-below";
6182 if (this.lastInsertClass != targetElClass){
6183 Ext.fly(n).replaceClass(this.lastInsertClass, targetElClass);
6184 this.lastInsertClass = targetElClass;
6192 onNodeOut : function(n, dd, e, data){
6193 this.removeDropIndicators(n);
6197 onNodeDrop : function(n, dd, e, data){
6198 if (this.ms.fireEvent("drop", this, n, dd, e, data) === false) {
6201 var pt = this.getDropPoint(e, n, dd);
6202 if (n != this.ms.fs.body.dom)
6203 n = this.view.findItemFromChild(n);
6205 if(this.ms.appendOnly) {
6206 insertAt = this.view.store.getCount();
6208 insertAt = n == this.ms.fs.body.dom ? this.view.store.getCount() - 1 : this.view.indexOf(n);
6209 if (pt == "below") {
6216 // Validate if dragging within the same MultiSelect
6217 if (data.sourceView == this.view) {
6218 // If the first element to be inserted below is the target node, remove it
6219 if (pt == "below") {
6220 if (data.viewNodes[0] == n) {
6221 data.viewNodes.shift();
6223 } else { // If the last element to be inserted above is the target node, remove it
6224 if (data.viewNodes[data.viewNodes.length - 1] == n) {
6225 data.viewNodes.pop();
6229 // Nothing to drop...
6230 if (!data.viewNodes.length) {
6234 // If we are moving DOWN, then because a store.remove() takes place first,
6235 // the insertAt must be decremented.
6236 if (insertAt > this.view.store.indexOf(data.records[0])) {
6242 for (var i = 0; i < data.records.length; i++) {
6243 var r = data.records[i];
6244 if (data.sourceView) {
6245 data.sourceView.store.remove(r);
6247 this.view.store.insert(dir == 'down' ? insertAt : insertAt++, r);
6248 var si = this.view.store.sortInfo;
6250 this.view.store.sort(si.field, si.direction);
6257 removeDropIndicators : function(n){
6259 Ext.fly(n).removeClass([
6260 "x-view-drag-insert-above",
6261 "x-view-drag-insert-left",
6262 "x-view-drag-insert-right",
6263 "x-view-drag-insert-below"]);
6264 this.lastInsertClass = "_noclass";
6269 setDroppable: function(ddGroup){
6270 if (!ddGroup) return;
6271 if (Ext.isArray(ddGroup)) {
6272 Ext.each(ddGroup, this.setDroppable, this);
6275 this.addToGroup(ddGroup);
6279 /* Fix for Opera, which does not seem to include the map function on Array's */
6280 if (!Array.prototype.map) {
6281 Array.prototype.map = function(fun){
6282 var len = this.length;
6283 if (typeof fun != 'function') {
6284 throw new TypeError();
6286 var res = new Array(len);
6287 var thisp = arguments[1];
6288 for (var i = 0; i < len; i++) {
6290 res[i] = fun.call(thisp, this[i], i, this);
6297 Ext.ns('Ext.ux.data');
6300 * @class Ext.ux.data.PagingMemoryProxy
6301 * @extends Ext.data.MemoryProxy
6302 * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
6304 Ext.ux.data.PagingMemoryProxy = Ext.extend(Ext.data.MemoryProxy, {
6305 constructor : function(data){
6306 Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);
6309 doRequest : function(action, rs, params, reader, callback, scope, options){
6314 result = reader.readRecords(this.data);
6317 this.fireEvent('loadexception', this, options, null, e);
6318 callback.call(scope, null, options, false);
6323 if (params.filter !== undefined) {
6324 result.records = result.records.filter(function(el){
6325 if (typeof(el) == 'object') {
6326 var att = params.filterCol || 0;
6327 return String(el.data[att]).match(params.filter) ? true : false;
6330 return String(el).match(params.filter) ? true : false;
6333 result.totalRecords = result.records.length;
6337 if (params.sort !== undefined) {
6338 // use integer as params.sort to specify column, since arrays are not named
6339 // params.sort=0; would also match a array without columns
6340 var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
6341 var fn = function(v1, v2){
6342 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
6344 result.records.sort(function(a, b){
6346 if (typeof(a) == 'object') {
6347 v = fn(a.data[params.sort], b.data[params.sort]) * dir;
6353 v = (a.index < b.index ? -1 : 1);
6358 // paging (use undefined cause start can also be 0 (thus false))
6359 if (params.start !== undefined && params.limit !== undefined) {
6360 result.records = result.records.slice(params.start, params.start + params.limit);
6362 callback.call(scope, result, options, true);
6367 Ext.data.PagingMemoryProxy = Ext.ux.data.PagingMemoryProxy;
6368 Ext.ux.PanelResizer = Ext.extend(Ext.util.Observable, {
6372 constructor: function(config){
6373 Ext.apply(this, config);
6375 Ext.ux.PanelResizer.superclass.constructor.call(this, config);
6381 if(this.panel.elements.indexOf('footer')==-1){
6382 p.elements += ',footer';
6384 p.on('render', this.onRender, this);
6387 onRender : function(p){
6388 this.handle = p.footer.createChild({cls:'x-panel-resize'});
6390 this.tracker = new Ext.dd.DragTracker({
6391 onStart: this.onDragStart.createDelegate(this),
6392 onDrag: this.onDrag.createDelegate(this),
6393 onEnd: this.onDragEnd.createDelegate(this),
6397 this.tracker.initEl(this.handle);
6398 p.on('beforedestroy', this.tracker.destroy, this.tracker);
6402 onDragStart: function(e){
6403 this.dragging = true;
6404 this.startHeight = this.panel.el.getHeight();
6405 this.fireEvent('dragstart', this, e);
6409 onDrag: function(e){
6410 this.panel.setHeight((this.startHeight-this.tracker.getOffset()[1]).constrain(this.minHeight, this.maxHeight));
6411 this.fireEvent('drag', this, e);
6415 onDragEnd: function(e){
6416 this.dragging = false;
6417 this.fireEvent('dragend', this, e);
6420 Ext.preg('panelresizer', Ext.ux.PanelResizer);Ext.ux.Portal = Ext.extend(Ext.Panel, {
6424 defaultType : 'portalcolumn',
6426 initComponent : function(){
6427 Ext.ux.Portal.superclass.initComponent.call(this);
6430 beforedragover:true,
6437 initEvents : function(){
6438 Ext.ux.Portal.superclass.initEvents.call(this);
6439 this.dd = new Ext.ux.Portal.DropZone(this, this.dropConfig);
6442 beforeDestroy : function() {
6446 Ext.ux.Portal.superclass.beforeDestroy.call(this);
6450 Ext.reg('portal', Ext.ux.Portal);
6452 Ext.ux.Portal.DropZone = Ext.extend(Ext.dd.DropTarget, {
6454 constructor : function(portal, cfg){
6455 this.portal = portal;
6456 Ext.dd.ScrollManager.register(portal.body);
6457 Ext.ux.Portal.DropZone.superclass.constructor.call(this, portal.bwrap.dom, cfg);
6458 portal.body.ddScrollConfig = this.ddScrollConfig;
6468 createEvent : function(dd, e, data, col, c, pos){
6470 portal: this.portal,
6478 status: this.dropAllowed
6482 notifyOver : function(dd, e, data){
6483 var xy = e.getXY(), portal = this.portal, px = dd.proxy;
6485 // case column widths
6487 this.grid = this.getGrid();
6490 // handle case scroll where scrollbars appear during drag
6491 var cw = portal.body.dom.clientWidth;
6494 }else if(this.lastCW != cw){
6497 this.grid = this.getGrid();
6501 var col = 0, xs = this.grid.columnX, cmatch = false;
6502 for(var len = xs.length; col < len; col++){
6503 if(xy[0] < (xs[col].x + xs[col].w)){
6508 // no match, fix last index
6513 // find insert position
6514 var p, match = false, pos = 0,
6515 c = portal.items.itemAt(col),
6516 items = c.items.items, overSelf = false;
6518 for(var len = items.length; pos < len; pos++){
6520 var h = p.el.getHeight();
6524 else if((p.el.getY()+(h/2)) > xy[1]){
6530 pos = (match && p ? pos : c.items.getCount()) + (overSelf ? -1 : 0);
6531 var overEvent = this.createEvent(dd, e, data, col, c, pos);
6533 if(portal.fireEvent('validatedrop', overEvent) !== false &&
6534 portal.fireEvent('beforedragover', overEvent) !== false){
6536 // make sure proxy width is fluid
6537 px.getProxy().setWidth('auto');
6540 px.moveProxy(p.el.dom.parentNode, match ? p.el.dom : null);
6542 px.moveProxy(c.el.dom, null);
6545 this.lastPos = {c: c, col: col, p: overSelf || (match && p) ? pos : false};
6546 this.scrollPos = portal.body.getScroll();
6548 portal.fireEvent('dragover', overEvent);
6550 return overEvent.status;
6552 return overEvent.status;
6557 notifyOut : function(){
6561 notifyDrop : function(dd, e, data){
6566 var c = this.lastPos.c,
6567 col = this.lastPos.col,
6568 pos = this.lastPos.p,
6570 dropEvent = this.createEvent(dd, e, data, col, c,
6571 pos !== false ? pos : c.items.getCount());
6573 if(this.portal.fireEvent('validatedrop', dropEvent) !== false &&
6574 this.portal.fireEvent('beforedrop', dropEvent) !== false){
6576 dd.proxy.getProxy().remove();
6577 panel.el.dom.parentNode.removeChild(dd.panel.el.dom);
6580 c.insert(pos, panel);
6587 this.portal.fireEvent('drop', dropEvent);
6589 // scroll position is lost on drop, fix it
6590 var st = this.scrollPos.top;
6592 var d = this.portal.body.dom;
6593 setTimeout(function(){
6599 delete this.lastPos;
6602 // internal cache of body and column coords
6603 getGrid : function(){
6604 var box = this.portal.bwrap.getBox();
6606 this.portal.items.each(function(c){
6607 box.columnX.push({x: c.el.getX(), w: c.el.getWidth()});
6612 // unregister the dropzone from ScrollManager
6614 Ext.dd.ScrollManager.unregister(this.portal.body);
6615 Ext.ux.Portal.DropZone.superclass.unreg.call(this);
6618 Ext.ux.PortalColumn = Ext.extend(Ext.Container, {
6620 //autoEl : 'div',//already defined by Ext.Component
6621 defaultType : 'portlet',
6622 cls : 'x-portal-column'
6625 Ext.reg('portalcolumn', Ext.ux.PortalColumn);
6626 Ext.ux.Portlet = Ext.extend(Ext.Panel, {
6634 Ext.reg('portlet', Ext.ux.Portlet);
6636 * @class Ext.ux.ProgressBarPager
6638 * Plugin (ptype = 'tabclosemenu') for displaying a progressbar inside of a paging toolbar instead of plain text
6640 * @ptype progressbarpager
6642 * Create a new ItemSelector
6643 * @param {Object} config Configuration options
6644 * @xtype itemselector
6646 Ext.ux.ProgressBarPager = Ext.extend(Object, {
6648 * @cfg {Integer} progBarWidth
6649 * <p>The default progress bar width. Default is 225.</p>
6653 * @cfg {String} defaultText
6654 * <p>The text to display while the store is loading. Default is 'Loading...'</p>
6656 defaultText : 'Loading...',
6658 * @cfg {Object} defaultAnimCfg
6659 * <p>A {@link Ext.Fx Ext.Fx} configuration object. Default is { duration : 1, easing : 'bounceOut' }.</p>
6663 easing : 'bounceOut'
6665 constructor : function(config) {
6667 Ext.apply(this, config);
6671 init : function (parent) {
6673 if(parent.displayInfo){
6674 this.parent = parent;
6675 var ind = parent.items.indexOf(parent.displayItem);
6676 parent.remove(parent.displayItem, true);
6677 this.progressBar = new Ext.ProgressBar({
6678 text : this.defaultText,
6679 width : this.progBarWidth,
6680 animate : this.defaultAnimCfg
6683 parent.displayItem = this.progressBar;
6685 parent.add(parent.displayItem);
6687 Ext.apply(parent, this.parentOverrides);
6689 this.progressBar.on('render', function(pb) {
6690 pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
6691 }, this, {single: true});
6697 // This method handles the click for the progress bar
6698 handleProgressBarClick : function(e){
6699 var parent = this.parent,
6700 displayItem = parent.displayItem,
6701 box = this.progressBar.getBox(),
6703 position = xy[0]-box.x,
6704 pages = Math.ceil(parent.store.getTotalCount()/parent.pageSize),
6705 newpage = Math.ceil(position/(displayItem.width/pages));
6707 parent.changePage(newpage);
6710 // private, overriddes
6713 // This method updates the information via the progress bar.
6714 updateInfo : function(){
6715 if(this.displayItem){
6716 var count = this.store.getCount(),
6717 pgData = this.getPageData(),
6718 pageNum = this.readPage(pgData),
6723 this.cursor+1, this.cursor+count, this.store.getTotalCount()
6726 pageNum = pgData.activePage; ;
6728 var pct = pageNum / pgData.pages;
6730 this.displayItem.updateProgress(pct, msg, this.animate || this.defaultAnimConfig);
6735 Ext.preg('progressbarpager', Ext.ux.ProgressBarPager);
6737 Ext.ns('Ext.ux.grid');
6740 * @class Ext.ux.grid.RowEditor
6741 * @extends Ext.Panel
6742 * Plugin (ptype = 'roweditor') that adds the ability to rapidly edit full rows in a grid.
6743 * A validation mode may be enabled which uses AnchorTips to notify the user of all
6744 * validation errors at once.
6748 Ext.ux.grid.RowEditor = Ext.extend(Ext.Panel, {
6752 cls: 'x-small-editor',
6753 buttonAlign: 'center',
6754 baseCls: 'x-row-editor',
6755 elements: 'header,footer,body',
6758 clicksToEdit: 'auto',
6764 cancelText: 'Cancel',
6765 commitChangesText: 'You need to commit or cancel your changes',
6766 errorText: 'Errors',
6772 initComponent: function(){
6773 Ext.ux.grid.RowEditor.superclass.initComponent.call(this);
6777 * Fired before the row editor is activated.
6778 * If the listener returns <tt>false</tt> the editor will not be activated.
6779 * @param {Ext.ux.grid.RowEditor} roweditor This object
6780 * @param {Number} rowIndex The rowIndex of the row just edited
6785 * Fired when the editor is cancelled.
6786 * @param {Ext.ux.grid.RowEditor} roweditor This object
6787 * @param {Boolean} forced True if the cancel button is pressed, false is the editor was invalid.
6791 * @event validateedit
6792 * Fired after a row is edited and passes validation.
6793 * If the listener returns <tt>false</tt> changes to the record will not be set.
6794 * @param {Ext.ux.grid.RowEditor} roweditor This object
6795 * @param {Object} changes Object with changes made to the record.
6796 * @param {Ext.data.Record} r The Record that was edited.
6797 * @param {Number} rowIndex The rowIndex of the row just edited
6802 * Fired after a row is edited and passes validation. This event is fired
6803 * after the store's update event is fired with this edit.
6804 * @param {Ext.ux.grid.RowEditor} roweditor This object
6805 * @param {Object} changes Object with changes made to the record.
6806 * @param {Ext.data.Record} r The Record that was edited.
6807 * @param {Number} rowIndex The rowIndex of the row just edited
6813 init: function(grid){
6815 this.ownerCt = grid;
6816 if(this.clicksToEdit === 2){
6817 grid.on('rowdblclick', this.onRowDblClick, this);
6819 grid.on('rowclick', this.onRowClick, this);
6821 grid.on('rowdblclick', this.onRowDblClick, this);
6825 // stopEditing without saving when a record is removed from Store.
6826 grid.getStore().on('remove', function() {
6827 this.stopEditing(false);
6832 keydown: this.onGridKey,
6833 columnresize: this.verifyLayout,
6834 columnmove: this.refreshFields,
6835 reconfigure: this.refreshFields,
6836 beforedestroy : this.beforedestroy,
6837 destroy : this.destroy,
6840 fn: this.positionButtons
6843 grid.getColumnModel().on('hiddenchange', this.verifyLayout, this, {delay:1});
6844 grid.getView().on('refresh', this.stopEditing.createDelegate(this, []));
6847 beforedestroy: function() {
6848 this.stopMonitoring();
6849 this.grid.getStore().un('remove', this.onStoreRemove, this);
6850 this.stopEditing(false);
6851 Ext.destroy(this.btns, this.tooltip);
6854 refreshFields: function(){
6856 this.verifyLayout();
6859 isDirty: function(){
6861 this.items.each(function(f){
6862 if(String(this.values[f.id]) !== String(f.getValue())){
6870 startEditing: function(rowIndex, doFocus){
6871 if(this.editing && this.isDirty()){
6872 this.showTooltip(this.commitChangesText);
6875 if(Ext.isObject(rowIndex)){
6876 rowIndex = this.grid.getStore().indexOf(rowIndex);
6878 if(this.fireEvent('beforeedit', this, rowIndex) !== false){
6879 this.editing = true;
6880 var g = this.grid, view = g.getView(),
6881 row = view.getRow(rowIndex),
6882 record = g.store.getAt(rowIndex);
6884 this.record = record;
6885 this.rowIndex = rowIndex;
6888 this.render(view.getEditorParent());
6890 var w = Ext.fly(row).getWidth();
6892 if(!this.initialized){
6895 var cm = g.getColumnModel(), fields = this.items.items, f, val;
6896 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6897 val = this.preEditValue(record, cm.getDataIndex(i));
6900 this.values[f.id] = Ext.isEmpty(val) ? '' : val;
6902 this.verifyLayout(true);
6903 if(!this.isVisible()){
6904 this.setPagePosition(Ext.fly(row).getXY());
6906 this.el.setXY(Ext.fly(row).getXY(), {duration:0.15});
6908 if(!this.isVisible()){
6909 this.show().doLayout();
6911 if(doFocus !== false){
6912 this.doFocus.defer(this.focusDelay, this);
6917 stopEditing : function(saveChanges){
6918 this.editing = false;
6919 if(!this.isVisible()){
6922 if(saveChanges === false || !this.isValid()){
6924 this.fireEvent('canceledit', this, saveChanges === false);
6930 cm = this.grid.colModel,
6931 fields = this.items.items;
6932 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6933 if(!cm.isHidden(i)){
6934 var dindex = cm.getDataIndex(i);
6935 if(!Ext.isEmpty(dindex)){
6936 var oldValue = r.data[dindex],
6937 value = this.postEditValue(fields[i].getValue(), oldValue, r, dindex);
6938 if(String(oldValue) !== String(value)){
6939 changes[dindex] = value;
6945 if(hasChange && this.fireEvent('validateedit', this, changes, r, this.rowIndex) !== false){
6947 Ext.iterate(changes, function(name, value){
6951 this.fireEvent('afteredit', this, changes, r, this.rowIndex);
6956 verifyLayout: function(force){
6957 if(this.el && (this.isVisible() || force === true)){
6958 var row = this.grid.getView().getRow(this.rowIndex);
6959 this.setSize(Ext.fly(row).getWidth(), Ext.isIE ? Ext.fly(row).getHeight() + 9 : undefined);
6960 var cm = this.grid.colModel, fields = this.items.items;
6961 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6962 if(!cm.isHidden(i)){
6964 if(i === (len - 1)){
6965 adjust += 3; // outer padding
6970 fields[i].setWidth(cm.getColumnWidth(i) - adjust);
6976 this.positionButtons();
6980 slideHide : function(){
6984 initFields: function(){
6985 var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
6986 this.removeAll(false);
6987 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6988 var c = cm.getColumnAt(i),
6991 ed = c.displayEditor || new Ext.form.DisplayField();
6994 ed.margins = pm('0 1 2 1');
6995 } else if(i == len - 1){
6996 ed.margins = pm('0 0 2 1');
6999 ed.margins = pm('0 0 2 0');
7002 ed.margins = pm('0 1 2 0');
7005 ed.setWidth(cm.getColumnWidth(i));
7007 if(ed.ownerCt !== this){
7008 ed.on('focus', this.ensureVisible, this);
7009 ed.on('specialkey', this.onKey, this);
7013 this.initialized = true;
7016 onKey: function(f, e){
7017 if(e.getKey() === e.ENTER){
7018 this.stopEditing(true);
7019 e.stopPropagation();
7023 onGridKey: function(e){
7024 if(e.getKey() === e.ENTER && !this.isVisible()){
7025 var r = this.grid.getSelectionModel().getSelected();
7027 var index = this.grid.store.indexOf(r);
7028 this.startEditing(index);
7029 e.stopPropagation();
7034 ensureVisible: function(editor){
7035 if(this.isVisible()){
7036 this.grid.getView().ensureVisible(this.rowIndex, this.grid.colModel.getIndexById(editor.column.id), true);
7040 onRowClick: function(g, rowIndex, e){
7041 if(this.clicksToEdit == 'auto'){
7042 var li = this.lastClickIndex;
7043 this.lastClickIndex = rowIndex;
7044 if(li != rowIndex && !this.isVisible()){
7048 this.startEditing(rowIndex, false);
7049 this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
7052 onRowDblClick: function(g, rowIndex, e){
7053 this.startEditing(rowIndex, false);
7054 this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
7057 onRender: function(){
7058 Ext.ux.grid.RowEditor.superclass.onRender.apply(this, arguments);
7059 this.el.swallowEvent(['keydown', 'keyup', 'keypress']);
7060 this.btns = new Ext.Panel({
7065 width: (this.minButtonWidth * 2) + (this.frameWidth * 2) + (this.buttonPad * 4), // width must be specified for IE
7070 text: this.saveText,
7071 width: this.minButtonWidth,
7072 handler: this.stopEditing.createDelegate(this, [true])
7075 text: this.cancelText,
7076 width: this.minButtonWidth,
7077 handler: this.stopEditing.createDelegate(this, [false])
7080 this.btns.render(this.bwrap);
7083 afterRender: function(){
7084 Ext.ux.grid.RowEditor.superclass.afterRender.apply(this, arguments);
7085 this.positionButtons();
7086 if(this.monitorValid){
7087 this.startMonitoring();
7092 if(this.monitorValid){
7093 this.startMonitoring();
7095 Ext.ux.grid.RowEditor.superclass.onShow.apply(this, arguments);
7099 Ext.ux.grid.RowEditor.superclass.onHide.apply(this, arguments);
7100 this.stopMonitoring();
7101 this.grid.getView().focusRow(this.rowIndex);
7104 positionButtons: function(){
7107 h = this.el.dom.clientHeight,
7109 scroll = view.scroller.dom.scrollLeft,
7110 bw = this.btns.getWidth(),
7111 width = Math.min(g.getWidth(), g.getColumnModel().getTotalWidth());
7113 this.btns.el.shift({left: (width/2)-(bw/2)+scroll, top: h - 2, stopFx: true, duration:0.2});
7118 preEditValue : function(r, field){
7119 var value = r.data[field];
7120 return this.autoEncode && typeof value === 'string' ? Ext.util.Format.htmlDecode(value) : value;
7124 postEditValue : function(value, originalValue, r, field){
7125 return this.autoEncode && typeof value == 'string' ? Ext.util.Format.htmlEncode(value) : value;
7128 doFocus: function(pt){
7129 if(this.isVisible()){
7131 cm = this.grid.getColumnModel(),
7134 index = this.getTargetColumnIndex(pt);
7136 for(var i = index||0, len = cm.getColumnCount(); i < len; i++){
7137 c = cm.getColumnAt(i);
7138 if(!c.hidden && c.getEditor()){
7139 c.getEditor().focus();
7146 getTargetColumnIndex: function(pt){
7147 var grid = this.grid,
7150 cms = grid.colModel.config,
7153 for(var len = cms.length, c; c = cms[i]; i++){
7155 if(Ext.fly(v.getHeaderCell(i)).getRegion().right >= x){
7164 startMonitoring : function(){
7165 if(!this.bound && this.monitorValid){
7168 run : this.bindHandler,
7169 interval : this.monitorPoll || 200,
7175 stopMonitoring : function(){
7178 this.tooltip.hide();
7182 isValid: function(){
7184 this.items.each(function(f){
7185 if(!f.isValid(true)){
7194 bindHandler : function(){
7196 return false; // stops binding
7198 var valid = this.isValid();
7199 if(!valid && this.errorSummary){
7200 this.showTooltip(this.getErrorText().join(''));
7202 this.btns.saveBtn.setDisabled(!valid);
7203 this.fireEvent('validation', this, valid);
7206 lastVisibleColumn : function() {
7207 var i = this.items.getCount() - 1,
7209 for(; i >= 0; i--) {
7210 c = this.items.items[i];
7217 showTooltip: function(msg){
7218 var t = this.tooltip;
7220 t = this.tooltip = new Ext.ToolTip({
7224 title: this.errorText,
7227 anchorToTarget: true,
7231 var v = this.grid.getView(),
7232 top = parseInt(this.el.dom.style.top, 10),
7233 scroll = v.scroller.dom.scrollTop,
7234 h = this.el.getHeight();
7236 if(top + h >= scroll){
7237 t.initTarget(this.lastVisibleColumn().getEl());
7245 }else if(t.rendered){
7250 getErrorText: function(){
7251 var data = ['<ul>'];
7252 this.items.each(function(f){
7253 if(!f.isValid(true)){
7254 data.push('<li>', f.getActiveError(), '</li>');
7261 Ext.preg('roweditor', Ext.ux.grid.RowEditor);
7262 Ext.ns('Ext.ux.grid');
7265 * @class Ext.ux.grid.RowExpander
7266 * @extends Ext.util.Observable
7267 * Plugin (ptype = 'rowexpander') that adds the ability to have a Column in a grid which enables
7268 * a second row body which expands/contracts. The expand/contract behavior is configurable to react
7269 * on clicking of the column, double click of the row, and/or hitting enter while a row is selected.
7271 * @ptype rowexpander
7273 Ext.ux.grid.RowExpander = Ext.extend(Ext.util.Observable, {
7275 * @cfg {Boolean} expandOnEnter
7276 * <tt>true</tt> to toggle selected row(s) between expanded/collapsed when the enter
7277 * key is pressed (defaults to <tt>true</tt>).
7279 expandOnEnter : true,
7281 * @cfg {Boolean} expandOnDblClick
7282 * <tt>true</tt> to toggle a row between expanded/collapsed when double clicked
7283 * (defaults to <tt>true</tt>).
7285 expandOnDblClick : true,
7292 menuDisabled : true,
7296 enableCaching : true,
7298 constructor: function(config){
7299 Ext.apply(this, config);
7303 * @event beforeexpand
7304 * Fires before the row expands. Have the listener return false to prevent the row from expanding.
7305 * @param {Object} this RowExpander object.
7306 * @param {Object} Ext.data.Record Record for the selected row.
7307 * @param {Object} body body element for the secondary row.
7308 * @param {Number} rowIndex The current row index.
7313 * Fires after the row expands.
7314 * @param {Object} this RowExpander object.
7315 * @param {Object} Ext.data.Record Record for the selected row.
7316 * @param {Object} body body element for the secondary row.
7317 * @param {Number} rowIndex The current row index.
7321 * @event beforecollapse
7322 * Fires before the row collapses. Have the listener return false to prevent the row from collapsing.
7323 * @param {Object} this RowExpander object.
7324 * @param {Object} Ext.data.Record Record for the selected row.
7325 * @param {Object} body body element for the secondary row.
7326 * @param {Number} rowIndex The current row index.
7328 beforecollapse: true,
7331 * Fires after the row collapses.
7332 * @param {Object} this RowExpander object.
7333 * @param {Object} Ext.data.Record Record for the selected row.
7334 * @param {Object} body body element for the secondary row.
7335 * @param {Number} rowIndex The current row index.
7340 Ext.ux.grid.RowExpander.superclass.constructor.call(this);
7343 if(typeof this.tpl == 'string'){
7344 this.tpl = new Ext.Template(this.tpl);
7350 this.bodyContent = {};
7353 getRowClass : function(record, rowIndex, p, ds){
7355 var content = this.bodyContent[record.id];
7356 if(!content && !this.lazyRender){
7357 content = this.getBodyContent(record, rowIndex);
7362 return this.state[record.id] ? 'x-grid3-row-expanded' : 'x-grid3-row-collapsed';
7365 init : function(grid){
7368 var view = grid.getView();
7369 view.getRowClass = this.getRowClass.createDelegate(this);
7371 view.enableRowBody = true;
7374 grid.on('render', this.onRender, this);
7375 grid.on('destroy', this.onDestroy, this);
7379 onRender: function() {
7380 var grid = this.grid;
7381 var mainBody = grid.getView().mainBody;
7382 mainBody.on('mousedown', this.onMouseDown, this, {delegate: '.x-grid3-row-expander'});
7383 if (this.expandOnEnter) {
7384 this.keyNav = new Ext.KeyNav(this.grid.getGridEl(), {
7385 'enter' : this.onEnter,
7389 if (this.expandOnDblClick) {
7390 grid.on('rowdblclick', this.onRowDblClick, this);
7395 onDestroy: function() {
7397 this.keyNav.disable();
7401 * A majority of the time, the plugin will be destroyed along with the grid,
7402 * which means the mainBody won't be available. On the off chance that the plugin
7403 * isn't destroyed with the grid, take care of removing the listener.
7405 var mainBody = this.grid.getView().mainBody;
7407 mainBody.un('mousedown', this.onMouseDown, this);
7411 onRowDblClick: function(grid, rowIdx, e) {
7412 this.toggleRow(rowIdx);
7415 onEnter: function(e) {
7417 var sm = g.getSelectionModel();
7418 var sels = sm.getSelections();
7419 for (var i = 0, len = sels.length; i < len; i++) {
7420 var rowIdx = g.getStore().indexOf(sels[i]);
7421 this.toggleRow(rowIdx);
7425 getBodyContent : function(record, index){
7426 if(!this.enableCaching){
7427 return this.tpl.apply(record.data);
7429 var content = this.bodyContent[record.id];
7431 content = this.tpl.apply(record.data);
7432 this.bodyContent[record.id] = content;
7437 onMouseDown : function(e, t){
7439 var row = e.getTarget('.x-grid3-row');
7440 this.toggleRow(row);
7443 renderer : function(v, p, record){
7444 p.cellAttr = 'rowspan="2"';
7445 return '<div class="x-grid3-row-expander"> </div>';
7448 beforeExpand : function(record, body, rowIndex){
7449 if(this.fireEvent('beforeexpand', this, record, body, rowIndex) !== false){
7450 if(this.tpl && this.lazyRender){
7451 body.innerHTML = this.getBodyContent(record, rowIndex);
7459 toggleRow : function(row){
7460 if(typeof row == 'number'){
7461 row = this.grid.view.getRow(row);
7463 this[Ext.fly(row).hasClass('x-grid3-row-collapsed') ? 'expandRow' : 'collapseRow'](row);
7466 expandRow : function(row){
7467 if(typeof row == 'number'){
7468 row = this.grid.view.getRow(row);
7470 var record = this.grid.store.getAt(row.rowIndex);
7471 var body = Ext.DomQuery.selectNode('tr:nth(2) div.x-grid3-row-body', row);
7472 if(this.beforeExpand(record, body, row.rowIndex)){
7473 this.state[record.id] = true;
7474 Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
7475 this.fireEvent('expand', this, record, body, row.rowIndex);
7479 collapseRow : function(row){
7480 if(typeof row == 'number'){
7481 row = this.grid.view.getRow(row);
7483 var record = this.grid.store.getAt(row.rowIndex);
7484 var body = Ext.fly(row).child('tr:nth(1) div.x-grid3-row-body', true);
7485 if(this.fireEvent('beforecollapse', this, record, body, row.rowIndex) !== false){
7486 this.state[record.id] = false;
7487 Ext.fly(row).replaceClass('x-grid3-row-expanded', 'x-grid3-row-collapsed');
7488 this.fireEvent('collapse', this, record, body, row.rowIndex);
7493 Ext.preg('rowexpander', Ext.ux.grid.RowExpander);
7496 Ext.grid.RowExpander = Ext.ux.grid.RowExpander;// We are adding these custom layouts to a namespace that does not
7497 // exist by default in Ext, so we have to add the namespace first:
7498 Ext.ns('Ext.ux.layout');
7501 * @class Ext.ux.layout.RowLayout
7502 * @extends Ext.layout.ContainerLayout
7503 * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of
7504 * each row can be specified as a percentage or fixed height. Row widths can also be fixed, percentage or auto.
7505 * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config,
7506 * and should generally not need to be created directly via the new keyword.</p>
7507 * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a
7508 * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it. The
7509 * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel.
7510 * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p>
7511 * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1.
7512 * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and
7513 * less than 1 (e.g., .25).</p>
7514 * <p>The basic rules for specifying row heights are pretty simple. The logic makes two passes through the
7515 * set of contained panels. During the first layout pass, all panels that either have a fixed height or none
7516 * specified (auto) are skipped, but their heights are subtracted from the overall container height. During the second
7517 * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on
7518 * the total <b>remaining</b> container height. In other words, percentage height panels are designed to fill the space
7519 * left over by all the fixed-height and/or auto-height panels. Because of this, while you can specify any number of rows
7520 * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your
7521 * layout may not render as expected. Example usage:</p>
7523 // All rows are percentages -- they must add up to 1
7524 var p = new Ext.Panel({
7525 title: 'Row Layout - Percentage Only',
7539 // Mix of height and rowHeight -- all rowHeight values must add
7540 // up to 1. The first row will take up exactly 120px, and the last two
7541 // rows will fill the remaining container height.
7542 var p = new Ext.Panel({
7543 title: 'Row Layout - Mixed',
7548 // standard panel widths are still supported too:
7549 width: '50%' // or 200
7561 Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
7568 allowContainerRemove: false,
7571 isValidParent : function(c, target){
7572 return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
7575 getLayoutTargetSize : function() {
7576 var target = this.container.getLayoutTarget(), ret;
7578 ret = target.getViewSize();
7580 // IE in strict mode will return a height of 0 on the 1st pass of getViewSize.
7581 // Use getStyleSize to verify the 0 height, the adjustment pass will then work properly
7583 if (Ext.isIE && Ext.isStrict && ret.height == 0){
7584 ret = target.getStyleSize();
7587 ret.width -= target.getPadding('lr');
7588 ret.height -= target.getPadding('tb');
7593 renderAll : function(ct, target) {
7595 // the innerCt prevents wrapping and shuffling while
7596 // the container is resizing
7597 this.innerCt = target.createChild({cls:'x-column-inner'});
7598 this.innerCt.createChild({cls:'x-clear'});
7600 Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
7604 onLayout : function(ct, target){
7605 var rs = ct.items.items,
7612 this.renderAll(ct, target);
7614 var size = this.getLayoutTargetSize();
7616 if(size.width < 1 && size.height < 1){ // display none?
7620 var h = size.height,
7623 this.innerCt.setSize({height:h});
7625 // some rows can be percentages while others are fixed
7626 // so we need to make 2 passes
7628 for(i = 0; i < len; i++){
7630 m = r.getPositionEl().getMargins('tb');
7633 ph -= (r.getHeight() + m);
7637 ph = ph < 0 ? 0 : ph;
7639 for(i = 0; i < len; i++){
7643 r.setSize({height: Math.floor(r.rowHeight*ph) - m});
7647 // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
7648 // spaces were accounted for properly. If not, re-layout.
7650 if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
7651 var ts = this.getLayoutTargetSize();
7652 if (ts.width != size.width){
7653 this.adjustmentPass = true;
7654 this.onLayout(ct, target);
7658 delete this.adjustmentPass;
7662 * @property activeItem
7667 Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;
7668 Ext.ns('Ext.ux.form');
7670 Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
7671 initComponent : function(){
7672 Ext.ux.form.SearchField.superclass.initComponent.call(this);
7673 this.on('specialkey', function(f, e){
7674 if(e.getKey() == e.ENTER){
7675 this.onTrigger2Click();
7680 validationEvent:false,
7681 validateOnBlur:false,
7682 trigger1Class:'x-form-clear-trigger',
7683 trigger2Class:'x-form-search-trigger',
7687 paramName : 'query',
7689 onTrigger1Click : function(){
7691 this.el.dom.value = '';
7693 this.store.baseParams = this.store.baseParams || {};
7694 this.store.baseParams[this.paramName] = '';
7695 this.store.reload({params:o});
7696 this.triggers[0].hide();
7697 this.hasSearch = false;
7701 onTrigger2Click : function(){
7702 var v = this.getRawValue();
7704 this.onTrigger1Click();
7708 this.store.baseParams = this.store.baseParams || {};
7709 this.store.baseParams[this.paramName] = v;
7710 this.store.reload({params:o});
7711 this.hasSearch = true;
7712 this.triggers[0].show();
7714 });Ext.ns('Ext.ux.form');
7717 * @class Ext.ux.form.SelectBox
7718 * @extends Ext.form.ComboBox
7719 * <p>Makes a ComboBox more closely mimic an HTML SELECT. Supports clicking and dragging
7720 * through the list, with item selection occurring when the mouse button is released.
7721 * When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}
7722 * on inner elements. Re-enabling editable after calling this will NOT work.</p>
7723 * @author Corey Gilmore http://extjs.com/forum/showthread.php?t=6392
7724 * @history 2007-07-08 jvs
7725 * Slight mods for Ext 2.0
7728 Ext.ux.form.SelectBox = Ext.extend(Ext.form.ComboBox, {
7729 constructor: function(config){
7730 this.searchResetDelay = 1000;
7731 config = config || {};
7732 config = Ext.apply(config || {}, {
7734 forceSelection: true,
7736 lastSearchTerm: false,
7737 triggerAction: 'all',
7741 Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);
7743 this.lastSelectedIndex = this.selectedIndex || 0;
7746 initEvents : function(){
7747 Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);
7748 // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE
7749 this.el.on('keydown', this.keySearch, this, true);
7750 this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);
7753 keySearch : function(e, target, options) {
7754 var raw = e.getKey();
7755 var key = String.fromCharCode(raw);
7758 if( !this.store.getCount() ) {
7763 case Ext.EventObject.HOME:
7768 case Ext.EventObject.END:
7773 case Ext.EventObject.PAGEDOWN:
7774 this.selectNextPage();
7778 case Ext.EventObject.PAGEUP:
7779 this.selectPrevPage();
7784 // skip special keys other than the shift key
7785 if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {
7788 if( this.lastSearchTerm == key ) {
7789 startIndex = this.lastSelectedIndex;
7791 this.search(this.displayField, key, startIndex);
7792 this.cshTask.delay(this.searchResetDelay);
7795 onRender : function(ct, position) {
7796 this.store.on('load', this.calcRowsPerPage, this);
7797 Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);
7798 if( this.mode == 'local' ) {
7800 this.calcRowsPerPage();
7804 onSelect : function(record, index, skipCollapse){
7805 if(this.fireEvent('beforeselect', this, record, index) !== false){
7806 this.setValue(record.data[this.valueField || this.displayField]);
7807 if( !skipCollapse ) {
7810 this.lastSelectedIndex = index + 1;
7811 this.fireEvent('select', this, record, index);
7815 afterRender : function() {
7816 Ext.ux.form.SelectBox.superclass.afterRender.apply(this, arguments);
7818 this.el.swallowEvent('mousedown', true);
7820 this.el.unselectable();
7821 this.innerList.unselectable();
7822 this.trigger.unselectable();
7823 this.innerList.on('mouseup', function(e, target, options) {
7824 if( target.id && target.id == this.innerList.id ) {
7830 this.innerList.on('mouseover', function(e, target, options) {
7831 if( target.id && target.id == this.innerList.id ) {
7834 this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;
7835 this.cshTask.delay(this.searchResetDelay);
7838 this.trigger.un('click', this.onTriggerClick, this);
7839 this.trigger.on('mousedown', function(e, target, options) {
7841 this.onTriggerClick();
7844 this.on('collapse', function(e, target, options) {
7845 Ext.getDoc().un('mouseup', this.collapseIf, this);
7848 this.on('expand', function(e, target, options) {
7849 Ext.getDoc().on('mouseup', this.collapseIf, this);
7853 clearSearchHistory : function() {
7854 this.lastSelectedIndex = 0;
7855 this.lastSearchTerm = false;
7858 selectFirst : function() {
7859 this.focusAndSelect(this.store.data.first());
7862 selectLast : function() {
7863 this.focusAndSelect(this.store.data.last());
7866 selectPrevPage : function() {
7867 if( !this.rowHeight ) {
7870 var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);
7871 this.focusAndSelect(this.store.getAt(index));
7874 selectNextPage : function() {
7875 if( !this.rowHeight ) {
7878 var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);
7879 this.focusAndSelect(this.store.getAt(index));
7882 search : function(field, value, startIndex) {
7883 field = field || this.displayField;
7884 this.lastSearchTerm = value;
7885 var index = this.store.find.apply(this.store, arguments);
7886 if( index !== -1 ) {
7887 this.focusAndSelect(index);
7891 focusAndSelect : function(record) {
7892 var index = Ext.isNumber(record) ? record : this.store.indexOf(record);
7893 this.select(index, this.isExpanded());
7894 this.onSelect(this.store.getAt(index), index, this.isExpanded());
7897 calcRowsPerPage : function() {
7898 if( this.store.getCount() ) {
7899 this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();
7900 this.rowsPerPage = this.maxHeight / this.rowHeight;
7902 this.rowHeight = false;
7908 Ext.reg('selectbox', Ext.ux.form.SelectBox);
7911 Ext.ux.SelectBox = Ext.ux.form.SelectBox;
7913 * Plugin for PagingToolbar which replaces the textfield input with a slider
7915 Ext.ux.SlidingPager = Ext.extend(Object, {
7916 init : function(pbar){
7917 var idx = pbar.items.indexOf(pbar.inputItem);
7918 Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
7921 var slider = new Ext.Slider({
7925 plugins: new Ext.slider.Tip({
7926 getText : function(thumb) {
7927 return String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
7931 changecomplete: function(s, v){
7936 pbar.insert(idx + 1, slider);
7938 change: function(pb, data){
7939 slider.setMaxValue(data.pages);
7940 slider.setValue(data.activePage);
7944 });Ext.ns('Ext.ux.form');
7947 * @class Ext.ux.form.SpinnerField
7948 * @extends Ext.form.NumberField
7949 * Creates a field utilizing Ext.ux.Spinner
7950 * @xtype spinnerfield
7952 Ext.ux.form.SpinnerField = Ext.extend(Ext.form.NumberField, {
7955 autoSize: Ext.emptyFn,
7956 onBlur: Ext.emptyFn,
7957 adjustSize: Ext.BoxComponent.prototype.adjustSize,
7959 constructor: function(config) {
7960 var spinnerConfig = Ext.copyTo({}, config, 'incrementValue,alternateIncrementValue,accelerate,defaultValue,triggerClass,splitterClass');
7962 var spl = this.spinner = new Ext.ux.Spinner(spinnerConfig);
7964 var plugins = config.plugins
7965 ? (Ext.isArray(config.plugins)
7966 ? config.plugins.push(spl)
7967 : [config.plugins, spl])
7970 Ext.ux.form.SpinnerField.superclass.constructor.call(this, Ext.apply(config, {plugins: plugins}));
7974 getResizeEl: function(){
7979 getPositionEl: function(){
7984 alignErrorIcon: function(){
7986 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
7990 validateBlur: function(){
7995 Ext.reg('spinnerfield', Ext.ux.form.SpinnerField);
7998 Ext.form.SpinnerField = Ext.ux.form.SpinnerField;
8000 * @class Ext.ux.Spinner
8001 * @extends Ext.util.Observable
8002 * Creates a Spinner control utilized by Ext.ux.form.SpinnerField
8004 Ext.ux.Spinner = Ext.extend(Ext.util.Observable, {
8006 alternateIncrementValue: 5,
8007 triggerClass: 'x-form-spinner-trigger',
8008 splitterClass: 'x-form-spinner-splitter',
8009 alternateKey: Ext.EventObject.shiftKey,
8013 constructor: function(config){
8014 Ext.ux.Spinner.superclass.constructor.call(this, config);
8015 Ext.apply(this, config);
8016 this.mimicing = false;
8019 init: function(field){
8022 field.afterMethod('onRender', this.doRender, this);
8023 field.afterMethod('onEnable', this.doEnable, this);
8024 field.afterMethod('onDisable', this.doDisable, this);
8025 field.afterMethod('afterRender', this.doAfterRender, this);
8026 field.afterMethod('onResize', this.doResize, this);
8027 field.afterMethod('onFocus', this.doFocus, this);
8028 field.beforeMethod('onDestroy', this.doDestroy, this);
8031 doRender: function(ct, position){
8032 var el = this.el = this.field.getEl();
8036 f.wrap = this.wrap = el.wrap({
8037 cls: "x-form-field-wrap"
8041 this.wrap = f.wrap.addClass('x-form-field-wrap');
8044 this.trigger = this.wrap.createChild({
8046 src: Ext.BLANK_IMAGE_URL,
8047 cls: "x-form-trigger " + this.triggerClass
8051 this.wrap.setWidth(el.getWidth() + this.trigger.getWidth());
8054 this.splitter = this.wrap.createChild({
8056 cls: this.splitterClass,
8057 style: 'width:13px; height:2px;'
8059 this.splitter.setRight((Ext.isIE) ? 1 : 2).setTop(10).show();
8061 this.proxy = this.trigger.createProxy('', this.splitter, true);
8062 this.proxy.addClass("x-form-spinner-proxy");
8063 this.proxy.setStyle('left', '0px');
8064 this.proxy.setSize(14, 1);
8066 this.dd = new Ext.dd.DDProxy(this.splitter.dom.id, "SpinnerDrag", {
8067 dragElId: this.proxy.id
8074 doAfterRender: function(){
8076 if (Ext.isIE && this.el.getY() != (y = this.trigger.getY())) {
8082 doEnable: function(){
8084 this.wrap.removeClass(this.field.disabledClass);
8088 doDisable: function(){
8090 this.wrap.addClass(this.field.disabledClass);
8091 this.el.removeClass(this.field.disabledClass);
8095 doResize: function(w, h){
8096 if (typeof w == 'number') {
8097 this.el.setWidth(w - this.trigger.getWidth());
8099 this.wrap.setWidth(this.el.getWidth() + this.trigger.getWidth());
8102 doFocus: function(){
8103 if (!this.mimicing) {
8104 this.wrap.addClass('x-trigger-wrap-focus');
8105 this.mimicing = true;
8106 Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {
8109 this.el.on('keydown', this.checkTab, this);
8114 checkTab: function(e){
8115 if (e.getKey() == e.TAB) {
8121 mimicBlur: function(e){
8122 if (!this.wrap.contains(e.target) && this.field.validateBlur(e)) {
8128 triggerBlur: function(){
8129 this.mimicing = false;
8130 Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
8131 this.el.un("keydown", this.checkTab, this);
8132 this.field.beforeBlur();
8133 this.wrap.removeClass('x-trigger-wrap-focus');
8134 this.field.onBlur.call(this.field);
8137 initTrigger: function(){
8138 this.trigger.addClassOnOver('x-form-trigger-over');
8139 this.trigger.addClassOnClick('x-form-trigger-click');
8142 initSpinner: function(){
8143 this.field.addEvents({
8149 this.keyNav = new Ext.KeyNav(this.el, {
8155 "down": function(e){
8160 "pageUp": function(e){
8162 this.onSpinUpAlternate();
8165 "pageDown": function(e){
8167 this.onSpinDownAlternate();
8173 this.repeater = new Ext.util.ClickRepeater(this.trigger, {
8174 accelerate: this.accelerate
8176 this.field.mon(this.repeater, "click", this.onTriggerClick, this, {
8177 preventDefault: true
8180 this.field.mon(this.trigger, {
8181 mouseover: this.onMouseOver,
8182 mouseout: this.onMouseOut,
8183 mousemove: this.onMouseMove,
8184 mousedown: this.onMouseDown,
8185 mouseup: this.onMouseUp,
8187 preventDefault: true
8190 this.field.mon(this.wrap, "mousewheel", this.handleMouseWheel, this);
8192 this.dd.setXConstraint(0, 0, 10)
8193 this.dd.setYConstraint(1500, 1500, 10);
8194 this.dd.endDrag = this.endDrag.createDelegate(this);
8195 this.dd.startDrag = this.startDrag.createDelegate(this);
8196 this.dd.onDrag = this.onDrag.createDelegate(this);
8199 onMouseOver: function(){
8200 if (this.disabled) {
8203 var middle = this.getMiddle();
8204 this.tmpHoverClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-overup' : 'x-form-spinner-overdown';
8205 this.trigger.addClass(this.tmpHoverClass);
8209 onMouseOut: function(){
8210 this.trigger.removeClass(this.tmpHoverClass);
8214 onMouseMove: function(){
8215 if (this.disabled) {
8218 var middle = this.getMiddle();
8219 if (((Ext.EventObject.getPageY() > middle) && this.tmpHoverClass == "x-form-spinner-overup") ||
8220 ((Ext.EventObject.getPageY() < middle) && this.tmpHoverClass == "x-form-spinner-overdown")) {
8225 onMouseDown: function(){
8226 if (this.disabled) {
8229 var middle = this.getMiddle();
8230 this.tmpClickClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-clickup' : 'x-form-spinner-clickdown';
8231 this.trigger.addClass(this.tmpClickClass);
8235 onMouseUp: function(){
8236 this.trigger.removeClass(this.tmpClickClass);
8240 onTriggerClick: function(){
8241 if (this.disabled || this.el.dom.readOnly) {
8244 var middle = this.getMiddle();
8245 var ud = (Ext.EventObject.getPageY() < middle) ? 'Up' : 'Down';
8246 this['onSpin' + ud]();
8250 getMiddle: function(){
8251 var t = this.trigger.getTop();
8252 var h = this.trigger.getHeight();
8253 var middle = t + (h / 2);
8258 //checks if control is allowed to spin
8259 isSpinnable: function(){
8260 if (this.disabled || this.el.dom.readOnly) {
8261 Ext.EventObject.preventDefault(); //prevent scrolling when disabled/readonly
8267 handleMouseWheel: function(e){
8268 //disable scrolling when not focused
8269 if (this.wrap.hasClass('x-trigger-wrap-focus') == false) {
8273 var delta = e.getWheelDelta();
8286 startDrag: function(){
8288 this._previousY = Ext.fly(this.dd.getDragEl()).getTop();
8292 endDrag: function(){
8298 if (this.disabled) {
8301 var y = Ext.fly(this.dd.getDragEl()).getTop();
8304 if (this._previousY > y) {
8307 if (this._previousY < y) {
8311 this['onSpin' + ud]();
8314 this._previousY = y;
8318 onSpinUp: function(){
8319 if (this.isSpinnable() == false) {
8322 if (Ext.EventObject.shiftKey == true) {
8323 this.onSpinUpAlternate();
8327 this.spin(false, false);
8329 this.field.fireEvent("spin", this);
8330 this.field.fireEvent("spinup", this);
8334 onSpinDown: function(){
8335 if (this.isSpinnable() == false) {
8338 if (Ext.EventObject.shiftKey == true) {
8339 this.onSpinDownAlternate();
8343 this.spin(true, false);
8345 this.field.fireEvent("spin", this);
8346 this.field.fireEvent("spindown", this);
8350 onSpinUpAlternate: function(){
8351 if (this.isSpinnable() == false) {
8354 this.spin(false, true);
8355 this.field.fireEvent("spin", this);
8356 this.field.fireEvent("spinup", this);
8360 onSpinDownAlternate: function(){
8361 if (this.isSpinnable() == false) {
8364 this.spin(true, true);
8365 this.field.fireEvent("spin", this);
8366 this.field.fireEvent("spindown", this);
8369 spin: function(down, alternate){
8370 var v = parseFloat(this.field.getValue());
8371 var incr = (alternate == true) ? this.alternateIncrementValue : this.incrementValue;
8372 (down == true) ? v -= incr : v += incr;
8374 v = (isNaN(v)) ? this.defaultValue : v;
8375 v = this.fixBoundries(v);
8376 this.field.setRawValue(v);
8379 fixBoundries: function(value){
8382 if (this.field.minValue != undefined && v < this.field.minValue) {
8383 v = this.field.minValue;
8385 if (this.field.maxValue != undefined && v > this.field.maxValue) {
8386 v = this.field.maxValue;
8389 return this.fixPrecision(v);
8393 fixPrecision: function(value){
8394 var nan = isNaN(value);
8395 if (!this.field.allowDecimals || this.field.decimalPrecision == -1 || nan || !value) {
8396 return nan ? '' : value;
8398 return parseFloat(parseFloat(value).toFixed(this.field.decimalPrecision));
8401 doDestroy: function(){
8403 this.trigger.remove();
8407 delete this.field.wrap;
8410 if (this.splitter) {
8411 this.splitter.remove();
8420 this.proxy.remove();
8423 if (this.repeater) {
8424 this.repeater.purgeListeners();
8430 Ext.form.Spinner = Ext.ux.Spinner;Ext.ux.Spotlight = function(config){
8431 Ext.apply(this, config);
8433 Ext.ux.Spotlight.prototype = {
8442 createElements : function(){
8443 var bd = Ext.getBody();
8445 this.right = bd.createChild({cls:'x-spotlight'});
8446 this.left = bd.createChild({cls:'x-spotlight'});
8447 this.top = bd.createChild({cls:'x-spotlight'});
8448 this.bottom = bd.createChild({cls:'x-spotlight'});
8450 this.all = new Ext.CompositeElement([this.right, this.left, this.top, this.bottom]);
8453 show : function(el, callback, scope){
8455 this.show.defer(50, this, [el, callback, scope]);
8458 this.el = Ext.get(el);
8460 this.createElements();
8463 this.all.setDisplayed('');
8464 this.applyBounds(true, false);
8466 Ext.EventManager.onWindowResize(this.syncSize, this);
8467 this.applyBounds(false, this.animate, false, callback, scope);
8469 this.applyBounds(false, false, false, callback, scope); // all these booleans look hideous
8473 hide : function(callback, scope){
8475 this.hide.defer(50, this, [callback, scope]);
8478 Ext.EventManager.removeResizeListener(this.syncSize, this);
8479 this.applyBounds(true, this.animate, true, callback, scope);
8482 doHide : function(){
8483 this.active = false;
8484 this.all.setDisplayed(false);
8487 syncSize : function(){
8488 this.applyBounds(false, false);
8491 applyBounds : function(basePts, anim, doHide, callback, scope){
8493 var rg = this.el.getRegion();
8495 var dw = Ext.lib.Dom.getViewWidth(true);
8496 var dh = Ext.lib.Dom.getViewHeight(true);
8498 var c = 0, cb = false;
8501 callback: function(){
8504 this.animated = false;
8508 Ext.callback(callback, scope, [this]);
8512 duration: this.duration,
8515 this.animated = true;
8518 this.right.setBounds(
8520 basePts ? dh : rg.top,
8522 basePts ? 0 : (dh - rg.top),
8525 this.left.setBounds(
8529 basePts ? 0 : rg.bottom,
8533 basePts ? dw : rg.left,
8535 basePts ? 0 : dw - rg.left,
8539 this.bottom.setBounds(
8542 basePts ? 0 : rg.right,
8551 Ext.callback(callback, scope, [this]);
8556 destroy : function(){
8569 Ext.Spotlight = Ext.ux.Spotlight;/**
8570 * @class Ext.ux.StatusBar
8571 * <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to
8572 * supporting the standard {@link Ext.Toolbar} interface for adding buttons, menus and other items, the StatusBar
8573 * provides a greedy status element that can be aligned to either side and has convenient methods for setting the
8574 * status text and icon. You can also indicate that something is processing using the {@link #showBusy} method.</p>
8579 bbar: new Ext.ux.StatusBar({
8582 // defaults to use when the status is cleared:
8583 defaultText: 'Default status text',
8584 defaultIconCls: 'default-icon',
8586 // values to set initially:
8588 iconCls: 'ready-icon',
8590 // any standard Toolbar items:
8593 }, '-', 'Plain Text']
8597 // Update the status bar later in code:
8598 var sb = Ext.getCmp('my-status');
8602 clear: true // auto-clear after a set interval
8605 // Set the status bar to show that something is processing:
8610 sb.clearStatus(); // once completeed
8612 * @extends Ext.Toolbar
8614 * Creates a new StatusBar
8615 * @param {Object/Array} config A config object
8617 Ext.ux.StatusBar = Ext.extend(Ext.Toolbar, {
8619 * @cfg {String} statusAlign
8620 * The alignment of the status element within the overall StatusBar layout. When the StatusBar is rendered,
8621 * it creates an internal div containing the status text and icon. Any additional Toolbar items added in the
8622 * StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be
8623 * rendered, in added order, to the opposite side. The status element is greedy, so it will automatically
8624 * expand to take up all sapce left over by any other items. Example usage:
8626 // Create a left-aligned status bar containing a button,
8627 // separator and text item that will be right-aligned (default):
8631 bbar: new Ext.ux.StatusBar({
8632 defaultText: 'Default status text',
8636 }, '-', 'Plain Text']
8640 // By adding the statusAlign config, this will create the
8641 // exact same toolbar, except the status and toolbar item
8642 // layout will be reversed from the previous example:
8646 bbar: new Ext.ux.StatusBar({
8647 defaultText: 'Default status text',
8649 statusAlign: 'right',
8652 }, '-', 'Plain Text']
8658 * @cfg {String} defaultText
8659 * The default {@link #text} value. This will be used anytime the status bar is cleared with the
8660 * <tt>useDefaults:true</tt> option (defaults to '').
8663 * @cfg {String} defaultIconCls
8664 * The default {@link #iconCls} value (see the iconCls docs for additional details about customizing the icon).
8665 * This will be used anytime the status bar is cleared with the <tt>useDefaults:true</tt> option (defaults to '').
8668 * @cfg {String} text
8669 * A string that will be <b>initially</b> set as the status message. This string
8670 * will be set as innerHTML (html tags are accepted) for the toolbar item.
8671 * If not specified, the value set for <code>{@link #defaultText}</code>
8675 * @cfg {String} iconCls
8676 * A CSS class that will be <b>initially</b> set as the status bar icon and is
8677 * expected to provide a background image (defaults to '').
8678 * Example usage:<pre><code>
8679 // Example CSS rule:
8680 .x-statusbar .x-status-custom {
8682 background: transparent url(images/custom-icon.gif) no-repeat 3px 2px;
8685 // Setting a default icon:
8686 var sb = new Ext.ux.StatusBar({
8687 defaultIconCls: 'x-status-custom'
8690 // Changing the icon:
8693 iconCls: 'x-status-custom'
8700 * The base class applied to the containing element for this component on render (defaults to 'x-statusbar')
8702 cls : 'x-statusbar',
8704 * @cfg {String} busyIconCls
8705 * The default <code>{@link #iconCls}</code> applied when calling
8706 * <code>{@link #showBusy}</code> (defaults to <tt>'x-status-busy'</tt>).
8707 * It can be overridden at any time by passing the <code>iconCls</code>
8708 * argument into <code>{@link #showBusy}</code>.
8710 busyIconCls : 'x-status-busy',
8712 * @cfg {String} busyText
8713 * The default <code>{@link #text}</code> applied when calling
8714 * <code>{@link #showBusy}</code> (defaults to <tt>'Loading...'</tt>).
8715 * It can be overridden at any time by passing the <code>text</code>
8716 * argument into <code>{@link #showBusy}</code>.
8718 busyText : 'Loading...',
8720 * @cfg {Number} autoClear
8721 * The number of milliseconds to wait after setting the status via
8722 * <code>{@link #setStatus}</code> before automatically clearing the status
8723 * text and icon (defaults to <tt>5000</tt>). Note that this only applies
8724 * when passing the <tt>clear</tt> argument to <code>{@link #setStatus}</code>
8725 * since that is the only way to defer clearing the status. This can
8726 * be overridden by specifying a different <tt>wait</tt> value in
8727 * <code>{@link #setStatus}</code>. Calls to <code>{@link #clearStatus}</code>
8728 * always clear the status bar immediately and ignore this value.
8733 * @cfg {String} emptyText
8734 * The text string to use if no text has been set. Defaults to
8735 * <tt>' '</tt>). If there are no other items in the toolbar using
8736 * an empty string (<tt>''</tt>) for this value would end up in the toolbar
8737 * height collapsing since the empty string will not maintain the toolbar
8738 * height. Use <tt>''</tt> if the toolbar should collapse in height
8739 * vertically when no text is specified and there are no other items in
8742 emptyText : ' ',
8748 initComponent : function(){
8749 if(this.statusAlign=='right'){
8750 this.cls += ' x-status-right';
8752 Ext.ux.StatusBar.superclass.initComponent.call(this);
8756 afterRender : function(){
8757 Ext.ux.StatusBar.superclass.afterRender.call(this);
8759 var right = this.statusAlign == 'right';
8760 this.currIconCls = this.iconCls || this.defaultIconCls;
8761 this.statusEl = new Ext.Toolbar.TextItem({
8762 cls: 'x-status-text ' + (this.currIconCls || ''),
8763 text: this.text || this.defaultText || ''
8768 this.add(this.statusEl);
8770 this.insert(0, this.statusEl);
8771 this.insert(1, '->');
8777 * Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the
8778 * status that was set after a specified interval.
8779 * @param {Object/String} config A config object specifying what status to set, or a string assumed
8780 * to be the status text (and all other options are defaulted as explained below). A config
8781 * object containing any or all of the following properties can be passed:<ul>
8782 * <li><tt>text</tt> {String} : (optional) The status text to display. If not specified, any current
8783 * status text will remain unchanged.</li>
8784 * <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see
8785 * {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>
8786 * <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will
8787 * automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not
8788 * specified, the new status will not be auto-cleared and will stay until updated again or cleared using
8789 * {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},
8790 * {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,
8791 * it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.
8792 * All other options will be defaulted as with the boolean option. To customize any other options,
8793 * you can pass an object in the format:<ul>
8794 * <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing
8795 * (defaults to {@link #autoClear}).</li>
8796 * <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback
8797 * executes (defaults to true which fades the status out).</li>
8798 * <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls
8799 * (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>
8801 * Example usage:<pre><code>
8802 // Simple call to update the text
8803 statusBar.setStatus('New status');
8805 // Set the status and icon, auto-clearing with default options:
8806 statusBar.setStatus({
8808 iconCls: 'x-status-custom',
8812 // Auto-clear with custom options:
8813 statusBar.setStatus({
8815 iconCls: 'x-status-custom',
8823 * @return {Ext.ux.StatusBar} this
8825 setStatus : function(o){
8828 if(typeof o == 'string'){
8831 if(o.text !== undefined){
8832 this.setText(o.text);
8834 if(o.iconCls !== undefined){
8835 this.setIcon(o.iconCls);
8840 wait = this.autoClear,
8841 defaults = {useDefaults: true, anim: true};
8843 if(typeof c == 'object'){
8844 c = Ext.applyIf(c, defaults);
8848 }else if(typeof c == 'number'){
8851 }else if(typeof c == 'boolean'){
8855 c.threadId = this.activeThreadId;
8856 this.clearStatus.defer(wait, this, [c]);
8862 * Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.
8863 * @param {Object} config (optional) A config object containing any or all of the following properties. If this
8864 * object is not specified the status will be cleared using the defaults below:<ul>
8865 * <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults
8866 * to false which clears immediately).</li>
8867 * <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and
8868 * {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>
8870 * @return {Ext.ux.StatusBar} this
8872 clearStatus : function(o){
8875 if(o.threadId && o.threadId !== this.activeThreadId){
8876 // this means the current call was made internally, but a newer
8877 // thread has set a message since this call was deferred. Since
8878 // we don't want to overwrite a newer message just ignore.
8882 var text = o.useDefaults ? this.defaultText : this.emptyText,
8883 iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';
8886 // animate the statusEl Ext.Element
8887 this.statusEl.el.fadeOut({
8891 callback: function(){
8897 this.statusEl.el.show();
8901 // hide/show the el to avoid jumpy text or icon
8902 this.statusEl.hide();
8907 this.statusEl.show();
8913 * Convenience method for setting the status text directly. For more flexible options see {@link #setStatus}.
8914 * @param {String} text (optional) The text to set (defaults to '')
8915 * @return {Ext.ux.StatusBar} this
8917 setText : function(text){
8918 this.activeThreadId++;
8919 this.text = text || '';
8921 this.statusEl.setText(this.text);
8927 * Returns the current status text.
8928 * @return {String} The status text
8930 getText : function(){
8935 * Convenience method for setting the status icon directly. For more flexible options see {@link #setStatus}.
8936 * See {@link #iconCls} for complete details about customizing the icon.
8937 * @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)
8938 * @return {Ext.ux.StatusBar} this
8940 setIcon : function(cls){
8941 this.activeThreadId++;
8945 if(this.currIconCls){
8946 this.statusEl.removeClass(this.currIconCls);
8947 this.currIconCls = null;
8950 this.statusEl.addClass(cls);
8951 this.currIconCls = cls;
8954 this.currIconCls = cls;
8960 * Convenience method for setting the status text and icon to special values that are pre-configured to indicate
8961 * a "busy" state, usually for loading or processing activities.
8962 * @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a
8963 * string to use as the status text (in which case all other options for setStatus will be defaulted). Use the
8964 * <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}
8965 * and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and
8966 * {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.
8967 * @return {Ext.ux.StatusBar} this
8969 showBusy : function(o){
8970 if(typeof o == 'string'){
8973 o = Ext.applyIf(o || {}, {
8974 text: this.busyText,
8975 iconCls: this.busyIconCls
8977 return this.setStatus(o);
8980 Ext.reg('statusbar', Ext.ux.StatusBar);
8982 * @class Ext.ux.TabCloseMenu
8984 * Plugin (ptype = 'tabclosemenu') for adding a close context menu to tabs. Note that the menu respects
8985 * the closable configuration on the tab. As such, commands like remove others and remove all will not
8986 * remove items that are not closable.
8989 * @param {Object} config The configuration options
8990 * @ptype tabclosemenu
8992 Ext.ux.TabCloseMenu = Ext.extend(Object, {
8994 * @cfg {String} closeTabText
8995 * The text for closing the current tab. Defaults to <tt>'Close Tab'</tt>.
8997 closeTabText: 'Close Tab',
9000 * @cfg {String} closeOtherTabsText
9001 * The text for closing all tabs except the current one. Defaults to <tt>'Close Other Tabs'</tt>.
9003 closeOtherTabsText: 'Close Other Tabs',
9006 * @cfg {Boolean} showCloseAll
9007 * Indicates whether to show the 'Close All' option. Defaults to <tt>true</tt>.
9012 * @cfg {String} closeAllTabsText
9013 * <p>The text for closing all tabs. Defaults to <tt>'Close All Tabs'</tt>.
9015 closeAllTabsText: 'Close All Tabs',
9017 constructor : function(config){
9018 Ext.apply(this, config || {});
9022 init : function(tabs){
9026 contextmenu: this.onContextMenu,
9027 destroy: this.destroy
9031 destroy : function(){
9032 Ext.destroy(this.menu);
9039 onContextMenu : function(tabs, item, e){
9041 var m = this.createMenu(),
9043 disableOthers = true,
9044 closeAll = m.getComponent('closeall');
9046 m.getComponent('close').setDisabled(!item.closable);
9047 tabs.items.each(function(){
9051 disableOthers = false;
9056 m.getComponent('closeothers').setDisabled(disableOthers);
9058 closeAll.setDisabled(disableAll);
9062 m.showAt(e.getPoint());
9065 createMenu : function(){
9069 text: this.closeTabText,
9071 handler: this.onClose
9073 if(this.showCloseAll){
9077 itemId: 'closeothers',
9078 text: this.closeOtherTabsText,
9080 handler: this.onCloseOthers
9082 if(this.showCloseAll){
9085 text: this.closeAllTabsText,
9087 handler: this.onCloseAll
9090 this.menu = new Ext.menu.Menu({
9097 onClose : function(){
9098 this.tabs.remove(this.active);
9101 onCloseOthers : function(){
9105 onCloseAll : function(){
9106 this.doClose(false);
9109 doClose : function(excludeActive){
9111 this.tabs.items.each(function(item){
9113 if(!excludeActive || item != this.active){
9118 Ext.each(items, function(item){
9119 this.tabs.remove(item);
9124 Ext.preg('tabclosemenu', Ext.ux.TabCloseMenu);Ext.ns('Ext.ux.grid');
9127 * @class Ext.ux.grid.TableGrid
9128 * @extends Ext.grid.GridPanel
9129 * A Grid which creates itself from an existing HTML table element.
9131 * 2007-03-01 Original version by Nige "Animal" White
9132 * 2007-03-10 jvs Slightly refactored to reuse existing classes * @constructor
9133 * @param {String/HTMLElement/Ext.Element} table The table element from which this grid will be created -
9134 * The table MUST have some type of size defined for the grid to fill. The container will be
9135 * automatically set to position relative if it isn't already.
9136 * @param {Object} config A config object that sets properties on this grid and has two additional (optional)
9137 * properties: fields and columns which allow for customizing data fields and columns for this grid.
9139 Ext.ux.grid.TableGrid = function(table, config){
9142 Ext.apply(this, config);
9143 var cf = config.fields || [], ch = config.columns || [];
9144 table = Ext.get(table);
9146 var ct = table.insertSibling();
9148 var fields = [], cols = [];
9149 var headers = table.query("thead th");
9150 for (var i = 0, h; h = headers[i]; i++) {
9151 var text = h.innerHTML;
9152 var name = 'tcol-' + i;
9154 fields.push(Ext.applyIf(cf[i] ||
9157 mapping: 'td:nth(' + (i + 1) + ')/@innerHTML'
9160 cols.push(Ext.applyIf(ch[i] ||
9164 'width': h.offsetWidth,
9170 var ds = new Ext.data.Store({
9171 reader: new Ext.data.XmlReader({
9176 ds.loadData(table.dom);
9178 var cm = new Ext.grid.ColumnModel(cols);
9180 if (config.width || config.height) {
9181 ct.setSize(config.width || 'auto', config.height || 'auto');
9184 ct.setWidth(table.getWidth());
9187 if (config.remove !== false) {
9194 'sm': new Ext.grid.RowSelectionModel(),
9198 Ext.ux.grid.TableGrid.superclass.constructor.call(this, ct, {});
9201 Ext.extend(Ext.ux.grid.TableGrid, Ext.grid.GridPanel);
9204 Ext.grid.TableGrid = Ext.ux.grid.TableGrid;
9207 * @class Ext.ux.TabScrollerMenu
9209 * Plugin (ptype = 'tabscrollermenu') for adding a tab scroller menu to tabs.
9211 * @param {Object} config Configuration options
9212 * @ptype tabscrollermenu
9214 Ext.ux.TabScrollerMenu = Ext.extend(Object, {
9216 * @cfg {Number} pageSize How many items to allow per submenu.
9220 * @cfg {Number} maxText How long should the title of each {@link Ext.menu.Item} be.
9224 * @cfg {String} menuPrefixText Text to prefix the submenus.
9226 menuPrefixText : 'Items',
9227 constructor : function(config) {
9228 config = config || {};
9229 Ext.apply(this, config);
9232 init : function(tabPanel) {
9233 Ext.apply(tabPanel, this.parentOverrides);
9235 tabPanel.tabScrollerMenu = this;
9243 var newFn = tabPanel.createScrollers.createSequence(thisRef.createPanelsMenu, this);
9244 tabPanel.createScrollers = newFn;
9249 // private && sequeneced
9250 createPanelsMenu : function() {
9251 var h = this.stripWrap.dom.offsetHeight;
9253 //move the right menu item to the left 18px
9254 var rtScrBtn = this.header.dom.firstChild;
9255 Ext.fly(rtScrBtn).applyStyles({
9259 var stripWrap = Ext.get(this.strip.dom.parentNode);
9260 stripWrap.applyStyles({
9261 'margin-right' : '36px'
9264 // Add the new righthand menu
9265 var scrollMenu = this.header.insertFirst({
9266 cls:'x-tab-tabmenu-right'
9268 scrollMenu.setHeight(h);
9269 scrollMenu.addClassOnOver('x-tab-tabmenu-over');
9270 scrollMenu.on('click', this.showTabsMenu, this);
9272 this.scrollLeft.show = this.scrollLeft.show.createSequence(function() {
9276 this.scrollLeft.hide = this.scrollLeft.hide.createSequence(function() {
9282 * Returns an the current page size (this.pageSize);
9283 * @return {Number} this.pageSize The current page size.
9285 getPageSize : function() {
9286 return this.pageSize;
9289 * Sets the number of menu items per submenu "page size".
9290 * @param {Number} pageSize The page size
9292 setPageSize : function(pageSize) {
9293 this.pageSize = pageSize;
9296 * Returns the current maxText length;
9297 * @return {Number} this.maxText The current max text length.
9299 getMaxText : function() {
9300 return this.maxText;
9303 * Sets the maximum text size for each menu item.
9304 * @param {Number} t The max text per each menu item.
9306 setMaxText : function(t) {
9310 * Returns the current menu prefix text String.;
9311 * @return {String} this.menuPrefixText The current menu prefix text.
9313 getMenuPrefixText : function() {
9314 return this.menuPrefixText;
9317 * Sets the menu prefix text String.
9318 * @param {String} t The menu prefix text.
9320 setMenuPrefixText : function(t) {
9321 this.menuPrefixText = t;
9323 // private && applied to the tab panel itself.
9325 // all execute within the scope of the tab panel
9327 showTabsMenu : function(e) {
9328 if (this.tabsMenu) {
9329 this.tabsMenu.destroy();
9330 this.un('destroy', this.tabsMenu.destroy, this.tabsMenu);
9331 this.tabsMenu = null;
9333 this.tabsMenu = new Ext.menu.Menu();
9334 this.on('destroy', this.tabsMenu.destroy, this.tabsMenu);
9336 this.generateTabMenuItems();
9338 var target = Ext.get(e.getTarget());
9339 var xy = target.getXY();
9341 //Y param + 24 pixels
9344 this.tabsMenu.showAt(xy);
9347 generateTabMenuItems : function() {
9348 var curActive = this.getActiveTab();
9349 var totalItems = this.items.getCount();
9350 var pageSize = this.tabScrollerMenu.getPageSize();
9353 if (totalItems > pageSize) {
9354 var numSubMenus = Math.floor(totalItems / pageSize);
9355 var remainder = totalItems % pageSize;
9357 // Loop through all of the items and create submenus in chunks of 10
9358 for (var i = 0 ; i < numSubMenus; i++) {
9359 var curPage = (i + 1) * pageSize;
9363 for (var x = 0; x < pageSize; x++) {
9364 index = x + curPage - pageSize;
9365 var item = this.items.get(index);
9366 menuItems.push(this.autoGenMenuItem(item));
9370 text : this.tabScrollerMenu.getMenuPrefixText() + ' ' + (curPage - pageSize + 1) + ' - ' + curPage,
9376 if (remainder > 0) {
9377 var start = numSubMenus * pageSize;
9379 for (var i = start ; i < totalItems; i ++ ) {
9380 var item = this.items.get(i);
9381 menuItems.push(this.autoGenMenuItem(item));
9385 text : this.tabScrollerMenu.menuPrefixText + ' ' + (start + 1) + ' - ' + (start + menuItems.length),
9392 this.items.each(function(item) {
9393 if (item.id != curActive.id && !item.hidden) {
9394 this.tabsMenu.add(this.autoGenMenuItem(item));
9400 autoGenMenuItem : function(item) {
9401 var maxText = this.tabScrollerMenu.getMaxText();
9402 var text = Ext.util.Format.ellipsis(item.title, maxText);
9406 handler : this.showTabFromMenu,
9408 disabled : item.disabled,
9410 iconCls : item.iconCls
9415 showTabFromMenu : function(menuItem) {
9416 this.setActiveTab(menuItem.tabToShow);
9421 Ext.reg('tabscrollermenu', Ext.ux.TabScrollerMenu);
9422 Ext.ns('Ext.ux.tree');
9425 * @class Ext.ux.tree.XmlTreeLoader
9426 * @extends Ext.tree.TreeLoader
9427 * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
9428 * Any text value included as a text node in the XML will be added to the parent node as an attribute
9429 * called <tt>innerText</tt>. Also, the tag name of each XML node will be added to the tree node as
9430 * an attribute called <tt>tagName</tt>.</p>
9431 * <p>By default, this class expects that your source XML will provide the necessary attributes on each
9432 * node as expected by the {@link Ext.tree.TreePanel} to display and load properly. However, you can
9433 * provide your own custom processing of node attributes by overriding the {@link #processNode} method
9434 * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
9436 * Creates a new XmlTreeloader.
9437 * @param {Object} config A config object containing config properties.
9439 Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
9441 * @property XML_NODE_ELEMENT
9442 * XML element node (value 1, read-only)
9445 XML_NODE_ELEMENT : 1,
9447 * @property XML_NODE_TEXT
9448 * XML text node (value 3, read-only)
9454 processResponse : function(response, node, callback){
9455 var xmlData = response.responseXML,
9456 root = xmlData.documentElement || xmlData;
9460 node.appendChild(this.parseXml(root));
9463 this.runCallback(callback, scope || node, [node]);
9465 this.handleFailure(response);
9470 parseXml : function(node) {
9472 Ext.each(node.childNodes, function(n){
9473 if(n.nodeType == this.XML_NODE_ELEMENT){
9474 var treeNode = this.createNode(n);
9475 if(n.childNodes.length > 0){
9476 var child = this.parseXml(n);
9477 if(typeof child == 'string'){
9478 treeNode.attributes.innerText = child;
9480 treeNode.appendChild(child);
9483 nodes.push(treeNode);
9485 else if(n.nodeType == this.XML_NODE_TEXT){
9486 var text = n.nodeValue.trim();
9487 if(text.length > 0){
9488 return nodes = text;
9497 createNode : function(node){
9499 tagName: node.tagName
9502 Ext.each(node.attributes, function(a){
9503 attr[a.nodeName] = a.nodeValue;
9506 this.processAttributes(attr);
9508 return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
9512 * Template method intended to be overridden by subclasses that need to provide
9513 * custom attribute processing prior to the creation of each TreeNode. This method
9514 * will be passed a config object containing existing TreeNode attribute name/value
9515 * pairs which can be modified as needed directly (no need to return the object).
9517 processAttributes: Ext.emptyFn
9521 Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;
9523 * @class Ext.ux.ValidationStatus
9524 * A {@link Ext.StatusBar} plugin that provides automatic error notification when the
9525 * associated form contains validation errors.
9526 * @extends Ext.Component
9528 * Creates a new ValiationStatus plugin
9529 * @param {Object} config A config object
9531 Ext.ux.ValidationStatus = Ext.extend(Ext.Component, {
9533 * @cfg {String} errorIconCls
9534 * The {@link #iconCls} value to be applied to the status message when there is a
9535 * validation error. Defaults to <tt>'x-status-error'</tt>.
9537 errorIconCls : 'x-status-error',
9539 * @cfg {String} errorListCls
9540 * The css class to be used for the error list when there are validation errors.
9541 * Defaults to <tt>'x-status-error-list'</tt>.
9543 errorListCls : 'x-status-error-list',
9545 * @cfg {String} validIconCls
9546 * The {@link #iconCls} value to be applied to the status message when the form
9547 * validates. Defaults to <tt>'x-status-valid'</tt>.
9549 validIconCls : 'x-status-valid',
9552 * @cfg {String} showText
9553 * The {@link #text} value to be applied when there is a form validation error.
9554 * Defaults to <tt>'The form has errors (click for details...)'</tt>.
9556 showText : 'The form has errors (click for details...)',
9558 * @cfg {String} showText
9559 * The {@link #text} value to display when the error list is displayed.
9560 * Defaults to <tt>'Click again to hide the error list'</tt>.
9562 hideText : 'Click again to hide the error list',
9564 * @cfg {String} submitText
9565 * The {@link #text} value to be applied when the form is being submitted.
9566 * Defaults to <tt>'Saving...'</tt>.
9568 submitText : 'Saving...',
9571 init : function(sb){
9572 sb.on('render', function(){
9573 this.statusBar = sb;
9574 this.monitor = true;
9575 this.errors = new Ext.util.MixedCollection();
9576 this.listAlign = (sb.statusAlign=='right' ? 'br-tr?' : 'bl-tl?');
9579 this.form = Ext.getCmp(this.form).getForm();
9580 this.startMonitoring();
9581 this.form.on('beforeaction', function(f, action){
9582 if(action.type == 'submit'){
9583 // Ignore monitoring while submitting otherwise the field validation
9584 // events cause the status message to reset too early
9585 this.monitor = false;
9588 var startMonitor = function(){
9589 this.monitor = true;
9591 this.form.on('actioncomplete', startMonitor, this);
9592 this.form.on('actionfailed', startMonitor, this);
9594 }, this, {single:true});
9600 // Grab the statusEl after the first layout.
9601 sb.statusEl.getEl().on('click', this.onStatusClick, this, {buffer:200});
9612 startMonitoring : function(){
9613 this.form.items.each(function(f){
9614 f.on('invalid', this.onFieldValidation, this);
9615 f.on('valid', this.onFieldValidation, this);
9620 stopMonitoring : function(){
9621 this.form.items.each(function(f){
9622 f.un('invalid', this.onFieldValidation, this);
9623 f.un('valid', this.onFieldValidation, this);
9628 onDestroy : function(){
9629 this.stopMonitoring();
9630 this.statusBar.statusEl.un('click', this.onStatusClick, this);
9631 Ext.ux.ValidationStatus.superclass.onDestroy.call(this);
9635 onFieldValidation : function(f, msg){
9640 this.errors.add(f.id, {field:f, msg:msg});
9642 this.errors.removeKey(f.id);
9644 this.updateErrorList();
9645 if(this.errors.getCount() > 0){
9646 if(this.statusBar.getText() != this.showText){
9647 this.statusBar.setStatus({text:this.showText, iconCls:this.errorIconCls});
9650 this.statusBar.clearStatus().setIcon(this.validIconCls);
9655 updateErrorList : function(){
9656 if(this.errors.getCount() > 0){
9658 this.errors.each(function(err){
9659 msg += ('<li id="x-err-'+ err.field.id +'"><a href="#">' + err.msg + '</a></li>');
9661 this.getMsgEl().update(msg+'</ul>');
9663 this.getMsgEl().update('');
9668 getMsgEl : function(){
9670 this.msgEl = Ext.DomHelper.append(Ext.getBody(), {
9671 cls: this.errorListCls+' x-hide-offsets'
9674 this.msgEl.on('click', function(e){
9675 var t = e.getTarget('li', 10, true);
9677 Ext.getCmp(t.id.split('x-err-')[1]).focus();
9680 }, this, {stopEvent:true}); // prevent anchor click navigation
9686 showErrors : function(){
9687 this.updateErrorList();
9688 this.getMsgEl().alignTo(this.statusBar.getEl(), this.listAlign).slideIn('b', {duration:0.3, easing:'easeOut'});
9689 this.statusBar.setText(this.hideText);
9690 this.form.getEl().on('click', this.hideErrors, this, {single:true}); // hide if the user clicks directly into the form
9694 hideErrors : function(){
9695 var el = this.getMsgEl();
9697 el.slideOut('b', {duration:0.2, easing:'easeIn'});
9698 this.statusBar.setText(this.showText);
9700 this.form.getEl().un('click', this.hideErrors, this);
9704 onStatusClick : function(){
9705 if(this.getMsgEl().isVisible()){
9707 }else if(this.errors.getCount() > 0){
9712 Ext.override(Ext.list.Column, {
9714 var types = Ext.data.Types,
9718 if(Ext.isString(this.type)){
9719 this.type = Ext.data.Types[this.type.toUpperCase()] || types.AUTO;
9722 this.type = types.AUTO;
9725 // named sortTypes are supported, here we look them up
9726 if(Ext.isString(st)){
9727 this.sortType = Ext.data.SortTypes[st];
9728 }else if(Ext.isEmpty(st)){
9729 this.sortType = this.type.sortType;
9734 Ext.tree.Column = Ext.extend(Ext.list.Column, {});
9735 Ext.tree.NumberColumn = Ext.extend(Ext.list.NumberColumn, {});
9736 Ext.tree.DateColumn = Ext.extend(Ext.list.DateColumn, {});
9737 Ext.tree.BooleanColumn = Ext.extend(Ext.list.BooleanColumn, {});
9739 Ext.reg('tgcolumn', Ext.tree.Column);
9740 Ext.reg('tgnumbercolumn', Ext.tree.NumberColumn);
9741 Ext.reg('tgdatecolumn', Ext.tree.DateColumn);
9742 Ext.reg('tgbooleancolumn', Ext.tree.BooleanColumn);
9745 * @class Ext.ux.tree.TreeGridNodeUI
9746 * @extends Ext.tree.TreeNodeUI
9748 Ext.ux.tree.TreeGridNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
9749 isTreeGridNodeUI: true,
9751 renderElements : function(n, a, targetNode, bulkRender){
9752 var t = n.getOwnerTree(),
9757 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
9760 '<tbody class="x-tree-node">',
9761 '<tr ext:tree-node-id="', n.id ,'" class="x-tree-node-el x-tree-node-leaf ', a.cls, '">',
9762 '<td class="x-treegrid-col">',
9763 '<span class="x-tree-node-indent">', this.indentMarkup, "</span>",
9764 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
9765 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon', (a.icon ? " x-tree-node-inline-icon" : ""), (a.iconCls ? " "+a.iconCls : ""), '" unselectable="on">',
9766 '<a hidefocus="on" class="x-tree-node-anchor" href="', a.href ? a.href : '#', '" tabIndex="1" ',
9767 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : '', '>',
9768 '<span unselectable="on">', (c.tpl ? c.tpl.apply(a) : a[c.dataIndex] || c.text), '</span></a>',
9772 for(i = 1, len = cols.length; i < len; i++){
9775 '<td class="x-treegrid-col ', (c.cls ? c.cls : ''), '">',
9776 '<div unselectable="on" class="x-treegrid-text"', (c.align ? ' style="text-align: ' + c.align + ';"' : ''), '>',
9777 (c.tpl ? c.tpl.apply(a) : a[c.dataIndex]),
9784 '</tr><tr class="x-tree-node-ct"><td colspan="', cols.length, '">',
9785 '<table class="x-treegrid-node-ct-table" cellpadding="0" cellspacing="0" style="table-layout: fixed; display: none; width: ', t.innerCt.getWidth() ,'px;"><colgroup>'
9787 for(i = 0, len = cols.length; i<len; i++) {
9788 buf.push('<col style="width: ', (cols[i].hidden ? 0 : cols[i].width) ,'px;" />');
9790 buf.push('</colgroup></table></td></tr></tbody>');
9792 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
9793 this.wrap = Ext.DomHelper.insertHtml("beforeBegin", n.nextSibling.ui.getEl(), buf.join(''));
9795 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(''));
9798 this.elNode = this.wrap.childNodes[0];
9799 this.ctNode = this.wrap.childNodes[1].firstChild.firstChild;
9800 var cs = this.elNode.firstChild.childNodes;
9801 this.indentNode = cs[0];
9802 this.ecNode = cs[1];
9803 this.iconNode = cs[2];
9804 this.anchor = cs[3];
9805 this.textNode = cs[3].firstChild;
9809 animExpand : function(cb){
9810 this.ctNode.style.display = "";
9811 Ext.ux.tree.TreeGridNodeUI.superclass.animExpand.call(this, cb);
9815 Ext.ux.tree.TreeGridRootNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
9816 isTreeGridNodeUI: true,
9819 render : function(){
9821 this.wrap = this.ctNode = this.node.ownerTree.innerCt.dom;
9822 this.node.expanded = true;
9826 // weird table-layout: fixed issue in webkit
9827 var ct = this.ctNode;
9828 ct.style.tableLayout = null;
9830 ct.style.tableLayout = 'fixed';
9835 destroy : function(){
9837 Ext.dd.Registry.unregister(this.elNode.id);
9842 collapse : Ext.emptyFn,
9843 expand : Ext.emptyFn
9845 * @class Ext.tree.ColumnResizer
9846 * @extends Ext.util.Observable
9848 Ext.tree.ColumnResizer = Ext.extend(Ext.util.Observable, {
9850 * @cfg {Number} minWidth The minimum width the column can be dragged to.
9851 * Defaults to <tt>14</tt>.
9855 constructor: function(config){
9856 Ext.apply(this, config);
9857 Ext.tree.ColumnResizer.superclass.constructor.call(this);
9860 init : function(tree){
9862 tree.on('render', this.initEvents, this);
9865 initEvents : function(tree){
9866 tree.mon(tree.innerHd, 'mousemove', this.handleHdMove, this);
9867 this.tracker = new Ext.dd.DragTracker({
9868 onBeforeStart: this.onBeforeStart.createDelegate(this),
9869 onStart: this.onStart.createDelegate(this),
9870 onDrag: this.onDrag.createDelegate(this),
9871 onEnd: this.onEnd.createDelegate(this),
9875 this.tracker.initEl(tree.innerHd);
9876 tree.on('beforedestroy', this.tracker.destroy, this.tracker);
9879 handleHdMove : function(e, t){
9882 hd = e.getTarget('.x-treegrid-hd', 3, true);
9885 var r = hd.getRegion(),
9887 pn = hd.dom.parentNode;
9889 if(x - r.left <= hw && hd.dom !== pn.firstChild) {
9890 var ps = hd.dom.previousSibling;
9891 while(ps && Ext.fly(ps).hasClass('x-treegrid-hd-hidden')) {
9892 ps = ps.previousSibling;
9895 this.activeHd = Ext.get(ps);
9896 ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
9898 } else if(r.right - x <= hw) {
9900 while(ns && Ext.fly(ns).hasClass('x-treegrid-hd-hidden')) {
9901 ns = ns.previousSibling;
9904 this.activeHd = Ext.get(ns);
9905 ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';
9908 delete this.activeHd;
9914 onBeforeStart : function(e){
9915 this.dragHd = this.activeHd;
9916 return !!this.dragHd;
9919 onStart : function(e){
9920 this.tree.headersDisabled = true;
9921 this.proxy = this.tree.body.createChild({cls:'x-treegrid-resizer'});
9922 this.proxy.setHeight(this.tree.body.getHeight());
9924 var x = this.tracker.getXY()[0];
9926 this.hdX = this.dragHd.getX();
9927 this.hdIndex = this.tree.findHeaderIndex(this.dragHd);
9929 this.proxy.setX(this.hdX);
9930 this.proxy.setWidth(x-this.hdX);
9932 this.maxWidth = this.tree.outerCt.getWidth() - this.tree.innerBody.translatePoints(this.hdX).left;
9935 onDrag : function(e){
9936 var cursorX = this.tracker.getXY()[0];
9937 this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));
9940 onEnd : function(e){
9941 var nw = this.proxy.getWidth(),
9944 this.proxy.remove();
9947 tree.columns[this.hdIndex].width = nw;
9948 tree.updateColumnWidths();
9950 setTimeout(function(){
9951 tree.headersDisabled = false;
9954 });Ext.ns('Ext.ux.tree');
9957 * @class Ext.ux.tree.TreeGridSorter
9958 * @extends Ext.tree.TreeSorter
9959 * Provides sorting of nodes in a {@link Ext.ux.tree.TreeGrid}. The TreeGridSorter automatically monitors events on the
9960 * associated TreeGrid that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
9961 * Example usage:<br />
9963 new Ext.ux.tree.TreeGridSorter(myTreeGrid, {
9966 sortType: function(node) {
9967 // sort by a custom, typed attribute:
9968 return parseInt(node.id, 10);
9973 * @param {TreeGrid} tree
9974 * @param {Object} config
9976 Ext.ux.tree.TreeGridSorter = Ext.extend(Ext.tree.TreeSorter, {
9978 * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
9980 sortClasses : ['sort-asc', 'sort-desc'],
9982 * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
9984 sortAscText : 'Sort Ascending',
9986 * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
9988 sortDescText : 'Sort Descending',
9990 constructor : function(tree, config) {
9991 if(!Ext.isObject(config)) {
9993 property: tree.columns[0].dataIndex || 'text',
9998 Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this, arguments);
10001 tree.on('headerclick', this.onHeaderClick, this);
10002 tree.ddAppendOnly = true;
10005 this.defaultSortFn = function(n1, n2){
10007 var dsc = me.dir && me.dir.toLowerCase() == 'desc';
10008 var p = me.property || 'text';
10009 var sortType = me.sortType;
10010 var fs = me.folderSort;
10011 var cs = me.caseSensitive === true;
10012 var leafAttr = me.leafAttr || 'leaf';
10015 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
10018 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
10022 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
10023 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
10025 return dsc ? +1 : -1;
10027 return dsc ? -1 : +1;
10033 tree.on('afterrender', this.onAfterTreeRender, this, {single: true});
10034 tree.on('headermenuclick', this.onHeaderMenuClick, this);
10037 onAfterTreeRender : function() {
10038 if(this.tree.hmenu){
10039 this.tree.hmenu.insert(0,
10040 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
10041 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
10044 this.updateSortIcon(0, 'asc');
10047 onHeaderMenuClick : function(c, id, index) {
10048 if(id === 'asc' || id === 'desc') {
10049 this.onHeaderClick(c, null, index);
10054 onHeaderClick : function(c, el, i) {
10055 if(c && !this.tree.headersDisabled){
10058 me.property = c.dataIndex;
10059 me.dir = c.dir = (c.dir === 'desc' ? 'asc' : 'desc');
10060 me.sortType = c.sortType;
10061 me.caseSensitive === Ext.isBoolean(c.caseSensitive) ? c.caseSensitive : this.caseSensitive;
10062 me.sortFn = c.sortFn || this.defaultSortFn;
10064 this.tree.root.cascade(function(n) {
10066 me.updateSort(me.tree, n);
10070 this.updateSortIcon(i, c.dir);
10075 updateSortIcon : function(col, dir){
10076 var sc = this.sortClasses;
10077 var hds = this.tree.innerHd.select('td').removeClass(sc);
10078 hds.item(col).addClass(sc[dir == 'desc' ? 1 : 0]);
10081 * @class Ext.ux.tree.TreeGridLoader
10082 * @extends Ext.tree.TreeLoader
10084 Ext.ux.tree.TreeGridLoader = Ext.extend(Ext.tree.TreeLoader, {
10085 createNode : function(attr) {
10086 if (!attr.uiProvider) {
10087 attr.uiProvider = Ext.ux.tree.TreeGridNodeUI;
10089 return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
10092 * @class Ext.ux.tree.TreeGrid
10093 * @extends Ext.tree.TreePanel
10097 Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, {
10098 rootVisible : false,
10101 borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
10102 cls : 'x-treegrid',
10104 columnResize : true,
10106 reserveScrollOffset : true,
10107 enableHdMenu : true,
10109 columnsText : 'Columns',
10111 initComponent : function() {
10113 this.root = new Ext.tree.AsyncTreeNode({text: 'Root'});
10116 // initialize the loader
10117 var l = this.loader;
10119 l = new Ext.ux.tree.TreeGridLoader({
10120 dataUrl: this.dataUrl,
10121 requestMethod: this.requestMethod,
10124 }else if(Ext.isObject(l) && !l.load){
10125 l = new Ext.ux.tree.TreeGridLoader(l);
10128 l.createNode = function(attr) {
10129 if (!attr.uiProvider) {
10130 attr.uiProvider = Ext.ux.tree.TreeGridNodeUI;
10132 return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
10137 Ext.ux.tree.TreeGrid.superclass.initComponent.call(this);
10139 this.initColumns();
10141 if(this.enableSort) {
10142 this.treeGridSorter = new Ext.ux.tree.TreeGridSorter(this, this.enableSort);
10145 if(this.columnResize){
10146 this.colResizer = new Ext.tree.ColumnResizer(this.columnResize);
10147 this.colResizer.init(this);
10150 var c = this.columns;
10151 if(!this.internalTpl){
10152 this.internalTpl = new Ext.XTemplate(
10153 '<div class="x-grid3-header">',
10154 '<div class="x-treegrid-header-inner">',
10155 '<div class="x-grid3-header-offset">',
10156 '<table cellspacing="0" cellpadding="0" border="0"><colgroup><tpl for="columns"><col /></tpl></colgroup>',
10157 '<thead><tr class="x-grid3-hd-row">',
10158 '<tpl for="columns">',
10159 '<td class="x-grid3-hd x-grid3-cell x-treegrid-hd" style="text-align: {align};" id="', this.id, '-xlhd-{#}">',
10160 '<div class="x-grid3-hd-inner x-treegrid-hd-inner" unselectable="on">',
10161 this.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
10162 '{header}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
10169 '<div class="x-treegrid-root-node">',
10170 '<table class="x-treegrid-root-table" cellpadding="0" cellspacing="0" style="table-layout: fixed;"></table>',
10175 if(!this.colgroupTpl) {
10176 this.colgroupTpl = new Ext.XTemplate(
10177 '<colgroup><tpl for="columns"><col style="width: {width}px"/></tpl></colgroup>'
10182 initColumns : function() {
10183 var cs = this.columns,
10188 for(i = 0; i < len; i++){
10191 c.xtype = c.xtype ? (/^tg/.test(c.xtype) ? c.xtype : 'tg' + c.xtype) : 'tgcolumn';
10197 if(this.enableSort !== false && c.sortable !== false) {
10199 this.enableSort = true;
10203 this.columns = columns;
10206 onRender : function(){
10207 Ext.tree.TreePanel.superclass.onRender.apply(this, arguments);
10209 this.el.addClass('x-treegrid');
10211 this.outerCt = this.body.createChild({
10212 cls:'x-tree-root-ct x-treegrid-ct ' + (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')
10215 this.internalTpl.overwrite(this.outerCt, {columns: this.columns});
10217 this.mainHd = Ext.get(this.outerCt.dom.firstChild);
10218 this.innerHd = Ext.get(this.mainHd.dom.firstChild);
10219 this.innerBody = Ext.get(this.outerCt.dom.lastChild);
10220 this.innerCt = Ext.get(this.innerBody.dom.firstChild);
10222 this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
10224 if(this.hideHeaders){
10225 this.header.dom.style.display = 'none';
10227 else if(this.enableHdMenu !== false){
10228 this.hmenu = new Ext.menu.Menu({id: this.id + '-hctx'});
10229 if(this.enableColumnHide !== false){
10230 this.colMenu = new Ext.menu.Menu({id: this.id + '-hcols-menu'});
10233 beforeshow: this.beforeColMenuShow,
10234 itemclick: this.handleHdMenuClick
10238 hideOnClick: false,
10239 text: this.columnsText,
10240 menu: this.colMenu,
10241 iconCls: 'x-cols-icon'
10244 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
10248 setRootNode : function(node){
10249 node.attributes.uiProvider = Ext.ux.tree.TreeGridRootNodeUI;
10250 node = Ext.ux.tree.TreeGrid.superclass.setRootNode.call(this, node);
10252 this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
10257 clearInnerCt : function(){
10259 var dom = this.innerCt.dom;
10260 while(dom.firstChild){
10261 dom.removeChild(dom.firstChild);
10264 Ext.ux.tree.TreeGrid.superclass.clearInnerCt.call(this);
10268 initEvents : function() {
10269 Ext.ux.tree.TreeGrid.superclass.initEvents.apply(this, arguments);
10271 this.mon(this.innerBody, 'scroll', this.syncScroll, this);
10272 this.mon(this.innerHd, 'click', this.handleHdDown, this);
10273 this.mon(this.mainHd, {
10275 mouseover: this.handleHdOver,
10276 mouseout: this.handleHdOut
10280 onResize : function(w, h) {
10281 Ext.ux.tree.TreeGrid.superclass.onResize.apply(this, arguments);
10283 var bd = this.innerBody.dom;
10284 var hd = this.innerHd.dom;
10290 if(Ext.isNumber(h)){
10291 bd.style.height = this.body.getHeight(true) - hd.offsetHeight + 'px';
10294 if(Ext.isNumber(w)){
10295 var sw = Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
10296 if(this.reserveScrollOffset || ((bd.offsetWidth - bd.clientWidth) > 10)){
10297 this.setScrollOffset(sw);
10300 setTimeout(function(){
10301 me.setScrollOffset(bd.offsetWidth - bd.clientWidth > 10 ? sw : 0);
10307 updateColumnWidths : function() {
10308 var cols = this.columns,
10309 colCount = cols.length,
10310 groups = this.outerCt.query('colgroup'),
10311 groupCount = groups.length,
10314 for(i = 0; i<colCount; i++) {
10316 for(j = 0; j<groupCount; j++) {
10318 g.childNodes[i].style.width = (c.hidden ? 0 : c.width) + 'px';
10322 for(i = 0, groups = this.innerHd.query('td'), len = groups.length; i<len; i++) {
10323 c = Ext.fly(groups[i]);
10324 if(cols[i] && cols[i].hidden) {
10325 c.addClass('x-treegrid-hd-hidden');
10328 c.removeClass('x-treegrid-hd-hidden');
10332 var tcw = this.getTotalColumnWidth();
10333 Ext.fly(this.innerHd.dom.firstChild).setWidth(tcw + (this.scrollOffset || 0));
10334 this.outerCt.select('table').setWidth(tcw);
10335 this.syncHeaderScroll();
10338 getVisibleColumns : function() {
10344 for(i = 0; i<len; i++) {
10345 if(!cs[i].hidden) {
10346 columns.push(cs[i]);
10352 getTotalColumnWidth : function() {
10354 for(var i = 0, cs = this.getVisibleColumns(), len = cs.length; i<len; i++) {
10355 total += cs[i].width;
10360 setScrollOffset : function(scrollOffset) {
10361 this.scrollOffset = scrollOffset;
10362 this.updateColumnWidths();
10366 handleHdDown : function(e, t){
10367 var hd = e.getTarget('.x-treegrid-hd');
10369 if(hd && Ext.fly(t).hasClass('x-grid3-hd-btn')){
10370 var ms = this.hmenu.items,
10372 index = this.findHeaderIndex(hd),
10377 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
10378 this.hdCtxIndex = index;
10380 this.fireEvent('headerbuttonclick', ms, c, hd, index);
10382 this.hmenu.on('hide', function(){
10383 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
10384 }, this, {single:true});
10386 this.hmenu.show(t, 'tl-bl?');
10389 var index = this.findHeaderIndex(hd);
10390 this.fireEvent('headerclick', this.columns[index], hd, index);
10395 handleHdOver : function(e, t){
10396 var hd = e.getTarget('.x-treegrid-hd');
10397 if(hd && !this.headersDisabled){
10398 index = this.findHeaderIndex(hd);
10399 this.activeHdRef = t;
10400 this.activeHdIndex = index;
10401 var el = Ext.get(hd);
10402 this.activeHdRegion = el.getRegion();
10403 el.addClass('x-grid3-hd-over');
10404 this.activeHdBtn = el.child('.x-grid3-hd-btn');
10405 if(this.activeHdBtn){
10406 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
10412 handleHdOut : function(e, t){
10413 var hd = e.getTarget('.x-treegrid-hd');
10414 if(hd && (!Ext.isIE || !e.within(hd, true))){
10415 this.activeHdRef = null;
10416 Ext.fly(hd).removeClass('x-grid3-hd-over');
10417 hd.style.cursor = '';
10421 findHeaderIndex : function(hd){
10423 var cs = hd.parentNode.childNodes;
10424 for(var i = 0, c; c = cs[i]; i++){
10433 beforeColMenuShow : function(){
10434 var cols = this.columns,
10435 colCount = cols.length,
10437 this.colMenu.removeAll();
10438 for(i = 1; i < colCount; i++){
10440 if(c.hideable !== false){
10441 this.colMenu.add(new Ext.menu.CheckItem({
10442 itemId: 'col-' + i,
10444 checked: !c.hidden,
10446 disabled: c.hideable === false
10453 handleHdMenuClick : function(item){
10454 var index = this.hdCtxIndex,
10455 id = item.getItemId();
10457 if(this.fireEvent('headermenuclick', this.columns[index], id, index) !== false) {
10458 index = id.substr(4);
10459 if(index > 0 && this.columns[index]) {
10460 this.setColumnVisible(index, !item.checked);
10467 setColumnVisible : function(index, visible) {
10468 this.columns[index].hidden = !visible;
10469 this.updateColumnWidths();
10473 * Scrolls the grid to the top
10475 scrollToTop : function(){
10476 this.innerBody.dom.scrollTop = 0;
10477 this.innerBody.dom.scrollLeft = 0;
10481 syncScroll : function(){
10482 this.syncHeaderScroll();
10483 var mb = this.innerBody.dom;
10484 this.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
10488 syncHeaderScroll : function(){
10489 var mb = this.innerBody.dom;
10490 this.innerHd.dom.scrollLeft = mb.scrollLeft;
10491 this.innerHd.dom.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
10494 registerNode : function(n) {
10495 Ext.ux.tree.TreeGrid.superclass.registerNode.call(this, n);
10496 if(!n.uiProvider && !n.isRoot && !n.ui.isTreeGridNodeUI) {
10497 n.ui = new Ext.ux.tree.TreeGridNodeUI(n);
10502 Ext.reg('treegrid', Ext.ux.tree.TreeGrid);