/*!@license
* Infragistics.Web.ClientUI Grid Editing 15.2.20152.1027
*
* Copyright (c) 2011-2015 Infragistics Inc.
*
* http://www.infragistics.com/
*
* Depends on:
* jquery-1.9.1.js
* jquery.ui-1.9.0.js
* modernizr.js (Optional)
* infragistics.ui.grid.framework.js
* infragistics.ui.grid.shared.js
* infragistics.ui.editors.js
* infragistics.ui.validator.js
* infragistics.ui.combo.js
* infragistics.ui.rating.js
* infragistics.ui.shared.js
* infragistics.dataSource.js
* infragistics.util.js
*/
(function($){"use strict";$.widget("ui.igGridUpdating",{options:{columnSettings:[{columnKey:null,editorType:null,editorProvider:null,editorOptions:null,required:null,readOnly:null,validation:null,defaultValue:null}],editMode:"row",enableDeleteRow:true,enableAddRow:true,validation:false,doneLabel:null,doneTooltip:null,cancelLabel:null,cancelTooltip:null,addRowLabel:null,addRowTooltip:null,deleteRowLabel:null,deleteRowTooltip:null,showDoneCancelButtons:true,enableDataDirtyException:true,startEditTriggers:"click,F2,enter",horizontalMoveOnEnter:false,excelNavigationMode:false,saveChangesSuccessHandler:null,saveChangesErrorHandler:null,swipeDistance:"100px",wrapAround:true,rowEditDialogOptions:{captionLabel:null,containment:"owner",width:"370px",height:"350px",animationDuration:200,showReadonlyEditors:true,showEditorsForHiddenColumns:false,namesColumnWidth:"150px",editorsColumnWidth:null,showDoneCancelButtons:true,dialogTemplate:null,dialogTemplateSelector:null,editorsTemplate:null,editorsTemplateSelector:null},inherit:false},events:{editRowStarting:"editRowStarting",editRowStarted:"editRowStarted",editRowEnding:"editRowEnding",editRowEnded:"editRowEnded",editCellStarting:"editCellStarting",editCellStarted:"editCellStarted",editCellEnding:"editCellEnding",editCellEnded:"editCellEnded",rowAdding:"rowAdding",rowAdded:"rowAdded",rowDeleting:"rowDeleting",rowDeleted:"rowDeleted",dataDirty:"dataDirty",generatePrimaryKeyValue:"generatePrimaryKeyValue",rowEditDialogBeforeOpen:"rowEditDialogBeforeOpen",rowEditDialogAfterOpen:"rowEditDialogAfterOpen",rowEditDialogBeforeClose:"rowEditDialogBeforeClose",rowEditDialogAfterClose:"rowEditDialogAfterClose",rowEditDialogContentsRendered:"rowEditDialogContentsRendered"},css:{buttonContainer:"ui-iggrid-buttoncontainer ui-widget-content ui-corner-all",button:"ui-iggrid-button ui-state-default ui-corner-all",doneButton:"ui-iggrid-donebutton ui-priority-primary ui-corner-all",cancelButton:"ui-iggrid-cancelbutton ui-corner-all",deleteButton:"ui-iggrid-deletebutton ui-state-default ui-corner-all",buttonHover:"ui-iggrid-buttonhover ui-state-hover",buttonDisabled:"ui-iggrid-buttondisabled ui-state-disabled",buttonActive:"ui-iggrid-buttonactive ui-state-active",doneIcon:"ui-iggrid-doneicon ui-icon ui-icon-check",cancelIcon:"ui-iggrid-cancelicon ui-icon ui-icon-cancel",buttonIconOnly:"ui-iggrid-button-icon-only",editingCell:"ui-iggrid-editingcell",addRow:"ui-iggrid-addrow ui-widget-header",addRowHover:"ui-iggrid-addrowhover ui-state-hover",addRowActive:"ui-iggrid-addrowactive ui-state-active",addRowIcon:"ui-iggrid-addrowicon ui-icon ui-icon-circle-plus",deleteIcon:"ui-iggrid-deleteicon ui-icon ui-icon-circle-close",editor:"ui-iggrid-editor",rowEditDialogHeaderCaption:"ui-dialog-titlebar ui-iggrid-filterdialogcaption ui-widget-header ui-corner-all ui-helper-reset ui-helper-clearfix",rowEditDialogHeaderCaptionTitle:"ui-dialog-title",rowEditDialogCloseButton:"ui-icon ui-icon-close",rowEditDialog:"ui-dialog ui-draggable ui-resizable ui-iggrid-dialog ui-widget ui-widget-content ui-corner-all",blockArea:"ui-widget-overlay ui-iggrid-blockarea",rowEditDialogButtonsContainer:"ui-dialog-buttonpane ui-widget-content ui-helper-clearfix",rowEditDialogTable:"ui-iggrid-filtertable ui-helper-reset"},setCellValue:function(rowId,colKey,value){var provider;if(rowId===null||rowId===undefined||$.type(colKey)!=="string"){return}if(value===undefined){throw new Error($.ig.GridUpdating.locale.undefinedCellValue)}if(!this._recOrPropFound(rowId,colKey)){throw new Error($.ig.GridUpdating.locale.recordOrPropertyNotFoundException)}if(this.isEditing()){if(this._originalValues.hasOwnProperty(colKey)){provider=this.editorForKey(colKey).igEditorFilter("option","provider");provider.setValue(value);this._editorTextChanged();return}else{this.endEdit(false,false)}}this._updateCell(rowId,colKey,value)},updateRow:function(rowId,values){var key,provider,shouldUpdate=false;if(rowId===null||rowId===undefined||$.type(values)!=="object"){return}if(!this._recOrPropFound(rowId)){throw new Error($.ig.GridUpdating.locale.recordOrPropertyNotFoundException)}if(this.isEditing()&&this._editingForRowId===rowId){for(key in values){if(values.hasOwnProperty(key)&&this._originalValues.hasOwnProperty(key)){provider=this.editorForKey(key).igEditorFilter("option","provider");provider.setValue(values[key])}else{this.endEdit(false,false);shouldUpdate=true;break}}this._editorTextChanged()}else{shouldUpdate=true}if(shouldUpdate){this._updateRow(rowId,values)}},addRow:function(values){var settings=this.options.columnSettings,i=settings?settings.length:0,defVals={},key,val;while(i-->0){key=settings[i].columnKey;val=settings[i].defaultValue;if(val!==undefined&&key!==undefined&&key!==null){defVals[key]=val}}this._addRow(null,$.extend(defVals,values),defVals,true)},deleteRow:function(rowId){if(rowId===null||rowId===undefined){return}if(!this._recOrPropFound(rowId)){throw new Error($.ig.GridUpdating.locale.recordOrPropertyNotFoundException)}if(this.isEditing()&&this._editingForRowId===rowId){this.endEdit(false)}this._deleteRow(null,rowId,true)},startEdit:function(rowId,column,raiseEvents){var columnIndex,columnKey,mode=this.options.editMode,visibleColumns=this.grid._visibleColumns(),cell,row;if(this.isEditing()){throw new Error($.ig.GridUpdating.locale.editingInProgress)}if($.type(column)==="string"){columnKey=column;columnIndex=this._getVisibleIndexForKey(columnKey)}else if($.type(column)==="number"&&column>=0&&column<visibleColumns.length){columnKey=visibleColumns[column].key;columnIndex=column}if(!columnKey||columnIndex===undefined||columnIndex===null){if(mode==="cell"){throw new Error($.ig.Grid.locale.columnNotFound.replace("{key}",columnKey))}columnKey=visibleColumns[0].key;columnIndex=0}if(mode==="cell"&&visibleColumns[columnIndex].readOnly){return false}switch(mode){case"dialog":return this._startEditDialog(null,!raiseEvents,rowId);case"row":row=this.grid.rowById(rowId);if(!row||!row.length){throw new Error($.ig.GridUpdating.locale.rowOrColumnSpecifiedOutOfView)}return this._startEditForRow(null,!raiseEvents,rowId,columnKey,row);case"cell":cell=this.grid.cellById(rowId,columnKey);if(!cell||!cell.length){throw new Error($.ig.GridUpdating.locale.rowOrColumnSpecifiedOutOfView)}return this._startEditForCell(null,!raiseEvents,rowId,columnKey,cell,true,false)}},startAddRowEdit:function(raiseEvents){if(this.isEditing()){throw new Error($.ig.GridUpdating.locale.editingInProgress)}if(!this.options.enableAddRow){return false}if(this.options.editMode==="dialog"){return this._startEditDialog(null,!raiseEvents,null,true)}return this._startEditForRow(null,!raiseEvents,null,null,this.grid.headersTable().children("thead").children("[data-add-row]").children(":not([data-skip='true'])").first())},endEdit:function(update,raiseEvents){var dialog;if(!this.isEditing()){return}if(this.options.editMode==="dialog"){dialog=$("#"+this.grid.id()+"_updating_dialog_container");if(dialog&&dialog.data("igGridModalDialog")){this._dialogClosingFromUI=!!raiseEvents;dialog.igGridModalDialog("closeModalDialog",update)}}else{return this._endEdit(null,!!update,!raiseEvents)}},findInvalid:function(){var key,all=this._editors,provider;for(key in all){if(all.hasOwnProperty(key)&&all[key]){provider=all[key].data("igEditorFilter").options.provider;provider.refreshValue();if(!all[key].data("igEditorFilter").options.provider.validate()){return key}}}return null},isEditing:function(){return!!this._originalValues},editorForKey:function(key){if(!this._editors){return null}return this._editors[key]||null},editorForCell:function(cell,create){var columnKey=this._getColumnKeyForCell(cell);if(!this._editors){this._editors={}}if(!this._editors[columnKey]&&create){this._editors[columnKey]=this._createEditor(cell,columnKey)}return this._editors[columnKey]||null},destroy:function(){if(this.options.enableAddRow){this._removeAddRow()}if(this.options.enableDeleteRow){this._removeDeleteButton()}if(this.options.showDoneCancelButtons&&this.options.editMode==="row"){this._removeDoneCancelButtons()}this._destroyAllEditors();this._unbindAllEvents();delete this._stopEditingHandler;delete this._gridHandlers;delete this._handlers;delete this._buttonHandlers;delete this._addNewRowHandlers;delete this._validationHandlers;delete this._dialogHandlers;delete this._editorCallbacks;$.Widget.prototype.destroy.call(this);return this},_setOption:function(key,value){var opts=this.options;if(opts[key]===value){return this}if(key==="editMode"){this.endEdit(false,false);this._destroyAllEditors()}$.Widget.prototype._setOption.apply(this,arguments);switch(key){case"rowEditDialogOptions":this._dialogInvalid=true;opts.rowEditDialogOptions=$.extend(opts.rowEditDialogOptions,value);break;case"enableDeleteRow":if(value===true){this._renderDeleteButton()}else{this._removeDeleteButton()}break;case"enableAddRow":if(value===true&&this.grid.options.showHeader){this._updateAddNewRow()}else{this._removeAddRow()}this._rebindEditTriggers();break;case"startEditTriggers":this._analyzeEditTriggers();this._rebindEditTriggers();break;case"columnSettings":this.endEdit(false,false);this._destroyAllEditors();this._processReadOnly();this.grid._renderData();break}if(key==="saveChangesSuccessHandler"){this._addDSSuccessHandler()}else if(key==="saveChangesErrorHandler"){this._addDSErrorHandler()}return this},_gridDataRendering:function(evt,ui){var ds,l,noCancel;if(ui&&ui.owner.id()!==this.grid.id()){return}ds=this.grid.dataSource;l=ds.data()?ds.data().length:0;if(!this.grid.options.showHeader){this._processReadOnly()}if(this.isEditing()){if(!this.endEdit(this.grid.options.autoCommit,true)){this.endEdit(false,true)}}this._pkVal=l+1;if(ds.pendingTransactions().length){if(this.options.enableDataDirtyException){noCancel=this._trigger(this.events.dataDirty,null,{});if(noCancel){throw new Error($.ig.GridUpdating.locale.dataDirtyException)}}}if(l&&!this.grid.options.primaryKey){throw new Error($.ig.Grid.locale.noPrimaryKeyDefined)}},_gridRendered:function(){this._rebindEditTriggers()},_rowsRendered:function(evt,ui){if(ui&&ui.owner&&ui.owner.id()!==this.grid.id()){return}this._paintModifiedCells()},_virtPreRender:function(evt,ui){if(ui&&ui.owner&&ui.owner.id()!==this.grid.id()){return}if(this.isEditing()){if(!this._endEdit(evt,true,false)){this._endEdit(evt,false,false)}}},_virtPostRender:function(evt,ui){if(ui&&ui.owner&&ui.owner.id()!==this.grid.id()){return}this._hideDeleteButton();this._paintModifiedCells()},_headerRendered:function(evt,ui){if(ui.owner.id()!==this.grid.id()){return}this._updateAddNewRow()},_columnFixed:function(){this._editorsContainerInvalid=true;if(this.options.enableAddRow){this._updateAddNewRow()}},_groupedColumnsChanged:function(){if(this.options.enableAddRow){this._updateAddNewRow()}},_hidingFinishing:function(){if(this.isEditing()){if(!this.endEdit(true,true)){this.endEdit(false,true)}}},_columnsModified:function(evt,ui){if(ui.owner.id()!==this.grid.id()){return}this._editorsContainerInvalid=true;if(this.options.enableAddRow){this._updateAddNewRow()}this._paintModifiedCells()},_scroll:function(){if(this.isEditing()){if(this._editingForRowId===null){this._positionDoneCancelButtons(this.grid.headersTable().find("tr[data-new-row]"))}else if(this._editingForRowId!==undefined){this._positionDoneCancelButtons(this.grid.rowById(this._editingForRowId))}this._hideValidatorMessages()}},_mouseDown:function(evt){var target=$(evt.target).closest("td"),targetContainer=target.closest(".ui-iggrid"),targetGrid=target.closest(".ui-iggrid-table"),re=new RegExp("^"+this.grid.id()+"(_fixed)?$"),selection=this.grid.element.data("igGridSelection");if(targetContainer.length&&targetContainer[0]===this.grid.container()[0]){if(this.isEditing()){if(!target.hasClass(this.css.editingCell)&&this._getRowId(target.closest("tr"))!==this._editingForRowId){this._endEdit(evt,true,false)}}if(this.grid.headersTable().children("thead").has(target).length||this.grid.fixedHeadersTable().children("thead").has(target).length){return}if(targetGrid.length&&targetGrid.attr("id").match(re)){if(selection&&!target.hasClass("ui-iggrid-selectedcell")){this._wait=true}}}},_clickTrigger:function(evt){var target=$(evt.target).closest("td"),targetGrid=target.closest(".ui-iggrid");if(targetGrid.length&&targetGrid[0]===this.grid.container()[0]){if(this._wait){delete this._wait;if(evt.type!=="dblclick"){return}}this._startEditForElement(evt,target)}},_keyDown:function(evt){var target=$(evt.target),targetGrid=target.closest(".ui-iggrid"),sel,row;if(!targetGrid.length||targetGrid[0]!==this.grid.container()[0]){return}if(target.is("td,tr")){if(evt.keyCode===$.ui.keyCode.ENTER&&this._editTriggers.enter||evt.keyCode===113&&this._editTriggers.f2){if(this.options.editMode==="cell"&&target.is("tr")){target=this._getEditableCellsForRow(target).first()}this._startEditForElement(evt,target)}else if(evt.keyCode===$.ui.keyCode.DELETE&&this.options.enableDeleteRow&&!this.isEditing()){sel=this.grid.element.data("igGridSelection");if(sel&&sel.options.mode==="row"&&sel.options.multipleSelection){this._deleteMultipleRows(evt)}else{row=target.closest("tr");if(this._isEditableRow(row)){this._deleteRow(evt,this._getRowId(row),false)}}}}},_touchStart:function(evt){this._firstTouchX=evt.originalEvent.touches&&evt.originalEvent.touches[0]?evt.originalEvent.touches[0].pageX:evt.originalEvent.clientX;this._firstTouchRow=evt.originalEvent.touches?$(evt.originalEvent.touches[0].target).closest("tr"):$(evt.originalEvent.target).closest("tr");this._storedScrollLeft=this.grid.scrollContainer().scrollLeft()||0;this._storedScrollWidth=this.grid.scrollContainer().width()||0},_touchEnd:function(evt){var changedTouchX=evt.originalEvent.changedTouches&&evt.originalEvent.changedTouches[0]?evt.originalEvent.changedTouches[0].pageX:evt.originalEvent.clientX;this._storedScrollLeft-=this.grid.scrollContainer().scrollLeft()||0;this._storedScrollWidth-=this.grid.scrollContainer().width()||0;if(this.options.enableDeleteRow&&Math.abs(changedTouchX-this._firstTouchX)>parseInt(this.options.swipeDistance,10)&&this._firstTouchRow&&this._storedScrollLeft===0&&this._storedScrollWidth===0){this._showDeleteButtonFor(this._firstTouchRow)}delete this._firstTouchX;delete this._firstTouchRow;delete this._storedScrollLeft;delete this._storedScrollWidth;delete this._firstTouchRow},_addRowFocus:function(evt){$(evt.target).closest("tr").addClass(this.css.addRowActive)},_addRowBlur:function(evt){$(evt.target).closest("tr").removeClass(this.css.addRowActive)},_rowMouseEnter:function(evt){var row=$(evt.target).closest("tr");if(!this.isEditing()&&this._isEditableRow(row)){this._showDeleteButtonFor(row)}else{this._hideDeleteButton()}},_containerMouseLeave:function(){this._hideDeleteButton()},_buttonMouseEnter:function(evt){var button=$(evt.target).closest(".ui-iggrid-button,.ui-iggrid-deletebutton");if(!button.hasClass("ui-state-disabled")){button.addClass(this.css.buttonHover)}},_buttonMouseLeave:function(evt){var button=$(evt.target).closest(".ui-iggrid-button,.ui-iggrid-deletebutton");button.removeClass(this.css.buttonHover)},_buttonFocus:function(evt){var button=$(evt.target).closest(".ui-iggrid-button,.ui-iggrid-deletebutton");if(!button.hasClass("ui-state-disabled")){button.addClass(this.css.buttonActive)}},_buttonBlur:function(evt){$(evt.target).removeClass(this.css.buttonActive)},_doneButtonClick:function(evt){var target=$(evt.target).closest(".ui-iggrid-button");if(!target.length||target.hasClass(this.css.buttonDisabled)){return}this._endEdit(evt,true)},_doneButtonKeyUp:function(evt){var target=$(evt.target).closest(".ui-iggrid-button");if(!target.length||target.hasClass(this.css.buttonDisabled)||evt.keyCode!==$.ui.keyCode.ENTER){return}this._endEdit(evt,true)},_cancelButtonKeyUp:function(evt){if(evt.keyCode===$.ui.keyCode.ENTER){this._stopEditing()}},_deleteButtonClick:function(evt){var rowId=$(evt.target).closest(".ui-iggrid-deletebutton").data("button-for");if(this._deleteRow(evt,rowId,false)){this._hideDeleteButton()}},_touchDeleteButtonClick:function(evt){var rowId=this._editingForRowId,target=$(evt.target).closest(".ui-iggrid-button");if(this.isEditing()&&!target.hasClass(this.css.buttonDisabled)){this._endEdit(evt,false,false);this._deleteRow(evt,rowId,false)}},_touchDeleteButtonKeyUp:function(evt){var rowId,target=$(evt.target).closest(".ui-iggrid-button");if(evt.keyCode===$.ui.keyCode.ENTER){rowId=this._editingForRowId;if(this.isEditing()&&!target.hasClass(this.css.buttonDisabled)){this._endEdit(evt,false,false);this._deleteRow(evt,rowId,false)}}},_dialogCloseClick:function(){var dialog=$("#"+this.grid.id()+"_updating_dialog_container");if(dialog&&dialog.data("igGridModalDialog")){this._dialogClosingFromUI=true;dialog.igGridModalDialog("closeModalDialog",false)}},_dialogDone:function(evt,ui){ui.toClose=true;this._dialogClosingFromUI=true},_dialogCancel:function(evt,ui){ui.toClose=true;this._dialogClosingFromUI=true},_dialogClosing:function(evt,ui){var dialog=ui.modalDialog;if(this._dialogClosingFromUI){this._trigger(this.events.rowEditDialogBeforeClose,evt,{owner:this,dialogElement:dialog})}return this._endEditDialog(evt,ui.accepted,ui.owner.getContent(),!this._dialogClosingFromUI)},_dialogClosed:function(evt,ui){if(this._dialogClosingFromUI){this._trigger(this.events.rowEditDialogAfterClose,evt,{owner:this,dialogElement:ui.modalDialog})}},_dialogOpening:function(evt,ui){var dialog=ui.modalDialog,opts=this.options.rowEditDialogOptions,rowId=this.grid._fixPKValue(dialog.attr("data-for-rowid")),isAdding=dialog.attr("data-isadding")==="true",content=dialog.igGridModalDialog("getContent"),templateParent,she=opts.showEditorsForHiddenColumns,cols=$.extend([],this.grid.options.columns),values=isAdding?this._getDefaultValues():this._getLatestValues(rowId),cache=content.find("[data-render-tmpl]").children(),invalid=!!this._editorsContainerInvalid;if(cache.length){if(!invalid){cache.detach()}else{this._clearEditorsFromContainer(cache);cache.remove()}}this._renderDialogContent(content,values);this._initDialogEditors(content,cols,values);templateParent=content.find("[data-render-tmpl]");if(templateParent.length&&!templateParent.children().length){if(!invalid){cache.appendTo(templateParent)}else{this._renderDialogTemplate(templateParent,cols,!she);delete this._editorsContainerInvalid}}this._initDialogEditors(content,cols,values);if(isAdding&&!this._anyEditorInvalid()){this._enableDoneButton()}else{this._disableDoneButton()}$.extend(this._originalValues,values,this._originalValues);this._trigger(this.events.rowEditDialogAfterOpen,evt,{owner:this,dialogElement:dialog});this._trigger(this.events.editRowStarted,evt,{owner:this,rowAdding:isAdding,rowID:rowId})},_editorErrorShowing:function(evt,ui){var colKey=this._getEditorKey(ui.owner.element);if(this._errorShownFor&&this._errorShownFor!==colKey){return false}},_editorErrorShown:function(evt,ui){var colKey=this._getEditorKey(ui.owner.element);this._errorShownFor=colKey;this._disableDoneButton()},_editorErrorHidden:function(){delete this._errorShownFor;this._enableDoneButton()},_editorTextChanged:function(){if(!this.findInvalid()){this._enableDoneButton()}},_editorKeyDown:function(evt,ui,columnKey){var keyCode=evt.keyCode,rowId,editor=this._editors[columnKey],providerWrapper=editor.data("igEditorFilter"),provider,row=ui.owner.element.closest("tr"),isAdd=row.hasClass("ui-iggrid-addrow")||row.attr("data-new-row");if(!row.length){return}if(providerWrapper){provider=providerWrapper.options.provider}if(keyCode===$.ui.keyCode.ESCAPE){if(this._revertValueForEditor(provider,columnKey)){evt.stopPropagation();return}}if(this.options.editMode==="dialog"){return}rowId=isAdd?null:this._getRowId(row);this._navigateElement(evt,keyCode,rowId,columnKey,isAdd)},_stopEditing:function(){if(this.isEditing()){this._endEdit(null,false)}},_paintModifiedCells:function(){var transactions=this.grid.pendingTransactions(),tran,i;for(i=0;i<transactions.length;i++){tran=transactions[i];this._updateUIForTransaction(tran)}},_removeAddRow:function(){this.grid.fixedHeadersTable().children("thead").children("tr[data-add-row='true'],tr[data-new-row='true']").remove();this.grid.headersTable().children("thead").children("tr[data-add-row='true'],tr[data-new-row='true']").remove()},_updateAddNewRow:function(){if(this.grid.hasFixedColumns()){this._updateAddNewRowForTable(true)}this._updateAddNewRowForTable(false)},_updateAddNewRowForTable:function(fixed){var numOfCols,thead,i,j,addRow,newRow,vcols,ihc;if(fixed){thead=this.grid.fixedHeadersTable().children("thead")}else{thead=this.grid.headersTable().children("thead")}this._renderAddNewRow(thead);vcols=$.extend([],this.grid._visibleColumns(fixed));ihc=this.grid._initialHiddenColumns;if(ihc&&ihc.length){for(i=0;i<ihc.length;i++){for(j=0;j<vcols.length;j++){if(ihc[i].key===vcols[j].key){$.ig.removeFromArray(vcols,j,j);break}}}}numOfCols=vcols.length;addRow=thead.children("tr[data-add-row='true']");addRow.children("td:last").attr("colspan",numOfCols);newRow=thead.children("tr[data-new-row='true']").empty();for(i=0;i<numOfCols;i++){$("<td></td>").attr("aria-readonly",!!vcols[i].readOnly).appendTo(newRow)}if(fixed&&this.grid.fixingDirection()==="left"||!fixed&&this.grid.fixingDirection()!=="left"){addRow.find("th[data-skip='true'],td[data-skip='true']").remove();newRow.find("th[data-skip='true'],td[data-skip='true']").remove();this.grid._headerInit(addRow,null,true);this.grid._headerInit(newRow,null,true)}},_toggleAddRow:function(){var newRow=this.grid.headersTable().find("tr[data-new-row]"),addRow=this.grid.headersTable().find("tr[data-add-row]"),height;if(this.grid.hasFixedColumns()){newRow=newRow.add(this.grid.fixedHeadersTable().find("tr[data-new-row]"));addRow=addRow.add(this.grid.fixedHeadersTable().find("tr[data-add-row]"))}if(newRow.is(":visible")){newRow.hide();addRow.show()}else{height=addRow.height();addRow.hide();newRow.show();newRow.css("height",height)}},_startEditForElement:function(evt,target){var mode=this.options.editMode,td=target.is("td")?target:null,tr=target.is("tr")?target:target.parent(),isAdding=tr.hasClass("ui-iggrid-addrow"),rowId=isAdding?null:this._getRowId(tr),editEnded=true,col;if(mode==="dialog"){if(!td){td=tr.children("td:not([data-skip='true'],[data-parent='true'])")}if(!this._isDataCell(td)||!this._isEditableRow(tr)){return false}this._startEditDialog(evt,false,rowId,isAdding)}else if(mode==="row"||tr.hasClass("ui-iggrid-addrow")){if(!td){td=tr.children("td:not([data-skip='true'],[data-parent='true'])")}if(!this._isDataCell(td)||!this._isEditableRow(tr)){return false}if(this.isEditing()){if(this._editingForRowId===rowId){return false}editEnded=this._endEdit(evt,true,false)}return!editEnded?false:this._startEditForRow(evt,false,rowId,null,td)}else if(mode==="cell"){if(!this._isEditableCell(td)){return false}if(this.isEditing()){col=this._getColumnKeyForCell(td);if(rowId===this._editingForRowId&&col&&this._originalValues.hasOwnProperty(col)){return false}editEnded=this._endEdit(evt,true,false)}return!editEnded?false:this._startEditForCell(evt,false,rowId,col,td,true,isAdding)}return false},_startEditDialog:function(evt,suppress,rowId,adding){var dialog=this._renderRowEditDialog(!!this._dialogInvalid);if(!suppress&&!this._trigger(this.events.editRowStarting,evt,{owner:this,rowAdding:adding,rowID:rowId})){return false}dialog.attr({"data-for-rowid":rowId,"data-isadding":adding});if(!suppress){this._trigger(this.events.rowEditDialogBeforeOpen,evt,{owner:this,dialogElement:dialog})}this._disableDoneButton();dialog.igGridModalDialog("openModalDialog");return true},_startEditForRow:function(evt,suppress,rowId,columnKey,element){var rowElement,args,editModeStarted=false,colElements,pair,columnToFocus=null,defaultIndex,i,allValues,cellValue,isAdding,visibleCols=this.grid._visibleColumns(),vcc=this.grid._virtualColumnCount||visibleCols.length,vci=this.grid._startColIndex||0;if(element.is("tr")){rowElement=element}else if(element.is("td")){rowElement=element.parent()}else{rowElement=this.grid.rowById(rowId)}isAdding=rowElement.hasClass("ui-iggrid-addrow");args={owner:this,rowAdding:isAdding,rowID:rowId};if(!suppress&&!this._trigger(this.events.editRowStarting,evt,args)){return}if(isAdding){rowElement=this._combineRowElements(rowElement);if(!rowElement.attr("[data-new-row]")){rowElement=rowElement.siblings("[data-new-row]");this._toggleAddRow()}}if(element&&element.is("td")&&!columnKey){columnKey=this._getColumnKeyForCell(element)}defaultIndex=isAdding?0:this._getVisibleIndexForKey(columnKey);defaultIndex=Math.min(Math.max(vci,defaultIndex),vci+vcc-1);if(!this.grid.columnByKey(columnKey).readOnly){columnToFocus=columnKey}else{i=defaultIndex+1;while(visibleCols[i].key!==columnKey){if(i===vci+vcc){i=vci}if(!visibleCols[i].readOnly){columnToFocus=visibleCols[i].key;break}i++}}colElements=this._getEditableElementsForRow(rowElement);allValues=isAdding?this._getDefaultValues():this._getLatestValues(rowId);for(i=0;i<colElements.length;i++){pair=colElements[i];cellValue=allValues[pair.colKey]===undefined?null:allValues[pair.colKey];editModeStarted=this._startEditForCell(evt,suppress,rowId,pair.colKey,pair.element,pair.colKey===columnToFocus,isAdding,cellValue)||editModeStarted}if(this.options.showDoneCancelButtons){this._showDoneCancelButtons();this._positionDoneCancelButtons(rowElement);if(isAdding&&!this._anyEditorInvalid()){this._enableDoneButton()}else{this._disableDoneButton()}if(this._renderTouchUI){this._updateDeleteButton(isAdding)}}if(editModeStarted){if(!suppress){this._trigger(this.events.editRowStarted,evt,args)}this._editingForRowId=isAdding?null:rowId;$.extend(this._originalValues,allValues,this._originalValues);this._selectionToggle(rowElement)}else{rowElement.children().removeClass(this.css.editingCell);return false}return true},_startEditForCell:function(evt,suppress,rowId,columnKey,element,focus,isAdding,value){var providerWrapper,provider,validator,args,editor,width,height;columnKey=columnKey||this._getColumnKeyForCell(element);rowId=rowId===null?this._getRowId(element.closest("tr")):rowId;if(element){element.addClass(this.css.editingCell);editor=this.editorForCell(element,true);providerWrapper=editor.data("igEditorFilter");if(providerWrapper){provider=providerWrapper.options.provider}else{return false}height=element.outerHeight();width=element.outerWidth();width=this._isLastScrollableCell(element)?width-this.grid._scrollbarWidth():width}if(value===undefined){value=this._getLatestValues(rowId,columnKey);value=value===undefined?null:value}args={owner:this,rowID:rowId,columnIndex:element?element.index():-1,columnKey:columnKey,editor:editor,value:value,rowAdding:isAdding};if(!suppress&&!this._trigger(this.events.editCellStarting,evt,args)){if(editor){provider.setValue(null)}element.removeClass(this.css.editingCell);return false}if(editor){editor.prependTo(element);provider.setSize(Math.max(8,width),Math.max(10,height));validator=provider.validator();provider.setValue(args.value)}this._originalValues=this._originalValues||{};this._originalValues[columnKey]=editor?provider.getValue():value;this._trigger(this.events.editCellStarted,evt,args);if(focus&&editor){this._activateEditor(editor)}this._hideDeleteButton();this._editingForRowId=rowId;if(this.options.editMode==="cell"&&!isAdding){this._selectionToggle(element)}return true},_endEditDialog:function(evt,shouldUpdate,dialogContent,suppress){var newValues={},prevValues=this._originalValues,update,colElements,hasInvalid,add=dialogContent.parent().attr("data-isadding")==="true",noCancel,isChanged,rowId=this.grid._fixPKValue(dialogContent.parent().data("for-rowid"));colElements=this._getEditedColumnElementsForDialog(dialogContent);if(shouldUpdate){hasInvalid=this._handleInvalid(colElements);if(hasInvalid){return false}newValues=this._getNewValuesForRow(colElements);isChanged=this._compareValues(prevValues,newValues);if(add){newValues=$.extend({},prevValues,newValues)}}update={update:shouldUpdate&&(isChanged||add)};if(!suppress){noCancel=this._fireEndingEvents(evt,prevValues,newValues,colElements,rowId,add,update);if(!noCancel){return false}}delete this._originalValues;delete this._editingForRowId;if(update.update&&(this._compareValues(prevValues,newValues)||add)){if(add){this._addRow(evt,newValues,prevValues,suppress)}else{this._updateRow(prevValues[this.grid.options.primaryKey],newValues,null)}}if(!suppress){this._fireEndedEvents(evt,prevValues,newValues,colElements,rowId,add,update)}this._hideValidatorMessages();return true},_endEdit:function(evt,shouldUpdate,suppress){var cell,row,rowId,colKey,colElements,hasInvalid,add,prevValues=this._originalValues,newValues={},isChanged,noCancel=true,update,val;cell=this.grid.container().find("."+this.css.editingCell).first();row=cell.closest("tr");rowId=this._getRowId(row);add=row.data("new-row");colElements=this._getEditedColumnElementsForRow(row);if(shouldUpdate){hasInvalid=this._handleInvalid(colElements);if(hasInvalid){return false}newValues=this._getNewValuesForRow(colElements);isChanged=this._compareValues(prevValues,newValues);if(add){newValues=$.extend({},prevValues,newValues)}}update={update:shouldUpdate&&(isChanged||add)};if(!suppress){noCancel=this._fireEndingEvents(evt,prevValues,newValues,colElements,rowId,add,update);if(!noCancel){return false}}this._closeEditingForRow(colElements);delete this._originalValues;delete this._editingForRowId;if(update.update&&(this._compareValues(prevValues,newValues)||add)){if(add){this._addRow(evt,newValues,prevValues,suppress)}else if(this.options.editMode==="cell"){colKey=colElements[0].colKey;cell=colElements[0].element;val=newValues[colKey];this._updateCell(rowId,colKey,val,cell)}else{this._updateRow(rowId,newValues,row)}}if(!suppress){this._fireEndedEvents(evt,prevValues,newValues,colElements,rowId,add,update)}this._hideDoneCancelButtons();if(add){this._toggleAddRow()}this._selectionToggle();return true},_handleInvalid:function(colElements){var i,key,editor,provider,providerWrapper;for(i=0;i<colElements.length;i++){key=colElements[i].colKey;editor=this.editorForKey(key);providerWrapper=editor.data("igEditorFilter");provider=providerWrapper.options.provider;if(editor&&editor.length&&editor.is(":visible")&&(providerWrapper.hasInvalidMessage()||!provider.validate()||!provider.isValid())){this._activateEditor(editor);this._disableDoneButton();return true}}return false},_fireEndingEvents:function(evt,prevValues,newValues,colElements,rowId,add,update){var i,colKey,editor,rArg,cArg,mode=this.options.editMode,noCancel;if(mode!=="cell"){rArg={owner:this,oldValues:prevValues,values:update.update?newValues:prevValues,rowID:rowId,update:update.update,rowAdding:add};noCancel=this._trigger(this.events.editRowEnding,evt,rArg);if(update.update){update.update=rArg.update}if(!noCancel){return false}}if(mode!=="dialog"){for(i=0;i<colElements.length;i++){colKey=colElements[i].colKey;editor=this.editorForKey(colKey);cArg={owner:this,rowID:rowId,columnIndex:colElements[i].element.index(),columnKey:colKey,editor:editor,value:newValues[colKey],oldValue:prevValues[colKey],update:update.update&&newValues[colKey]!==prevValues[colKey],rowAdding:add};noCancel=this._trigger(this.events.editCellEnding,evt,cArg);if(!noCancel&&mode==="cell"){return false}if(update.update){if(mode==="cell"&&!add){update.update=cArg.update}else{if(!cArg.update){newValues[colKey]=prevValues[colKey]}}}}}return true},_fireEndedEvents:function(evt,prevValues,newValues,colElements,rowId,add,update){var i,colKey,editor,rArg,cArg,mode=this.options.editMode;if(mode!=="dialog"){for(i=0;i<colElements.length;i++){colKey=colElements[i].colKey;editor=this.editorForKey(colKey);cArg={owner:this,rowID:rowId,columnIndex:colElements[i].element.index(),columnKey:colKey,editor:editor,value:newValues[colKey],oldValue:prevValues[colKey],update:update.update&&newValues[colKey]!==prevValues[colKey],rowAdding:add};this._trigger(this.events.editCellEnded,evt,cArg)}}if(mode!=="cell"){rArg={owner:this,oldValues:prevValues,values:update.update?newValues:prevValues,rowID:rowId,update:update.update,rowAdding:add};
this._trigger(this.events.editRowEnded,evt,rArg)}},_getNewValuesForRow:function(colElements){var i,key,editor,provider,providerWrapper,newValues={};for(i=0;i<colElements.length;i++){key=colElements[i].colKey;editor=this.editorForKey(key);providerWrapper=editor.data("igEditorFilter");provider=providerWrapper.options.provider;provider.refreshValue();newValues[key]=provider.getValue()}return newValues},_compareValues:function(prevValues,newValues){var key,noChange=true;for(key in newValues){if(newValues.hasOwnProperty(key)){if($.type(newValues[key])==="date"&&$.type(prevValues[key])==="date"){noChange=noChange&&newValues[key].getTime()===prevValues[key].getTime()}else{noChange=noChange&&newValues[key]===prevValues[key]}}}return!noChange},_closeEditingForRow:function(colElements){var i,colKey,editor,provider,providerWrapper;for(i=0;i<colElements.length;i++){colKey=colElements[i].colKey;editor=this.editorForKey(colKey);providerWrapper=editor.data("igEditorFilter");provider=providerWrapper.options.provider;providerWrapper.remove();colElements[i].element.closest("td").removeClass(this.css.editingCell)}},_createEditor:function(cell,columnKey,element){var vh=this._validationHandlers,colSetting=this._getColSettingsForCol(columnKey),column=this.grid.columnByKey(columnKey),provider=colSetting?colSetting.editorProvider:null,editorOptions,validatorOptions,required,editorMargins,wrapper,elem,format=column.format;editorMargins=!element?this._getEditorMargins(cell):null;if(colSetting){editorOptions=colSetting.editorOptions||{};validatorOptions=editorOptions.validatorOptions;required=colSetting.required;if(!validatorOptions&&(colSetting.validation||required)){validatorOptions={}}if(required){validatorOptions.required=true;editorOptions.required=true}}if(!validatorOptions&&this.options.validation){validatorOptions={}}if(validatorOptions){if(!this.grid.element.igValidator){throw new Error($.ig.GridUpdating.locale.igValidatorException)}if(colSetting){colSetting.editorOptions=editorOptions}editorOptions.validatorOptions=validatorOptions;validatorOptions.notificationOptions=validatorOptions.notificationOptions||{};if(!element){validatorOptions.notificationOptions.mode="popover";validatorOptions.notificationOptions.containment=this.grid.container();validatorOptions.notificationOptions.appendTo=this.grid.container()}}if(!provider){provider=this._getProviderForKey(column,colSetting)}elem=provider.createEditor(this._editorCallbacks,columnKey,colSetting?colSetting.editorOptions||null:null,this._getNextTabIndex(),format,element);provider.attachErrorEvents(vh.errorShowing,vh.errorShown,vh.errorHidden);if(!element){elem.addClass(this.css.editor).css({marginLeft:editorMargins.x+"px",marginTop:editorMargins.y+"px"});elem.css("position","absolute")}wrapper=elem.igEditorFilter({provider:provider});return wrapper},_getProviderForKey:function(column,setting){var provider,dataType=column.dataType,format=column.format,editorType=setting?setting.editorType:null,value,ds;if(dataType==="bool"){provider=new $.ig.EditorProviderBoolean;if(format==="checkbox"||!format&&this.grid.options.renderCheckboxes){provider.renderFormat="checkbox"}else{provider.renderFormat="dropdown"}}else if(editorType==="combo"){provider=new $.ig.EditorProviderCombo}else if(editorType==="rating"){provider=new $.ig.EditorProviderRating}else if(editorType==="mask"){provider=new $.ig.EditorProviderMask}else if((editorType||format)==="currency"){provider=new $.ig.EditorProviderCurrency}else if((editorType||format)==="percent"){provider=new $.ig.EditorProviderPercent}else if(editorType==="numeric"||dataType==="number"){provider=new $.ig.EditorProviderNumeric}else if(editorType==="text"||dataType==="string"){provider=new $.ig.EditorProviderText}else if(editorType==="datepicker"){provider=new $.ig.EditorProviderDatePicker}else if((editorType||dataType)==="date"){provider=new $.ig.EditorProviderDate}else{ds=this.grid.dataSource;if(ds&&ds.data()&&ds.data().length){value=ds.data()[0][column.key];switch($.type(value)){case"number":return new $.ig.EditorProviderNumeric;case"string":return new $.ig.EditorProviderText;case"date":return new $.ig.EditorProviderDate;case"boolean":provider=new $.ig.EditorProviderBoolean;if(format==="checkbox"||!format&&this.grid.options.renderCheckboxes){provider.renderFormat="checkbox"}else{provider.renderFormat="dropdown"}return provider}}throw new Error($.ig.GridUpdating.locale.editorTypeCannotBeDetermined+column.key)}return provider},_getEditorKey:function(element){var id=element.attr("id"),colKey,idx;if(id&&id.length){idx=id.indexOf("_editorfor_");colKey=idx>0?id.substring(idx+10):null}if(!colKey){colKey=this._getColumnKeyForCell(element.closest("td"))}return colKey},_getEditorMargins:function(cell){if(!cell||!cell.length){return{x:0,y:0}}if(!this._editorMargins){var btw=parseInt(cell.css("borderTopWidth"),10);var paddingTop=parseInt(cell.css("paddingTop"),10);var blw=parseInt(cell.css("borderLeftWidth"),10);var paddingLeft=parseInt(cell.css("paddingLeft"),10);this._editorMargins={x:-1*(paddingLeft+blw),y:-1*(paddingTop+btw)}}return this._editorMargins},_getColSettingsForCol:function(colKey){var i,settings=this.options.columnSettings;if(!settings){return null}for(i=0;i<settings.length;i++){if(settings[i].columnKey===colKey){return settings[i]}}},_destroyAllEditors:function(){var key;for(key in this._editors){if(this._editors.hasOwnProperty(key)){if(this._editors[key].data("igEditorFilter")){this._editors[key].igEditorFilter("destroy");this._editors[key].remove()}}}delete this._editors},_navigateElement:function(evt,keyCode,rowId,columnKey,isAdd){if(keyCode===$.ui.keyCode.TAB||this.options.horizontalMoveOnEnter&&keyCode===$.ui.keyCode.ENTER){if(evt.shiftKey){return this._navigateLeft(evt,rowId,columnKey,isAdd)}this._navigateRight(evt,rowId,columnKey,isAdd)}if(keyCode===$.ui.keyCode.ENTER){if(isAdd){return this._endEdit(evt,true,false)}if(evt.shiftKey){return this._navigateUp(evt,rowId,columnKey)}return this._navigateDown(evt,rowId,columnKey)}if(keyCode===$.ui.keyCode.ESCAPE){return this._stopEditing()}if(this.options.excelNavigationMode){switch(keyCode){case $.ui.keyCode.LEFT:return this._navigateLeft(evt,rowId,columnKey,isAdd);case $.ui.keyCode.RIGHT:return this._navigateRight(evt,rowId,columnKey,isAdd);case $.ui.keyCode.DOWN:if(!isAdd){return this._navigateDown(evt,rowId,columnKey)}break;case $.ui.keyCode.UP:if(!isAdd){return this._navigateUp(evt,rowId,columnKey)}break}}},_navigateLeft:function(evt,rowId,columnKey,isAdd){if(!isAdd&&this.options.editMode==="cell"){return this._navigateLeftForCell(evt,rowId,columnKey)}},_navigateLeftForCell:function(evt,rowId,columnKey){var i,cols=this.grid._visibleColumns(),nextCell,curRow=this.grid.rowById(rowId);if(!this._endEdit(evt,true,false)){return}for(i=0;i<cols.length;i++){if(cols[i].key===columnKey){break}}while(curRow.length){rowId=this._getRowId(curRow);while(--i>=0){if(!cols[i].readOnly){nextCell=this.grid.cellById(rowId,cols[i].key);this._startEditForCell(evt,false,rowId,cols[i].key,nextCell,true,false);evt.preventDefault();return}}curRow=curRow.prevAll(":not([data-container],[data-grouprow],.ui-iggrid-deletedrecord):visible").first();if(!curRow.length&&this.options.wrapAround){curRow=this.element.children("tbody").children("tr:not([data-container=true]):last")}i=cols.length}},_navigateRight:function(evt,rowId,columnKey,isAdd){if(!isAdd&&this.options.editMode==="cell"){return this._navigateRightForCell(evt,rowId,columnKey)}},_navigateRightForCell:function(evt,rowId,columnKey){var i,cols=this.grid._visibleColumns(),nextCell,curRow=this.grid.rowById(rowId);if(!this._endEdit(evt,true,false)){return}for(i=0;i<cols.length;i++){if(cols[i].key===columnKey){break}}while(curRow.length){rowId=this._getRowId(curRow);while(++i<cols.length){if(!cols[i].readOnly){nextCell=this.grid.cellById(rowId,cols[i].key);this._startEditForCell(evt,false,rowId,cols[i].key,nextCell,true,false);evt.preventDefault();return}}curRow=curRow.nextAll(":not([data-container],[data-grouprow],.ui-iggrid-deletedrecord):visible").first();if(!curRow.length&&this.options.wrapAround){curRow=this.element.children("tbody").children("tr:first")}i=-1}},_navigateUp:function(evt,rowId,columnKey,element){var nextCell,curRow=element?element.closest("tr"):this.grid.rowById(rowId);if(!this._endEdit(evt,true,false)){return}curRow=curRow.prevAll(":not([data-container],[data-grouprow],.ui-iggrid-deletedrecord):visible").first();if(!curRow.length&&this.options.wrapAround){curRow=this.element.children("tbody").children("tr:not([data-container=true]):last")}if(curRow.length){rowId=this._getRowId(curRow);nextCell=this.grid.cellById(rowId,columnKey);if(this.options.editMode==="row"){this._startEditForRow(evt,false,rowId,columnKey,nextCell)}else{this._startEditForCell(evt,false,rowId,columnKey,nextCell,true,false)}evt.originalEvent.stopPropagation();evt.originalEvent.preventDefault()}},_navigateDown:function(evt,rowId,columnKey,element){var nextCell,curRow=element?element.closest("tr"):this.grid.rowById(rowId);if(!this._endEdit(evt,true,false)){return}curRow=curRow.nextAll(":not([data-container],[data-grouprow],.ui-iggrid-deletedrecord):visible").first();if(!curRow.length&&this.options.wrapAround){curRow=this.element.children("tbody").children("tr:first")}if(curRow.length){rowId=this._getRowId(curRow);nextCell=this.grid.cellById(rowId,columnKey);if(this.options.editMode==="row"){this._startEditForRow(evt,false,rowId,columnKey,nextCell)}else{this._startEditForCell(evt,false,rowId,columnKey,nextCell,true,false)}evt.originalEvent.stopPropagation();evt.originalEvent.preventDefault()}},_updateUnboundValuesForRow:function(row){if(!this.grid._hasUnboundColumns){return}var i,uc=this.grid._unboundColumns,col,f,rec;if(!uc||!uc.length){return}if($.type(row)==="object"){rec=row}for(i=0;i<uc.length;i++){col=uc[i];if(col&&col.editModeUnboundValues!=="manual"&&col.formula){if(col.formula){f=this.grid._getUnboundColumnFormula(col);if(f){if(!rec){rec=this.grid.findRecordByKey(row)}if(!rec){return}rec[col.key]=f.apply(col,[rec,this.grid.element])}}}}},_isEditableRow:function(row){return row&&row.is("tr")&&!row.hasClass(this.grid.css.deletedRecord)&&!row.attr("data-grouprow")&&(row.attr("data-id")!==undefined||row.attr("data-add-row")!==undefined)},_isEditableCell:function(cell){return this._isDataCell(cell)&&cell.attr("aria-readonly")!=="true"&&this._isEditableRow(cell.parent())},_isDataCell:function(cell){return cell&&cell.is("td")&&!cell.attr("data-skip")&&!cell.attr("data-parent")},_isLastScrollableCell:function(cell){return cell&&cell.is(":last-child")&&(parseInt(cell.css("padding-right"),10)>12||this.grid._hscrollbar().is(":visible")&&this.grid._hasVerticalScrollbar)&&this.grid.scrollContainer()&&this.grid.scrollContainer().has(cell).length},_selectionToggle:function(element){var sel=this.grid.element.data("igGridSelection");if(!sel){return}sel._suspend=!sel._suspend;if(element){this._actElement=element}else{this._actElement.focus()}},_showDoneCancelButtons:function(){var container=this._findElementInScrollContainer(".ui-iggrid-buttoncontainer:first");if(!container.length){container=this._renderDoneCancelButtons()}container.show()},_hideDoneCancelButtons:function(){var container=this._findElementInScrollContainer(".ui-iggrid-buttoncontainer:first");if(container.length){container.hide()}},_positionDoneCancelButtons:function(row){var container=this._findElementInScrollContainer(".ui-iggrid-buttoncontainer:first"),sbw=this.grid._hasVerticalScrollbar===true?this.grid._scrollbarWidth():0,left,top,sc,contHeight,scHeight,rowPos,go=this.grid.options,v,hasHeight=go.height!==null&&go.height!==undefined,scrContainer;row=this._combineRowElements(row);sc=container.parent();left=sc.outerWidth()-container.outerWidth()-sbw+sc.scrollLeft();if(!sc.has(row).length&&sc[0]!==this.grid.container()[0]){top=sc.scrollTop()}else{contHeight=container.outerHeight();scHeight=sc.outerHeight();rowPos=row.position();top=rowPos.top+row.outerHeight();if(top+contHeight>scHeight){top=rowPos.top-contHeight}if(!hasHeight){v=go.virtualization||go.rowVirtualization||go.columnVirtualization;scrContainer=v?this.grid._vdisplaycontainer():this.grid.scrollContainer();if(scrContainer.length){top+=scrContainer.position().top}}top+=sc.scrollTop()}container.css({top:top,left:left})},_disableDoneButton:function(){if(this.options.editMode==="dialog"){$("#"+this.grid.id()+"_updating_dialog_container").igGridModalDialog("option","buttonApplyDisabled",true)}else{$("#"+this.grid.id()+"_updating_done").addClass(this.css.buttonDisabled).removeClass(this.css.buttonActive)}},_enableDoneButton:function(){if(this.options.editMode==="dialog"){$("#"+this.grid.id()+"_updating_dialog_container").igGridModalDialog("option","buttonApplyDisabled",false)}else{$("#"+this.grid.id()+"_updating_done").removeClass(this.css.buttonDisabled)}},_updateDeleteButton:function(isAdding){var button=$("#"+this.grid.id()+"_updating_delete_touch");if(button.length){if(isAdding||!this.options.enableDeleteRow){button.addClass(this.css.buttonDisabled)}else{button.removeClass(this.css.buttonDisabled)}}},_showDeleteButtonFor:function(row){var db=$("#"+this.grid.id()+"_updating_deletehover"),go=this.grid.options,v,hasHeight=go.height!==null&&go.height!==undefined,sbw=this.grid._hasVerticalScrollbar===true?this.grid._scrollbarWidth():0,left,top,sc,offset=0,scrContainer;if(db.length){db.show();sc=db.parent();if(!hasHeight){v=go.virtualization||go.rowVirtualization||go.columnVirtualization;scrContainer=v?this.grid._vdisplaycontainer():this.grid.scrollContainer();if(scrContainer.length){offset=scrContainer.position().top}}left=sc.outerWidth()-db.outerWidth()-sbw+sc.scrollLeft()-5;top=row.position().top+row.outerHeight()/2-db.outerHeight()/2+sc.scrollTop()+offset;db.css({top:top,left:left});db.data("button-for",this._getRowId(row))}},_hideDeleteButton:function(){var db=$("#"+this.grid.id()+"_updating_deletehover");if(db.length){db.hide()}},_getNextTabIndex:function(){var gti=this.grid.options.tabIndex;return gti+1},_getRowId:function(element){return this.grid._fixPKValue(element.attr("data-id"))},_getEditableElementsForRow:function(row){var result=[],i,cells=this._getEditableCellsForRow(row),editableCols=$.grep(this.grid._visibleColumns(),function(col){return!col.readOnly}),vcc=this.grid._virtualColumnCount||this.grid._visibleColumns().length,vci=this.grid._startColIndex||0;for(i=0;i<editableCols.length;i++){result.push({colKey:editableCols[i].key,element:i>=vci&&i<vci+vcc?cells.eq(i-vci):null})}return result},_getEditedColumnElementsForRow:function(row){var result=[],cells,i;cells=this._getEditableCellsForRow(row).filter("."+this.css.editingCell);for(i=0;i<cells.length;i++){result.push({colKey:this._getColumnKeyForCell(cells.eq(i)),element:cells.eq(i)})}return result},_getEditedColumnElementsForDialog:function(content){var result=[],cols=this.grid.options.columns,i,key,element;for(i=0;i<cols.length;i++){key=cols[i].key;element=content.find("[data-editor-for-"+key.toLowerCase()+"]");if(element.length===1){result.push({colKey:key,element:element})}}return result},_getEditableCellsForRow:function(row){return this._combineRowElements(row).children("td[aria-readonly='false']:not([data-skip='true'],[data-parent])")},_combineRowElements:function(row){var frow,urow,fixingDir=this.grid.fixingDirection(),type=row.attr("data-new-row")?"[data-new-row]":"[data-add-row]";if(this.grid.hasFixedColumns()){if(this.grid._isFixedElement(row)){frow=row;urow=row.parent().is("thead")?this.grid.headersTable().children("thead").children("tr"+type):this._getRowByIndex(this._getIndexForRow(row),false)}else{urow=row;frow=row.parent().is("thead")?this.grid.fixedHeadersTable().children("thead").children("tr"+type):this._getRowByIndex(this._getIndexForRow(row),true)}return fixingDir==="left"?frow.add(urow):urow.add(frow)}return row},_getVisibleIndexForKey:function(columnKey){var vc=this.grid._visibleColumns(),i;for(i=0;i<vc.length;i++){if(vc[i].key===columnKey){return i}}return null},_getRowByIndex:function(index,fixed){var tbody=fixed?this.grid.fixedBodyContainer().find("tbody"):this.grid.element.find("tbody");return tbody.children("tr:not([data-container])").eq(index)},_getIndexForRow:function(row){return row.closest("tbody").children("tr:not([data-container])").index(row)+(this.grid._startRowIndex||0)},_getColumnKeyForCell:function(cell){var col=this.grid._getColumnByTD(cell);return col?col.column.key:null},_analyzeEditTriggers:function(){var trg=this.options.startEditTriggers,key;this._editTriggers={click:false,dblclick:false,f2:false,enter:false};for(key in this._editTriggers){if(this._editTriggers.hasOwnProperty(key)){if($.type(trg)==="array"){this._editTriggers[key]=$.inArray(key,trg)}else{this._editTriggers[key]=trg.toLowerCase().indexOf(key)>=0}}}},_rebindEditTriggers:function(){var selector="#"+this.grid.id()+">tbody>tr>td,#"+this.grid.id()+"_fixed>tbody>tr>td",hId,scr;if(this.options.enableAddRow&&this.grid.options.showHeader){hId=this.grid.headersTable().attr("id");selector+=",#"+hId+">thead>tr.ui-iggrid-addrow,#"+hId+"_fixed>thead>tr.ui-iggrid-addrow"}this.grid.container().off(".triggers");this.grid.container().on({"mousedown.triggers":this._handlers.mouseDown},selector);if(this._editTriggers.dblclick){this.grid.container().on({"dblclick.triggers":this._handlers.clickTrigger},selector)}else if(this._editTriggers.click){this.grid.container().on({"click.triggers":this._handlers.clickTrigger},selector)}this.grid.container().on({"keydown.triggers":this._handlers.keyDown},selector.replace(/>td/g,""));if(this.options.enableDeleteRow){this._renderDeleteButton()}scr=this._addElementToScrollContainer($());if(scr&&scr.length&&scr[0]!==this.grid.container()[0]){scr.unbind("scroll",this._handlers.scroll).bind("scroll",this._handlers.scroll)}},_getLatestValues:function(id,columnKey){var original,record,transactions,i,notNew=false;original=this.grid.dataSource.findRecordByKey(id);record=jQuery.extend(true,{},original);transactions=this.grid.dataSource.pendingTransactions();for(i=transactions.length-1;i>=0;i--){if(transactions[i].rowId===id){switch(transactions[i].type){case"row":case"newrow":jQuery.extend(true,record,transactions[i].row);break;case"cell":record[transactions[i].col]=transactions[i].value;break;case"deleterow":record=null;break}notNew=true}}if(original||notNew){return $.type(columnKey)==="string"?record[columnKey]:record}throw new Error($.ig.GridUpdating.locale.recordOrPropertyNotFoundException)},_getDefaultValues:function(columnKey){var defVals=this._defaultValues,allValues,settings=this.options.columnSettings,i,gpkArgs;if(!defVals){defVals={};for(i=0;i<settings.length;i++){if(settings[i].defaultValue!==undefined&&$.type(settings[i].columnKey)==="string"){defVals[settings[i].columnKey]=settings[i].defaultValue}}this._defaultValues=defVals}allValues=jQuery.extend(true,{},defVals);if((!columnKey||columnKey===this.grid.options.primaryKey)&&!defVals.hasOwnProperty(columnKey)){gpkArgs={};if(this._getPKType()==="string"){gpkArgs.value=String(this._pkVal)}else{gpkArgs.value=this._pkVal}this._trigger(this.events.generatePrimaryKeyValue,null,gpkArgs);allValues[this.grid.options.primaryKey]=gpkArgs.value}return columnKey?allValues[columnKey]:allValues},_getPKType:function(){var pk=this.grid.options.primaryKey,pkType,pkColumn,data=this.grid.dataSource._data;if(!this._pkt){if(!pk){throw new Error($.ig.GridUpdating.locale.noPrimaryKeyException)}pkColumn=this.grid.columnByKey(pk);if(pkColumn&&pkColumn.dataType){pkType=pkColumn.dataType}else{pkType=data&&data.length>0&&data[0][pk]!==null&&data[0][pk]!==undefined?$.type(data[0][pk]):null}this._pkt=pkType}return this._pkt},_updateUIForTransaction:function(t,element){var go=this.grid.options,autoCommit=go.autoCommit,v=go.virtualization||go.rowVirtualization||go.columnVirtualization,fv=go.virtualizationMode==="fixed",row,vals,pk,grp,idx,nextRow;switch(t.type){case"newrow":grp=this.grid.element.children("tbody").children("tr.ui-iggrid-groupedrow").length>0;this._updateUnboundValuesForRow(t.row);if(v&&!autoCommit){break}if(grp){this.grid.element.data("igGridGroupBy")._renderNewRow(t.row)}else{this.grid.renderNewRow(t.row)}row=this.grid.rowById(t.rowId);if(!autoCommit&&row.length){this._combineRowElements(row).addClass(this.grid.css.modifiedRecord)}break;case"cell":pk=autoCommit&&t.col===go.primaryKey?t.value:t.rowId;row=element?element.parent():this.grid.rowById(pk);vals=this._getLatestValues(pk);vals[t.col]=t.value;this._updateUnboundValuesForRow(vals);if(!row||!row.length){break}this.grid._renderRow(vals,row);if(!autoCommit){this._combineRowElements(row).addClass(this.grid.css.modifiedRecord)}else{this._combineRowElements(row).attr("data-id",pk).data("id",pk)}break;case"row":pk=autoCommit&&t.row.hasOwnProperty(go.primaryKey)?t.row[go.primaryKey]:t.rowId;row=element||this.grid.rowById(pk);vals=$.extend({},this._getLatestValues(pk),t.row);this._updateUnboundValuesForRow(vals);if(!row||!row.length){break}this.grid._renderRow(vals,row);if(!autoCommit){this._combineRowElements(row).addClass(this.grid.css.modifiedRecord)}else{this._combineRowElements(row).attr("data-id",pk).data("id",pk)}break;case"deleterow":row=element||this.grid.rowById(t.rowId);if(autoCommit&&v){this._deleteRowVirtualization(row,fv);break}if(!row||!row.length){break}if(autoCommit){idx=row.index();row=this._combineRowElements(row);nextRow=row.next("tr[data-container='true']");if(nextRow.length===1){nextRow.remove()}row.remove();this.grid._reapplyZebraStyle(idx)}else{this._combineRowElements(row).addClass(this.grid.css.deletedRecord)}break}return row},_processReadOnly:function(){var i,col,colSettings=this.options.columnSettings;if(colSettings){for(i=0;i<colSettings.length;i++){if(colSettings[i].readOnly){col=this.grid.columnByKey(colSettings[i].columnKey);if(col){col.readOnly=true}}}}},_isMultiLineText:function(key){var cs=this._getColSettingsForCol(key);if(cs&&cs.editorOptions){return cs.editorOptions.textMode==="multiline"}return false},_anyEditorInvalid:function(){var key,all=this._editors,provider;for(key in all){if(all.hasOwnProperty(key)&&all[key]){provider=all[key].data("igEditorFilter").options.provider;provider.refreshValue();if(!all[key].data("igEditorFilter").options.provider.isValid()){return true}}}return false},_revertValueForEditor:function(provider,columnKey){var oval,nval;provider.refreshValue();nval=provider.getValue();oval=this._originalValues[columnKey];if($.type(nval)==="date"&&$.type(oval)==="date"&&nval.getTime()!==oval.getTime()){provider.setValue(new Date(oval.getTime()));return true}if(oval!==nval){provider.setValue(oval);return true}return false},_hideValidatorMessages:function(){var key,e=this._editors,editor,wrapper;for(key in e){if(e.hasOwnProperty(key)){editor=e[key];wrapper=editor.data("igEditorFilter");if(wrapper&&wrapper.hasInvalidMessage()){editor.igNotifier("hide")}}}},_addDSSuccessHandler:function(){var fS,grid=this.grid;if(this._addChangesSuccessHandler!==null&&this._addChangesSuccessHandler!==undefined){grid.dataSource._removeChangesSuccessHandler(this._addChangesSuccessHandler)}fS=this.options.saveChangesSuccessHandler;if(fS){if($.type(fS)==="string"&&window[fS]&&$.type(window[fS])==="function"){fS=window[fS]}}if($.type(fS)!=="function"){fS=null}this._addChangesSuccessHandler=function(data){if(data.Success){if(grid.rows().parent().find("."+grid.css.deletedRecord).length){grid._renderData()}grid.rows().removeClass(grid.css.modifiedRecord);if(fS){fS(data)}}};grid.dataSource._addChangesSuccessHandler(this._addChangesSuccessHandler)},_addDSErrorHandler:function(){var fE;if(this._addChangesErrorHandler!==null&&this._addChangesErrorHandler!==undefined){this.grid.dataSource._removeChangesErrorHandler(this._addChangesErrorHandler)}if(this.options.saveChangesErrorHandler){fE=this.options.saveChangesErrorHandler;if($.type(fE)==="string"&&window[fE]&&$.type(window[fE])==="function"){fE=window[fE]}if($.type(fE)==="function"){this._addChangesErrorHandler=function(jqXHR,textStatus,errorThrown){fE(jqXHR,textStatus,errorThrown)};this.grid.dataSource._addChangesErrorHandler(this._addChangesErrorHandler)}}},_deleteRowVirtualization:function(row,fixed){if(fixed){if(this.grid._startRowIndex+this.grid._virtualRowCount===this.grid._totalRowCount){this.grid._startRowIndex=Math.max(0,this.grid._startRowIndex-1)}this.grid._totalRowCount--;if(this.grid._virtualRowCount>this.grid._totalRowCount){this.grid._buildVirtualDom()}else{this.grid._renderVirtualRecords();this.grid._setScrollContainerHeight(this.grid._totalRowCount*parseInt(this.grid.options.avgRowHeight,10))}}else{this.grid._rerenderVirtualRecordsContinuous()}},_childrenWithAddRowEnabled:function(opts,inheritedRule){var i,j,cl,clr;if(opts.columnLayouts){for(i=0;i<opts.columnLayouts.length;i++){cl=opts.columnLayouts[i];if(inheritedRule!==null&&inheritedRule!==undefined){clr=inheritedRule}else{clr=$.ui.igGridUpdating.prototype.options.enableAddRow}if(cl.features&&cl.features.length>0){for(j=0;j<cl.features.length;j++){if(cl.features[j].name==="Updating"){return cl.features[j].enableAddRow===null||cl.features[j].enableAddRow===undefined?clr:cl.features[j].enableAddRow}}}else{return inheritedRule===true}}}return false},_recOrPropFound:function(rowId,colKey){var pendingTransactions=this.grid.dataSource.pendingTransactions(),rec,i=pendingTransactions.length,found;rec=this.grid.dataSource.findRecordByKey(rowId);found=!!rec;if(colKey){found=found&&rec.hasOwnProperty(colKey)}if(!found){while(--i>=0){if(pendingTransactions[i].rowId===rowId){return colKey?pendingTransactions[i].row.hasOwnProperty(colKey):true}}return false}return true},_activateEditor:function(editor){var cell=editor.closest("td");this._scrollTo(cell);editor.igEditorFilter("setFocus")},_scrollTo:function(cell){var scrollContainer=this.grid.scrollContainer(),cellPosition,ct,cl;if(scrollContainer.length&&scrollContainer.has(cell)){cellPosition=cell.position();ct=cellPosition.top+scrollContainer.scrollTop();cl=cellPosition.left+scrollContainer.scrollLeft();if(cellPosition.left<0){scrollContainer.scrollLeft(cl)}else if(cl+cell.outerWidth()>scrollContainer.scrollLeft()+scrollContainer.outerWidth()){scrollContainer.scrollLeft(cl+cell.outerWidth()-scrollContainer.outerWidth())}if(cellPosition.top<0){scrollContainer.scrollTop(ct)}else if(ct+cell.outerHeight()>scrollContainer.scrollTop()+scrollContainer.outerHeight()){scrollContainer.scrollTop(ct+cell.outerHeight()-scrollContainer.outerHeight())}}},_deleteRow:function(evt,rowId,suppress){var arg,t,autoCommit=this.grid.options.autoCommit,row=this.grid.rowById(rowId);if(row.hasClass(this.grid.css.deletedRecord)){return}arg={owner:this,element:row,rowID:rowId};if(!suppress){if(!this._trigger(this.events.rowDeleting,evt,arg)){return false}}t=this.grid.dataSource.deleteRow(rowId,autoCommit);row=this._updateUIForTransaction(t,row);this._notifyRowDeleted(rowId,row);if(!suppress){this._trigger(this.events.rowDeleted,evt,arg)}return true},_deleteMultipleRows:function(evt){var selectedRows=this.grid.element.igGridSelection("selectedRows"),i;for(i=0;i<selectedRows.length;i++){if(selectedRows[i]&&selectedRows[i].hasOwnProperty("id")&&!selectedRows[i].element.hasClass(this.grid.css.deletedRecord)){this._deleteRow(evt,selectedRows[i].id,false)}}},_updateRow:function(rowId,updateObj,row){var t,autoCommit=this.grid.options.autoCommit;row=row||this.grid.rowById(rowId);t=this.grid.dataSource.updateRow(rowId,updateObj,autoCommit);this._updateUIForTransaction(t,row);this._notifyRowUpdated(rowId,row)},_updateCell:function(rowId,colKey,value,cell){var t,autoCommit=this.grid.options.autoCommit;t=this.grid.dataSource.setCellValue(rowId,colKey,value,autoCommit);this._updateUIForTransaction(t,cell);this._notifyCellUpdated(rowId,cell)},_addRow:function(evt,addObj,defVals,suppress){var arg,key,t,row;addObj=$.extend({},defVals,addObj);arg={owner:this,values:addObj,oldValues:defVals};if(!suppress){if(!this._trigger(this.events.rowAdding,evt,arg)){return false}}key=addObj[this.grid.options.primaryKey];t=this.grid.dataSource.addRow(key,addObj,this.grid.options.autoCommit);row=this._updateUIForTransaction(t);this._notifyRowAdded(row);if($.type(this._pkVal)==="number"){this._pkVal++}if(!suppress){this._trigger(this.events.rowAdded,evt,arg)}},_notifyRowAdded:function(row){var rs=this.grid.element.data("igGridRowSelectors"),pa=this.grid.element.data("igGridPaging"),su=this.grid.element.data("igGridSummaries");if(rs&&typeof rs._rowAdded==="function"){rs._rowAdded(row)}if(pa&&typeof pa._rowAdded==="function"){pa._rowAdded(row)}if(su&&typeof su._rowAdded==="function"){su._rowAdded(row)}this.grid._fireInternalEvent("_internalRowAdded",{row:row})},_notifyRowDeleted:function(rowId,element){var se=this.grid.element.data("igGridSelection"),pa=this.grid.element.data("igGridPaging"),su=this.grid.element.data("igGridSummaries");if(se&&typeof se._rowDeleted==="function"){se._rowDeleted(rowId,element)}if(su&&typeof su._rowDeleted==="function"){su._rowDeleted(rowId,element)}if(pa&&typeof pa._rowDeleted==="function"){pa._rowDeleted(rowId,element)}this.grid._fireInternalEvent("_internalRowDeleted",{rowID:rowId,row:element})},_notifyCellUpdated:function(rowId,cell){this.grid._fireInternalEvent("_internalCellUpdated",{rowID:rowId,cell:cell})},_notifyRowUpdated:function(rowId,row){this.grid._fireInternalEvent("_internalRowUpdated",{rowID:rowId,row:row})},_renderRowEditDialog:function(rerender){var opts=this.options.rowEditDialogOptions,container,containment,captionsContainer,closeButton,dialogSelector="#"+this.grid.id()+"_updating_dialog_container",titleLabel=opts.captionLabel!==null?opts.captionLabel:$.ig.GridUpdating.locale.rowEditDialogCaptionLabel,doneButtonLabel=this.options.doneLabel!==null?this.options.doneLabel:$.ig.GridUpdating.locale.doneLabel,doneButtonTitle=this.options.doneTooltip!==null?this.options.doneTooltip:$.ig.GridUpdating.locale.doneTooltip,cancelButtonLabel=this.options.cancelLabel!==null?this.options.cancelLabel:$.ig.GridUpdating.locale.cancelLabel,cancelButtonTitle=this.options.cancelTooltip!==null?this.options.cancelTooltip:$.ig.GridUpdating.locale.cancelTooltip;container=$(dialogSelector);if(container.length){if(!rerender){return container}container.igGridModalDialog("destroy");container.remove();this._destroyAllEditors()}if(opts.containment==="owner"){containment=this.grid._rootContainer()}else{containment="window"}container=$("<div></div>").appendTo(this.grid._rootContainer()).attr("id",dialogSelector.substring(1));container.igGridModalDialog({containment:containment,renderFooterButtons:opts.showDoneCancelButtons,modalDialogCaptionText:titleLabel,modalDialogWidth:opts.width,modalDialogHeight:opts.height,buttonApplyText:doneButtonLabel,buttonApplyTitle:doneButtonTitle,buttonCancelText:cancelButtonLabel,buttonCancelTitle:cancelButtonTitle,animationDuration:opts.animationDuration,buttonApplyDisabled:true,gridContainer:this.grid._rootContainer(),modalDialogOpening:this._dialogHandlers.dialogOpening,modalDialogClosing:this._dialogHandlers.dialogClosing,modalDialogClosed:this._dialogHandlers.dialogClosed,buttonOKClick:this._dialogHandlers.dialogDone,buttonCancelClick:this._dialogHandlers.dialogCancel});captionsContainer=container.igGridModalDialog("getCaptionButtonContainer");closeButton=$("<button></button>").attr("id",this.grid.id()+"_updating_dialog_closeButton").appendTo(captionsContainer);closeButton.igButton({onlyIcons:true,icons:{primary:this.css.rowEditDialogCloseButton},width:"20px",height:"20px",click:this._dialogHandlers.dialogCloseClick});this._dialogInvalid=false;this._editorsContainerInvalid=true;this._trigger(this.events.rowEditDialogContentsRendered,null,{owner:this,dialogElement:container});return container},_renderDialogContent:function(content,values){var opts=this.options.rowEditDialogOptions,colgroup,tmpl;this._clearEditorsFromContainer(content);content.empty();if(opts.dialogTemplateSelector){tmpl=$(opts.dialogTemplateSelector);content.append($(this._jsr?tmpl.render(values):$.ig.tmpl(tmpl.html().fullTrim(),values)))
}else if(opts.dialogTemplate){tmpl=opts.dialogTemplate;content.append($(this._jsr?$.render[this.grid.id()+"_rowEditDialogTemplate"](values):$.ig.tmpl(tmpl,values)))}else{content.html(this._defaultDialogTemplate);content.find("table").addClass(this.css.rowEditDialogTable);colgroup=content.find("colgroup");colgroup.children(":first").css("width",opts.namesColumnWidth);colgroup.children(":last").css("width",opts.editorsColumnWidth);colgroup.parent().css("width","100%")}},_renderDialogTemplate:function(tmplParent,cols,onlyVisible){var opts=this.options.rowEditDialogOptions,tmpl,i,tr,e;cols=onlyVisible?$.grep(cols,function(col){return!col.hidden}):cols;if(!opts.showReadonlyEditors){cols=$.grep(cols,function(col){return!col.readOnly})}if(opts.editorsTemplateSelector){tmpl=$(opts.editorsTemplateSelector);tmplParent.append($(this._jsr?tmpl.render(cols):$.ig.tmpl(tmpl.html().fullTrim(),cols)))}else if(opts.editorsTemplate){tmpl=opts.editorsTemplate;tmplParent.append($(this._jsr?$.render[this.grid.id()+"_rowEditDialogEditorsTemplate"](cols):$.ig.tmpl(tmpl,cols)))}else{for(i=0;i<cols.length;i++){tr=$("<tr></tr>");$("<td>"+(cols[i].headerText||cols[i].key)+"</td>").appendTo(tr);$("<td></td>").appendTo(tr);e=this._isMultiLineText(cols[i].key)?$("<textarea></textarea>"):$("<input />");e.attr("data-editor-for-"+cols[i].key,"").appendTo(tr.children(":last"));tr.appendTo(tmplParent)}}},_initDialogEditors:function(content,cols,values){var i=0,provider,providerWrapper,ro,key,element,val,settings;this._editors=this._editors||{};while(i<cols.length){key=cols[i].key;ro=!!cols[i].readOnly;val=values[key]===undefined?null:values[key];element=content.find("[data-editor-for-"+key.toLowerCase()+"]");if(element.length===1){providerWrapper=element.data("igEditorFilter");if(providerWrapper){provider=providerWrapper.options.provider;provider.setValue(val)}else{if(ro){settings=this._getColSettingsForCol(key);if(!settings){this.options.columnSettings.push({columnKey:key,editorOptions:{readOnly:true}})}else{$.extend(true,settings,{editorOptions:{readOnly:true}})}}providerWrapper=this._createEditor(null,key,element);this._editors[key]=providerWrapper;provider=providerWrapper.igEditorFilter("option","provider");provider.setValue(val)}this._originalValues=this._originalValues||{};this._originalValues[key]=provider.getValue();$.ig.removeFromArray(cols,i,i)}else{i++}}},_clearEditorsFromContainer:function(content){var cols=this.grid.options.columns,i=-1,key,element,providerWrapper;while(++i<cols.length){key=cols[i].key;element=content.find("[data-editor-for-"+key.toLowerCase()+"]");if(element.length){providerWrapper=this.editorForKey(key).data("igEditorFilter");if(providerWrapper){this.editorForKey(key).igEditorFilter("destroy");delete this._editors[key]}}}},_renderDoneCancelButtons:function(){var buttonContainer,buttonsParent,doneButton,cancelButton,deleteButton,doneButtonLabel=this.options.doneLabel!==null?this.options.doneLabel:$.ig.GridUpdating.locale.doneLabel,doneButtonTitle=this.options.doneTooltip!==null?this.options.doneTooltip:$.ig.GridUpdating.locale.doneTooltip,cancelButtonLabel=this.options.cancelLabel!==null?this.options.cancelLabel:$.ig.GridUpdating.locale.cancelLabel,cancelButtonTitle=this.options.cancelTooltip!==null?this.options.cancelTooltip:$.ig.GridUpdating.locale.cancelTooltip,doneSelector,cancelSelector,deleteSelector;buttonContainer=$("<div></div>").css("position","absolute").attr("unselectable","on").addClass(this.css.buttonContainer);buttonsParent=this._addElementToScrollContainer(buttonContainer);doneButton=$("<span></span").attr("id",this.grid.id()+"_updating_done").addClass(this.css.button).addClass(this.css.doneButton).attr({unselectable:"on",tabIndex:this._getNextTabIndex()+1,title:doneButtonTitle}).appendTo(buttonContainer);$("<span></span>").css("display","inline-block").addClass(this.css.doneIcon).attr("unselectable","on").appendTo(doneButton);if(doneButtonLabel&&doneButton.length){$("<span></span>").css("display","inline-block").attr("unselectable","on").html(doneButtonLabel).appendTo(doneButton)}else{doneButton.addClass(this.css.buttonIconOnly)}cancelButton=$("<span></span>").attr("id",this.grid.id()+"_updating_cancel").addClass(this.css.button).addClass(this.css.cancelButton).attr({unselectable:"on",tabIndex:this._getNextTabIndex()+1,title:cancelButtonTitle}).appendTo(buttonContainer);$("<span></span>").css("display","inline-block").addClass(this.css.cancelIcon).attr("unselectable","on").appendTo(cancelButton);if(cancelButtonLabel&&cancelButtonLabel.length){$("<span></span>").css("display","inline-block").attr("unselectable","on").html(cancelButtonLabel).appendTo(cancelButton)}else{cancelButton.addClass(this.css.buttonIconOnly)}if(this._renderTouchUI&&this.options.enableDeleteRow){deleteButton=$("<span />").attr("id",this.grid.id()+"_updating_delete_touch").addClass(this.css.button).addClass(this.css.doneButton).attr({unselectable:"on",tabIndex:this._getNextTabIndex()+1,title:this.options.deleteRowTooltip!==null?this.options.deleteRowTooltip:$.ig.GridUpdating.locale.deleteRowTooltip}).prependTo(buttonContainer);$("<span />").css({display:"inline-block",left:0}).addClass(this.css.deleteIcon).attr("unselectable","on").appendTo(deleteButton);$("<span />").css("display","inline-block").attr("unselectable","on").html(this.options.deleteRowLabel!==null?this.options.deleteRowLabel:$.ig.GridUpdating.locale.deleteRowLabel).appendTo(deleteButton);deleteButton.css("float","left");doneButton.css("float","right");cancelButton.css("float","right");buttonContainer.css("width",buttonsParent.outerWidth());deleteSelector="#"+deleteButton.attr("id")}doneSelector="#"+doneButton.attr("id");cancelSelector="#"+cancelButton.attr("id");this.grid.container().on({"mouseenter.donecancel":this._buttonHandlers.mouseEnter,"mouseleave.donecancel":this._buttonHandlers.mouseLeave,"focus.donecancel":this._buttonHandlers.focus,"blur.donecancel":this._buttonHandlers.blur},doneSelector+","+cancelSelector+(deleteSelector?","+deleteSelector:""));this.grid.container().on({"click.donecancel":this._buttonHandlers.doneClick,"keyup.donecancel":this._buttonHandlers.doneKeyUp},doneSelector);this.grid.container().on({"click.donecancel":this._buttonHandlers.cancelClick,"keyup.donecancel":this._buttonHandlers.cancelKeyUp},cancelSelector);if(deleteSelector){this.grid.container().on({"click.donecancel":this._buttonHandlers.touchDeleteClick,"keyup.donecancel":this._buttonHandlers.touchDeleteKeyUp},deleteSelector)}return buttonContainer},_removeDoneCancelButtons:function(){var container=this._findElementInScrollContainer(".ui-iggrid-buttoncontainer:first");this.grid.container().off(".donecancel");container.remove()},_renderDeleteButton:function(){var deleteButton,deleteParent,ubodySelector="#"+this.grid.id()+">tbody",fbodySelector="#"+this.grid.id()+"_fixed>tbody",deleteSelector="#"+this.grid.id()+"_updating_deletehover",deleteButtonTitle=this.options.deleteRowTooltip!==null?this.options.deleteRowTooltip:$.ig.GridUpdating.locale.deleteRowTooltip;deleteButton=$(deleteSelector);if(deleteButton.length){return}deleteButton=$("<span></span>").attr("id",deleteSelector.substring(1)).css("position","absolute").addClass(this.css.deleteButton).attr({unselectable:"on",title:deleteButtonTitle});deleteButton.hide();$("<span></span>").css("display","inline-block").addClass(this.css.deleteIcon).attr("unselectable","on").appendTo(deleteButton);deleteParent=this._addElementToScrollContainer(deleteButton);this.grid.container().on({"mouseenter.deletebutton":this._buttonHandlers.mouseEnter,"mouseleave.deletebutton":this._buttonHandlers.mouseLeave,"click.deletebutton":this._buttonHandlers.deleteClick,"pointerup.deletebutton":this._buttonHandlers.deleteClick,"keyup.deletebutton":this._buttonHandlers.deleteClick},deleteSelector);this.grid.container().on({"mouseenter.deletebutton":this._handlers.mouseEnter},ubodySelector+">tr,"+fbodySelector+">tr");if(this._renderTouchUI){this.grid.container().on({"touchstart.deletebutton":this._handlers.touchStart,"touchend.deletebutton":this._handlers.touchEnd},ubodySelector+">tr,"+fbodySelector+">tr")}if(deleteParent[0]===this.grid.container()[0]){this.grid.container().bind("mouseleave.deletebutton",this._handlers.mouseLeave)}else{this.grid.container().on({"mouseleave.deletebutton":this._handlers.mouseLeave},"#"+deleteParent.attr("id"))}},_removeDeleteButton:function(){$("#"+this.grid.id()+"_updating_deletehover").remove();this.grid.container().off(".deletebutton");this.grid.container().unbind(".deletebutton")},_renderAddNewRow:function(thead){var addRowLabel=this.options.addRowLabel!==null?this.options.addRowLabel:$.ig.GridUpdating.locale.addRowLabel,addRowTitle=this.options.addRowTooltip!==null?this.options.addRowTooltip:$.ig.GridUpdating.locale.addRowTooltip,addTr,newTr,mainTd;addTr=thead.children("tr[data-add-row='true']");if(!addTr.length){addTr=$("<tr></tr>").addClass(this.css.addRow).attr({"data-add-row":true,tabIndex:this.grid.options.tabIndex}).appendTo(thead)}addTr.empty();mainTd=$("<td></td>").attr("title",addRowTitle).addClass(this.css.addRow).appendTo(addTr);$("<span></span>").css("display","inline-block").addClass(this.css.addRowIcon).appendTo(mainTd);$("<span></span>").text(addRowLabel).css("outline",0).attr("tabIndex",0).appendTo(mainTd);newTr=thead.children("tr[data-new-row='true']");if(!newTr.length){newTr=$("<tr></tr>").attr("data-new-row","true").attr("data-role","newrow").appendTo(thead).hide()}},_addElementToScrollContainer:function(element){var go=this.grid.options,container,hasHeight=go.height!==null&&go.height!==undefined;if(!hasHeight){container=this.grid.container();element.appendTo(container)}else{if(go.virtualization||go.rowVirtualization||go.columnVirtualization){container=this.grid._vdisplaycontainer()}else{container=this.grid.scrollContainer()}element.prependTo(container)}return container},_findElementInScrollContainer:function(selector){var go=this.grid.options,container,hasHeight=go.height!==null&&go.height!==undefined;if(!hasHeight){container=this.grid.container()}else{if(go.virtualization||go.rowVirtualization||go.columnVirtualization){container=this.grid._vdisplaycontainer()}else{container=this.grid.scrollContainer()}}return container.children(selector)},_createHandlers:function(){this._stopEditingHandler=this._stopEditingHandler||$.proxy(this._stopEditing,this);this._gridHandlers=this._gridHandlers||{stopEditing:this._stopEditingHandler,gridDataRendering:$.proxy(this._gridDataRendering,this),rowsRendered:$.proxy(this._rowsRendered,this),headerRendering:$.proxy(this._processReadOnly,this),headerRendered:$.proxy(this._headerRendered,this),rendered:$.proxy(this._headerRendered,this),virtualFrameChanging:$.proxy(this._virtPreRender,this),virtualFrameChanged:$.proxy(this._virtPostRender,this),columnsCollectionModified:$.proxy(this._columnsModified,this)};this._handlers=this._handlers||{mouseDown:$.proxy(this._mouseDown,this),clickTrigger:$.proxy(this._clickTrigger,this),keyDown:$.proxy(this._keyDown,this),focus:$.proxy(this._focus,this),blur:$.proxy(this._blur,this),touchStart:$.proxy(this._touchStart,this),touchEnd:$.proxy(this._touchEnd,this),mouseEnter:$.proxy(this._rowMouseEnter,this),mouseLeave:$.proxy(this._containerMouseLeave,this),scroll:$.proxy(this._scroll,this)};this._buttonHandlers=this._buttonHandlers||{mouseEnter:$.proxy(this._buttonMouseEnter,this),mouseLeave:$.proxy(this._buttonMouseLeave,this),focus:$.proxy(this._buttonFocus,this),blur:$.proxy(this._buttonBlur,this),doneClick:$.proxy(this._doneButtonClick,this),doneKeyUp:$.proxy(this._doneButtonKeyUp,this),cancelClick:this._stopEditingHandler,cancelKeyUp:$.proxy(this._cancelButtonKeyUp,this),deleteClick:$.proxy(this._deleteButtonClick,this),touchDeleteClick:$.proxy(this._touchDeleteButtonClick,this),touchDeleteKeyUp:$.proxy(this._touchDeleteButtonKeyUp,this)};this._addNewRowHandlers=this._addNewRowHandlers||{focus:$.proxy(this._addRowFocus,this),blur:$.proxy(this._addRowBlur,this)};this._validationHandlers=this._validationHandlers||{errorShowing:$.proxy(this._editorErrorShowing,this),errorShown:$.proxy(this._editorErrorShown,this),errorHidden:$.proxy(this._editorErrorHidden,this)};this._dialogHandlers=this._dialogHandlers||{dialogCloseClick:$.proxy(this._dialogCloseClick,this),dialogOpening:$.proxy(this._dialogOpening,this),dialogClosing:$.proxy(this._dialogClosing,this),dialogClosed:$.proxy(this._dialogClosed,this),dialogDone:$.proxy(this._dialogDone,this),dialogCancel:$.proxy(this._dialogCancel,this)};this._editorCallbacks=this._editorCallbacks||{keyDown:$.proxy(this._editorKeyDown,this),textChanged:$.proxy(this._editorTextChanged,this)}},_unbindAllEvents:function(){this.grid.element.off({iggriduidirty:this._gridHandlers.stopEditing,iggridresizingcolumnresizing:this._gridHandlers.stopEditing,ighierarchicalgridrowexpanded:this._gridHandlers.stopEditing,iggridrendered:this._gridHandlers.gridRendered,iggriddatarendering:this._gridHandlers.gridDataRendering,iggridrowsrendered:this._gridHandlers.rowsRendered,iggridvirtualrendering:this._gridHandlers.virtualFrameChanging,iggridvirtualrecordsrender:this._gridHandlers.virtualFrameChanged,iggridcolumnscollectionmodified:this._gridHandlers.columnsCollectionModified,iggridheaderrendering:this._gridHandlers.headerRendering});if(this.options.enableAddRow){this.grid.element.off({iggridheaderrenderedinternal:this._gridHandlers.headerRendered,iggridrendered:this._gridHandlers.rendered})}this.grid.container().off({click:this._handlers.click})},_bindGridEvents:function(){this.grid.element.on({iggriduidirty:this._gridHandlers.stopEditing,iggridresizingcolumnresizing:this._gridHandlers.stopEditing,ighierarchicalgridrowexpanded:this._gridHandlers.stopEditing,iggriddatarendering:this._gridHandlers.gridDataRendering,iggridrowsrendered:this._gridHandlers.rowsRendered,iggridvirtualrendering:this._gridHandlers.virtualFrameChanging,iggridvirtualrecordsrender:this._gridHandlers.virtualFrameChanged,iggridcolumnscollectionmodified:this._gridHandlers.columnsCollectionModified,iggridheaderrendering:this._gridHandlers.headerRendering});if(this.options.enableAddRow){this.grid.element.on({iggridheaderrenderedinternal:this._gridHandlers.headerRendered,iggridrendered:this._gridHandlers.rendered})}},_injectGrid:function(gridInstance,isRebind){var hg,cl;this.grid=gridInstance;if(isRebind){return}this._dialogInvalid=true;this._defaultDialogTemplate="<table><colgroup><col></col><col></col></colgroup><tbody data-render-tmpl></tbody></table>";this._editors=this._editors||{};if(this.options.excelNavigationMode&&this.options.editMode!=="cell"&&this.options.editMode!=="row"){throw new Error($.ig.GridUpdating.locale.excelNavigationNotSupportedWithCurrentEditMode)}this._createHandlers();this._bindGridEvents();this._addDSSuccessHandler();this._addDSErrorHandler();this._analyzeEditTriggers();if(this.grid.options._isHierarchicalGrid&&this.grid._originalOptions){if(this.options.inherit){this.grid._shouldAlwaysRenderChildIndicator=this._childrenWithAddRowEnabled(this.grid.options,this.options.enableAddRow)}else{this.grid._shouldAlwaysRenderChildIndicator=this._childrenWithAddRowEnabled(this.grid.options)}if(!this.grid.dataSource.settings.schema.layouts){hg=this.grid.element.closest(".ui-iggrid-root").data("igHierarchicalGrid");cl=[];hg._parseLayouts(cl,"",this.grid._originalOptions);this.grid.dataSource.settings.schema.layouts=cl}}this._renderTouchUI=typeof Modernizr==="object"&&Modernizr.touch===true;if(window.navigator.msPointerEnabled||window.navigator.pointerEnabled){this.grid.element.css("-ms-touch-action","none");this.grid.element.css("touch-action","none")}if(String(this.grid.options.templatingEngine).toLowerCase()==="jsrender"){this._jsr=true;if(this.options.rowEditDialogOptions.dialogTemplate&&typeof this.options.rowEditDialogOptions.dialogTemplate==="string"){$.templates(this.grid.id()+"_rowEditDialogTemplate",this.options.rowEditDialogOptions.dialogTemplate)}if(this.options.rowEditDialogOptions.editorsTemplate&&typeof this.options.rowEditDialogOptions.editorsTemplate==="string"){$.templates(this.grid.id()+"_rowEditDialogEditorsTemplate",this.options.rowEditDialogOptions.editorsTemplate)}}}});$.extend($.ui.igGridUpdating,{version:"15.2.20152.1027"})})(jQuery);