/*!@license * Infragistics.Web.ClientUI Tree Grid 19.1.20 * * Copyright (c) 2011-2019 Infragistics Inc. * * http://www.infragistics.com/ * * Depends on: * jquery-1.9.1.js * jquery.ui.core.js * jquery.ui.widget.js * infragistics.ui.grid.framework.js * infragistics.ui.editors.js * infragistics.ui.shared.js * infragistics.dataSource.js * infragistics.util.js * infragistics.ui.treegrid.js * infragistics.ui.grid.rowselectors.js */ (function(factory){if(typeof define==="function"&&define.amd){define(["./infragistics.ui.treegrid","./infragistics.ui.grid.rowselectors"],factory)}else{return factory(jQuery)}})(function($){"use strict";$.widget("ui.igTreeGridRowSelectors",$.ui.igGridRowSelectors,{options:{rowSelectorNumberingMode:"sequential",checkBoxMode:"biState",inherit:false},css:{rowSelectorChecked:"ui-state-checked",checkBoxP:"ui-icon ui-icon-check-p ui-igcheckbox-normal-on",checkBoxF:"ui-icon ui-icon-check-f ui-igcheckbox-normal-on"},_create:function(){this.element.data($.ui.igGridRowSelectors.prototype.widgetName,this.element.data($.ui.igTreeGridRowSelectors.prototype.widgetName));$.ui.igGridRowSelectors.prototype._create.apply(this,arguments);this._cIndexes={};this._indexCache={};this._path="";this._pathBuild=false;this._nCache={};this._recordNumbers={};this._checkboxStates={}},destroy:function(){this._superApply(arguments);this.element.removeData($.ui.igGridRowSelectors.prototype.widgetName)},changeLocale:function(){this._superApply(arguments)},_recordsRendering:function(){$.ui.igGridRowSelectors.prototype._recordsRendering.apply(this,arguments);if(this.options.rowSelectorNumberingMode==="sequential"){if(this._cIdx===this.options.rowNumberingSeed){this._numberRecords(this.grid.dataSource.data())}return}this._cIndexes={};this._pathBuild=false;this._nCache={};this._numberRecordsWithParents(this.grid.dataSource.data(),"")},_rsExpandCollapseRow:function(row,expand){if(expand){this._cIndexes={};this._path=(row instanceof $?row.find("span.ui-iggrid-rowselector-row-number").html():this.element.find("[data-id='"+row+"']").find("span.ui-iggrid-rowselector-row-number").html())+".";this._pathBuild=true}$.ui.igTreeGrid.prototype._expandCollapseRow.apply(this.grid,arguments)},_applyNumberToNewChild:function(directParent,row){var directParentId,childrenLength,rsNumber;directParentId=directParent[this.grid.options.primaryKey];childrenLength=directParent[this.grid.options.childDataKey]?directParent[this.grid.options.childDataKey].length:1;if(!$.isEmptyObject(this._nCache)){rsNumber=this._nCache[directParentId]+"."+childrenLength;this._nCache[row.data("id")]=rsNumber}else if(this.element.find("[data-id='"+directParentId+"']").length!==0){rsNumber=this.element.find("[data-id='"+directParentId+"']").find("span.ui-iggrid-rowselector-row-number").html();rsNumber+="."+childrenLength}row.find("span.ui-iggrid-rowselector-row-number").html(rsNumber)},_childRowRendering:function(args){if(this.options.rowSelectorNumberingMode==="sequential"){return}this._getCurrentNumberForNewChild(args.parentId,args.id);this._nCache[args.parentId].children++},_redirectFunctions:function(){if(this._functionsRedirected===false){this._expandCollapseRowHandler=$.proxy(this._rsExpandCollapseRow,this);if(this.options.rowSelectorNumberingMode!=="sequential"){this.grid._expandCollapseRow=this._expandCollapseRowHandler}if(this.options.checkBoxMode!=="biState"){this._select=$.proxy(this._selectHandler,this);this._deselect=$.proxy(this._deselectHandler,this);this._handleCheck=$.proxy(this._handleTriStateCheck,this);this._handleHeaderCheck=$.proxy(this._handleTriStateHeaderCheck,this)}}$.ui.igGridRowSelectors.prototype._redirectFunctions.apply(this,arguments)},_injectGrid:function(){var i;$.ui.igGridRowSelectors.prototype._injectGrid.apply(this,arguments);for(i=0;i"+(this._recordNumbers[rowData[pKey]]||"")+""}if(!$.isEmptyObject(this._nCache)){if(rowData.hasOwnProperty("__fr")){path=this._getCurrentNumberForNewChild(rowData.__fr)}else if(this._nCache[rowData[pKey]]){path=this._nCache[rowData[pKey]].path||""}else{this._nCache[rowData[pKey]]={children:0,path:String(this._getNextNumberForParent())};path=this._nCache[rowData[pKey]].path}return""+path+""}return this._super(rowData)},_getCurrentNumberForNewChild:function(parentId,rowId){var childIdx=this._nCache[parentId].path+"."+(this._nCache[parentId].children+1);if(rowId!==undefined){this._nCache[rowId]={path:childIdx,children:0}}return childIdx},_getNextNumberForParent:function(){var i,pt=this.grid.dataSource.pendingTransactions(),count=0;for(i=0;i";if(o.enableRowNumbering){markup+=this._getCurrentNumber(rowData)}if(o.enableCheckBoxes){markup+=this._getTriStateCheckBox(rowData,selected&&o.checkBoxMode!=="triState"||checkStateDefined)}markup+="";return markup},_getTriStateCheckBox:function(rowData,checked){var markup="",dataChk="off",checkBoxState=this.css.checkBoxOff,pKey=this.grid.options.primaryKey;if(checked){dataChk="on";checkBoxState=this._checkboxStates[rowData[pKey]]===0?this.css.checkBoxP:this.css.checkBoxF}markup+="";markup+="";return markup},_numberRecordsWithParents:function(data,currentPath){var pKey=this.grid.options.primaryKey,childDataKey=this.grid.options.childDataKey,counter=1,cPath,dataLen,i,dataRow;if($.type(data)==="array"){dataLen=data.length;for(i=0;i=0;i--){parentRow=parents[i].row;element=this._getRowById(parentRow[pKey]);res=this._rowSelectorFromSelection({element:element});action(parentRow,res)}},_checkParent:function(parentRow,res){var pKey=this.grid.options.primaryKey,childDataKey=this.grid.options.childDataKey,parentRowId=parentRow[pKey];if(this._areAllChildrenChecked(parentRow[childDataKey])){this._checkboxStates[parentRowId]=1;res.checkbox.parent().addClass(this.css.rowSelectorChecked)}else{this._checkboxStates[parentRowId]=0;res.checkbox.parent().addClass(this.css.rowSelectorChecked)}this._alterTriStateCheckbox(res.checkbox,this._checkboxStates[parentRowId])},_uncheckParent:function(parentRow,res){var pKey=this.grid.options.primaryKey,childDataKey=this.grid.options.childDataKey,parentRowId=parentRow[pKey];if(this._hasCheckedChildren(parentRow[childDataKey])){this._checkboxStates[parentRowId]=0;this._alterTriStateCheckbox(res.checkbox,0)}else{delete this._checkboxStates[parentRowId];res.checkbox.parent().removeClass(this.css.rowSelectorChecked);this._alterTriStateCheckbox(res.checkbox)}},_changeChildrenCheckState:function(rowId,toCheck){var grid=this.grid,children=grid.dataSource.getChildrenByKey(rowId,grid.dataSource._data)||[],pKey=grid.options.primaryKey,childDataKey=grid.options.childDataKey,i,childId,child,element,res;for(i=0;i0&&inner.length>0){if(checkState===0){checkbox.attr("data-chk","mixed");inner.removeClass(this.css.checkBoxOff).removeClass(this.css.checkBoxF).addClass(this.css.checkBoxP)}else if(checkState===1){checkbox.attr("data-chk","on");inner.removeClass(this.css.checkBoxOff).removeClass(this.css.checkBoxP).addClass(this.css.checkBoxF)}else{checkbox.attr("data-chk","off");inner.removeClass(this.css.checkBoxP).removeClass(this.css.checkBoxF).addClass(this.css.checkBoxOff)}}},_clearSelection:function(){var rsCells,self=this;if(this.grid.hasFixedColumns()&&this.grid.fixingDirection()==="left"){rsCells=this.grid.fixedBodyContainer().find("tbody").find("th.ui-iggrid-selectedcell").removeClass(this.css.rowSelectorSelected)}else{rsCells=this.grid.element.children("tbody").find("th.ui-iggrid-selectedcell").removeClass(this.css.rowSelectorSelected)}if(this.options.enableCheckBoxes&&this.options.checkBoxMode!=="triState"){$.each(rsCells,function(){self._alterCheckbox($(this).children("span:last"),false)});this._alterCheckbox(this._headerCheckbox(),false)}},_areAllRecordsChecked:function(sl,dvl){var size=0;for(var key in this._checkboxStates){if(this._checkboxStates.hasOwnProperty(key)){if(this._checkboxStates[key]===0){return false}if(this._checkboxStates[key]===1){size++}}}return size===dvl},_getDataView:function(){return this.grid.dataSource.flatDataView()},_getAllData:function(){if(this._flatData){return this._flatData}else{this._flatData=this.grid.dataSource.generateFlatData().flatData;return this._flatData}},_handleTriStateCheck:function(checkbox){var row,rowId,upd,sel,offset;if(!checkbox){return}upd=this.grid.element.data("igGridUpdating");sel=this._getSelectionInstance();if(sel&&sel._suspend){if(upd){if(upd.findInvalid()){return}upd._endEdit(null,true)}else{return}}offset=this._v?this.grid._startRowIndex:0;row=checkbox.parent().parent();if(this.grid.hasFixedColumns()){if(this.grid.fixedBodyContainer().attr("data-fixing-direction")==="left"){row=row.add(this.grid.element.find("tbody > tr").eq(row.index()))}else{row=row.add(this.grid.fixedBodyContainer().find("tbody > tr").eq(row.index()))}}rowId=this.grid._fixPKValue(row.attr("data-id"));if(rowId===null||rowId===undefined){rowId=row.closest("tbody").children("tr:not([data-container])").index(row)+offset}this.changeCheckStateById(rowId,checkbox.attr("data-chk")==="off");if(!this._suspendHeader){this._updateHeader()}},_handleTriStateHeaderCheck:function(checkbox){var dv=this._getDataView(),elem=this.grid.element,toCheck=checkbox.attr("data-chk")==="off",templateData,c,all;this._changeCheckStateForRows(dv,toCheck);this._alterCheckbox(checkbox,toCheck);if(this.options.enableSelectAllForPaging&&elem.data("igGridPaging")){c=this.checkedRows().length;all=this._getAllData().length;templateData=[{checked:c,unchecked:all-c,allCheckedRecords:c,totalRecordsCount:all}];this._renderOverlay(templateData,toCheck)}},_selectAllFromOverlay:function(){if(this.options.checkBoxMode==="biState"){this._changeCheckStateForAllRecords(this._getSelectionInstance(),true)}else{this._changeCheckStateForRows(this._getAllData(),true)}},_deselectAllFromOverlay:function(){if(this.options.checkBoxMode==="biState"){this._changeCheckStateForAllRecords(this._getSelectionInstance(),false)}else{this._changeCheckStateForRows(this._getAllData(),false)}},_getRowById:function(identifier){var urow,frow=$();if(this.grid.hasFixedColumns()){frow=this.grid.rowById(identifier,true)}urow=this.grid.rowById(identifier,false);return urow instanceof $?urow.add(frow):$()},_changeCheckStateForRows:function(dv,toCheck){var i,res,element,rowId,pKey=this.grid.options.primaryKey;for(i=0;i