Skip to content

Commit bbcf98d

Browse files
Dispatching event within errorHandler function while executing upload asset via asset tree (#887)
* chore(events): added new event to handle add asset error while adding asset via asset tree * chore(asset/tree.js): added custom event and dispatch the event within error handler, omit the default action using showNotification --------- Co-authored-by: Patrick Bitzer <[email protected]>
1 parent 795cc36 commit bbcf98d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

public/js/pimcore/asset/tree.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,22 @@
263263
pimcore.elementservice.refreshNodeAllTrees("asset", parentNode.get("id"));
264264
}
265265
}.bind(this);
266-
266+
267267
var errorHandler = function (e) {
268-
var res = Ext.decode(e["responseText"]);
269-
pimcore.helpers.showNotification(t("error"), res.message ? res.message : t("error"), "error", e["responseText"]);
268+
const res = Ext.decode(e["responseText"]);
269+
const addAssetError = new CustomEvent(pimcore.events.assetTreeAddAssetError, {
270+
detail: res,
271+
cancelable: true
272+
});
273+
274+
/*
275+
The default return value of dispatchEvent is true, but if you add event.preventDefault() in the listener,
276+
it will return false and the default action will not be triggered.
277+
*/
278+
const addAssetErrorCancelled = document.dispatchEvent(addAssetError);
279+
if (addAssetErrorCancelled) {
280+
pimcore.helpers.showNotification(t("error"), res.message ? res.message : t("error"), "error", e["responseText"]);
281+
}
270282
finishedErrorHandler();
271283
}.bind(this);
272284

public/js/pimcore/events.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@
159159
* url returning the metadata definitions is passed as parameter
160160
*/
161161
pimcore.events.prepareAssetMetadataGridConfigurator = "pimcore.gridConfigurator.assetMetadata.prepare";
162+
163+
/**
164+
* upload via asset tree and handle the error
165+
* response is passed as parameter
166+
*/
167+
pimcore.events.assetTreeAddAssetError = "pimcore.events.assetTree.addAssetError";
162168

163169
/**
164170
* before context menu is opened

0 commit comments

Comments
 (0)