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