datatable-min.js revision 8947d1099a91880ec4e5be929041b1cebb9a3a55
YUI.add("datatable-base",function(B){function T(Y){T.superclass.constructor.apply(this,arguments);}T.NAME="column";T.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},className:{},editor:{},formatter:{},resizeable:{},sortable:{},hidden:{},width:{},minWidth:{},maxAutoWidth:{}};B.extend(T,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");},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);}});B.Column=T;var G=B.Lang;function I(Y){I.superclass.constructor.apply(this,arguments);}I.NAME="columnset";I.ATTRS={columns:{setter:"_setColumns"},tree:{readOnly:true,value:[]},flat:{readOnly:true,value:[]},hash:{readOnly:true,value:{}},keys:{readOnly:true,value:[]}};B.extend(I,B.Base,{_setColumns:function(Y){return B.clone(Y);},initializer:function(){var Y=[],i=[],h={},g=[],f=this.get("columns"),d=this;function e(q,l,p){var n=0,k=l.length,m,o,j;q++;if(!Y[q]){Y[q]=[];}for(;n<k;++n){m=l[n];m=G.isString(m)?{key:m}:m;o=new B.Column(m);m.yuiColumnId=o.get("id");i.push(o);h[o.get("id")]=o;if(p){o._set("parent",p);}if(G.isArray(m.children)){j=m.children;o._set("children",j);d._setColSpans(o,m);d._cascadePropertiesToChildren(o,j);if(!Y[q+1]){Y[q+1]=[];}e(q,j,o);}else{o._set("keyIndex",g.length);o._set("colspan",1);g.push(o);}Y[q].push(o);}q--;}e(-1,f);this._set("tree",Y);this._set("flat",i);this._set("hash",h);this._set("keys",g);this._setRowSpans();this._setHeaders();},destructor:function(){},_cascadePropertiesToChildren:function(f,d){var e=0,Y=d.length,g;for(;e<Y;++e){g=d[e];if(f.get("className")&&(g.className===undefined)){g.className=f.get("className");}if(f.get("editor")&&(g.editor===undefined)){g.editor=f.get("editor");}if(f.get("formatter")&&(g.formatter===undefined)){g.formatter=f.get("formatter");}if(f.get("resizeable")&&(g.resizeable===undefined)){g.resizeable=f.get("resizeable");}if(f.get("sortable")&&(g.sortable===undefined)){g.sortable=f.get("sortable");}if(f.get("hidden")){g.hidden=true;}if(f.get("width")&&(g.width===undefined)){g.width=f.get("width");}if(f.get("minWidth")&&(g.minWidth===undefined)){g.minWidth=f.get("minWidth");}if(f.get("maxAutoWidth")&&(g.maxAutoWidth===undefined)){g.maxAutoWidth=f.get("maxAutoWidth");}}},_setColSpans:function(f,d){var e=0;function Y(j){var k=j.children,h=0,g=k.length;for(;h<g;++h){if(G.isArray(k[h].children)){Y(k[h]);}else{e++;}}}Y(d);f._set("colspan",e);},_setRowSpans:function(){function Y(e){var f=1,h,g,d,j;function i(o,n){n=n||1;var m=0,k=o.length,l;for(;m<k;++m){l=o[m];if(G.isArray(l.children)){n++;i(l.children,n);n--;}else{if(l.get&&G.isArray(l.get("children"))){n++;i(l.get("children"),n);n--;}else{if(n>f){f=n;}}}}}for(d=0;d<e.length;d++){h=e[d];i(h);for(j=0;j<h.length;j++){g=h[j];if(!G.isArray(g.get("children"))){g._set("rowspan",f);}else{g._set("rowspan",1);}}f=1;}}Y(this.get("tree"));},_setHeaders:function(){var h,f,e=this.get("keys"),d=0,Y=e.length;function g(j,i){j.push(i.get("key"));if(i.get("parent")){g(j,i.get("parent"));}}for(;d<Y;++d){h=[];f=e[d];g(h,f);f._set("headers",h.reverse().join(" "));}},getColumn:function(){}});B.Columnset=I;var L=B.Lang,c=B.Node,Z=B.ClassNameManager.getClassName,K=B.bind,N="datatable",D="focus",C="keydown",W="mouseover",b="mouseout",J="mouseup",O="mousedown",H="click",E="doubleclick",P=Z(N,"columns"),A=Z(N,"data"),F=Z(N,"msg"),M=Z(N,"liner"),U=Z(N,"first"),R=Z(N,"last"),V='<th id="{id}" rowspan="{rowspan}" colspan="{colspan}"><div class="'+M+'">{value}</div></th>',Q='<tr id="{id}"></tr>',X='<td headers="{headers}"><div class="'+M+'">{value}</div></td>',S="{value}";function a(Y){a.superclass.constructor.apply(this,arguments);}a.NAME="dataTable";a.ATTRS={columnset:{setter:"_setColumnset"},recordset:{setter:"_setRecordset"},state:{value:new B.State(),readOnly:true},strings:{valueFn:function(){return B.Intl.get("datatable-base");}},thValueTemplate:{value:S},tdValueTemplate:{value:S},trTemplate:{value:Q}};a.HTML_PARSER={attrA:function(Y){}};B.extend(a,B.Widget,{thTemplate:V,tdTemplate:X,_theadNode:null,_tbodyNode:null,_msgNode:null,_setColumnset:function(Y){return L.isArray(Y)?new B.Columnset({columns:Y}):Y;},_setRecordset:function(Y){if(L.isArray(Y)){Y=new B.Recordset({records:Y});}Y.addTarget(this);return Y;},initializer:function(){this.publish("addTheadTr",{defaultFn:K("_defAddTheadTrFn",this),queuable:false});this.publish("addTheadTh",{defaultFn:K("_defAddTheadThFn",this),queuable:false});this.publish("addTr",{defaultFn:K("_defAddTrFn",this),queuable:false});this.publish("addTd",{defaultFn:K("_defAddTdFn",this),queuable:false});this.publish("theadCellClick",{emitFacade:false});this.publish("theadRowClick",{emitFacade:false});this.publish("theadClick",{emitFacade:false});},destructor:function(){this.get("recordset").removeTarget(this);},renderUI:function(){var Y=this._createTableNode();Y=Y?this._createColgroupNode(this._tableNode):false;Y=Y?this._createTheadNode(this._tableNode):false;Y=Y?this._createTbodyNode(this._tableNode):false;Y=Y?this._createMessageNode(this._tableNode):false;Y=Y?this._createCaptionNode(this._tableNode):false;return Y;},_createTableNode:function(){if(!this._tableNode){this._tableNode=this.get("contentBox").appendChild(c.create("<table></table>"));}return this._tableNode;},_createColgroupNode:function(f){var e=this.get("columnset").get("keys"),d=0,Y=e.length,g=["<colgroup>"];for(;d<Y;++d){g.push("<col></col>");}g.push("</colgroup>");this._colgroupNode=f.insertBefore(c.create(g.join("")),f.get("firstChild"));
return this._colgroupNode;},_createTheadNode:function(Y){if(Y){this._theadNode=Y.insertBefore(c.create("<thead class='"+P+"'></thead>"),this._colgroupNode.next());return this._theadNode;}},_createTbodyNode:function(Y){this._tbodyNode=Y.appendChild(c.create("<tbody class='"+A+"'></tbody>"));return this._tbodyNode;},_createMessageNode:function(Y){this._msgNode=Y.insertBefore(c.create("<tbody class='"+F+"'></tbody>"),this._tbodyNode);return this._msgNode;},_createCaptionNode:function(Y){this._captionNode=Y.invoke("createCaption");return this._captionNode;},bindUI:function(){var g=this._tableNode,d=this.get("contentBox"),e="thead."+P+">tr>th",f="tbody."+A+">tr>td",Y="tbody."+F+">tr>td";g.delegate(D,K(this._onTheadFocus,this),e);g.delegate(C,K(this._onTheadKeydown,this),e);g.delegate(W,K(this._onTheadMouseover,this),e);g.delegate(b,K(this._onTheadMouseout,this),e);g.delegate(J,K(this._onTheadMouseup,this),e);g.delegate(O,K(this._onTheadMousedown,this),e);g.delegate(H,K(this._onTheadClick,this),e);d.delegate(E,K(this._onTheadDoubleclick,this),e);g.delegate(D,K(this._onTbodyFocus,this),f);g.delegate(C,K(this._onTbodyKeydown,this),f);g.delegate(W,K(this._onTbodyMouseover,this),f);g.delegate(b,K(this._onTbodyMouseout,this),f);g.delegate(J,K(this._onTbodyMouseup,this),f);g.delegate(O,K(this._onTbodyMousedown,this),f);g.delegate("click",K(this._onTbodyClick,this),f);d.delegate(E,K(this._onTbodyDoubleclick,this),f);g.delegate(D,K(this._onMsgFocus,this),Y);g.delegate(C,K(this._onMsgKeydown,this),Y);g.delegate(W,K(this._onMsgMouseover,this),Y);g.delegate(b,K(this._onMsgMouseout,this),Y);g.delegate(J,K(this._onMsgMouseup,this),Y);g.delegate(O,K(this._onMsgMousedown,this),Y);g.delegate("click",K(this._onMsgClick,this),Y);d.delegate(E,K(this._onMsgDoubleclick,this),Y);},_onTheadFocus:function(){},_onTheadKeydown:function(){},_onTheadMouseover:function(){},_onTheadMouseout:function(){},_onTheadMouseup:function(){},_onTheadMousedown:function(){},_onTheadClick:function(Y){this.fire("theadCellClick",Y);this.fire("theadRowClick",Y);this.fire("theadClick",Y);},_onTheadDoubleclick:function(){},_onTbodyFocus:function(){},_onTbodyKeydown:function(){},_onTbodyMouseover:function(){},_onTbodyMouseout:function(){},_onTbodyMouseup:function(){},_onTbodyMousedown:function(){},_onTbodyClick:function(Y){},_onTbodyDoubleclick:function(){},_onMsgFocus:function(){},_onMsgKeydown:function(){},_onMsgMouseover:function(){},_onMsgMouseout:function(){},_onMsgMouseup:function(){},_onMsgMousedown:function(){},_onMsgClick:function(Y){},_onMsgDoubleclick:function(){},syncUI:function(){this._uiSetStrings(this.get("strings"));this._uiSetColumnset(this.get("columnset"));this._uiSetRecordset(this.get("recordset"));},_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.set("innerHTML",Y);},_afterColumnsetChange:function(Y){this._uiSetColumnset(Y.newVal);},_uiSetColumnset:function(h){var d=h.get("tree"),e=this._theadNode,g=0,Y=d.length,j,f;while(e.get("firstChild")){e.removeChild(e.get("firstChild"));}for(;g<Y;++g){f=d[g];j=c.create(this._getTheadTrMarkup(f));if(g===0){j.addClass(U);}if(g===Y-1){j.addClass(R);}this.fire("addTheadTr",{columns:f,thead:e,tr:j});}},_defAddTheadTrFn:function(l){var f=l.columns,k=l.thead,j=l.tr,d=0,Y=f.length,g,h;for(;d<Y;++d){g=f[d];h=c.create(this._getTheadThMarkup({value:g.get("label")},g));this.fire("addTheadTh",{column:g,tr:j,th:h});}k.appendChild(j);},_getTheadTrMarkup:function(Y){return B.substitute(this.get("trTemplate"),{});},_defAddTheadThFn:function(Y){Y.tr.appendChild(Y.th);},_getTheadThMarkup:function(d,Y){d.column=Y;d.id=Y.get("id");d.value=B.substitute(this.get("thValueTemplate"),d);d.colspan=Y.get("colspan");d.rowspan=Y.get("rowspan");return B.substitute(this.thTemplate,d);},_afterRecordsetChange:function(Y){this._uiSetRecordset(Y.newVal);},_uiSetRecordset:function(d){var e=0,Y=3;for(;e<Y;++e){this.fire("addTr",{record:d.getRecord(e),index:e});}},_defAddTrFn:function(i){var Y=i.record,d=i.index,f=this._tbodyNode,h=f.get("children").item(d)||null,g=f.one("#"+Y.get("id"))||this._createBodyTr(Y);f.insertBefore(g,h);return g;},_createBodyTr:function(Y){var d=c.create(this._getDataTrMarkup(Y));this._createTdNodes(Y,d);return d;},_getDataTrMarkup:function(Y){return B.substitute(this.get("trTemplate"),{id:Y.get("id")});},_createTdNodes:function(d,h){var e=0,g=this.get("columnset").get("keys"),Y=g.length,f=[];for(;e<Y;++e){f.push(this._getTdNodeMarkup(d,g[e]));}h.appendChild(c.create(f.join("")));},_getTdNodeMarkup:function(Y,d){var e={};e.headers=d.get("headers");e.value=this.formatDataCell(Y,d);return B.substitute(this.tdTemplate,e);},formatDataCell:function(Y,d){var e={};e.data=Y.get("data");e.value=Y.getValue(d.get("key"));return B.substitute(this.get("tdValueTemplate"),e);}});B.namespace("DataTable").Base=a;},"@VERSION@",{lang:["en"],requires:["intl","substitute","widget","recordset"]});YUI.add("datatable-sort",function(G){var A=G.ArraySort.compare,C="asc",B="desc",H=G.ClassNameManager.getClassName("datatable","sortable"),E='<a class="{link_class}" title="{link_title}" href="{link_href}">{value}</a>';function F(I,J,K){F.superclass.constructor.apply(this,arguments);}G.mix(F,{NS:"sort",NAME:"recordsetSort",ATTRS:{dt:{},defaultSorter:{value:function(K,I,L,M){var J=A(K.getValue(L),I.getValue(L),M);if(J===0){return A(K.get("id"),I.get("id"),M);}else{return J;}}}}});G.extend(F,G.Plugin.Base,{initializer:function(I){this.addTarget(this.get("dt"));this.publish("sort",{defaultFn:G.bind("_defSortFn",this)});},destructor:function(I){},_defSortFn:function(I){this.get("host").get("records").sort(function(K,J){return(I.sorter)(K,J,I.field,I.desc);});},sort:function(I,J,K){this.fire("sort",{field:I,desc:J,sorter:K||this.get("defaultSorter")});},custom:function(){alert("sort custom");},asc:function(){alert("sort asc");
},desc:function(){alert("sort desc");},reverse:function(){alert("sort reverse");}});G.namespace("Plugin").RecordsetSort=F;function D(){D.superclass.constructor.apply(this,arguments);}G.mix(D,{NS:"sort",NAME:"dataTableSort",ATTRS:{sortedBy:{value:null}}});G.extend(D,G.Plugin.Base,{thLinkTemplate:E,initializer:function(I){var J=this.get("host");J.get("recordset").plug(F,{dt:J});this.doBefore("_getTheadThMarkup",this._beforeGetTheadThMarkup);J.on("addTheadTh",function(K){K.th.addClass(H);});J.on("theadCellClick",this._onEventSortColumn);J.after("recordsetSort:sort",function(){J._uiSetRecordset(J.get("recordset"));});J.after("sortedByChangeEvent",function(){alert("ok");});if(J.get("rendered")){J._uiSetColumnset(J.get("columnset"));}},_beforeGetTheadThMarkup:function(J,I){if(I.get("sortable")){J.value=G.substitute(this.thLinkTemplate,{link_class:"foo",link_title:"bar",link_href:"bat",value:J.value});}},_onEventSortColumn:function(M){M.halt();var K=this.get("columnset").get("hash")[M.currentTarget.get("id")],L=K.get("field"),J=this.get("sortedBy"),I=(J&&J.field===L&&J.dir===C)?B:C,N=K.get("sortFn");if(K.get("sortable")){this.get("recordset").sort.sort(L,I===B,N);this.set("sortedBy",{field:L,dir:I});}}});G.namespace("Plugin").DataTableSort=D;},"@VERSION@",{lang:["en"],requires:["plugin","datatable-base"]});YUI.add("datatable-colresize",function(E){var B=E.ClassNameManager.getClassName,F="datatable",A=B(F,"liner"),D='<div class="'+A+'">{value}</div>';function C(){C.superclass.constructor.apply(this,arguments);}E.mix(C,{NS:"colresize",NAME:"dataTableColResize",ATTRS:{}});E.extend(C,E.Plugin.Base,{thLinerTemplate:D,tdLinerTemplate:D,initializer:function(G){this.get("host").thTemplate=E.substitute(this.get("host").thTemplate,{value:this.thLinerTemplate});this.get("host").tdTemplate=E.substitute(this.get("host").tdTemplate,{value:this.tdLinerTemplate});}});E.namespace("Plugin").DataTableColResize=C;},"@VERSION@",{requires:["plugin","dd","datatable-base"]});YUI.add("datatable",function(A){},"@VERSION@",{use:["datatable-base","datatable-sort","datatable-colresize"]});