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
This commit is contained in:
nathangray 2020-07-29 13:20:01 -06:00 committed by Ralf Becker
parent 732582305b
commit 370fd63088
2 changed files with 22 additions and 0 deletions

View File

@ -295,6 +295,7 @@ var et2_dataview_controller = /** @class */ (function () {
* otherwise. * otherwise.
*/ */
et2_dataview_controller.prototype._insertDataRow = function (_entry, _update) { 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 // Abort if the entry already has a row but the _insert flag is not set
if (_entry.row && !_update) { if (_entry.row && !_update) {
return true; return true;
@ -330,6 +331,15 @@ var et2_dataview_controller = /** @class */ (function () {
if (createdRow && _entry.row) { if (createdRow && _entry.row) {
this._grid.insertRow(_entry.idx, _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; return this.hasData;
}; };
/** /**

View File

@ -458,6 +458,18 @@ export class et2_dataview_controller
this._grid.insertRow(_entry.idx, _entry.row); 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; return this.hasData;
} }