From 4405035a82e0420909a2cf98611594bf4b732478 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 14 Sep 2021 15:42:40 +0200 Subject: [PATCH] Move assets events in the module doc --- src/asset_manager/index.js | 20 +++++++++++++++++++- src/asset_manager/view/FileUploader.js | 20 +++++++++----------- src/editor/index.js | 9 ++------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/asset_manager/index.js b/src/asset_manager/index.js index 504c9ce34..6f266e614 100644 --- a/src/asset_manager/index.js +++ b/src/asset_manager/index.js @@ -13,7 +13,17 @@ * ```js * const assetManager = editor.AssetManager; * ``` + * ## Available Events + * * `asset:add` - Added new asset. The [Asset] is passed as an argument to the callback. + * * `asset:remove` - Asset removed. The [Asset] is passed as an argument to the callback. + * * `asset:update` - Asset updated. The updated [Asset] and the object containing changes are passed as arguments to the callback. + * * `asset:upload:start` - Before the upload is started. + * * `asset:upload:end` - After the upload is ended. + * * `asset:upload:error` - On any error in upload, passes the error as an argument. + * * `asset:upload:response` - On upload response, passes the result as an argument. + * * `asset` - Catch-all event for all the events mentioned above. An object containing all the available data about the triggered event is passed as an argument to the callback. * + * ## Methods * * [add](#add) * * [get](#get) * * [getAll](#getall) @@ -27,6 +37,8 @@ * * [getType](#gettype) * * [getTypes](#gettypes) * + * [Asset]: asset.html + * * @module AssetManager */ @@ -98,6 +110,11 @@ export default () => { return this; }, + __propEv(ev, ...data) { + this.em.trigger(ev, ...data); + this.getAll().trigger(ev, ...data); + }, + /** * Add new asset/s to the collection. URLs are supposed to be unique * @param {String|Object|Array|Array} asset URL strings or an objects representing the resource. @@ -247,7 +264,8 @@ export default () => { const obj = { collection: assetsVis, // Collection visible in asset manager globalCollection: assets, - config: c + config: c, + module: this }; fu = new FileUpload(obj); obj.fu = fu; diff --git a/src/asset_manager/view/FileUploader.js b/src/asset_manager/view/FileUploader.js index a3256d9c9..694eb49c7 100644 --- a/src/asset_manager/view/FileUploader.js +++ b/src/asset_manager/view/FileUploader.js @@ -26,6 +26,7 @@ export default Backbone.View.extend( initialize(opts = {}) { this.options = opts; const c = opts.config || {}; + this.module = c.module; this.config = c; this.em = this.config.em; this.pfx = c.stylePrefix || ''; @@ -54,8 +55,8 @@ export default Backbone.View.extend( * @private */ onUploadStart() { - const em = this.config.em; - em && em.trigger('asset:upload:start'); + const { module } = this; + module && module.__propEv('asset:upload:start'); }, /** @@ -64,9 +65,8 @@ export default Backbone.View.extend( * @private */ onUploadEnd(res) { - const { $el, config } = this; - const em = config.em; - em && em.trigger('asset:upload:end', res); + const { $el, module } = this; + module && module.__propEv('asset:upload:end', res); const input = $el.find('input'); input && input.val(''); }, @@ -77,10 +77,10 @@ export default Backbone.View.extend( * @private */ onUploadError(err) { - const em = this.config.em; + const { module } = this; console.error(err); this.onUploadEnd(err); - em && em.trigger('asset:upload:error', err); + module && module.__propEv('asset:upload:error', err); }, /** @@ -89,9 +89,7 @@ export default Backbone.View.extend( * @private */ onUploadResponse(text, clb) { - const em = this.config.em; - const config = this.config; - const target = this.target; + const { module, config, target } = this; let json; try { json = typeof text === 'string' ? JSON.parse(text) : text; @@ -99,7 +97,7 @@ export default Backbone.View.extend( json = text; } - em && em.trigger('asset:upload:response', json); + module && module.__propEv('asset:upload:response', json); if (config.autoAdd && target) { target.add(json.data, { at: 0 }); diff --git a/src/editor/index.js b/src/editor/index.js index f11ed9f46..b95c0923e 100644 --- a/src/editor/index.js +++ b/src/editor/index.js @@ -42,13 +42,6 @@ * * `block:drag:start` - Started dragging block, model of the block is passed as an argument * * `block:drag` - Dragging block, the block's model and the drag event are passed as arguments * * `block:drag:stop` - Dragging of the block is stopped. As agruments for the callback you get, the dropped component model (if dropped successfully) and the model of the block - * ### Assets - * * `asset:add` - New asset added - * * `asset:remove` - Asset removed - * * `asset:upload:start` - Before the upload is started - * * `asset:upload:end` - After the upload is ended - * * `asset:upload:error` - On any error in upload, passes the error as an argument - * * `asset:upload:response` - On upload response, passes the result as an argument * ### Keymaps * * `keymap:add` - New keymap added. The new keyamp object is passed as an argument * * `keymap:remove` - Keymap removed. The removed keyamp object is passed as an argument @@ -93,6 +86,8 @@ * * `abort:{commandName}` - Triggered when the command execution is aborted (`editor.on(`run:preview:before`, opts => opts.abort = 1);`) * * `run` - Triggered on run of any command. The id and the result are passed as arguments to the callback * * `stop` - Triggered on stop of any command. The id and the result are passed as arguments to the callback + * ### Assets + * Check the [Assets](/api/assets.html) module. * ### Modal * Check the [Modal](/api/modal_dialog.html) module. * ### Devices