// 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:widgets/Query/setting/SortFields.html":'\x3cdiv\x3e\r\n\t\x3cdiv\x3e${nls.configureFieldsTip}\x3c/div\x3e\r\n\t\x3cdiv class\x3d"add-with-icon" data-dojo-attach-event\x3d"onclick:_onAddNewClicked"\x3e\r\n\t\t\x3cspan class\x3d"jimu-icon jimu-icon-add"\x3e\x3c/span\x3e\r\n\t\t\x3cspan class\x3d"add-label"\x3e${nls.addNew}\x3c/span\x3e\r\n\t\x3c/div\x3e\r\n\t\x3cdiv data-dojo-attach-point\x3d"tableDiv"\x3e\x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dijit/registry dijit/form/Select dojo/text!./SortFields.html dojo/on dojo/query dojo/_base/lang dojo/_base/array dojo/_base/html jimu/dijit/SimpleTable".split(" "),function(p,q,r,t,l,m,u,h,k,d,f,n,v){return p([q,r,t],{baseClass:"jimu-query-setting-sort-fields",templateString:u,_allFieldNames:null,_sortTipClassName:"sort-tip",_fieldNameSelectClassName:"field-name-select",_sortTypeSelectClassName:"sort-type-select",
nls:null,layerDefinition:null,orderByFields:null,validSortFieldTypes:[],postCreate:function(){this.inherited(arguments);var b=f.filter(this.layerDefinition.fields,d.hitch(this,function(a){return 0<=this.validSortFieldTypes.indexOf(a.type)}));this._allFieldNames=f.map(b,function(a){return a.name});this._initTable();this.orderByFields?this._setOrderByFields(this.orderByFields):this.orderByFields=[]},_initTable:function(){var b={autoHeight:!1,style:"height:187px",fields:[{name:"sortTip",title:this.nls.field,
type:"text",width:"100px"},{name:"fieldName",title:"",type:"extension",create:d.hitch(this,this._create4FieldName),setValue:d.hitch(this,this._setValue4FieldName),getValue:d.hitch(this,this._getValue4FieldName)},{name:"sortType",title:this.nls.sortingOrder,type:"extension",create:d.hitch(this,this._create4SortType),setValue:d.hitch(this,this._setValue4SortType),getValue:d.hitch(this,this._getValue4SortType)},{name:"actions",title:this.nls.actions,type:"actions",actions:["up","down","delete"],width:"120px"}]};
this.table=new v(b);this.own(h(this.table,"row-up",d.hitch(this,this._onTableRowUp)));this.own(h(this.table,"row-down",d.hitch(this,this._onTableRowDown)));this.table.placeAt(this.tableDiv);this.table.startup()},getOrderByFields:function(){var b=this.table.getData();return f.map(b,d.hitch(this,function(a){return a.fieldName+" "+a.sortType}))},_getFieldAlias:function(b){for(var a=this.layerDefinition.fields,c=0;c<a.length;c++)if(a[c].name===b)return b=a[c].alias||b;return b},_getRestFields:function(){var b=
this._getAllFieldSelects(),a=f.map(b,d.hitch(this,function(c){return c.get("value")}));return f.filter(this._allFieldNames,d.hitch(this,function(c){return 0>a.indexOf(c)}))},_onAddNewClicked:function(){var b=this._getRestFields();if(0!==b.length){var a="";a=0===this.table.getRows().length?this.nls.sortBy:this.nls.thenBy;this.table.addRow({sortTip:a,fieldName:b[0],sortType:"ASC"})}},_setOrderByFields:function(b){this.table.clear();b=b||[];f.forEach(b,d.hitch(this,function(a,c){var e=a.split(" ");a=
e[0];var g="ASC";e[1]&&"string"===typeof e[1]&&(e[1]=e[1].toUpperCase(),"DESC"===e[1]&&(g="DESC"));e="";e=0===c?this.nls.sortBy:this.nls.thenBy;this.table.addRow({sortTip:e,fieldName:a,sortType:g})}))},_getAllFieldSelects:function(){var b=k("."+this._fieldNameSelectClassName,this.table.tbody);return f.map(b,d.hitch(this,function(a){return l.byNode(a)}))},_getSelectFromTd:function(b,a){b=k("."+a,b)[0];return l.byNode(b)},_onTableRowUp:function(){this._resetSortTips()},_onTableRowDown:function(){this._resetSortTips()},
_getAllSortTipDivs:function(){return k(".sortTip .normal-text-div",this.table.tbody)},_resetSortTips:function(){var b=this.table.getRows();f.forEach(b,d.hitch(this,function(a,c){var e="";e=0===c?this.nls.sortBy:this.nls.thenBy;this.table.editRow(a,{sortTip:e})}));b=this._getAllSortTipDivs();f.forEach(b,d.hitch(this,function(a,c){a.innerHTML=0===c?this.nls.sortBy:this.nls.thenBy}))},_create4FieldName:function(b){var a=this._getRestFields(),c=new m({style:"width:120px;height:20px;"});n.addClass(c.domNode,
this._fieldNameSelectClassName);c.placeAt(b);f.forEach(a,d.hitch(this,function(e){var g=this._getFieldAlias(e);c.addOption({value:e,label:g})}));this.own(h(c,"change",d.hitch(this,this._onFieldNameSelectChanged)))},_setValue4FieldName:function(b,a){this._getSelectFromTd(b,this._fieldNameSelectClassName).set("value",a)},_getValue4FieldName:function(b){return this._getSelectFromTd(b,this._fieldNameSelectClassName).get("value")},_onFieldNameSelectChanged:function(){var b=this._getAllFieldSelects();f.forEach(b,
d.hitch(this,function(a){var c=a.get("value"),e=a.getOptions();e=f.filter(e,d.hitch(this,function(g){return g.value!==c}));a.removeOption(e);e=this._getRestFields();f.forEach(e,d.hitch(this,function(g){if(g!==c){var w=this._getFieldAlias(g);a.addOption({value:g,label:w})}}))}))},_create4SortType:function(b){var a=new m({style:"width:120px;height:20px;"});n.addClass(a.domNode,this._sortTypeSelectClassName);a.placeAt(b);a.addOption({value:"ASC",label:this.nls.ascending,selected:!0});a.addOption({value:"DESC",
label:this.nls.descending})},_setValue4SortType:function(b,a){b=this._getSelectFromTd(b,this._sortTypeSelectClassName);"ASC"!==a&&"DESC"!==a||b.set("value",a)},_getValue4SortType:function(b){return this._getSelectFromTd(b,this._sortTypeSelectClassName).get("value")}})});