Skip to content

Commit

Permalink
*fixed recursion, mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
jspears committed Apr 10, 2012
1 parent feffffa commit c61f68b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
47 changes: 36 additions & 11 deletions plugins/modeleditor/edit-display-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,52 @@ var EditModel = function (k, Model, options) {
this.title = this.model.title;
this.plural = this.model.plural;
this.editors = options.editors;
this.__defineGetter__('data', function(){
var obj = {};
_u(this.model.paths).each(function(v,k){
obj[k] = _u.extend({},v);
var sub = v.subSchema;
var cur = obj[k];
while(sub){
_u(sub).each(function(vv,kk){
if (kk !== 'subSchema'){
cur[kk] = vv;
}

});

sub = sub.subSchema;

}
});

return obj;
});
this.__defineGetter__('paths', function () {
var paths = this.schema;
return _u.map(this.schema, function (v, k) {
paths[k].path = k;
});
})
this.__defineGetter__('fields', function(){
return Object.keys(util.flatten(this.model.paths)) ;
});
this.__defineGetter__('fieldsets', function (v, k) {
var fieldsets = [
{
legend:'Edit ' + this.title,
fields:['title', 'plural', 'hidden', 'labelAttr', 'fieldsets', 'list_fields']
}
];
_u(this.model.paths).each(function (v, k) {
_u(this.fields).each(function (k) {
fieldsets.push({
legend:'Property [' + k + ']',
legend:this.title+'.' + k,
fields:['paths.' + k + '.title', 'paths.' + k + '.help', 'paths.' + k + '.views', 'paths.' + k + '.type', 'paths.' + k + '.dataType', 'paths.' + k + '.required']
})
});
}, this);
return fieldsets;
})

}
EditModel.prototype.schema = {
plural:{
Expand All @@ -86,7 +110,7 @@ EditModel.prototype.schema = {
}
};
EditModel.prototype.schemaFor = function () {

var fields = this.fields;
var schema = this._schema = _u.extend({}, this.schema);
this._schema.fieldsets = {
type:'List',
Expand All @@ -103,29 +127,26 @@ EditModel.prototype.schemaFor = function () {
fields:{
title:'Fields to be used in this fieldset',
type:'MultiEditor',
options:Object.keys(this.model.paths)
options:fields
}
}

}
this._schema.list_fields = {
type:'List',
listType:'Select',
options:Object.keys(this.model.paths),
options:fields,
help:'Fields to Show in the List View',
title:'List View',
sortable:true
}

var obj = (this._schema.paths = { subSchema:{}, type:'Object'}).subSchema;
var editors = this.editors;
_u(this.model.paths).each(function (v, k) {
// if (k.indexOf('.') > -1)
// return;
console.log('k', k, 'v', v);
obj[k] = {type:'Object'};
obj[k].subSchema =createSubSchema(this.editors, k, v);


}, this);

return this._schema;
Expand Down Expand Up @@ -171,7 +192,11 @@ function createSubSchema(editors, k, v) {
type:'Checkbox'
}
}

if (v.subSchema){
_u(v.subSchema).each(function(vv,kk){
obj[kk] = {type:'Object', subSchema:createSubSchema(editors, kk, vv)};
});
}
return obj;
}
var EditField = function (Field) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/modeleditor/modeleditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ EditPlugin.prototype.routes = function () {

this.app.get(base + '/admin/model/:modelName', function (req, res) {
var editModel = res.local('editModel');
var model = _u.extend({}, editModel.modelPaths[req.params.modelName].model);
var model = _u.extend({}, editModel.modelPaths[req.params.modelName].data);
delete model._paths;
res.send({
status:0,
Expand Down
5 changes: 2 additions & 3 deletions plugins/modeleditor/views/admin/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ define([
], function (_,Backbone, EditView, template) {
"use strict";

var fieldsets = {{html JSON.stringify(model.fieldsets) }};
var schema = {{html JSON.stringify(model.schemaFor()) }};
var fieldsets = eval('({{html JSON.stringify(model.fieldsets) }})');
var schema = eval('({{html JSON.stringify(model.schemaFor()) }})');
schema.fieldsets.itemToString = function(obj){
var fields = '['+obj.fields.join(',')+']';
if (fields.length > 30)
Expand All @@ -37,7 +37,6 @@ define([
}
return Backbone.Model.prototype.get.call(this, key);
}

});
return EditView.extend({
fieldsets:fieldsets,
Expand Down

0 comments on commit c61f68b

Please sign in to comment.