/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */
//>>built
define("esri/dijit/geoenrichment/BaseWidget",["../../declare","dojo/_base/lang","dojo/Evented","dojo/dom-construct","dojo/dom-attr","./dom","dojo/on","./lang","dijit/Destroyable","dijit/layout/BorderContainer","dijit/layout/ContentPane"],function(_1,_2,_3,_4,_5,_6,on,_7,_8,_9,_a){function _b(a,b,_c){if(a>b){return _c?-1:1;}else{if(a<b){return _c?1:-1;}else{return 0;}}};var _d=_1("esri.dijit.geoenrichment.BaseWidget",[_3],{parent:null,dataEvents:null,_state:null,_widthExpanded:280,_widthCollapsed:217,autoWidth:true,autoHeight:true,expanded:true,constructor:function(_e){if(!_e){throw "Parent HTML element was not specified";}this._state={sortBy:0,sortDesc:false};this.parent=_e;},setDataProvider:function(_f){this._destroyDataEvents();if(!_f){return;}this.feedData(_f);this.dataEvents=new _8();this.dataEvents.own(_f.on("data",_2.hitch(this,this.feedData,_f)));},_destroyDataEvents:function(){if(this.dataEvents){this.dataEvents.destroy();this.dataEvents=null;}},feedData:function(_10){this._data=_10.getData();this.update();},destroy:function(_11){if(!_11){this._destroyDataEvents();}if(this._root){_4.destroy(this._root);this._root=null;}if(this.ui){this.ui.destroy();}},updateUI:function(){if(this.sortTriangles){for(var i in this.sortTriangles){if(this._state.sortBy==+i){if(this._state.sortDesc){this.sortTriangles[i].innerHTML="&#9660;";}else{this.sortTriangles[i].innerHTML="&#9650;";}}else{this.sortTriangles[i].innerHTML="";}}}var _12=this._data.title;if(!_12){this.title.innerHTML="";this.title.style.display="none";}else{this.title.innerHTML=_12;this.title.style.display="block";}},updateUIExpanded:function(){this.updateUI();},updateUICollapsed:function(){this.updateUI();},createUI:function(_13){this.title=_13.addHeader("div",{"class":"BaseWidget_Title"});},createUIExpanded:function(_14){this.createUI(_14);},createUICollapsed:function(_15){this.createUI(_15);},createUIPrivate:function(){var _16;if(this.autoHeight){_16=new _17();}else{_16=new _18();}if(this.expanded){this.createUIExpanded(_16);}else{this.createUICollapsed(_16);}this.ui=_16.build(this._root);},updateUIPrivate:function(){if(this.expanded){this.updateUIExpanded();}else{this.updateUICollapsed();}this.ui.resize();on.emit(this,"resize",[this._root.scrollWidth,this._root.scrollHeight]);},updateSize:function(){if(this.autoWidth){var _19=this.expanded?this._widthExpanded:this._widthCollapsed;this._root.style.width=_19+"px";}else{this._root.style.width="100%";}if(this.autoHeight){this._root.style.height="auto";}else{this._root.style.height="100%";}},update:function(){var _1a=this;if(!this._data||!this._state){return;}if(!this._root){this._root=_4.create("div",{"class":"WidgetBack"},this.parent);this.updateSize();this.createUIPrivate();}this.updateUIPrivate();},_appendSortHeader:function(tr,_1b,_1c,_1d){var td=tr.insertCell(-1);for(var _1e in _1d){_5.set(td,_1e,_1d[_1e]);}var _1f=_4.create("span",{"class":"SortLink",innerHTML:_1b},td);_1f.onclick=_2.hitch(this,this.sortBy,_1c);_6.text(_1f," ");if(!this.sortTriangles){this.sortTriangles=[];}this.sortTriangles[_1c]=_4.create("span",{"class":"SortArrow"},_1f);},sortBy:function(_20){if(this._state.sortBy==_20){this._state.sortDesc=!this._state.sortDesc;}else{this._state.sortDesc=false;}this._state.sortBy=_20;this.updateUIPrivate();},_sortRows:function(_21){var by=this._state.sortBy;if(_7.isNumber(by)){var _22=this._state.sortDesc;_21.sort(function(_23,_24){return _b(_23[by],_24[by],_22);});}},_getNumericFields:function(){var _25=[];for(var i=0;i<this._data.getColCount();i++){var _26=this._data.getCol(i);if(_26.name=="NAME"){continue;}_25.push(i);}return _25;},setState:function(_27){_2.mixin(this._state,_27);},getState:function(key){return this._state?this._state[key]:null;}});var _28=_1(null,{headerClass:null,contentClass:null,footerClass:null,constructor:function(){this.headerClass=["BaseWidget_HeaderPane"];this.contentClass=["BaseWidget_ContentPane"];this.footerClass=["BaseWidget_FooterPane"];},addHeader:function(_29,_2a){if(!this.header){this.header=document.createDocumentFragment();}return _4.create(_29,_2a,this.header);},addContent:function(_2b,_2c){if(!this.content){this.content=document.createDocumentFragment();}return _4.create(_2b,_2c,this.content);},addFooter:function(_2d,_2e){if(!this.footer){this.footer=document.createDocumentFragment();}return _4.create(_2d,_2e,this.footer);},build:function(_2f){throw "Not implemented";}});var _17=_1([_28],{build:function(_30){this._append(_30,this.header,this.headerClass);this._append(_30,this.content,this.contentClass);this._append(_30,this.footer,this.footerClass);return {resize:function(){},destroy:function(){}};},_append:function(_31,_32,_33){if(!_32){return;}if(!_33||_33.length==0){_31.appendChild(_32);}else{var _34=_4.create("div",{"class":_33.join(" ")},_31);_34.appendChild(_32);}}});var _18=_1([_28],{build:function(_35){this.border=new _9({style:"height: 100%; width: 100%;",gutters:false});this._append("top",this.header,this.headerClass);this._append("center",this.content,this.contentClass);this._append("bottom",this.footer,this.footerClass);_35.appendChild(this.border.domNode);return this.border;},_append:function(_36,_37,_38){if(!_37){return;}var _39;if(_38&&_38.length>0){_39=_38.join(" ");}this.border.addChild(new _a({region:_36,content:_37,"class":_39}));}});return _d;});