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.
49 lines
894 B
49 lines
894 B
define(['backbone'],
|
|
function (Backbone) {
|
|
/**
|
|
* @class JsonGenerator
|
|
* */
|
|
return Backbone.Model.extend({
|
|
|
|
/** @inheritdoc */
|
|
getId : function()
|
|
{
|
|
return 'json';
|
|
},
|
|
|
|
/** @inheritdoc */
|
|
build: function(model)
|
|
{
|
|
var json = model.toJSON();
|
|
this.beforeEach(json);
|
|
|
|
// Avoid jshint 'loopfunc' error
|
|
_.each(json,function(v, attr){
|
|
var obj = json[attr];
|
|
if(obj instanceof Backbone.Model){
|
|
json[attr] = this.build(obj);
|
|
}else if(obj instanceof Backbone.Collection){
|
|
var coll = obj;
|
|
json[attr] = [];
|
|
if(coll.length){
|
|
coll.each(function (el, index) {
|
|
json[attr][index] = this.build(el);
|
|
}, this);
|
|
}
|
|
}
|
|
|
|
}, this);
|
|
|
|
return json;
|
|
},
|
|
|
|
/**
|
|
* Execute on each object
|
|
* @param {Object} obj
|
|
*/
|
|
beforeEach: function(obj) {
|
|
delete obj.status;
|
|
}
|
|
|
|
});
|
|
});
|
|
|