From 855d6defc9a594ba16b7889ba0e7cca8c41c23d6 Mon Sep 17 00:00:00 2001 From: nathangray Date: Fri, 9 Oct 2020 10:15:17 -0600 Subject: [PATCH] Etemplate: Fix push add to an empty nextmatch would leave the 'No matches found' and throw errors for row actions --- api/js/etemplate/et2_dataview_controller.js | 9 +++++++-- api/js/etemplate/et2_dataview_controller.ts | 11 +++++++++-- api/js/etemplate/et2_extension_nextmatch.js | 5 +++++ api/js/etemplate/et2_extension_nextmatch.ts | 6 ++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/api/js/etemplate/et2_dataview_controller.js b/api/js/etemplate/et2_dataview_controller.js index ace5772df4..66f1f656d2 100644 --- a/api/js/etemplate/et2_dataview_controller.js +++ b/api/js/etemplate/et2_dataview_controller.js @@ -337,8 +337,13 @@ var et2_dataview_controller = /** @class */ (function () { if (createdRow && _entry.row) { this._grid.insertRow(_entry.idx, _entry.row); } + // Remove 'No matches found' row + var row = jQuery(".egwGridView_empty", this._grid.innerTbody).remove(); + if (row.length) { + this._selectionMgr.unregisterRow("", 0); + } // Update index map only for push (autorefresh disabled) - if (this._indexMap[_entry.idx].uid !== _entry.uid) { + if (this._indexMap[_entry.idx] && this._indexMap[_entry.idx].uid !== _entry.uid) { var max = parseInt(Object.keys(this._indexMap).reduce(function (a, b) { return _this._indexMap[a] > _this._indexMap[b] ? a : b; })); for (var idx = max; idx >= _entry.idx; idx--) { var entry = this._indexMap[idx]; @@ -348,8 +353,8 @@ var et2_dataview_controller = /** @class */ (function () { this._selectionMgr._registeredRows[entry.uid].idx = entry.idx; } } - this._indexMap[_entry.idx] = _entry; } + this._indexMap[_entry.idx] = _entry; return this.hasData; }; /** diff --git a/api/js/etemplate/et2_dataview_controller.ts b/api/js/etemplate/et2_dataview_controller.ts index 38df076077..2b19773547 100644 --- a/api/js/etemplate/et2_dataview_controller.ts +++ b/api/js/etemplate/et2_dataview_controller.ts @@ -467,8 +467,15 @@ export class et2_dataview_controller this._grid.insertRow(_entry.idx, _entry.row); } + // Remove 'No matches found' row + var row = jQuery(".egwGridView_empty",this._grid.innerTbody).remove(); + if(row.length) + { + this._selectionMgr.unregisterRow("", 0); + } + // Update index map only for push (autorefresh disabled) - if(this._indexMap[_entry.idx].uid !== _entry.uid) + if(this._indexMap[_entry.idx] && this._indexMap[_entry.idx].uid !== _entry.uid) { let max = parseInt(Object.keys(this._indexMap).reduce((a, b) => this._indexMap[a] > this._indexMap[b] ? a : b)); for(let idx = max; idx >= _entry.idx; idx--) @@ -481,8 +488,8 @@ export class et2_dataview_controller this._selectionMgr._registeredRows[entry.uid].idx = entry.idx; } } - this._indexMap[_entry.idx] = _entry } + this._indexMap[_entry.idx] = _entry; return this.hasData; } diff --git a/api/js/etemplate/et2_extension_nextmatch.js b/api/js/etemplate/et2_extension_nextmatch.js index 9ccb07a75f..3fb3cd3c44 100644 --- a/api/js/etemplate/et2_extension_nextmatch.js +++ b/api/js/etemplate/et2_extension_nextmatch.js @@ -527,6 +527,7 @@ var et2_nextmatch = /** @class */ (function (_super) { // This will remove the last row! // That's OK, because grid adds one in this.controller.deleteRow() this.dataview.grid.setTotalCount(total); + this.controller._selectionMgr.setTotalCount(total); // Re-enable automatic updating this.dataview.grid.doInvalidate = true; this.dataview.grid.invalidate(); @@ -559,6 +560,7 @@ var et2_nextmatch = /** @class */ (function (_super) { this.nm.controller.deleteRow(this.uid); // Adjust total rows, clean grid this.nm.controller._grid.setTotalCount(this.nm.controller._grid._total - _row_ids.length); + this.controller._selectionMgr.setTotalCount(this.nm.controller._grid._total); } }, { type: _type, nm: this_1, uid: uid_1, prefix: this_1.controller.dataStorePrefix }, [_row_ids]); return { value: void 0 }; @@ -622,6 +624,7 @@ var et2_nextmatch = /** @class */ (function (_super) { } // Update does not need to increase row count, but refresh_add() adds it in this.controller._grid.setTotalCount(this.controller._grid.getTotalCount() - 1); + this.controller._selectionMgr.setTotalCount(this.controller._grid.getTotalCount()); return true; }; /** @@ -657,6 +660,7 @@ var et2_nextmatch = /** @class */ (function (_super) { //if(stored?.timestamp >= time) return; // Increase displayed row count or we lose the last row when we add and the total is wrong this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount() + 1); + this.nm.controller._selectionMgr.setTotalCount(this.nm.controller._grid.getTotalCount()); // Insert at the top of the list, or where app said var entry = this.nm.controller._selectionMgr._getRegisteredRowsEntry(this.uid); entry.idx = typeof this.index == "number" ? this.index : 0; @@ -667,6 +671,7 @@ var et2_nextmatch = /** @class */ (function (_super) { // Delete from internal references this.nm.controller.deleteRow(this.uid); this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount() - 1); + this.nm.controller._selectionMgr.setTotalCount(this.nm.controller._grid.getTotalCount()); } this.nm.egw().dataUnregisterUID(this.uid, this.nm._push_add_callback, this); }; diff --git a/api/js/etemplate/et2_extension_nextmatch.ts b/api/js/etemplate/et2_extension_nextmatch.ts index c1b07ffe00..b9409bd94c 100644 --- a/api/js/etemplate/et2_extension_nextmatch.ts +++ b/api/js/etemplate/et2_extension_nextmatch.ts @@ -813,6 +813,8 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 // This will remove the last row! // That's OK, because grid adds one in this.controller.deleteRow() this.dataview.grid.setTotalCount(total); + this.controller._selectionMgr.setTotalCount(total); + // Re-enable automatic updating this.dataview.grid.doInvalidate = true; this.dataview.grid.invalidate(); @@ -860,6 +862,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 // Adjust total rows, clean grid this.nm.controller._grid.setTotalCount(this.nm.controller._grid._total- _row_ids.length); + this.controller._selectionMgr.setTotalCount(this.nm.controller._grid._total); } }, {type: _type, nm: this, uid: uid, prefix: this.controller.dataStorePrefix}, [_row_ids] ); @@ -923,6 +926,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 } // Update does not need to increase row count, but refresh_add() adds it in this.controller._grid.setTotalCount(this.controller._grid.getTotalCount()-1); + this.controller._selectionMgr.setTotalCount(this.controller._grid.getTotalCount()); return true; } @@ -969,6 +973,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 // Increase displayed row count or we lose the last row when we add and the total is wrong this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount()+1); + this.nm.controller._selectionMgr.setTotalCount(this.nm.controller._grid.getTotalCount()); // Insert at the top of the list, or where app said var entry = this.nm.controller._selectionMgr._getRegisteredRowsEntry(this.uid); @@ -981,6 +986,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 // Delete from internal references this.nm.controller.deleteRow(this.uid); this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount()-1); + this.nm.controller._selectionMgr.setTotalCount(this.nm.controller._grid.getTotalCount()); } this.nm.egw().dataUnregisterUID(this.uid, this.nm._push_add_callback, this); }