datatable-base-min.js revision 772c99f483000bc957c80ccb621d31f244e188f4
YUI.add("datatable-base",function(D){var Q="column";function M(Y){M.superclass.constructor.apply(this,arguments);}M.NAME="column";M.ATTRS={id:{valueFn:"_defaultId",writeOnce:true},key:{valueFn:"_defaultKey"},field:{valueFn:"_defaultField"},label:{valueFn:"_defaultLabel"},keyIndex:{readOnly:true},parent:{readOnly:true},children:{},colspan:{readOnly:true},rowspan:{readOnly:true},thNode:{readOnly:true},thLinerNode:{readOnly:true},thLabelNode:{readOnly:true},abbr:{value:null},headers:{},classnames:{readOnly:true,getter:"_getClassnames"},editor:{},formatter:{},resizeable:{},sortable:{},hidden:{},width:{},minWidth:{},maxAutoWidth:{}};D.extend(M,D.Widget,{_defaultId:function(){return D.guid();},_defaultKey:function(Y){return Y||D.guid();},_defaultField:function(Y){return Y||this.get("key");},_defaultLabel:function(Y){return Y||this.get("key");},initializer:function(){},destructor:function(){},syncUI:function(){this._uiSetAbbr(this.get("abbr"));},_afterAbbrChange:function(Y){this._uiSetAbbr(Y.newVal);},_uiSetAbbr:function(Y){this._thNode.set("abbr",Y);},_getClassnames:function(){return D.ClassNameManager.getClassName(Q,this.get("id"));}});D.Column=M;var k=D.Lang;function W(Y){W.superclass.constructor.apply(this,arguments);}W.NAME="columnset";W.ATTRS={columns:{setter:"_setColumns"},tree:{readOnly:true,value:[]},flat:{readOnly:true,value:[]},hash:{readOnly:true,value:{}},keys:{readOnly:true,value:[]}};D.extend(W,D.Base,{_setColumns:function(Y){return D.clone(Y);},initializer:function(){var Y=[],q=[],p={},o=[],n=this.get("columns"),l=this;function m(y,t,x){var v=0,s=t.length,u,w,r;y++;if(!Y[y]){Y[y]=[];}for(;v<s;++v){u=t[v];u=k.isString(u)?{key:u}:u;w=new D.Column(u);u.yuiColumnId=w.get("id");q.push(w);p[w.get("id")]=w;if(x){w._set("parent",x);}if(k.isArray(u.children)){r=u.children;w._set("children",r);l._setColSpans(w,u);l._cascadePropertiesToChildren(w,r);if(!Y[y+1]){Y[y+1]=[];}m(y,r,w);}else{w._set("keyIndex",o.length);w._set("colspan",1);o.push(w);}Y[y].push(w);}y--;}m(-1,n);this._set("tree",Y);this._set("flat",q);this._set("hash",p);this._set("keys",o);this._setRowSpans();this._setHeaders();},destructor:function(){},_cascadePropertiesToChildren:function(n,l){var m=0,Y=l.length,o;for(;m<Y;++m){o=l[m];if(n.get("className")&&(o.className===undefined)){o.className=n.get("className");}if(n.get("editor")&&(o.editor===undefined)){o.editor=n.get("editor");}if(n.get("formatter")&&(o.formatter===undefined)){o.formatter=n.get("formatter");}if(n.get("resizeable")&&(o.resizeable===undefined)){o.resizeable=n.get("resizeable");}if(n.get("sortable")&&(o.sortable===undefined)){o.sortable=n.get("sortable");}if(n.get("hidden")){o.hidden=true;}if(n.get("width")&&(o.width===undefined)){o.width=n.get("width");}if(n.get("minWidth")&&(o.minWidth===undefined)){o.minWidth=n.get("minWidth");}if(n.get("maxAutoWidth")&&(o.maxAutoWidth===undefined)){o.maxAutoWidth=n.get("maxAutoWidth");}}},_setColSpans:function(n,l){var m=0;function Y(q){var r=q.children,p=0,o=r.length;for(;p<o;++p){if(k.isArray(r[p].children)){Y(r[p]);}else{m++;}}}Y(l);n._set("colspan",m);},_setRowSpans:function(){function Y(n){var o=1,r,q,l,t;function s(w,v){v=v||1;var u=0,m=w.length,p;for(;u<m;++u){p=w[u];if(k.isArray(p.children)){v++;s(p.children,v);v--;}else{if(p.get&&k.isArray(p.get("children"))){v++;s(p.get("children"),v);v--;}else{if(v>o){o=v;}}}}}for(l=0;l<n.length;l++){r=n[l];s(r);for(t=0;t<r.length;t++){q=r[t];if(!k.isArray(q.get("children"))){q._set("rowspan",o);}else{q._set("rowspan",1);}}o=1;}}Y(this.get("tree"));},_setHeaders:function(){var p,n,m=this.get("keys"),l=0,Y=m.length;function o(r,q){r.push(q.get("key"));if(q.get("parent")){o(r,q.get("parent"));}}for(;l<Y;++l){p=[];n=m[l];o(p,n);n._set("headers",p.reverse().join(" "));}},getColumn:function(){}});D.Columnset=W;var T=D.Lang,d=D.Lang.substitute,E=D.Node,S=E.create,O=D.ClassNameManager.getClassName,a=D.bind,P="datatable",f="focus",j="keydown",L="mouseover",g="mouseout",J="mouseup",V="mousedown",Z="click",C="doubleclick",F=O(P,"columns"),X=O(P,"data"),B=O(P,"msg"),K=O(P,"liner"),c=O(P,"first"),H=O(P,"last"),b="<table></table>",U="<col></col>",h='<thead class="'+F+'"></thead>',G='<tbody class="'+X+'"></tbody>',i='<th id="{id}" rowspan="{rowspan}" colspan="{colspan}" class="{classnames}"><div class="'+K+'">{value}</div></th>',e='<tr id="{id}"></tr>',A='<td headers="{headers}" class="{classnames}"><div class="'+K+'">{value}</div></td>',I="{value}",N='<tbody class="'+B+'"></tbody>';function R(Y){R.superclass.constructor.apply(this,arguments);}D.mix(R,{NAME:"dataTable",ATTRS:{columnset:{setter:"_setColumnset"},recordset:{setter:"_setRecordset"},strings:{valueFn:function(){return D.Intl.get("datatable-base");}},thValueTemplate:{value:I},tdValueTemplate:{value:I},trTemplate:{value:e}},HTML_PARSER:{}});D.extend(R,D.Widget,{thTemplate:i,tdTemplate:A,_theadNode:null,_tbodyNode:null,_msgNode:null,_setColumnset:function(Y){return T.isArray(Y)?new D.Columnset({columns:Y}):Y;},_afterColumnsetChange:function(Y){this._uiSetColumnset(Y.newVal);},_setRecordset:function(Y){if(T.isArray(Y)){Y=new D.Recordset({records:Y});}Y.addTarget(this);return Y;},_afterRecordsetChange:function(Y){this._uiSetRecordset(Y.newVal);},initializer:function(Y){},destructor:function(){this.get("recordset").removeTarget(this);},renderUI:function(){var Y=this._addTableNode(this.get("contentBox"))&&this._addColgroupNode(this._tableNode)&&this._addTheadNode(this._tableNode)&&this._addTbodyNode(this._tableNode)&&this._addMessageNode(this._tableNode)&&this._addCaptionNode(this._tableNode);},_addTableNode:function(Y){if(!this._tableNode){this._tableNode=Y.appendChild(S(b));}return this._tableNode;},_addColgroupNode:function(m){var Y=this.get("columnset").get("keys").length,l=0,n=["<colgroup>"];for(;l<Y;++l){n.push(U);}n.push("</colgroup>");this._colgroupNode=m.insertBefore(S(n.join("")),m.get("firstChild"));return this._colgroupNode;},_addTheadNode:function(Y){if(Y){this._theadNode=Y.insertBefore(S(h),this._colgroupNode.next());return this._theadNode;
}},_addTbodyNode:function(Y){this._tbodyNode=Y.appendChild(S(G));return this._tbodyNode;},_addMessageNode:function(Y){this._msgNode=Y.insertBefore(S(N),this._tbodyNode);return this._msgNode;},_addCaptionNode:function(Y){this._captionNode=Y.invoke("createCaption");return this._captionNode;},bindUI:function(){var o=this._tableNode,l=this.get("contentBox"),m="thead."+F+">tr>th",n="tbody."+X+">tr>td",Y="tbody."+B+">tr>td";this.publish("theadCellClick",{defaultFn:this._defTheadCellClickFn,emitFacade:false,queuable:true});this.publish("theadRowClick",{defaultFn:this._defTheadRowClickFn,emitFacade:false,queuable:true});this.publish("theadClick",{defaultFn:this._defTheadClickFn,emitFacade:false,queuable:true});o.delegate(f,this._onDomEvent,m,this,"theadCellFocus");o.delegate(j,this._onDomEvent,m,this,"theadCellKeydown");o.delegate(L,this._onDomEvent,m,this,"theadCellMousedown");o.delegate(g,this._onDomEvent,m,this,"theadCellMouseout");o.delegate(J,this._onDomEvent,m,this,"theadCellMouseup");o.delegate(V,this._onDomEvent,m,this,"theadCellMousedown");o.delegate(Z,this._onDomEvent,m,this,"theadCellClick");l.delegate(C,this._onEvent,m,this,"theadCellDoubleclick");o.delegate(f,this._onDomEvent,m,this,"tbodyCellFocus");o.delegate(j,this._onDomEvent,m,this,"tbodyCellKeydown");o.delegate(L,this._onDomEvent,m,this,"tbodyCellMouseover");o.delegate(g,this._onDomEvent,m,this,"tbodyCellMouseout");o.delegate(J,this._onDomEvent,m,this,"tbodyCellMouseup");o.delegate(V,this._onDomEvent,m,this,"tbodyCellMousedown");o.delegate(Z,this._onDomEvent,m,this,"tbodyCellClick");l.delegate(C,this._onEvent,m,this,"tbodyCellDoubleclick");o.delegate(f,this._onDomEvent,Y,this,"msgCellFocus");o.delegate(j,this._onDomEvent,Y,this,"msgCellKeydown");o.delegate(L,this._onDomEvent,Y,this,"msgCellMouseover");o.delegate(g,this._onDomEvent,Y,this,"msgCellMouseout");o.delegate(J,this._onDomEvent,Y,this,"msgCellMouseup");o.delegate(V,this._onDomEvent,Y,this,"msgCellMousedown");o.delegate(Z,this._onDomEvent,Y,this,"msgCellClick");l.delegate(C,this._onDomEvent,Y,this,"msgCellDoubleclick");},_onDomEvent:function(l,Y){this.fire(Y,l);},_defTheadCellClickFn:function(Y){this.fire("theadRowClick",Y);},_defTheadRowClickFn:function(Y){this.fire("theadClick",Y);},_defTheadClickFn:function(Y){},syncUI:function(){this._uiSetColumnset(this.get("columnset"));this._uiSetRecordset(this.get("recordset"));this._uiSetStrings(this.get("strings"));},_afterStringsChange:function(Y){this._uiSetStrings(Y.newVal);},_uiSetStrings:function(Y){this._uiSetSummary(Y.summary);this._uiSetCaption(Y.caption);},_uiSetSummary:function(Y){this._tableNode.set("summary",Y);},_uiSetCaption:function(Y){this._captionNode.setContent(Y);},_uiSetColumnset:function(n){var l=n.get("tree"),o=this._theadNode,m=0,Y=l.length;o.get("children").remove(true);for(;m<Y;++m){this._addTheadTrNode({thead:o,columns:l[m]},(m===0),(m===Y-1));}},_addTheadTrNode:function(m,Y,l){m.tr=this._createTheadTrNode(m,Y,l);this._attachTheadTrNode(m);},_createTheadTrNode:function(s,l,r){var q=S(d(this.get("trTemplate"),s)),n=0,m=s.columns,Y=m.length,p;if(l){q.addClass(c);}if(r){q.addClass(H);}for(;n<Y;++n){p=m[n];this._addTheadThNode({value:p.get("label"),column:p,tr:q});}return q;},_attachTheadTrNode:function(Y){Y.thead.appendChild(Y.tr);},_addTheadThNode:function(Y){Y.th=this._createTheadThNode(Y);this._attachTheadThNode(Y);},_createTheadThNode:function(l){var Y=l.column;l.id=Y.get("id");l.colspan=Y.get("colspan");l.rowspan=Y.get("rowspan");l.classnames=Y.get("classnames");l.value=d(this.get("thValueTemplate"),l);return S(d(this.thTemplate,l));},_attachTheadThNode:function(Y){Y.tr.appendChild(Y.th);},_uiSetRecordset:function(l){var m=0,Y=l.getLength(),n={tbody:this._tbodyNode};for(;m<Y;++m){n.record=l.getRecord(m);n.rowindex=m;this._addTbodyTrNode(n);}},_addTbodyTrNode:function(m){var l=m.tbody,Y=m.record;m.tr=l.one("#"+Y.get("id"))||this._createTbodyTrNode(m);this._attachTbodyTrNode(m);},_createTbodyTrNode:function(q){var p=S(d(this.get("trTemplate"),{id:q.record.get("id")})),l=0,n=this.get("columnset").get("keys"),Y=n.length,m;q.tr=p;for(;l<Y;++l){q.column=n[l];this._addTbodyTdNode(q);}return p;},_attachTbodyTrNode:function(q){var m=q.tbody,p=q.tr,Y=q.record,l=q.rowindex,n=m.get("children").item(l)||null;m.insertBefore(p,n);},_addTbodyTdNode:function(Y){Y.td=this._createTbodyTdNode(Y);this._attachTbodyTdNode(Y);},_createTbodyTdNode:function(l){var Y=l.column;l.headers=Y.get("headers");l.classnames=Y.get("classnames");l.value=this.formatDataCell(l);return S(d(this.tdTemplate,l));},_attachTbodyTdNode:function(Y){Y.tr.appendChild(Y.td);},formatDataCell:function(l){var Y=l.record;l.data=Y.get("data");l.value=Y.getValue(l.column.get("key"));return d(this.get("tdValueTemplate"),l);}});D.namespace("DataTable").Base=R;},"@VERSION@",{requires:["intl","substitute","widget","recordset-base"],lang:["en"]});