From 344a63b37cd98523482197a56b2b2e3f129fb6c7 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 17 Jan 2014 17:57:59 +0000 Subject: [PATCH] Fix removing (delete) a row from nextmatch - Fix broken destroy callback - Fix caching & actions to be removed - Fix always removing the last row also - Fix indexing so arrow keys work over sparse indexMap --- etemplate/js/et2_dataview_controller.js | 6 ++++- .../js/et2_dataview_controller_selection.js | 13 ++++++++-- etemplate/js/et2_extension_nextmatch.js | 26 ++++++++++++++++--- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/etemplate/js/et2_dataview_controller.js b/etemplate/js/et2_dataview_controller.js index a4659bde8d..b034edb69a 100644 --- a/etemplate/js/et2_dataview_controller.js +++ b/etemplate/js/et2_dataview_controller.js @@ -568,7 +568,10 @@ var et2_dataview_controller = Class.extend({ // If there's no data, stop if(typeof _data == "undefined" || _data == null) { - this._destroyCallback(); + this.self._destroyCallback.call( + this, + this.entry.row + ); return; } @@ -632,6 +635,7 @@ var et2_dataview_controller = Class.extend({ if (this.entry.row) { var tr = this.entry.row.getDOMNode(); + this.self._selectionMgr._updateState(this.entry.uid, EGW_AO_STATE_NORMAL) this.self._selectionMgr.unregisterRow(this.entry.uid, tr); } diff --git a/etemplate/js/et2_dataview_controller_selection.js b/etemplate/js/et2_dataview_controller_selection.js index 4de4d7455b..fb3de221f7 100644 --- a/etemplate/js/et2_dataview_controller_selection.js +++ b/etemplate/js/et2_dataview_controller_selection.js @@ -152,6 +152,7 @@ var et2_dataview_selectionManager = Class.extend( if (!_noDelete && this._registeredRows[_uid].state === EGW_AO_STATE_NORMAL) { + delete this._indexMap[this._registeredRows[_uid].idx]; delete this._registeredRows[_uid]; } @@ -326,8 +327,16 @@ var et2_dataview_selectionManager = Class.extend( } function getElementRelatively (_step) { - return getIndexAO(Math.max(0, - Math.min(self._total - 1, _entry.idx + _step))); + var count = self._total; + var element = null; + var idx = _entry.idx; + while(element == null && count > 0 && idx <= self._total) + { + count--; + element = getIndexAO(Math.max(0, + Math.min(self._total - 1, idx += _step))); + } + return element; }; _entry.ao.getPrevious = function (_step) { diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index 8756c6ec4f..6e696bbe8f 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -456,14 +456,34 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], } break; case "delete": + // Record current & next index + var entry = this.controller._selectionMgr._getRegisteredRowsEntry(uid); + var next = entry.ao.getNext(1); + if(next == null || !next.id) + { + // No next, select previous + next = entry.ao.getPrevious(1); + } + // Select next row + if(next && next.id) + { + this.controller._selectionMgr._handleSelect(next.id); + } + // Blank the row this.egw().dataStoreUID(uid,null); // Stop caring about this ID this.egw().dataUnregisterUID(uid); // Update the count this.options.settings.total -= 1; - // This triggers an invalidate, which may update the grid in needed - this.dataview.grid.setTotalCount(this.options.settings.total); + // This removes the last row (in addition), doesn't matter if that wasn't the right one, + // then triggers an invalidate, which may update the grid + // this.dataview.grid.setTotalCount(this.options.settings.total); + // Update directly instead + this.dataview.grid._total -= this.options.settings.total; + this.controller._selectionMgr._total = this.options.settings.total; + this.header.count_total.text(this.options.settings.total+""); + break; case "edit": case "add": @@ -474,7 +494,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], } } // Trigger an event so app code can act on it - $j(this).triggerHandler("refresh",[this]); + $j(this).triggerHandler("refresh",[this,_row_ids,_type]); }, /**