Browse Source

Move assets events in the module doc

pull/3795/head
Artur Arseniev 4 years ago
parent
commit
4405035a82
  1. 20
      src/asset_manager/index.js
  2. 20
      src/asset_manager/view/FileUploader.js
  3. 9
      src/editor/index.js

20
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<String>|Array<Object>} 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;

20
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 });

9
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

Loading…
Cancel
Save