Grid.js
5.57 KB
//>>built
define("dojo/_base/declare dojo/_base/lang dojo/dom-construct dojo/dom-class dojo/on dojo/has ./List ./util/misc dojo/_base/sniff".split(" "),function(l,q,m,r,x,y,z,t){function p(b,a){a&&a.nodeType&&b.appendChild(a)}l=l(z,{columns:null,hasNeutralSort:!1,cellNavigation:!0,tabableHeader:!0,showHeader:!0,column:function(b){return"object"!==typeof b?this.columns[b]:this.cell(b).column},listType:"grid",cell:function(b,a){if(b.column&&b.element)return b;b.target&&b.target.nodeType&&(b=b.target);var c;if(b.nodeType){do{if(this._rowIdToObject[b.id])break;
var d=b.columnId;if(d){a=d;c=b;break}b=b.parentNode}while(b&&b!==this.domNode)}if(!c&&"undefined"!==typeof a){var e=this.row(b);if(d=e&&e.element)for(var d=d.getElementsByTagName("td"),f=0;f<d.length;f++)if(d[f].columnId===a){c=d[f];break}}if(null!=b)return{row:e||this.row(b),column:a&&this.column(a),element:c}},createRowCells:function(b,a,c,d,e){var f=m.create("table",{className:"dgrid-row-table",role:"presentation"}),g=9>y("ie")?m.create("tbody",null,f):f,l,v,p,w,q,u,h,n,k,r;c=c||this.subRows;v=
0;for(p=c.length;v<p;v++)for(u=c[v],l=m.create("tr",null,g),u.className&&(l.className=u.className),w=0,q=u.length;w<q;w++){h=u[w];n=h.id;k=h.field?" field-"+t.escapeCssIdentifier(h.field,"-"):"";(r="function"===typeof h.className?h.className(d):h.className)&&(k+=" "+r);k=m.create(b,{className:"dgrid-cell"+(n?" dgrid-column-"+t.escapeCssIdentifier(n,"-"):"")+k,role:"th"===b?"columnheader":"gridcell"});k.columnId=n;if(n=h.colSpan)k.colSpan=n;if(n=h.rowSpan)k.rowSpan=n;a(k,h,d,e);l.appendChild(k)}return f},
_createBodyRowCell:function(b,a,c,d){var e=c;a.get?e=a.get(c):"field"in a&&"_item"!==a.field&&(e=c[a.field]);a.renderCell?p(b,a.renderCell(c,e,b,d)):this._defaultRenderCell.call(a,c,e,b,d)},_createHeaderRowCell:function(b,a){var c=a.headerNode=b,d=a.field;d&&(b.field=d);a.renderHeaderCell?p(c,a.renderHeaderCell(c)):("label"in a||a.field)&&c.appendChild(document.createTextNode("label"in a?a.label:a.field));!1!==a.sortable&&d&&"_item"!==d&&(b.sortable=!0,b.className+=" dgrid-sortable")},left:function(b,
a){b.element||(b=this.cell(b));return this.cell(this._move(b,-(a||1),"dgrid-cell"))},right:function(b,a){b.element||(b=this.cell(b));return this.cell(this._move(b,a||1,"dgrid-cell"))},_defaultRenderCell:function(b,a,c){if(this.formatter){var d=this.formatter,e=this.grid.formatterScope;c.innerHTML="string"===typeof d&&e?e[d](a,b):this.formatter(a,b)}else null!=a&&c.appendChild(document.createTextNode(a))},renderRow:function(b,a){b=this.createRowCells("td",q.hitch(this,"_createBodyRowCell"),a&&a.subRows,
b,a);a=m.create("div",{role:"row"});a.appendChild(b);return a},renderHeader:function(){var b=this,a=this.headerNode;a.setAttribute("role","row");m.empty(a);var c=this.createRowCells("th",q.hitch(this,"_createHeaderRowCell"),this.subRows&&this.subRows.headerRows);this._rowIdToObject[c.id=this.id+"-header"]=this.columns;a.appendChild(c);this._sortListener&&this._sortListener.remove();this._sortListener=x(c,"click,keydown",function(d){if("click"===d.type||32===d.keyCode||!y("opera")&&13===d.keyCode){var c=
d.target,f,g;do if(c.sortable){f=c.field||c.columnId;g=b.sort[0];f=b.hasNeutralSort&&g&&g.property===f&&g.descending?[]:[{property:f,descending:g&&g.property===f&&!g.descending}];g={bubbles:!0,cancelable:!0,grid:b,parentType:d.type,sort:f};x.emit(d.target,"dgrid-sort",g)&&(b._sortNode=c,b.set("sort",f));break}while((c=c.parentNode)&&c!==a)}})},resize:function(){var b=this.headerNode.firstChild,a=this.contentNode,c;this.inherited(arguments);a.style.width="";a&&b&&(c=b.offsetWidth)>a.offsetWidth&&(a.style.width=
c+"px")},destroy:function(){this._destroyColumns();this._sortListener&&this._sortListener.remove();this.inherited(arguments)},_setSort:function(){this.inherited(arguments);this.updateSortArrow(this.sort)},_findSortArrowParent:function(b){var a=this.columns,c;for(c in a){var d=a[c];if(d.field===b)return d.headerNode}},updateSortArrow:function(b,a){this._lastSortedArrow&&(r.remove(this._lastSortedArrow.parentNode,"dgrid-sort-up dgrid-sort-down"),m.destroy(this._lastSortedArrow),delete this._lastSortedArrow);
a&&(this.sort=b);b[0]&&(a=b[0].property,b=b[0].descending,a=this._sortNode||this._findSortArrowParent(a),delete this._sortNode,a&&(a=a.contents||a,this._lastSortedArrow=m.create("div",{className:"dgrid-sort-arrow ui-icon",innerHTML:"\x26nbsp;",role:"presentation"},a,"first"),r.add(a,"dgrid-sort-"+(b?"down":"up")),this.resize()))},styleColumn:function(b,a){return this.addCssRule("#"+t.escapeCssIdentifier(this.domNode.id)+" .dgrid-column-"+t.escapeCssIdentifier(b,"-"),a)},_configColumns:function(b,
a){var c=[],d=a instanceof Array;t.each(a,function(e,f){"string"===typeof e&&(a[f]=e={label:e});d||e.field||(e.field=f);f=e.id=e.id||(isNaN(f)?f:b+f);this._configColumn&&(this._configColumn(e,a,b),f=e.id);d&&(this.columns[f]=e);e.grid=this;c.push(e)},this);return d?a:c},_destroyColumns:function(){this.cleanup()},configStructure:function(){var b=this.subRows,a=this._columns=this.columns;this.columns=!a||a instanceof Array?{}:a;if(b)for(a=0;a<b.length;a++)b[a]=this._configColumns(a+"-",b[a]);else this.subRows=
[this._configColumns("",a)]},_getColumns:function(){return this._columns||this.columns},_setColumns:function(b){this._destroyColumns();this.subRows=null;this.columns=b;this._updateColumns()},_setSubRows:function(b){this._destroyColumns();this.subRows=b;this._updateColumns()},_updateColumns:function(){this.configStructure();this.renderHeader();this.refresh();this._lastCollection&&this.renderArray(this._lastCollection);this._started&&(this.sort.length?(this._lastSortedArrow=null,this.updateSortArrow(this.sort)):
this.resize())}});l.appendIfNode=p;return l});