/*
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-table",function(f){var c=f.Array,b=f.Lang,d=b.sub,a=b.isArray,e=b.isFunction;f.namespace("DataTable").TableView=f.Base.create("table",f.View,[],{CAPTION_TEMPLATE:'<caption class="{className}"/>',TABLE_TEMPLATE:'<table cellspacing="0" class="{className}"/>',getCell:function(h,g){return this.body&&this.body.getCell&&this.body.getCell.apply(this.body,arguments);},getClassName:function(){var g=this.host,h=(g&&g.constructor.NAME)||this.constructor.NAME;if(g&&g.getClassName){return g.getClassName.apply(g,arguments);}else{return f.ClassNameManager.getClassName.apply(f.ClassNameManager,[h].concat(c(arguments,0,true)));}},getRecord:function(){return this.body&&this.body.getRecord&&this.body.getRecord.apply(this.body,arguments);},getRow:function(g){return this.body&&this.body.getRow&&this.body.getRow.apply(this.body,arguments);},_afterSummaryChange:function(g){this._uiSetSummary(g.newVal);},_afterCaptionChange:function(g){this._uiSetCaption(g.newVal);},_afterWidthChange:function(g){this._uiSetWidth(g.newVal);},_bindUI:function(){var g;if(!this._eventHandles){g=f.bind("_relayAttrChange",this);this._eventHandles=this.after({columnsChange:g,modelListChange:g,summaryChange:f.bind("_afterSummaryChange",this),captionChange:f.bind("_afterCaptionChange",this),widthChange:f.bind("_afterWidthChange",this)});}},_createTable:function(){return f.Node.create(d(this.TABLE_TEMPLATE,{className:this.getClassName("table")})).empty();},_defRenderBodyFn:function(g){g.view.render();},_defRenderFooterFn:function(g){g.view.render();},_defRenderHeaderFn:function(g){g.view.render();},_defRenderTableFn:function(i){var g=this.get("container"),h=this.getAttrs();if(!this.tableNode){this.tableNode=this._createTable();}h.host=this.get("host")||this;h.table=this;h.container=this.tableNode;this._uiSetCaption(this.get("caption"));this._uiSetSummary(this.get("summary"));this._uiSetWidth(this.get("width"));if(this.head||i.headerView){if(!this.head){this.head=new i.headerView(f.merge(h,i.headerConfig));}this.fire("renderHeader",{view:this.head});}if(this.foot||i.footerView){if(!this.foot){this.foot=new i.footerView(f.merge(h,i.footerConfig));}this.fire("renderFooter",{view:this.foot});}h.columns=this.displayColumns;if(this.body||i.bodyView){if(!this.body){this.body=new i.bodyView(f.merge(h,i.bodyConfig));}this.fire("renderBody",{view:this.body});}if(!g.contains(this.tableNode)){g.append(this.tableNode);}this._bindUI();},destructor:function(){if(this.head&&this.head.destroy){this.head.destroy();}delete this.head;if(this.foot&&this.foot.destroy){this.foot.destroy();}delete this.foot;if(this.body&&this.body.destroy){this.body.destroy();}delete this.body;if(this._eventHandles){this._eventHandles.detach();delete this._eventHandles;}if(this.tableNode){this.tableNode.remove().destroy(true);}},_extractDisplayColumns:function(){var g=this.get("columns"),i=[];function h(m){var l,j,k;for(l=0,j=m.length;l<j;++l){k=m[l];if(a(k.children)){h(k.children);}else{i.push(k);}}}h(g);this.displayColumns=i;},_initEvents:function(){this.publish({renderTable:{defaultFn:f.bind("_defRenderTableFn",this)},renderHeader:{defaultFn:f.bind("_defRenderHeaderFn",this)},renderBody:{defaultFn:f.bind("_defRenderBodyFn",this)},renderFooter:{defaultFn:f.bind("_defRenderFooterFn",this)}});},initializer:function(g){this.host=g.host;this._initEvents();this._extractDisplayColumns();this.after("columnsChange",this._extractDisplayColumns,this);},_relayAttrChange:function(h){var g=h.attrName,i=h.newVal;if(this.head){this.head.set(g,i);}if(this.foot){this.foot.set(g,i);}if(this.body){if(g==="columns"){i=this.displayColumns;}this.body.set(g,i);}},render:function(){if(this.get("container")){this.fire("renderTable",{headerView:this.get("headerView"),headerConfig:this.get("headerConfig"),bodyView:this.get("bodyView"),bodyConfig:this.get("bodyConfig"),footerView:this.get("footerView"),footerConfig:this.get("footerConfig")});}return this;},_uiSetCaption:function(i){var h=this.tableNode,g=this.captionNode;if(i){if(!g){this.captionNode=g=f.Node.create(d(this.CAPTION_TEMPLATE,{className:this.getClassName("caption")}));h.prepend(this.captionNode);}g.setHTML(i);}else{if(g){g.remove(true);delete this.captionNode;}}},_uiSetSummary:function(g){if(g){this.tableNode.setAttribute("summary",g);}else{this.tableNode.removeAttribute("summary");}},_uiSetWidth:function(g){var h=this.tableNode;h.setStyle("width",!g?"":(this.get("container").get("offsetWidth")-(parseInt(h.getComputedStyle("borderLeftWidth"),10)|0)-(parseInt(h.getComputedStyle("borderLeftWidth"),10)|0))+"px");h.setStyle("width",g);},_validateView:function(g){return e(g)&&g.prototype.render;}},{ATTRS:{columns:{validator:a},width:{value:"",validator:b.isString},headerView:{value:f.DataTable.HeaderView,validator:"_validateView"},footerView:{validator:"_validateView"},bodyView:{value:f.DataTable.BodyView,validator:"_validateView"}}});},"3.6.0pr3",{requires:["datatable-core","datatable-head","datatable-body","view","classnamemanager"]});