happstack-yui-7351.0.0: bundle/datatable-core/datatable-core-min.js
/*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("datatable-core",function(b){var e=b.Attribute.INVALID_VALUE,g=b.Lang,d=g.isFunction,m=g.isObject,h=g.isArray,c=g.isString,l=g.isNumber,j=g.sub,f=b.Array,k=b.Object.keys,i;function a(p){var q={},n;for(n in p){q[n]=p[n];}return q;}i=b.namespace("DataTable").Core=function(){};i.ATTRS={columns:{validator:h,getter:"_getColumns"},recordType:{setter:"_setRecordType",writeOnce:true},data:{value:[],setter:"_setData",getter:"_getData"},headerView:{validator:"_validateView",writeOnce:true},footerView:{validator:"_validateView",writeOnce:true},bodyView:{validator:"_validateView",writeOnce:true},summary:{value:"",setter:b.Escape.html},caption:{value:""},recordset:{setter:"_setRecordset",getter:"_getRecordset",lazyAdd:false},columnset:{setter:"_setColumnset",getter:"_getColumnset",lazyAdd:false}};b.mix(i.prototype,{CAPTION_TEMPLATE:'<caption class="{className}"/>',TABLE_TEMPLATE:'<table cellspacing="0" class="{className}"/>',TBODY_TEMPLATE:'<tbody class="{className}"/>',TFOOT_TEMPLATE:'<tfoot class="{className}"/>',THEAD_TEMPLATE:'<thead class="{className}"/>',delegate:function(){var n=this.get("contentBox");return n.delegate.apply(n,arguments);},getCell:function(o,n){return this.body&&this.body.getCell&&this.body.getCell.apply(this.body,arguments);},getColumn:function(p){var o,r,q,n,s;if(m(p)&&!h(p)){o=p;}else{o=this.get("columns."+p);}if(o){return o;}r=this.get("columns");if(l(p)||h(p)){p=f(p);s=r;for(q=0,n=p.length-1;s&&q<n;++q){s=s[p[q]]&&s[p[q]].children;}return(s&&s[p[q]])||null;}return null;},getRecord:function(o){var n=this.data.getById(o)||this.data.getByClientId(o);if(!n){if(l(o)){n=this.data.item(o);}if(!n&&this.body&&this.body.getRecord){n=this.body.getRecord.apply(this.body,arguments);}}return n||null;},getRow:function(n){return this.body&&this.body.getRow&&this.body.getRow.apply(this.body,arguments);},syncUI:function(){this._uiSetCaption(this.get("caption"));this._uiSetSummary(this.get("summary"));if(this.head){this.fire("renderHeader",{view:this.head});}if(this.body){this.fire("renderBody",{view:this.body});}if(this.foot){this.fire("renderFooter",{view:this.foot});}},_afterColumnsChange:function(n){this._setColumnMap(n.newVal);this._setDisplayColumns(n.newVal);},_afterDataChange:function(o){var n=o.newVal;if(this.head){this.head.set("modelList",n);}if(this.body){this.body.set("modelList",n);}if(this.foot){this.foot.set("modelList",n);}},bindUI:function(){this.after("dataChange",b.bind("_afterDataChange",this));},_createRecordClass:function(p){var o,q,n;if(h(p)){o={};for(q=0,n=p.length;q<n;++q){o[p[q]]={};}}else{if(m(p)){o=p;}}return b.Base.create("record",b.Model,[],null,{ATTRS:o});},_createTable:function(){return b.Node.create(j(this.TABLE_TEMPLATE,{className:this.getClassName("table")})).empty();},_createTBody:function(){return b.Node.create(j(this.TBODY_TEMPLATE,{className:this.getClassName("data")}));},_createTFoot:function(){return b.Node.create(j(this.TFOOT_TEMPLATE,{className:this.getClassName("footer")}));},_createTHead:function(){return b.Node.create(j(this.THEAD_TEMPLATE,{className:this.getClassName("columns")}));},_defRenderBodyFn:function(n){n.view.render();},_defRenderFooterFn:function(n){n.view.render();},_defRenderHeaderFn:function(n){n.view.render();},_defRenderTableFn:function(o){var n;this._tableNode=this._createTable();if(o.headerView){n=a(o.headerConfig||{});n.container=this._theadNode=this._createTHead();this.head=new o.headerView(n);this.head.addTarget(this);this._tableNode.insertBefore(this._theadNode,this._tableNode.one("> tfoot, > tbody"));}if(o.footerView){n=a(o.footerConfig||{});n.container=this._tfootNode=this._createTFoot();this.foot=new o.footerView(n);this.foot.addTarget(this);this._tableNode.insertBefore(this._tfootNode,this._tableNode.one("> tbody"));}if(o.bodyView){n=a(o.bodyConfig||{});n.container=this._tbodyNode=this._createTBody();this.body=new o.bodyView(n);this.body.addTarget(this);this._tableNode.append(this._tbodyNode);}},_getColumns:function(o,n){return n.length>8?this._columnMap:o;},_getColumnset:function(o,n){return this.get(n.replace(/^columnset/,"columns"));},_getData:function(n){return this.data||n;},_initColumns:function(){var n=this.get("columns"),o=this.get("recordType");if(!n){n=(o&&o.ATTRS)?k(o.ATTRS):[];this.set("columns",n,{silent:true});}this._setColumnMap(n);this._setDisplayColumns(n);},_initData:function(){var o=this.get("data"),p,n;if(h(o)){p=this.get("recordType");n=o;o=new b.ModelList();if(p){o.model=p;o.reset(n,{silent:true});}this.set("data",o,{silent:true});}this.data=o;this.data.addTarget(this);},_initEvents:function(){this.publish({renderTable:{fireOnce:true,defaultFn:b.bind("_defRenderTableFn",this)},renderHeader:{defaultFn:b.bind("_defRenderHeaderFn",this)},renderBody:{defaultFn:b.bind("_defRenderBodyFn",this)},renderFooter:{defaultFn:b.bind("_defRenderFooterFn",this)}});},initializer:function(){this._initColumns();this._initRecordType();this._initData();this._initViewConfig();this._initEvents();this.after("columnsChange",this._afterColumnsChange);this._UI_ATTRS={BIND:this._UI_ATTRS.BIND.concat(["caption","summary"]),SYNC:this._UI_ATTRS.SYNC.concat(["caption","summary"])};},_initRecordType:function(){var q,n,r,p,o;if(!this.get("recordType")){q=this.get("data");n=this._columnMap;if(q.model){r=q.model;}else{if(q.size&&q.size()){r=q.model=q.item(0).constructor;}else{if(h(q)&&q.length){r=(q[0].constructor.ATTRS)?q[0].constructor:this._createRecordClass(k(q[0]));}else{o=k(n);if(o.length){r=this._createRecordClass(o);}}}}if(r){this.set("recordType",r,{silent:true});if(!n||!n.length){this._initColumns();}}else{p=this.after(["columnsChange","recordTypeChange","dataChange"],function(s){p.detach();if(!this.data.model){this._initRecordType();this.data.model=this.get("recordType");}});}}},_initViewConfig:function(){this._viewConfig={source:this,cssPrefix:this._cssPrefix};this._headerConfig=b.Object(this._viewConfig);this._bodyConfig=b.Object(this._viewConfig);this._footerConfig=b.Object(this._viewConfig);},_parseColumns:function(n){var r={},o={};
function q(s){s=s.replace(/\s+/,"-");if(o[s]){s+=(o[s]++);}else{o[s]=1;}return s;}function p(y,x){var w,s,t,v,u;for(w=0,s=y.length;w<s;++w){t=y[w];if(c(t)){y[w]=t={key:t};}u=b.stamp(t);if(!t.id){t.id=u;}if(t.field){t.name=t.field;}if(x){t._parent=x;}else{delete t._parent;}if(h(t.children)){if(t.name){r[q(t.name)]=t;}p(t.children,t);}else{v=t.key;if(v&&!r[v]){r[v]=t;}t._id=q(t.name||t.key||t.id);r[t._id]=t;}}}p(n);return r;},renderUI:function(){var n=this.get("contentBox"),o;if(n){this._viewConfig.columns=this.get("columns");this._viewConfig.modelList=this.data;this.fire("renderTable",{headerView:this.get("headerView"),headerConfig:this._headerConfig,bodyView:this.get("bodyView"),bodyConfig:this._bodyConfig,footerView:this.get("footerView"),footerConfig:this._footerConfig});o=this._tableNode;if(o){if(!o.inDoc()||!o.ancestor().compareTo(n)){n.append(o);}}}},_setColumnMap:function(n){this._columnMap=this._parseColumns(n);},_setColumnset:function(n){if(n&&b.Columnset&&n instanceof b.Columnset){n=n.get("definitions");}this.set("columns",n);return h(n)?n:e;},_setData:function(n){if(n===null){n=[];}if(h(n)){if(this.data){if(!this.data.model&&n.length){this.set("recordType",k(n[0]));}this.data.reset(n);n=this.data;}}else{if(n&&n.each&&n.getAttrs){this.data=n;}else{n=e;}}return n;},_setDisplayColumns:function(n){function o(t){var s=[],r,p,q;for(r=0,p=t.length;r<p;++r){q=t[r];if(q.children){s.push.apply(s,o(q.children));}else{s.push(q);}}return s;}this._displayColumns=o(n);},_setRecordset:function(o){var n;if(o&&b.Recordset&&o instanceof b.Recordset){n=[];o.each(function(p){n.push(p.get("data"));});o=n;}this.set("data",o);return o;},_setRecordType:function(o){var n;if(d(o)&&o.prototype.set&&o.prototype.getAttrs){n=o;}else{if(m(o)){n=this._createRecordClass(o);}}return n||e;},_uiSetCaption:function(p){var o=this._tableNode,n=this._captionNode;if(p){if(!n){this._captionNode=n=b.Node.create(j(this.CAPTION_TEMPLATE,{className:this.getClassName("caption")}));o.prepend(this._captionNode);}n.setContent(p);}else{if(n){n.remove(true);delete this._captionNode;}}},_uiSetSummary:function(n){if(n){this._tableNode.setAttribute("summary",n);}else{this._tableNode.removeAttribute("summary");}},_uiSetWidth:function(n){var o=this._tableNode;if(l(n)){n+=this.DEF_UNIT;}if(c(n)){this._uiSetDim("width",n);o.setStyle("width",!n?"":(this.get("boundingBox").get("offsetWidth")-(parseInt(o.getComputedStyle("borderLeftWidth"),10)|0)-(parseInt(o.getComputedStyle("borderLeftWidth"),10)|0))+"px");o.setStyle("width",n);}},_validateView:function(n){return n===null||(d(n)&&n.prototype.render);}});},"3.5.1",{requires:["escape","model-list","node-event-delegate"]});