From 148f0cc5ce750993db0347c4e2ded0ad06364877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 24 Sep 2024 12:10:24 +0200 Subject: [PATCH] Keep current record if it has not been destroyed after removal This allows to keep selected the removed record on the xxx2Many widgets such that it is easy to undo the removal. --- sao/src/model.js | 1 + sao/src/screen.js | 7 ++++++- tryton/tryton/gui/window/view_form/model/group.py | 1 + tryton/tryton/gui/window/view_form/screen/screen.py | 6 +++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sao/src/model.js b/sao/src/model.js index 874a411e45..3250f70d39 100644 --- a/sao/src/model.js +++ b/sao/src/model.js @@ -241,6 +241,7 @@ array._remove = function(record) { var idx = this.indexOf(record); this.splice(idx, 1); + record.destroy(); }; array.unremove = function(record) { this.record_removed.splice(this.record_removed.indexOf(record), 1); diff --git a/sao/src/screen.js b/sao/src/screen.js index df8c1df4cf..f57e46a074 100644 --- a/sao/src/screen.js +++ b/sao/src/screen.js @@ -1689,6 +1689,7 @@ if (jQuery.isEmptyObject(records)) { return prm; } + var current_record = this.current_record; if (delete_) { // TODO delete children before parent prm = this.group.delete_(records); @@ -1716,7 +1717,11 @@ // TODO destroy } } - this.current_record = null; + if (current_record && !current_record.destroyed) { + this.current_record = current_record; + } else { + this.current_record = null; + } return jQuery.when.apply(jQuery, prms).then(() => { return this.display().done(() => { this.set_cursor(); diff --git a/tryton/tryton/gui/window/view_form/model/group.py b/tryton/tryton/gui/window/view_form/model/group.py index 960eb5ec9b..d823437cc7 100644 --- a/tryton/tryton/gui/window/view_form/model/group.py +++ b/tryton/tryton/gui/window/view_form/model/group.py @@ -128,6 +128,7 @@ class Group(list): self._group_list_changed('record-removed', record, idx) super(Group, self).remove(record) del self.__id2record[record.id] + record.destroy() def clear(self): # Use reversed order to minimize the cursor reposition as the cursor diff --git a/tryton/tryton/gui/window/view_form/screen/screen.py b/tryton/tryton/gui/window/view_form/screen/screen.py index 11e08ac30f..bd903f3770 100644 --- a/tryton/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/tryton/gui/window/view_form/screen/screen.py @@ -793,6 +793,7 @@ class Screen: records = records or self.selected_records if not records: return + current_record = self.current_record if delete: # Must delete children records before parent records.sort(key=lambda r: r.depth, reverse=True) @@ -820,7 +821,10 @@ class Screen: record.parent.save(force_reload=False) record.destroy() - self.current_record = None + if current_record and not current_record.destroyed: + self.current_record = current_record + else: + self.current_record = None self.set_cursor() self.display() return True