(function() { var GridBaseEndlessPagingHelper = ASPx.CreateClass(null, { constructor: function(grid) { this.grid = grid; this.showLoadingPanelAtBottom = false; this.focusedRowIndexInfo = { beforeCallback: -1, underCallback: -1, afterCallback: -1 }; this.endlessCallbackComplete = false; }, GetItemsContainer: function(){ return this.grid.GetMainTable(); }, GetItemElements: function(){ var container = this.GetItemsContainer(); return container.tagName == "TABLE" ? container.rows : container.childNodes; }, GetEditingItemElements: function(){ var elements = [ ]; var row = this.grid.GetEditingRow(); if(row) elements.push(row); return elements; }, OnBeforeCallback: function(command) { this.endlessCallbackComplete = false; this.showLoadingPanelAtBottom = command === ASPxClientGridViewCallbackCommand.NextPage; this.focusedRowIndexInfo.beforeCallback = this.focusedRowIndexInfo.underCallback = this.GetFocusedItemIndex(); this.focusedRowIndexInfo.afterCallback = -1; this.ResetActiveElement(); }, OnAfterCallback: function() { var grid = this.grid; var lpContainer = grid.GetEndlessPagingLPContainer(); if(lpContainer) ASPx.SetElementDisplay(lpContainer, grid.pageIndex + 1 != grid.pageCount); this.CorrectItemIDs(); this.focusedRowIndexInfo.afterCallback = this.GetFocusedItemIndex(); this.CheckFocusedItemIndexChangedOnCallback(); grid.UpdateItemsStyle(); }, GetFocusedItemIndex: function(){ return -1; }, ResetActiveElement: function() { var activeElement = ASPx.GetActiveElement(); if(activeElement && ASPx.GetIsParent(this.GetItemsContainer(), activeElement)) { try { activeElement.blur(); } catch(e) { } } }, CheckFocusedItemIndexChangedOnCallback: function() { var info = this.focusedRowIndexInfo; if(info.beforeCallback === info.underCallback && info.underCallback === info.afterCallback) return; if(info.beforeCallback !== info.afterCallback) { this.grid.ChangeFocusedItemStyle(info.beforeCallback, false); this.grid.ChangeFocusedItemStyle(info.underCallback, false); } else if(info.beforeCallback !== info.underCallback) { this.grid.ChangeFocusedItemStyle(info.beforeCallback, false); this.grid.ChangeFocusedItemStyle(info.underCallback, true); this.grid.focusedRowIndex = info.underCallback; } this.grid._setFocusedItemInputValue(); }, OnGridFocusedItemChanged: function() { if(this.grid.InCallback()) this.focusedRowIndexInfo.underCallback = this.GetFocusedItemIndex(); }, CorrectItemIDs: function() { var grid = this.grid; var itemElements = this.GetItemElements(); if(itemElements.length == 0) return; var index = -1; var editingElements = this.GetEditingItemElements(); for(var i = 0; i < itemElements.length; i++) { var item = itemElements[i]; var id = item.id; if(!id) continue; var editingItemIndex = editingElements.indexOf(item); if(editingItemIndex > -1 && !this.IsEditRowHasDisplayedDataRow() && !grid.IsNewItemEditing()) { if(editingItemIndex == 0) index++; continue; } index = this.CorrectDataItemID(item, index); } ASPx.CacheHelper.DropCache(grid); }, CorrectDataItemID: function(item, prevVisibleIndex){ var supposedVisibleIndex = prevVisibleIndex; var regEx = this.grid.GetItemVisibleIndexRegExp(); var matches = regEx.exec(item.id); if(matches && matches.length == 3) { var visibleIndex = parseInt(matches[2]); if(this.IsNewRecord(visibleIndex)) return supposedVisibleIndex; if(this.IsDataItem(item)) supposedVisibleIndex++; if(visibleIndex != supposedVisibleIndex) item.id = item.id.replace(regEx, "$1" + supposedVisibleIndex); } return supposedVisibleIndex; }, IsEditRowHasDisplayedDataRow: function() { return false; }, IsDataItemID: function(id){ return false; }, IsDataItem: function(element) { if(element) return this.IsDataItemID(element.id); return false; }, IsBatchEditMode: function() { return ASPx.GridCommonUtils.IsBatchEditMode(this.grid); }, IsNewRecord: function(key) { return this.IsBatchEditMode() && this.grid.GetBatchEditHelper().IsNewRecord(key); }, NeedShowLoadingPanelAtBottom: function(){ return this.showLoadingPanelAtBottom && this.grid.GetEndlessPagingLPContainer(); }, OnCallback: function(str) { if(!this.grid.GetMainElement()) return; var result = eval(str.slice(str.indexOf("|") + 1)); this.UpdateKeyValues(result.pageKeys); this.UpdateGroupState(result.groupState); this.UpdateCellMergingState(result.cellMergeState); this.UpdateGroupLevelState(result.groupLevelState); if(result.removeEditForm) this.RemoveEditFormRow(); if(result.html) ASPx.SetInnerHtml(this.grid.GetEndlessPagingUpdatableContainer(), result.html); this.UpdateDataItems(result.dataTableInfo); this.grid.cButtonIDs = result.cButtonIDs; this.endlessCallbackComplete = true; }, UpdateDataItems: function(updateInfo) { if(!updateInfo || updateInfo.length == 0) return; for(var i = 0; i < updateInfo.length; i++) this.UpdateDataItemsCore(updateInfo[i]); }, UpdateDataItemsCore: function(updateInfo) { if(!updateInfo) return; var removeIndex = updateInfo[0]; var removeCount = updateInfo[1]; var addIndex = updateInfo[2]; var html = updateInfo[3]; this.RemoveDataItems(removeIndex, removeCount); if(addIndex < 0 || !html) return; var startItem = null; var visibleIndex = addIndex; do { startItem = this.grid.GetItem(visibleIndex); } while(!startItem && ++visibleIndex < this.grid.pageRowCount); var itemElements = this.GetItemElements(); var startRowIndex = startItem ? ASPx.Data.ArrayIndexOf(itemElements, startItem) : itemElements.length; this.InsertItems(this.GetItemsContainer(), html, startRowIndex); }, RemoveDataItems: function(removeIndex, removeCount) { if(removeIndex < 0 || removeCount <= 0) return; var startItem = this.grid.GetItem(removeIndex); if(!startItem) { startItem = this.grid.GetItem(++removeIndex); removeCount--; } var endItem = null; var visibleIndex = removeIndex + removeCount; do { endItem = this.grid.GetItem(visibleIndex); } while(!endItem && ++visibleIndex < this.grid.pageRowCount); var itemElements = this.GetItemElements(); var startRowIndex = ASPx.Data.ArrayIndexOf(itemElements, startItem); var endRowIndex = endItem ? ASPx.Data.ArrayIndexOf(itemElements, endItem) : itemElements.length; for(var i = endRowIndex - 1; i >= startRowIndex && startRowIndex >= 0; i--) this.RemoveItemFromLayout(itemElements[i]); }, InsertItems: function(container, rowsHtml, index) { if(!container || container.tagName != "TABLE") return; ASPx.InsertRowsBefore(container, rowsHtml, index); }, RemoveEditFormRow: function() { var editingElements = this.GetEditingItemElements(); for(var i = 0; i < editingElements.length; i++) this.RemoveItemFromLayout(editingElements[i]); ASPx.RemoveElement(this.grid.GetEditingErrorItem()); }, RemoveItemFromLayout: function(itemElement) { ASPx.RemoveElement(itemElement); }, UpdateKeyValues: function(updateInfo) { this.UpdateArray(this.grid.keys, updateInfo); this.grid.stateObject.keys = this.grid.keys; this.grid.EnsureRowKeys(); }, UpdateGroupState: function(updateInfo) { this.UpdateArray(this.grid.stateObject.endlessPagingGroupState, updateInfo); }, UpdateCellMergingState: function(cellMergeState){ }, UpdateGroupLevelState: function(groupLevelState) { }, UpdateArray: function(array, updateInfo) { if(!updateInfo) return; var removeIndex = updateInfo[0]; var removeCount = updateInfo[1]; var addIndex = updateInfo[2]; var newArray = updateInfo[3]; for(var i = 0; i < removeCount; i++) ASPx.Data.ArrayRemoveAt(array, removeIndex); for(var i = 0; i < newArray.length; i++) ASPx.Data.ArrayInsert(array, newArray[i], addIndex + i); } }); var CardViewEndlessPagingHelper = ASPx.CreateClass(GridBaseEndlessPagingHelper, { constructor: function(grid){ this.constructor.prototype.constructor.call(this, grid); grid.FocusedCardChanged.AddHandler(function() { this.OnGridFocusedItemChanged(); }.aspxBind(this)); }, IsFlowLayout: function(){ var mainElement = this.grid.GetMainTable(); return mainElement && ASPx.ElementHasCssClass(mainElement, "dxcvFT"); }, IsBreakpointsLayout: function() { var mainElement = this.grid.GetMainTable(); return mainElement && ASPx.ElementHasCssClass(mainElement, "dxcvBPT"); }, IsTableLayout: function() { return !this.IsFlowLayout() && !this.IsBreakpointsLayout(); }, GetBreakpointsLayoutItemContainer: function(itemElement) { if(this.IsBreakpointsLayoutContainer(itemElement.parentNode)) return itemElement.parentNode; return itemElement; }, GetItemsContainer: function(){ if(this.IsTableLayout()) return GridBaseEndlessPagingHelper.prototype.GetItemsContainer.call(this); return this.grid.GetMainTable().rows[0].cells[0]; }, GetItemElements: function(){ if(this.IsFlowLayout()) return GridBaseEndlessPagingHelper.prototype.GetItemElements.call(this); if(this.IsBreakpointsLayout()) return this.GetBreakpointsLayoutItemElements(); return this.GetDataCardCells(); }, GetBreakpointsLayoutItemElements: function() { var itemElements = GridBaseEndlessPagingHelper.prototype.GetItemElements.call(this), result = []; for(var i = 0; i < itemElements.length; i++) { var element = itemElements[i]; if(this.IsLayoutItem(element)) result.push(element); else if(this.IsBreakpointsLayoutContainer(element)) { var innerDataItemsElements = Array.prototype.slice.call(element.children).filter(this.IsLayoutItem.bind(this)); result = result.concat(innerDataItemsElements); } } return result; }, GetDataCardCells: function(){ return ASPx.GetNodesByPartialClassName(this.grid.GetMainTable(), "dxcvCard"); }, RemoveItemFromLayout: function(itemElement) { var element = itemElement; if(this.IsBreakpointsLayout() && this.IsLayoutItem(itemElement)) element = this.GetBreakpointsLayoutItemContainer(itemElement); GridBaseEndlessPagingHelper.prototype.RemoveItemFromLayout.call(this, element); }, RemoveDataItems: function(removeIndex, removeCount){ GridBaseEndlessPagingHelper.prototype.RemoveDataItems.call(this, removeIndex, removeCount); if(this.IsTableLayout()) this.UpdateTableLayout(this.GetDataCardCells()); }, InsertItems: function(container, itemsHtml, index){ if(this.IsTableLayout()) { var cells = this.GetDataCardCells(); this.UpdateTableLayout(this.InsertDataCellsHtml(cells, itemsHtml, index)); } else this.InsertDivBasedItems(container, itemsHtml, index); }, InsertDivBasedItems: function(container, itemsHtml, index){ var item; if(index >= 0 && index < container.children.length) item = container.children[index]; if(item) item.insertAdjacentHTML("beforeBegin", itemsHtml); else container.insertAdjacentHTML("beforeEnd", itemsHtml); }, InsertDataCellsHtml: function(cells, cellsHtml, index){ if(!cellsHtml) return cells; var table = this.grid.GetMainTable(); var tbody = table.tBodies[0]; var row = document.createElement("TR"); var cell = document.createElement("TD"); cell.innerHTML = "