mirror of https://github.com/artf/grapesjs.git
8 changed files with 256 additions and 203 deletions
@ -1,68 +1,20 @@ |
|||||
var Backbone = require('backbone'); |
import TypeableCollection from 'domain_abstract/model/TypeableCollection'; |
||||
var Asset = require('./Asset'); |
|
||||
var AssetImage = require('./AssetImage'); |
module.exports = require('backbone').Collection.extend(TypeableCollection).extend({ |
||||
|
getTypes() { |
||||
module.exports = Backbone.Collection.extend({ |
return [{ |
||||
|
id: 'image', |
||||
model: AssetImage, |
model: require('./AssetImage'), |
||||
|
view: require('./../view/AssetImageView'), |
||||
initialize(models, opt) { |
isType(value) { |
||||
|
if (typeof value == 'string') { |
||||
this.model = (attrs, options) => { |
return { |
||||
var model; |
type: 'image', |
||||
switch(attrs.type){ |
src: value, |
||||
default: |
} |
||||
model = new AssetImage(attrs, options); |
} |
||||
} |
return value; |
||||
return model; |
} |
||||
}; |
}]; |
||||
|
} |
||||
}, |
|
||||
|
|
||||
/** |
|
||||
* Add new image asset to the collection |
|
||||
* @param {string} url URL of the image |
|
||||
* @param {Object} opts Options |
|
||||
* @return {this} |
|
||||
* @private |
|
||||
*/ |
|
||||
addImg(url, opts) { |
|
||||
this.add({ |
|
||||
type: 'image', |
|
||||
src: url, |
|
||||
}, opts); |
|
||||
return this; |
|
||||
}, |
|
||||
|
|
||||
/** |
|
||||
* Prevent inserting assets with the same 'src' |
|
||||
* Seems like idAttribute is not working with dynamic model assignament |
|
||||
* @private |
|
||||
*/ |
|
||||
add(models, opt) { |
|
||||
var mods = []; |
|
||||
models = models instanceof Array ? models : [models]; |
|
||||
|
|
||||
for (var i = 0, len = models.length; i < len; i++) { |
|
||||
var model = models[i]; |
|
||||
|
|
||||
if(typeof model === 'string') |
|
||||
model = {src: model, type: 'image'}; |
|
||||
|
|
||||
if(!model || !model.src) |
|
||||
continue; |
|
||||
|
|
||||
var found = this.where({src: model.src}); |
|
||||
|
|
||||
if(!found.length) |
|
||||
mods.push(model); |
|
||||
} |
|
||||
|
|
||||
if(mods.length == 1) |
|
||||
mods = mods[0]; |
|
||||
|
|
||||
return Backbone.Collection.prototype.add.apply(this, [mods, opt]); |
|
||||
}, |
|
||||
|
|
||||
|
|
||||
}); |
}); |
||||
|
|||||
@ -1,12 +1,23 @@ |
|||||
var Backbone = require('backbone'); |
var Backbone = require('backbone'); |
||||
|
|
||||
module.exports = Backbone.View.extend({ |
module.exports = Backbone.View.extend({ |
||||
initialize(o) { |
|
||||
|
initialize(o = {}) { |
||||
this.options = o; |
this.options = o; |
||||
|
this.collection = o.collection; |
||||
this.config = o.config || {}; |
this.config = o.config || {}; |
||||
this.pfx = this.config.stylePrefix || ''; |
this.pfx = this.config.stylePrefix || ''; |
||||
this.ppfx = this.config.pStylePrefix || ''; |
this.ppfx = this.config.pStylePrefix || ''; |
||||
this.className = this.pfx + 'asset'; |
this.className = this.pfx + 'asset'; |
||||
this.listenTo( this.model, 'destroy remove', this.remove); |
this.listenTo(this.model, 'destroy remove', this.remove); |
||||
|
const init = this.init && this.init.bind(this); |
||||
|
init && init(o); |
||||
|
}, |
||||
|
|
||||
|
render() { |
||||
|
const el = this.el; |
||||
|
el.innerHTML = this.template(this, this.model); |
||||
|
el.className = this.className; |
||||
|
return this; |
||||
}, |
}, |
||||
}); |
}); |
||||
|
|||||
Loading…
Reference in new issue