// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
require({cache:{"url:jimu/dijit/_filter/pageControlForQuery.html":'\x3cdiv class\x3d"pageControl pageItem"\x3e\r\n  \x3c!--\r\n  \x3cdiv data-dojo-attach-point\x3d"prevPage" class\x3d"pageBtn pageDisabled pageItem"\x3e\x3c-prevPage\x3c/div\x3e\r\n  \x3cdiv class\x3d"pageItem" data-dojo-attach-point\x3d"currentPage"\x3e1\x3c/div\x3e\r\n  \x3cdiv data-dojo-attach-point\x3d"nextPage" class\x3d"pageBtn pageItem"\x3enextPage-\x3e\x3c/div\x3e\r\n  --\x3e\r\n\r\n  \x3c!-- \x3cdiv data-dojo-attach-point\x3d"addNextPage"\x3eLoad more data(Test)\x3c/div\x3e --\x3e\r\n\x3c/div\x3e'}});
define("dojo/Deferred esri/tasks/query dojo/_base/array dojo/_base/lang dojo/_base/declare jimu/Query jimu/LayerStructure dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dojo/text!./pageControlForQuery.html jimu/filterUtils jimu/utils".split(" "),function(l,m,n,f,r,h,t,u,v,w,x,y,p){return r([u,v,w],{templateString:x,layerUrl:null,fieldInfo:null,fieldPopupInfo:null,spatialReference:null,layerDefinition:null,isNumberField:!1,showNullValues:!1,_isUniqueValueCacheFinish:!1,_uniqueValueCache:{},
_uniqueValueCacheForOtherTypes:{},_codedvalueCache:[],cascadeFilterExprs:"1\x3d1",numbericFieldLength:{esriFieldTypeOID:32,esriFieldTypeSmallInteger:16,esriFieldTypeInteger:32,esriFieldTypeSingle:128,esriFieldTypeDouble:1024},pageIndex:1,pageSize:1E3,postCreate:function(){this.inherited(arguments);this.spatialReference=t.getInstance().map.spatialReference;this.reset();this.queryType=h.getQueryType(this.layerDefinition);this.isNumberField?this.fieldLength=this.numbericFieldLength[this.fieldInfo.type]:
(this.filterUtils=new y,this.isLayerHosted=p.isHostedService(this.layerUrl))},reset:function(){this.pageIndex=1;this._isUniqueValueCacheFinish=!1;this._uniqueValueCache={};this._uniqueValueCacheForOtherTypes={};this._codedvalueCache=[]},isKeyQueryLoader:!1,_searchKey:function(a){var c=new l,b=new m,e="";this.isNumberField?e="CAST("+this.fieldInfo.name+" AS CHAR("+this.fieldLength+")) LIKE '%"+a+"%'":(e=this.isLayerHosted&&this.filterUtils.containsNonLatinCharacter(a)?"N":"",e=this.isLayerHosted?this.fieldInfo.name+
" LIKE "+e+"'%"+a.replace(/'/g,"''")+"%'":"UPPER("+this.fieldInfo.name+") LIKE "+e+"'%"+a.replace(/'/g,"''").toUpperCase()+"%'");b.where="(("+this.cascadeFilterExprs+") AND ("+e+"))";b.geometry=null;b.outSpatialReference=this.spatialReference;b.outFields=[this.fieldInfo.name];b.returnDistinctValues=!0;b.returnGeometry=!1;b.orderByFields=b.outFields;this.layerLoaderForKey=new h({url:this.layerUrl,query:b,pageSize:this.pageSize});this.isKeyQueryLoader=!0;this._uniqueValueCacheForOtherTypes={};this.queryByPage(!0).then(f.hitch(this,
function(d){c.resolve(d)}),f.hitch(this,function(d){c.reject("reject:"+d)}));return c},_searchKeyLocal:function(a){a=a.toUpperCase();this.isKeyQueryLoader=!1;var c=[],b=this._codedvalueCache;if(0<b.length)for(var e=0;e<b.length;e++){var d=b[e];d.label&&0<=d.label.toString().toUpperCase().indexOf(a)&&c.push(d)}else for(e in b=this._uniqueValueCache,b)for(var g=b[e],k=0;k<g.length;k++){d=g[k];var q=d.label;q&&0<=q.toString().toUpperCase().indexOf(a)&&c.push(d)}return c},queryByPage:function(a){var c=
new l;this.layerLoader&&this.layerLoader.query.where!==this.cascadeFilterExprs&&(this.layerLoader=null,this.isKeyQueryLoader=!1,this.reset());if(!this.layerLoader){var b=new m;b.where=this.cascadeFilterExprs;b.geometry=null;b.outSpatialReference=this.spatialReference;b.outFields=[this.fieldInfo.name];b.returnDistinctValues=!0;b.returnGeometry=!1;b.orderByFields=b.outFields;this.layerLoader=new h({url:this.layerUrl,query:b,pageSize:this.pageSize})}a&&(this.pageIndex=1);a=[];if(this.isKeyQueryLoader){if(this._uniqueValueCacheForOtherTypes[this.pageIndex])return a=
this._resolveValueLabelsFromCache(this._uniqueValueCacheForOtherTypes),c.resolve(a),c;a=this.layerLoaderForKey}else{if(this._uniqueValueCache[this.pageIndex])return a=this._resolveValueLabelsFromCache(this._uniqueValueCache),c.resolve(a),c;a=this.layerLoader}1===this.queryType?a.queryByPage(this.pageIndex).then(f.hitch(this,function(e){if(e){var d=e.features||[];e=d.length;this.showNullValues||(d=this._getNotNullValues(d));d=this._getValueLabelsFromFeatures(d);this.isKeyQueryLoader?(this._uniqueValueCacheForOtherTypes[this.pageIndex-
1]=d,e<this.pageSize&&(this._uniqueValueCacheForOtherTypes[this.pageIndex]=[])):(this._uniqueValueCache[this.pageIndex-1]=d,e<this.pageSize&&(this._uniqueValueCache[this.pageIndex]=[],this._isUniqueValueCacheFinish=!0));0===d.length&&this.pageIndex--;c.resolve(d)}else c.reject("Can't get features from current layer")}),f.hitch(this,function(e){c.reject(e)})):a.getAllFeatures().then(f.hitch(this,function(e){if(e){var d=e.features||[];this.showNullValues||(d=this._getNotNullValues(d));e=0<d.length?
!0:!1;d=this._getDistinctValues(d);d=this._getValueLabelsFromFeatures(d);d=this.isKeyQueryLoader?this._getAndStoreValueLabelsForOtherTypes(d,this._uniqueValueCacheForOtherTypes):this._getAndStoreValueLabelsForOtherTypes(d,this._uniqueValueCache);this._isUniqueValueCacheFinish=!0;c.resolve(e?d:[])}else c.reject("Can't get features from current layer")}),f.hitch(this,function(e){c.reject(e)}));this.pageIndex++;return c},_resolveValueLabelsFromCache:function(a){a=a[this.pageIndex];0!==a.length&&this.pageIndex++;
return a},_getAndStoreValueLabelsForOtherTypes:function(a,c){for(var b=0;b<a.length;b+=this.pageSize)c[parseInt(b/this.pageSize,10)+1]=a.slice(b,b+this.pageSize);for(var e in c)a=parseInt(e,10)+1,c[a]||(c[a]=[]);return c[1]},_getDistinctValues:function(a){var c={},b=[],e;for(e in a){var d=a[e],g=d.attributes[this.fieldInfo.name];c[g]||(c[g]=!0,b.push(d))}return b},_getNotNullValues:function(a){return a=n.filter(a,f.hitch(this,function(c){c=c.attributes[this.fieldInfo.name];return"\x3cNull\x3e"!==
c&&null!==c}))},_getValueLabelsFromFeatures:function(a){var c=this.fieldInfo.name;a=n.map(a,function(b){return b.attributes[c]});a=p._getValues(this.layerDefinition,this.fieldPopupInfo,c,a);"esriFieldTypeDate"===this.fieldInfo.type&&(a=this._getDistinctValueLabelsByFormat(a));return a},_getDistinctValueLabelsByFormat:function(a){var c={},b=[],e;for(e in a){var d=a[e].value;c[d]||(c[d]=!0,b.push(a[e]))}return b}})});