Browse Source

Improve TypeableCollection

pull/281/head
Artur Arseniev 9 years ago
parent
commit
5f9ba62325
  1. 4
      dist/grapes.min.js
  2. 2
      package.json
  3. 9
      src/asset_manager/index.js
  4. 26
      src/asset_manager/model/Assets.js
  5. 5
      src/asset_manager/view/AssetsView.js
  6. 9
      src/domain_abstract/model/TypeableCollection.js

4
dist/grapes.min.js

File diff suppressed because one or more lines are too long

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"description": "Free and Open Source Web Builder Framework", "description": "Free and Open Source Web Builder Framework",
"version": "0.9.33", "version": "0.9.34",
"author": "Artur Arseniev", "author": "Artur Arseniev",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"homepage": "http://grapesjs.com", "homepage": "http://grapesjs.com",

9
src/asset_manager/index.js

@ -63,6 +63,10 @@ module.exports = () => {
*/ */
storageKey: 'assets', storageKey: 'assets',
getConfig() {
return c;
},
/** /**
* Initialize module * Initialize module
* @param {Object} config Configurations * @param {Object} config Configurations
@ -84,7 +88,7 @@ module.exports = () => {
} }
// Global assets collection // Global assets collection
assets = new Assets(c.assets); assets = new Assets([]);
const obj = { const obj = {
// Collection visible in asset manager // Collection visible in asset manager
collection: new Assets([]), collection: new Assets([]),
@ -257,6 +261,9 @@ module.exports = () => {
postRender(editorView) { postRender(editorView) {
c.dropzone && fu.initDropzone(editorView); c.dropzone && fu.initDropzone(editorView);
// Leave it here for custom types
assets.add(c.assets, {silent: 1});
}, },
/** /**

26
src/asset_manager/model/Assets.js

@ -1,20 +1,18 @@
import TypeableCollection from 'domain_abstract/model/TypeableCollection'; import TypeableCollection from 'domain_abstract/model/TypeableCollection';
module.exports = require('backbone').Collection.extend(TypeableCollection).extend({ module.exports = require('backbone').Collection.extend(TypeableCollection).extend({
getTypes() { types: [{
return [{ id: 'image',
id: 'image', model: require('./AssetImage'),
model: require('./AssetImage'), view: require('./../view/AssetImageView'),
view: require('./../view/AssetImageView'), isType(value) {
isType(value) { if (typeof value == 'string') {
if (typeof value == 'string') { return {
return { type: 'image',
type: 'image', src: value,
src: value,
}
} }
return value;
} }
}]; return value;
} }
}]
}); });

5
src/asset_manager/view/AssetsView.js

@ -40,11 +40,6 @@ module.exports = Backbone.View.extend({
this.listenTo(this.collection, 'add', this.addToAsset ); this.listenTo(this.collection, 'add', this.addToAsset );
this.listenTo(this.collection, 'deselectAll', this.deselectAll); this.listenTo(this.collection, 'deselectAll', this.deselectAll);
this.listenTo(this.collection, 'reset', this.render); this.listenTo(this.collection, 'reset', this.render);
/*
this.events = {};
this.events.submit = 'addFromStr';
this.delegateEvents();
*/
}, },
/** /**

9
src/domain_abstract/model/TypeableCollection.js

@ -2,6 +2,7 @@ const Model = Backbone.Model;
const View = Backbone.View; const View = Backbone.View;
export default { export default {
types: [],
initialize(models, opts) { initialize(models, opts) {
this.model = (attrs = {}, options = {}) => { this.model = (attrs = {}, options = {}) => {
@ -68,7 +69,7 @@ export default {
* @return {Array} * @return {Array}
*/ */
getTypes() { getTypes() {
return []; return this.types;
}, },
/** /**
@ -104,9 +105,9 @@ export default {
const type = this.getType(id); const type = this.getType(id);
const ModelInst = type ? type.model : Model; const ModelInst = type ? type.model : Model;
const ViewInst = type ? type.view : View; const ViewInst = type ? type.view : View;
let {model, view, isType} = definition; let {model, view, isType} = definition;;
model = model instanceof Model ? model : ModelInst.extend(model); model = model instanceof Model ? model : ModelInst.extend(model || {});
view = view instanceof View ? view : ViewInst.extend(view); view = view instanceof View ? view : ViewInst.extend(view || {});
if (type) { if (type) {
type.model = model; type.model = model;

Loading…
Cancel
Save