Skip to content

Commit

Permalink
[Bug] Avoid multiple save ajax calls (#347)
Browse files Browse the repository at this point in the history
* draft: avoid multiple save, fix notification delay

* remove console log

* extend to documents and assets (even though we don't have any autosave there) and increased popup alert time

Co-authored-by: robertSt7 <[email protected]>

* setting saving to false when disallowing on preSave event

* setting saving to false when disallowing on preSave event

* refactor to saveInProgress

* remove hideDelay changes

* Apply suggestions from code review

Co-authored-by: Divesh Pahuja <[email protected]>

---------

Co-authored-by: robertSt7 <[email protected]>
Co-authored-by: Divesh Pahuja <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2023
1 parent d9564cd commit cc2a010
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions public/js/pimcore/asset/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ pimcore.asset.asset = Class.create(pimcore.element.abstract, {
}

this.tab.mask();
this.saving = true;

const preSaveAsset = new CustomEvent(pimcore.events.preSaveAsset, {
detail: {
Expand All @@ -377,6 +378,7 @@ pimcore.asset.asset = Class.create(pimcore.element.abstract, {
const isAllowed = document.dispatchEvent(preSaveAsset);
if (!isAllowed) {
this.tab.unmask();
this.saving = false;
return false;
}

Expand Down Expand Up @@ -432,6 +434,9 @@ pimcore.asset.asset = Class.create(pimcore.element.abstract, {
failure: function () {
this.tab.unmask();
}.bind(this),
callback: function (){
this.saving = false;
}.bind(this),
params: params
});
},
Expand Down
11 changes: 11 additions & 0 deletions public/js/pimcore/document/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ pimcore.document.document = Class.create(pimcore.element.abstract, {
return;
}

if (this.saveInProgress()){
pimcore.helpers.showNotification(t("warning"), t("Another saving process is in progress, please wait and retry again"), "info");
return;
}

if(typeof task !== 'string') {
task = '';
}
Expand All @@ -112,9 +117,12 @@ pimcore.document.document = Class.create(pimcore.element.abstract, {
cancelable: true
});

this.saving = true;

const isAllowed = document.dispatchEvent(preSaveDocument);
if (!isAllowed) {
this.tab.unmask();
this.saving = false;
return false;
}

Expand Down Expand Up @@ -188,6 +196,9 @@ pimcore.document.document = Class.create(pimcore.element.abstract, {
failure: function () {
this.tab.unmask();
}.bind(this),
callback: function (){
this.saving = false;
}.bind(this),
});
} else {
this.tab.unmask();
Expand Down
5 changes: 5 additions & 0 deletions public/js/pimcore/element/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pimcore.registerNS("pimcore.element.abstract");
pimcore.element.abstract = Class.create({

dirty: false,
saving: false,

/**
* if allowDirtyClose is true, a tab can be closed whether
Expand Down Expand Up @@ -244,6 +245,10 @@ pimcore.element.abstract = Class.create({
}
},

saveInProgress: function(){
return this.saving;
},

setAddToHistory: function (addToHistory) {
this.addToHistory = addToHistory;
},
Expand Down
10 changes: 9 additions & 1 deletion public/js/pimcore/object/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,6 @@ pimcore.object.object = Class.create(pimcore.object.abstract, {
},

save: function (task, only, callback, successCallback) {

var omitMandatoryCheck = false;

// unpublish and save version is possible without checking mandatory fields
Expand All @@ -776,6 +775,10 @@ pimcore.object.object = Class.create(pimcore.object.abstract, {
if (this.tab.disabled || (this.tab.isMasked() && task != 'autoSave')) {
return;
}
if (this.saveInProgress()){
pimcore.helpers.showNotification(t("warning"), t("Another saving process is in progress, please wait and retry again"), "info");
return;
}

if(task != 'autoSave'){
this.tab.mask();
Expand All @@ -797,9 +800,11 @@ pimcore.object.object = Class.create(pimcore.object.abstract, {
const isAllowed = document.dispatchEvent(preSaveObject);
if (!isAllowed) {
this.tab.unmask();
this.saving = false;
return false;
}

this.saving = true;
Ext.Ajax.request({
url: Routing.generate('pimcore_admin_dataobject_dataobject_save', {task: task}),
method: "PUT",
Expand Down Expand Up @@ -882,6 +887,9 @@ pimcore.object.object = Class.create(pimcore.object.abstract, {
}.bind(this),
failure: function (response) {
this.tab.unmask();
}.bind(this),
callback: function (){
this.saving = false;
}.bind(this)
});

Expand Down

0 comments on commit cc2a010

Please sign in to comment.