From 370fd63088514c8ec2a124c53660996bcd3027d9 Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 29 Jul 2020 13:20:01 -0600 Subject: [PATCH] Etemplate: Update controller indexMap when adding a new row Fixes deleting former top mail that got moved down by a pushed new mail removed both newly added and the selected mail --- api/js/etemplate/et2_dataview_controller.js | 10 ++++++++++ api/js/etemplate/et2_dataview_controller.ts | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/api/js/etemplate/et2_dataview_controller.js b/api/js/etemplate/et2_dataview_controller.js index 87abcd7ce7..a02cf66051 100644 --- a/api/js/etemplate/et2_dataview_controller.js +++ b/api/js/etemplate/et2_dataview_controller.js @@ -295,6 +295,7 @@ var et2_dataview_controller = /** @class */ (function () { * otherwise. */ et2_dataview_controller.prototype._insertDataRow = function (_entry, _update) { + var _this = this; // Abort if the entry already has a row but the _insert flag is not set if (_entry.row && !_update) { return true; @@ -330,6 +331,15 @@ var et2_dataview_controller = /** @class */ (function () { if (createdRow && _entry.row) { this._grid.insertRow(_entry.idx, _entry.row); } + // Update index map + if (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--) { + this._indexMap[idx].idx = idx + 1; + this._indexMap[this._indexMap[idx].idx] = this._indexMap[idx]; + } + 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 7de0a670c1..6c3a2711b8 100644 --- a/api/js/etemplate/et2_dataview_controller.ts +++ b/api/js/etemplate/et2_dataview_controller.ts @@ -458,6 +458,18 @@ export class et2_dataview_controller this._grid.insertRow(_entry.idx, _entry.row); } + // Update index map + if(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--) + { + this._indexMap[idx].idx = idx+1; + this._indexMap[this._indexMap[idx].idx] = this._indexMap[idx]; + } + this._indexMap[_entry.idx] = _entry + } + return this.hasData; }