mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.6 KiB
74 lines
1.6 KiB
import Backbone from 'backbone';
|
|
import Properties from './Properties';
|
|
|
|
export default Backbone.Model.extend({
|
|
defaults: {
|
|
index: '',
|
|
value: '',
|
|
values: {},
|
|
active: false,
|
|
preview: false,
|
|
properties: [],
|
|
},
|
|
|
|
initialize() {
|
|
const prp = this.get('properties');
|
|
var value = this.get('value');
|
|
this.set('properties', prp instanceof Properties ? prp : new Properties(prp));
|
|
const props = this.get('properties');
|
|
props.forEach(this.onPropAdd, this);
|
|
this.listenTo(props, 'add', this.onPropAdd);
|
|
|
|
// If there is no value I'll try to get it from values
|
|
// I need value setted to make preview working
|
|
if (!value) {
|
|
var val = '';
|
|
var values = this.get('values');
|
|
|
|
for (var prop in values) {
|
|
val += ' ' + values[prop];
|
|
}
|
|
|
|
this.set('value', val.trim());
|
|
}
|
|
},
|
|
|
|
getValues() {
|
|
return this.get('values');
|
|
},
|
|
|
|
getIndex() {
|
|
const coll = this.collection;
|
|
return coll ? coll.indexOf(this) : -1;
|
|
},
|
|
|
|
onPropAdd(prop) {
|
|
const coll = this.collection;
|
|
prop.parent = coll && coll.property;
|
|
},
|
|
|
|
/**
|
|
* Get property at some index
|
|
* @param {Number} index
|
|
* @return {Object}
|
|
*/
|
|
getPropertyAt(index) {
|
|
return this.get('properties').at(index);
|
|
},
|
|
|
|
getPropertyValue(property) {
|
|
let result = '';
|
|
this.get('properties').each(prop => {
|
|
if (prop.get('property') == property) {
|
|
result = prop.getFullValue();
|
|
}
|
|
});
|
|
return result;
|
|
},
|
|
|
|
getFullValue() {
|
|
let result = [];
|
|
this.get('properties').each(prop => result.push(prop.getFullValue()));
|
|
return result.join(' ').trim();
|
|
},
|
|
});
|
|
|