/*
YUI 3.6.0pr3 (build 1)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("datatable-body",function(a){var d=a.Lang,e=d.isArray,j=d.isNumber,b=d.isString,i=d.sub,h=a.Escape.html,c=a.Array,f=a.bind,g=a.Object;a.namespace("DataTable").BodyView=a.Base.create("tableBody",a.View,[],{CELL_TEMPLATE:'<td {headers} class="{className}">{content}</td>',ROW_TEMPLATE:'<tr id="{rowId}" data-yui3-record="{clientId}" class="{rowClass}">{content}</tr>',TBODY_TEMPLATE:'<tbody class="{className}"></tbody>',getCell:function(m,l){var o=this.tbodyNode,q,k,n,p;if(m&&o){if(e(m)){q=o.get("children").item(m[0]);k=q&&q.get("children").item(m[1]);}else{if(a.instanceOf(m,a.Node)){k=m.ancestor("."+this.getClassName("cell"),true);}}if(k&&l){p=o.get("firstChild.rowIndex");if(b(l)){switch(l){case"above":l=[-1,0];break;case"below":l=[1,0];break;case"next":l=[0,1];break;case"previous":l=[0,-1];break;}}if(e(l)){n=k.get("parentNode.rowIndex")+l[0]-p;q=o.get("children").item(n);n=k.get("cellIndex")+l[1];k=q&&q.get("children").item(n);}}}return k||null;},getClassName:function(){var l=this.host,k;if(l&&l.getClassName){return l.getClassName.apply(l,arguments);}else{k=c(arguments);k.unshift(this.constructor.NAME);return a.ClassNameManager.getClassName.apply(a.ClassNameManager,k);}},getRecord:function(l){var n=this.get("modelList"),m=this.tbodyNode,o=null,k;if(m){if(b(l)){l=m.one("#"+l);}if(a.instanceOf(l,a.Node)){o=l.ancestor(function(p){return p.get("parentNode").compareTo(m);},true);k=o&&n.getByClientId(o.getData("yui3-record"));}}return k||null;},getRow:function(m){var k=this.tbodyNode,l=null;if(k){if(m){m=this._idMap[m.get?m.get("clientId"):m]||m;}l=j(m)?k.get("children").item(m):k.one("#"+m);}return l;},render:function(){var m=this.get("container"),n=this.get("modelList"),l=this.get("columns"),k=this.tbodyNode||(this.tbodyNode=this._createTBodyNode());this._createRowTemplate(l);if(n){k.setHTML(this._createDataHTML(l));this._applyNodeFormatters(k,l);}if(k.get("parentNode")!==m){m.appendChild(k);}this.bindUI();return this;},_afterColumnsChange:function(k){this.render();},_afterDataChange:function(k){this.render();},_afterModelListChange:function(l){var k=this._eventHandles;if(k.dataChange){k.dataChange.detach();this.bindUI();}if(this.tbodyNode){this.render();}},_applyNodeFormatters:function(p,k){var r=this.host,n=this.get("modelList"),m=[],l="."+this.getClassName("liner"),s,o,q;for(o=0,q=k.length;o<q;++o){if(k[o].nodeFormatter){m.push(o);}}if(n&&m.length){s=p.get("childNodes");n.each(function(x,y){var v={data:x.toJSON(),record:x,rowIndex:y},D=s.item(y),w,z,u,B,C,A,t;if(D){C=D.get("childNodes");for(w=0,z=m.length;w<z;++w){A=C.item(m[w]);if(A){u=v.column=k[m[w]];B=u.key||u.id;v.value=x.get(B);v.td=A;v.cell=A.one(l)||A;t=u.nodeFormatter.call(r,v);if(t===false){A.destroy(true);}}}}});}},bindUI:function(){var k=this._eventHandles,m=this.get("modelList"),l=m.model.NAME+":change";if(!k.columnsChange){k.columnsChange=this.after("columnsChange",f("_afterColumnsChange",this));}if(m&&!k.dataChange){k.dataChange=m.after(["add","remove","reset",l],f("_afterDataChange",this));}},_createDataHTML:function(l){var m=this.get("modelList"),k="";if(m){m.each(function(o,n){k+=this._createRowHTML(o,n,l);},this);}return k;},_createRowHTML:function(r,t,n){var p=r.toJSON(),k=r.get("clientId"),v={rowId:this._getRowId(k),clientId:k,rowClass:(t%2)?this.CLASS_ODD:this.CLASS_EVEN},w=this.host||this,q,s,l,m,u,o;for(q=0,s=n.length;q<s;++q){l=n[q];u=p[l.key];m=l._id||l.key;v[m+"-className"]="";if(l.formatter){o={value:u,data:p,column:l,record:r,className:"",rowClass:"",rowIndex:t};if(typeof l.formatter==="string"){if(u!==undefined){u=i(l.formatter,o);}}else{u=l.formatter.call(w,o);if(u===undefined){u=o.value;}v[m+"-className"]=o.className;v.rowClass+=" "+o.rowClass;}}if(u===undefined||u===null||u===""){u=l.emptyCellValue||"";}v[m]=l.allowHTML?u:h(u);v.rowClass=v.rowClass.replace(/\s+/g," ");}return i(this._rowTemplate,v);},_createRowTemplate:function(n){var q="",t=this.CELL_TEMPLATE,p,r,m,s,o,l,k;for(p=0,r=n.length;p<r;++p){m=n[p];s=m.key;o=m._id||s;l=(m._headers||[]).length>1?'headers="'+m._headers.join(" ")+'"':"";k={content:"{"+o+"}",headers:l,className:this.getClassName("col",o)+" "+(m.className||"")+" "+this.getClassName("cell")+" {"+o+"-className}"};if(m.nodeFormatter){k.content="";}q+=i(m.cellTemplate||t,k);}this._rowTemplate=i(this.ROW_TEMPLATE,{content:q});},_createTBodyNode:function(){return a.Node.create(i(this.TBODY_TEMPLATE,{className:this.getClassName("data")}));},destructor:function(){(new a.EventHandle(g.values(this._eventHandles))).detach();},_getRowId:function(k){return this._idMap[k]||(this._idMap[k]=a.guid());},initializer:function(k){this.host=k.host;this._eventHandles={modelListChange:this.after("modelListChange",f("_afterModelListChange",this))};this._idMap={};this.CLASS_ODD=this.getClassName("odd");this.CLASS_EVEN=this.getClassName("even");}});},"3.6.0pr3",{requires:["datatable-core","view","classnamemanager"]});