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.
This commit is contained in:
Cédric Krier
2024-09-24 12:10:24 +02:00
parent 92192b789a
commit 148f0cc5ce
4 changed files with 13 additions and 2 deletions
+1
View File
@@ -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);
+6 -1
View File
@@ -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();
@@ -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
@@ -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