Skip to content

EspoCRM – Open Source CRM Application

fix list model removal recovery

Yuri Kuznetsovbd33d7036588
diff --git a/client/src/views/record/list.js b/client/src/views/record/list.js
index d06eadf14c..78a06e07ca 100644
--- a/client/src/views/record/list.js
+++ b/client/src/views/record/list.js
@@ -3521,7 +3521,12 @@ class ListRecordView extends View {
}
// noinspection JSUnusedGlobalSymbols
- actionQuickRemove(data) {
+ /**
+ * @protected
+ * @param {{id?: string}} [data]
+ * @return {Promise<void>}
+ */
+ async actionQuickRemove(data) {
data = data || {};
const id = data.id;
@@ -3531,6 +3536,11 @@ class ListRecordView extends View {
}
const model = this.collection.get(id);
+ const index = this.collection.indexOf(model);
+
+ if (!model) {
+ throw new Error("No model.");
+ }
if (!this.getAcl().checkModel(model, 'delete')) {
Espo.Ui.error(this.translate('Access denied'));
@@ -3538,27 +3548,30 @@ class ListRecordView extends View {
return;
}
- this.confirm({
+ await this.confirm({
message: this.translate('removeRecordConfirmation', 'messages', this.scope),
confirmText: this.translate('Remove'),
- }, () => {
- this.collection.trigger('model-removing', id);
- this.collection.remove(model);
+ });
- Espo.Ui.notifyWait();
+ this.collection.trigger('model-removing', id);
+ this.collection.remove(model);
- model.destroy({wait: true, fromList: true})
- .then(() => {
- Espo.Ui.success(this.translate('Removed'));
+ Espo.Ui.notifyWait();
- this.trigger('after:delete', model);
- this.removeRecordFromList(id);
- })
- .catch(() => {
- // @todo Revert to the same position.
- this.collection.push(model);
- });
- });
+ try {
+ await model.destroy({wait: true, fromList: true});
+ } catch (e) {
+ if (!this.collection.models.includes(model)) {
+ this.collection.add(model, {at: index});
+ }
+
+ return;
+ }
+
+ Espo.Ui.success(this.translate('Removed'));
+
+ this.trigger('after:delete', model);
+ this.removeRecordFromList(id);
}
/**
diff --git a/client/src/views/record/panels/relationship.js b/client/src/views/record/panels/relationship.js
index 93014d2d1c..39496079bd 100644
--- a/client/src/views/record/panels/relationship.js
+++ b/client/src/views/record/panels/relationship.js
@@ -821,31 +821,45 @@ class RelationshipPanelView extends BottomPanelView {
* A `remove-related` action.
*
* @protected
+ * @param {{id?: string}} [data]
+ * @return {Promise<void>}
*/
- actionRemoveRelated(data) {
+ async actionRemoveRelated(data) {
const id = data.id;
- this.confirm({
+ const model = this.collection.get(id);
+ const index = this.collection.indexOf(model);
+
+ if (!model) {
+ throw new Error("No model.");
+ }
+
+ await this.confirm({
message: this.translate('removeRecordConfirmation', 'messages'),
confirmText: this.translate('Remove'),
- }, () => {
- const model = this.collection.get(id);
+ });
- Espo.Ui.notifyWait();
+ Espo.Ui.notifyWait();
- model
- .destroy()
- .then(() => {
- Espo.Ui.success(this.translate('Removed'));
+ try {
+ await model.destroy({wait: true});
+ } catch (e) {
+ if (!this.collection.models.includes(model)) {
+ this.collection.add(model, {at: index});
+ }
- this.collection.fetch();
+ return;
+ }
- this.model.trigger('after:unrelate');
- this.model.trigger('after:unrelate:' + this.link);
- this.processSyncBack();
- });
- });
+ Espo.Ui.success(this.translate('Removed'));
+
+ this.collection.fetch().then(() => {});
+
+ this.model.trigger('after:unrelate');
+ this.model.trigger(`after:unrelate:${this.link}`);
+
+ this.processSyncBack();
}
// noinspection JSUnusedGlobalSymbols