// 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
define("dojo/_base/declare dijit/_WidgetBase dijit/_TemplatedMixin dojo/Evented dojo/_base/lang dojo/_base/html dojo/_base/array dojo/on dojo/query dijit/registry jimu/utils jimu/dijit/CheckBox dijit/form/Select".split(" "),function(w,x,y,z,h,d,m,r,l,u,q,v,A){return w([x,y,z],{baseClass:"jimu-simple-table",declaredClass:"jimu.dijit.SimpleTable",templateString:'\x3cdiv\x3e\x3cdiv class\x3d"head-section" data-dojo-attach-point\x3d"headDiv"\x3e\x3cdiv class\x3d"table-div" data-dojo-attach-point\x3d"headTableDiv"\x3e\x3ctable class\x3d"table" cellspacing\x3d"0" data-dojo-attach-point\x3d"tableInHeadSection"\x3e\x3ccolgroup data-dojo-attach-point\x3d"headColgroup"\x3e\x3c/colgroup\x3e\x3cthead class\x3d"simple-table-thead simple-table-title"  data-dojo-attach-point\x3d"thead"\x3e\x3c/thead\x3e\x3c/table\x3e\x3c/div\x3e\x3c/div\x3e\x3cdiv class\x3d"body-section" data-dojo-attach-point\x3d"bodyDiv"\x3e\x3cdiv class\x3d"table-div" data-dojo-attach-point\x3d"bodyTableDiv"\x3e\x3ctable class\x3d"table" cellspacing\x3d"0"data-dojo-attach-point\x3d"tableInBodySection"\x3e\x3ccolgroup data-dojo-attach-point\x3d"bodyColgroup"\x3e\x3c/colgroup\x3e\x3ctbody class\x3d"simple-table-tbody" data-dojo-attach-point\x3d"tbody"\x3e\x3c/tbody\x3e\x3c/table\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e',
_name:null,_rowIndex:0,_rowHeight:30,_headHeight:36,REPEATING_ERROR:"REPEATING_ERROR",_classSimpleTableRow:"simple-table-row",_classFirstSimpleTableRow:"first-simple-table-row",_classLastSimpleTableRow:"last-simple-table-row",_classJimuStateDisabled:"jimu-state-disabled",_classRowUpDiv:"row-up-div",_classRowDownDiv:"row-down-div",_classVerticalScroll:"vertical-scroll",autoHeight:!0,selectable:!1,fields:null,singleClickEdit:!1,postMixInProperties:function(){this.nls=window.jimuNls.simpleTable},postCreate:function(){this.inherited(arguments);
this._initSelf()},startup:function(){this.inherited(arguments);this.updateUI()},_initSelf:function(){this.own(q.bindClickAndDblclickEvents(this.tableInBodySection,h.hitch(this,function(c){if(c=q.getAncestorDom(c.target||c.srcElement,function(e){return d.hasClass(e,"simple-table-row")&&d.hasClass(e,"not-empty")},this.tbody))this.selectRow(c),this._onClickRow(c)}),h.hitch(this,function(c){if(c=q.getAncestorDom(c.target||c.srcElement,function(e){return d.hasClass(e,"simple-table-row")&&d.hasClass(e,
"not-empty")},this.tbody))this.selectRow(c),this._onDblClickRow(c)})));var a=Math.random().toString();this._name="jimu_table_"+a.slice(2,a.length);if(this.fields&&0<this.fields.length){var b=d.create("tr",{},this.thead);m.forEach(this.fields,h.hitch(this,function(c){var e="auto";"actions"===c.type&&(c.name="actions");c.hidden?e=1:void 0!==c.width&&null!==c.width?e=c.width:"actions"!==c.type||c.name||(c.width=this._calculateActionsWidth(c)+20,e=c.width);d.create("col",{width:e},this.headColgroup);
d.create("col",{width:e},this.bodyColgroup);e=d.create("th",{innerHTML:q.sanitizeHTML(c.title),title:c.title},b);if("checkbox"===c.type){e.innerHTML="";var g=new v({label:c.title});this.own(r(g.domNode,"click",h.hitch(this,function(){g.getValue()?this._checkAllTdCheckBoxes(c.name):this._uncheckAllTdCheckBoxes(c.name)})));g.placeAt(e)}d.addClass(e,"simple-table-field");c.hidden&&d.addClass(e,"hidden-column");c["class"]&&d.addClass(e,c["class"]);d.addClass(e,c.name)}))}else this.fields=null},_getThCheckBox:function(a){var b=
null;a=l(".simple-table-field."+a+" .jimu-checkbox",this.thead)[0];return b=u.byNode(a)},_getAllEnabledTdCheckBoxes:function(a){a=l(".simple-table-cell."+a+" .jimu-checkbox",this.tbody);a=m.map(a,function(b){return u.byNode(b)});return a=m.filter(a,function(b){return b.getStatus()})},_checkAllTdCheckBoxes:function(a){a=this._getAllEnabledTdCheckBoxes(a);m.forEach(a,function(b){b.getValue()||b.setValue(!0)})},_uncheckAllTdCheckBoxes:function(a){a=this._getAllEnabledTdCheckBoxes(a);m.forEach(a,function(b){b.getValue()&&
b.setValue(!1)})},_delaySyncThCheckBoxStatusWithAllTdCheckBoxes:function(a){setTimeout(h.hitch(this,function(){this._syncThCheckBoxStatusWithAllTdCheckBoxes(a)}),100)},_syncThCheckBoxStatusWithAllTdCheckBoxes:function(a){var b=this._getAllEnabledTdCheckBoxes(a);b=m.filter(b,h.hitch(this,function(c){return c.getStatus()}));0!==b.length&&(a=this._getThCheckBox(a),m.every(b,function(c){return c.getValue()})?a.getValue()||a.setValue(!0):a.getValue()&&a.setValue(!1))},clear:function(){var a=this._getNotEmptyRows(),
b=m.map(a,h.hitch(this,function(c){return this.getRowData(c)}));d.empty(this.tbody);m.forEach(a,h.hitch(this,function(c,e){this._onDeleteRow(c,b[e])}));this.updateUI();this._rowIndex=0;this._onClearRows(a)},addRows:function(a){var b=[];this.fields&&a&&0<a.length&&m.forEach(a,h.hitch(this,function(c){b.push(this.addRow(c,-1,!0))}));this.updateUI();return b},addRow:function(a,b,c){this._rowIndex++;var e={success:!1,tr:null,errorCode:null,errorMessage:null,repeatFields:null};if(!this.fields||"object"!==
typeof a)return e;var g=m.filter(this.fields,h.hitch(this,function(k){return"text"===k.type&&!0===k.unique}));g=m.filter(g,h.hitch(this,function(k){return 0<this.getRowDataArrayByFieldValue(k.name,a[k.name]).length}));if(0<g.length)return e.errorCode=this.REPEATING_ERROR,e.errorMessage="repeating data",e.repeatFields=g,e;var f=d.create("tr",{"class":"simple-table-row not-empty"},this.tbody);d.setAttr(f,"rowId","row"+this._rowIndex);m.forEach(this.fields,h.hitch(this,function(k){var n=a[k.name],p=
k.type,t=null;"actions"===p?t=this._createActionsTd(f,k):("text"===p?t=this._createTextTd(f,k,n):"radio"===p?t=this._createRadioTd(f,k,n):"checkbox"===p?t=this._createCheckboxTd(f,k,n):"empty"===p?t=this._createEmptyTd(f,k):"extension"===p?t=this._createExtensionTd(f,k,n):"dropdown"===p&&(t=this._createDropdownTd(f,k,n)),k.hidden&&d.addClass(t,"hidden-column"))}));c||(this.updateUI(),c=this.getRows(),"number"===typeof b&&0<=b&&b<c.length&&d.place(f,c[b],"before"));e.success=!0;e.tr=f;e.errorMessage=
null;this._onAddRow(f);return e},deleteRow:function(a){if(a){var b=this.getRowData(a);d.destroy(a);this.updateUI();this._onDeleteRow(a,b)}},selectRow:function(a){this.selectable&&(l(".simple-table-row",this.tbody).removeClass("jimu-state-active"),d.addClass(a,"jimu-state-active"),this._onSelectRow(a))},updateUI:function(){this._updateRowClassName();this._updateHeight();d.removeClass(this.domNode,this._classVerticalScroll);0<this.bodyDiv.clientHeight&&this.bodyDiv.clientHeight<this.bodyDiv.scrollHeight&&
d.addClass(this.domNode,this._classVerticalScroll);m.forEach(this.fields,h.hitch(this,function(a){"checkbox"===a.type&&this._delaySyncThCheckBoxStatusWithAllTdCheckBoxes(a.name)}))},_updateHeadTableWidth:function(){if(this.domNode){var a=d.getContentBox(this.tableInBodySection).w,b="100%";"number"===typeof a&&0<a&&(b=a+"px");d.setStyle(this.tableInHeadSection,"width",b)}},_updateHeight:function(){var a=this.getRows();this.autoHeight&&d.setStyle(this.domNode,"height",this._headHeight+this._rowHeight*
(0<a.length?a.length:1)+1+"px");a&&0<a.length&&this.bodyTableDiv&&(a=d.getMarginSize(a[0]))&&a.h&&d.setStyle(this.bodyTableDiv,"backgroundSize","1px "+a.h+"px")},_updateRowClassName:function(){var a=l("."+this._classFirstSimpleTableRow,this.tbody)[0];a&&(a=l("."+this._classRowUpDiv,a)[0])&&d.removeClass(a,this._classJimuStateDisabled);(a=l("."+this._classLastSimpleTableRow,this.tbody)[0])&&(a=l("."+this._classRowDownDiv,a)[0])&&d.removeClass(a,this._classJimuStateDisabled);a=l("."+this._classSimpleTableRow,
this.tbody);a.removeClass("odd");a.removeClass("even");a.removeClass(this._classFirstSimpleTableRow);a.removeClass(this._classLastSimpleTableRow);m.forEach(a,h.hitch(this,function(c,e){0===e%2?d.addClass(c,"odd"):d.addClass(c,"even")}));if(0<a.length){var b=a[0];d.addClass(b,this._classFirstSimpleTableRow);(b=l("."+this._classRowUpDiv,b)[0])&&d.addClass(b,this._classJimuStateDisabled);a=a[a.length-1];d.addClass(a,this._classLastSimpleTableRow);(a=l("."+this._classRowDownDiv,a)[0])&&d.addClass(a,this._classJimuStateDisabled)}},
_createTextTd:function(a,b,c){var e=null;return e=b.editable?this._createEditableTextTd(a,b,c):this._createNormalTextTd(a,b,c)},_createNormalTextTd:function(a,b,c){var e=d.toDom('\x3ctd class\x3d"simple-table-cell normal-text-td"\x3e\x3cdiv class\x3d"normal-text-div"\x3e\x3c/div\x3e\x3c/td\x3e');d.addClass(e,b.name);var g=l("div",e)[0];g.innerHTML=q.sanitizeHTML(c)||"";g.title=c||"";b["class"]&&d.addClass(e,b["class"]);d.place(e,a);return e},_createEditableTextTd:function(a,b,c){var e=d.toDom('\x3ctd class\x3d"editable-text-td '+
b.name+'"\x3e\x3cdiv class\x3d"editable-div"\x3e\x3c/div\x3e\x3cinput class\x3d"editable-input" type\x3d"text" style\x3d"display:none;" /\x3e\x3c/td\x3e');d.addClass(e,"simple-table-cell");d.place(e,a);b["class"]&&d.addClass(e,b["class"]);var g=l("div",e)[0],f=l("input",e)[0];g.innerHTML=q.sanitizeHTML(c)||"";""!==g.innerHTML&&(g.title=g.innerText||g.innerHTML);f.value=g.innerHTML;this.own(r(g,this.singleClickEdit?"click":"dblclick",h.hitch(this,function(k){this.singleClickEdit||k.stopPropagation();
f.value=g.innerText||g.innerHTML;d.setStyle(g,"display","none");d.setStyle(f,"display","inline");f.focus();f.select&&f.select()})));this.own(r(f,"blur",h.hitch(this,function(){f.value=h.trim(q.sanitizeHTML(f.value));var k=g.innerText||g.innerHTML,n=f.value;""!==n?b.unique?0<this.getRowDataArrayByFieldValue(b.name,n,a).length?f.value=k:g.innerHTML=q.sanitizeHTML(n):g.innerHTML=q.sanitizeHTML(n):f.value=k;d.setStyle(f,"display","none");d.setStyle(g,"display","block")})));return e},_createRadioTd:function(a,
b,c){var e=d.toDom('\x3ctd class\x3d"radio-td '+b.name+'"\x3e\x3cinput class\x3d"jimu-radio-btn" type\x3d"radio" /\x3e\x3c/td\x3e');d.addClass(e,"simple-table-cell");d.place(e,a);b["class"]&&d.addClass(e,b["class"]);a=l("input",e)[0];a.name=b.radio&&"row"===b.radio?this._name+this._rowIndex:this._name+b.name;a.checked=!0===c;return e},_createCheckboxTd:function(a,b,c){var e=d.toDom('\x3ctd class\x3d"checkbox-td '+b.name+'"\x3e\x3c/td\x3e');d.addClass(e,"simple-table-cell");d.place(e,a);b["class"]&&
d.addClass(e,b["class"]);var g=new v({onChange:h.hitch(this,function(){this._delaySyncThCheckBoxStatusWithAllTdCheckBoxes(b.name);"function"===typeof b.onChange&&setTimeout(h.hitch(this,function(){b.onChange(a,g)}),200)})});this.own(r(g,"status-change",h.hitch(this,function(){this._delaySyncThCheckBoxStatusWithAllTdCheckBoxes(b.name)})));this._setValueForCheckBox(g,c);g.placeAt(e);return e},_createActionsTd:function(a,b){var c=d.toDom('\x3ctd class\x3d"actions-td"\x3e\x3cdiv class\x3d"action-item-parent jimu-float-leading"\x3e\x3c/div\x3e\x3c/td\x3e');
d.addClass(c,"simple-table-cell");var e=l(".action-item-parent",c)[0];d.place(c,a);b["class"]&&d.addClass(c,b["class"]);m.forEach(b.actions,h.hitch(this,function(g){"up"===g?(g=d.create("div",{"class":"action-item jimu-float-leading row-up-div jimu-icon jimu-icon-up"},e),g.title=this.nls.moveUp,this.own(r(g,"click",h.hitch(this,function(f){f.stopPropagation();if(this.onBeforeRowUp(a)){f=l(".simple-table-row",this.tbody);var k=m.indexOf(f,a);0<k&&(f=f[k-1])&&(d.place(a,f,"before"),this.updateUI(),
this.emit("row-up",a))}})))):"down"===g?(g=d.create("div",{"class":"action-item jimu-float-leading row-down-div jimu-icon jimu-icon-down"},e),g.title=this.nls.moveDown,this.own(r(g,"click",h.hitch(this,function(f){f.stopPropagation();if(this.onBeforeRowDown(a)){f=l(".simple-table-row",this.tbody);var k=m.indexOf(f,a);k<f.length-1&&(f=f[k+1])&&(d.place(a,f,"after"),this.updateUI(),this.emit("row-down",a))}})))):"edit"===g?(g=d.create("div",{"class":"action-item jimu-float-leading row-edit-div jimu-icon jimu-icon-edit"},
e),g.title=this.nls.edit,this.own(r(g,"click",h.hitch(this,function(f){f.stopPropagation();this.onBeforeRowEdit(a)&&this._onActionsEdit(a)})))):"delete"===g&&(g=d.create("div",{"class":"action-item jimu-float-leading row-delete-div jimu-icon jimu-icon-delete"},e),g.title=this.nls.deleteRow,this.own(r(g,"click",h.hitch(this,function(f){f.stopPropagation();this.onBeforeRowDelete(a)&&this.deleteRow(a)}))))}));b=this._calculateActionsWidth(b)+"px";d.setStyle(e,"width",b);return c},_calculateActionsWidth:function(a){return 20*
m.map(a.actions,function(b){return"up"===b||"down"===b||"edit"===b||"delete"===b}).length},_createEmptyTd:function(a,b){a=d.create("td",{"class":b.name},a);d.addClass(a,"simple-table-cell");d.addClass(a,"empty-text-td");b["class"]&&d.addClass(a,b["class"]);return a},_createExtensionTd:function(a,b,c){a=d.create("td",{"class":b.name},a);d.addClass(a,"simple-table-cell");d.addClass(a,"extension-td");b["class"]&&d.addClass(a,b["class"]);b.create&&"function"===typeof b.create&&b.create(a);b.setValue&&
"function"===typeof b.setValue&&b.setValue(a,c);return a},_createDropdownTd:function(a,b,c){a=d.create("td",{"class":b.name},a);d.addClass(a,"simple-table-cell");d.addClass(a,"dropdown-td");b["class"]&&d.addClass(a,b["class"]);(new A({options:c})).placeAt(a);return a},editRow:function(a,b){var c={success:!1,tr:null,errorCode:null,errorMessage:null,repeatFields:null};if(!this.fields||"object"!==typeof b||!d.isDescendant(a,this.tbody))return c;var e=h.mixin([],this.fields);e=m.filter(e,h.hitch(this,
function(f){return"text"===f.type&&!0===f.unique}));e=m.filter(e,h.hitch(this,function(f){return 0<this.getRowDataArrayByFieldValue(f.name,b[f.name],a).length}));if(0<e.length)return c.errorCode=this.REPEATING_ERROR,c.errorMessage="repeating data",c.repeatFields=e,c;var g=l(".simple-table-cell",a);m.forEach(this.fields,h.hitch(this,function(f,k){if(b.hasOwnProperty(f.name)){k=g[k];var n=b[f.name],p=f.type;"text"===p?f.editable?this._editEditableText(k,f,n):this._editNormalText(k,f,n):"radio"===p?
this._editRadio(k,f,n):"checkbox"===p?this._editCheckbox(k,f,n):"extension"===p?this._editExtension(k,f,n):"dropdown"===p&&this._editDropdown(k,f,n)}}));c.success=!0;c.tr=a;c.errorMessage=null;this._onEditRow(a);return c},_editNormalText:function(a,b,c){a=l("div",a)[0];a.innerHTML=q.sanitizeHTML(c)||"";a.title=a.innerHTML},_editEditableText:function(a,b,c){b=l("div",a)[0];b.innerHTML=q.sanitizeHTML(c)||"";l("input",a)[0].value=b.innerHTML},_editRadio:function(a,b,c){l("input",a)[0].checked=!0===c},
_editCheckbox:function(a,b,c){a=l(".jimu-checkbox",a)[0];a=u.byNode(a);this._setValueForCheckBox(a,c)},_setValueForCheckBox:function(a,b){null===b?a.setStatus(!1):(a.setStatus(!0),b!==a.getValue()&&a.setValue(b))},_editExtension:function(a,b,c){b.setValue&&"function"===typeof b.setValue&&b.setValue(a,c)},_editDropdown:function(a,b,c){a=l(".dijitSelect",a)[0];u.byNode(a).set("value",c)},_getAllRows:function(){return l(".simple-table-row",this.tbody)},_getNotEmptyRows:function(){var a=this._getAllRows();
return m.filter(a,h.hitch(this,function(b){return!d.hasClass(b,"empty")}))},_getEmptyRows:function(){var a=this._getAllRows();return m.filter(a,h.hitch(this,function(b){return d.hasClass(b,"empty")}))},getRows:function(){return this._getNotEmptyRows()},getSelectedRow:function(){var a=null,b=l(".simple-table-row",this.tbody);b=m.filter(b,h.hitch(this,function(c){return!d.hasClass(c,"empty")&&d.hasClass(c,"jimu-state-active")}));0<b.length&&(a=b[0]);return a},getSelectedRowData:function(){var a=null,
b=this.getSelectedRow();b&&(a=this._getRowDataByTr(b));return a},getData:function(a){var b=this._getNotEmptyRows();a&&(b=m.filter(b,h.hitch(this,function(c){return c!==a})));return m.map(b,h.hitch(this,function(c){return this._getRowDataByTr(c)}))},getRowData:function(a){return this._getRowDataByTr(a)},_getRowDataByTr:function(a){var b=null;if(a)b={};else return null;m.forEach(this.fields,h.hitch(this,function(c){var e=c.type;if("actions"!==e){var g=c.name;b[g]=null;var f=l(".simple-table-cell."+
g,a)[0];f&&("text"===e?(c=l("div",f)[0],b[g]=c.innerText||c.innerHTML):"radio"===e?(c=l("input",f)[0],b[g]=c.checked):"checkbox"===e?(c=l(".jimu-checkbox",f)[0],c=u.byNode(c),c.getStatus()?b[g]=c.getValue():b[g]=null):"extension"===e?c.getValue&&"function"===typeof c.getValue&&(b[g]=c.getValue(f,c)):"dropdown"===e&&(c=l(".dijitSelect",f)[0],c=u.byNode(c),b[g]=c.get("value")))}}));return b},getRowDataArrayByFieldValue:function(a,b,c){var e=[];if(!this.fields||!m.some(this.fields,h.hitch(this,function(g){return g.name===
a})))return[];c=this.getData(c);return e=m.filter(c,h.hitch(this,function(g){return g[a]==b}))},moveToTop:function(a){a&&a.parentNode===this.tbody&&d.place(a,this.tbody,"first")},_onClickRow:function(a){this.emit("row-click",a)},_onDblClickRow:function(a){this.emit("row-dblclick",a)},_onSelectRow:function(a){this.emit("row-select",a)},_onAddRow:function(a){this.emit("row-add",a)},_onEditRow:function(a){this.emit("row-edit",a)},_onDeleteRow:function(a,b){this.emit("row-delete",a,b)},_onEnterRow:function(a){this.emit("row-enter",
a)},_onClearRows:function(a){this.emit("rows-clear",a)},_onActionsEdit:function(a){this.emit("actions-edit",a)},onBeforeRowUp:function(a){return!0},onBeforeRowDown:function(a){return!0},onBeforeRowEdit:function(a){return!0},onBeforeRowDelete:function(a){return!0}})});