//>>built
define("mill/queryBuilder/provider",["dojo/data/ItemFileReadStore","mill/mill"],function(){window.mill||(mill={});mill.queryBuilder||(mill.queryBuilder={});mill.queryBuilder.provider||(mill.queryBuilder.provider={});dojo.mixin(mill.queryBuilder.provider,{dtString:0,dtInteger:1,dtFloat:2,dtDate:3,dtTime:4,dtDateTime:5,dtBoolean:6,dtEnumeration:7,dtReference:8,dtBlob:9,dmAlways:0,dmNever:1,dmOnDemand:2,handle:"",_tables:null,_options:null,options:function(){this._options||(this._options=[],dojo.xhrPost({url:mill.getRequestUrl(this.handle,
"options.xml"),handleAs:"xml",sync:!0,preventCache:!0,load:dojo.hitch(this,function(b){dojo.forEach(b.documentElement.childNodes,dojo.hitch(this,function(a){this._options.push({ID:mill.fieldValue(a,"ID"),Caption:mill.fieldValue(a,"Caption"),Name:mill.fieldValue(a,"Name"),TypeInfoID:mill.fieldValue(a,"TypeInfo"),Group:mill.fieldValue(a,"Group"),Tab:mill.fieldValue(a,"Tab"),Value:mill.fieldValue(a,"Value")})}));return b})}));return this._options},_templates:null,templates:function(){this._templates||
(this._templates=[],dojo.xhrPost({url:mill.getRequestUrl(this.handle,"templates.xml"),handleAs:"xml",sync:!0,preventCache:!0,load:dojo.hitch(this,function(b){dojo.forEach(b.documentElement.childNodes,dojo.hitch(this,function(a){this._templates.push({Name:mill.fieldValue(a,"Name")})}));return b})}));return this._templates},tables:function(b){this._tables||(this._tables={},dojo.xhrPost({url:mill.getRequestUrl(this.handle,"tables.xml"),handleAs:"xml",sync:!0,preventCache:!0,load:dojo.hitch(this,function(a){dojo.forEach(a.documentElement.childNodes,
dojo.hitch(this,function(c){this._tables[mill.fieldValue(c,"ID")]={ID:mill.fieldValue(c,"ID"),Caption:mill.fieldValue(c,"Caption"),Name:mill.fieldValue(c,"Name"),RootAvailable:"1"==mill.fieldValue(c,"RootAvailable"),PrimaryKeyID:mill.fieldValue(c,"PrimaryKeyID"),UplinkID:mill.fieldValue(c,"UplinkID"),HasPersistentClause:"1"==mill.fieldValue(c,"HasPersistentClause")}}));return a})}));return b?this._tables[b]:this._tables},_types:null,types:function(){this._types||(this._types={},dojo.xhrPost({url:mill.getRequestUrl(this.handle,
"types.xml"),handleAs:"xml",sync:!0,preventCache:!0,load:dojo.hitch(this,function(b){dojo.forEach(b.documentElement.childNodes,dojo.hitch(this,function(a){var c={ID:mill.fieldValue(a,"ID"),Name:mill.fieldValue(a,"Name"),Caption:mill.fieldValue(a,"Caption"),SimpleType:parseInt(mill.fieldValue(a,"SimpleType")),Required:"1"==mill.fieldValue(a,"Required")};switch(c.SimpleType){case this.dtString:dojo.mixin(c,{Length:parseInt(mill.fieldValue(a,"Length"))});break;case this.dtReference:dojo.mixin(c,{TableID:mill.fieldValue(a,
"TargetTableID")})}this._types[mill.fieldValue(a,"ID")]=c}));return b})}));return this._types},tablesStore:function(b){var a=this.tables(),c={identifier:"ID",label:"Caption",items:[]},d;for(d in a)b?b(a[d])&&c.items.push(dojo.clone(a[d])):c.items.push(dojo.clone(a[d]));c.items.sort(this._compareCaptions);return new dojo.data.ItemFileReadStore({data:c})},fields:function(b){var a=this.tables(b);if(a)return a.fields&&a.preConditions||(a.fields={},a.preConditions=[],dojo.xhrPost({url:mill.getRequestUrl(this.handle,
"fields.xml"),handleAs:"xml",sync:!0,preventCache:!0,content:{table:b},load:dojo.hitch(this,function(c){dojo.forEach(c.documentElement.childNodes,dojo.hitch(this,function(d){if("field"==d.nodeName)a.fields[mill.fieldValue(d,"ID")]={ID:mill.fieldValue(d,"ID"),Name:mill.fieldValue(d,"Name"),Caption:mill.fieldValue(d,"Caption"),TypeInfoID:mill.fieldValue(d,"TypeInfo"),DisplayMode:mill.fieldValue(d,"DisplayMode"),Category:mill.fieldValue(d,"Category")};else if("preCondition"==d.nodeName){var e=d.getElementsByTagName("parameter"),
g={ID:mill.fieldValue(d,"ID"),Caption:mill.fieldValue(d,"Caption"),Category:mill.fieldValue(d,"Category"),Parameters:[]};dojo.forEach(e,function(f){g.Parameters.push({ID:mill.fieldValue(f,"ID"),Caption:mill.fieldValue(f,"Caption"),Name:mill.fieldValue(f,"Name"),TypeInfoID:mill.fieldValue(f,"TypeInfo"),Group:mill.fieldValue(f,"Group"),Tab:mill.fieldValue(f,"Tab"),Value:mill.fieldValue(f,"Value")})});a.preConditions.push(g)}}));return c})})),a.fields},_compareCaptions:function(b,a){return b.Caption>
a.Caption?1:b.Caption<a.Caption?-1:0},gridData:function(b,a){return this.gridDataArgs({sync:!1,content:a?{handle:a}:{query:b}})},gridDataArgs:function(b){dojo.mixin(b,{url:mill.getRequestUrl(this.handle,"gridData.xml"),preventCache:!0,handleAs:"xml"});return dojo.xhrPost(b)},closeGridData:function(b){return dojo.xhrPost({url:mill.getRequestUrl(this.handle,"closeGridData.xml"),handleAs:"xml",sync:!1,preventCache:!0,content:{handle:b}})},downloadExcel:function(b,a,c,d){var e=document.createElement("form");
if(dojo.isIE){e.insertAdjacentHTML("afterBegin","\x3cinput type\x3d'hidden' name\x3d'query'/\x3e");var g=e.childNodes[0]}else g=e.appendChild(document.createElement("input")),g.type="hidden",g.name="query";if(dojo.isIE){e.insertAdjacentHTML("afterBegin","\x3cinput type\x3d'hidden' name\x3d'titles'/\x3e");var f=e.childNodes[0]}else f=e.appendChild(document.createElement("input")),f.type="hidden",f.name="titles";if(dojo.isIE){e.insertAdjacentHTML("afterBegin","\x3cinput type\x3d'hidden' name\x3d'template'/\x3e");
var h=e.childNodes[0]}else h=e.appendChild(document.createElement("input")),h.type="hidden",h.name="template";e.method="POST";e.action=mill.getRequestUrl(this.handle,"excelWorkBook"+(d||".xls"));e.target="_blank";g.value=b;f.value=a;h.value=c;document.body.appendChild(e);e.submit();document.body.removeChild(e)},persistentClause:function(b,a){var c,d=this._tables[b];d&&(d.PersistentClauses?c=d.PersistentClauses[a]:d.PersistentClauses={});c||dojo.xhrPost({url:mill.getRequestUrl(this.handle,"persistentClause.xml"),
handleAs:"xml",sync:!0,preventCache:!0,content:{table:b,alias:a},load:function(e){c=mill.decodeDataNode(e.documentElement);d&&(d.PersistentClauses[a]=c);return e}});return c}})});