/*
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-core",function(a){var d=a.Attribute.INVALID_VALUE,f=a.Lang,c=f.isFunction,k=f.isObject,g=f.isArray,b=f.isString,j=f.isNumber,e=a.Array,i=a.Object.keys,h;h=a.namespace("DataTable").Core=function(){};h.ATTRS={columns:{validator:g,setter:"_setColumns",getter:"_getColumns"},recordType:{getter:"_getRecordType",setter:"_setRecordType"},data:{valueFn:"_initData",setter:"_setData",lazyAdd:false},recordset:{setter:"_setRecordset",getter:"_getRecordset",lazyAdd:false},columnset:{setter:"_setColumnset",getter:"_getColumnset",lazyAdd:false}};a.mix(h.prototype,{getColumn:function(n){var m,p,o,l,q;if(k(n)&&!g(n)){m=n;}else{m=this.get("columns."+n);}if(m){return m;}p=this.get("columns");if(j(n)||g(n)){n=e(n);q=p;for(o=0,l=n.length-1;q&&o<l;++o){q=q[n[o]]&&q[n[o]].children;}return(q&&q[n[o]])||null;}return null;},getRecord:function(m){var l=this.data.getById(m)||this.data.getByClientId(m);if(!l){if(j(m)){l=this.data.item(m);}if(!l&&this.view&&this.view.getRecord){l=this.view.getRecord.apply(this.view,arguments);}}return l||null;},_allowAdHocAttrs:true,_afterColumnsChange:function(l){this._setColumnMap(l.newVal);},_afterDataChange:function(m){var l=m.newVal;this.data=m.newVal;if(!this.get("columns")&&l.size()){this._initColumns();}},_afterRecordTypeChange:function(m){var l=this.data.toJSON();this.data.model=m.newVal;this.data.reset(l);if(!this.get("columns")&&l){if(l.length){this._initColumns();}else{this.set("columns",i(m.newVal.ATTRS));}}},_createRecordClass:function(n){var m,o,l;if(g(n)){m={};for(o=0,l=n.length;o<l;++o){m[n[o]]={};}}else{if(k(n)){m=n;}}return a.Base.create("record",a.Model,[],null,{ATTRS:m});},destructor:function(){new a.EventHandle(a.Object.values(this._eventHandles)).detach();},_getColumns:function(m,l){return l.length>8?this._columnMap:m;},_getColumnset:function(m,l){return this.get(l.replace(/^columnset/,"columns"));},_getRecordType:function(l){return l||(this.data&&this.data.model);},_initColumns:function(){var l=this.get("columns")||[],m;if(!l.length&&this.data.size()){m=this.data.item(0);if(m.toJSON){m=m.toJSON();}this.set("columns",i(m));}this._setColumnMap(l);},_initCoreEvents:function(){this._eventHandles.coreAttrChanges=this.after({columnsChange:a.bind("_afterColumnsChange",this),recordTypeChange:a.bind("_afterRecordTypeChange",this),dataChange:a.bind("_afterDataChange",this)});},_initData:function(){var m=this.get("recordType"),l=new a.ModelList();if(m){l.model=m;}return l;},_initDataProperty:function(l){var m;if(!this.data){m=this.get("recordType");if(l&&l.each&&l.toJSON){this.data=l;if(m){this.data.model=m;}}else{this.data=new a.ModelList();if(m){this.data.model=m;}}this.data.addTarget(this);}},initializer:function(l){var n=l.data,m=l.columns,o;this._initDataProperty(n);if(!m){o=(l.recordType||l.data===this.data)&&this.get("recordType");if(o){m=i(o.ATTRS);}else{if(g(n)&&n.length){m=i(n[0]);}}if(m){this.set("columns",m);}}this._initColumns();this._eventHandles={};this._initCoreEvents();},_setColumnMap:function(l){var n={};function m(s){var r,o,p,q;for(r=0,o=s.length;r<o;++r){p=s[r];q=p.key;if(q&&!n[q]){n[q]=p;}n[p._id]=p;if(p.children){m(p.children);}}}m(l);this._columnMap=n;},_setColumns:function(s){var p={},o=[],n=[],m=a.Array.indexOf;function l(w){var x={},u,v,t;o.push(w);n.push(x);for(u in w){if(w.hasOwnProperty(u)){v=w[u];if(g(v)){x[u]=v.slice();}else{if(k(v,true)){t=m(v,o);x[u]=t===-1?l(v):n[t];}else{x[u]=w[u];}}}}return x;}function r(t){t=t.replace(/\s+/,"-");if(p[t]){t+=(p[t]++);}else{p[t]=1;}return t;}function q(z,y){var x=[],w,t,u,v;for(w=0,t=z.length;w<t;++w){x[w]=u=b(z[w])?{key:z[w]}:l(z[w]);v=a.stamp(u);if(!u.id){u.id=v;}if(u.field){u.name=u.field;}if(y){u._parent=y;}else{delete u._parent;}u._id=r(u.name||u.key||u.id);if(g(u.children)){u.children=q(u.children,u);}}return x;}return s&&q(s);},_setColumnset:function(l){this.set("columns",l);return g(l)?l:d;},_setData:function(l){if(l===null){l=[];}if(g(l)){this._initDataProperty();this.data.reset(l,{silent:true});l=this.data;}else{if(!l||!l.each||!l.toJSON){l=d;}}return l;},_setRecordset:function(m){var l;if(m&&a.Recordset&&m instanceof a.Recordset){l=[];m.each(function(n){l.push(n.get("data"));});m=l;}this.set("data",m);return m;},_setRecordType:function(m){var l;if(c(m)&&m.prototype.toJSON&&m.prototype.setAttrs){l=m;}else{if(k(m)){l=this._createRecordClass(m);}}return l||d;}});},"3.6.0pr3",{requires:["escape","model-list","node-event-delegate"]});