Commit 201a9994 authored by Jérome Perrin's avatar Jérome Perrin

first step of recursive fieldsets

parent c2b365fd
......@@ -17,17 +17,20 @@
initGadgetMixin(gadget_klass);
gadget_klass
.declareMethod("render", function (property_list, data) {
.declareMethod("render", function (property_list, data, key) {
var gadget = this,
queue,
value,
property;
gadget.key = key; // used for recursive fieldsets
gadget.props.field_gadget_list = [];
function addField(property, value) {
var sub_gadget;
queue
.push(function () {
// XXX this is incorrect for recursive fieldsets.
// we should use nested fieldset with legend
gadget.props.element.insertAdjacentHTML(
'beforeend',
label_template({
......@@ -35,6 +38,10 @@
"name": (property.name || property.id)
})
);
if (property._class === "Dream.PropertyList") {
// Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html");
}
if (property.type === "number") {
return gadget.declareGadget("../number_field/index.html");
}
......@@ -44,11 +51,15 @@
return gadget.declareGadget("../string_field/index.html");
})
.push(function (gg) {
sub_gadget = gg;
var choice = property.choice || [],
default_opt = choice[0] ? [choice[0][1]] : [""];
sub_gadget = gg;
value = (data[property.id] === undefined ?
value : data[property.id]);
if (gg.__title === 'Fieldset') {
// XXX there must be a better way instead of using __title ?
return gg.render(property.property_list, value, property.id);
}
return sub_gadget.render({field_json: {
title: (property.description || ''),
key: property.id,
......@@ -70,10 +81,8 @@
.push(function () {
Object.keys(property_list).forEach(function (i) {
property = property_list[i];
if (property._class === "Dream.Property") {
value = property._default || "";
addField(property, value);
}
});
});
......@@ -82,18 +91,21 @@
// getContent of all subfields
.declareMethod("getContent", function () {
var i, promise_list = [];
var i, promise_list = [], gadget = this;
for (i = 0; i < this.props.field_gadget_list.length; i += 1) {
promise_list.push(this.props.field_gadget_list[i].getContent());
}
return RSVP.Queue()
.push(function () { return RSVP.all(promise_list); })
.push(function (result_list) {
var name, result = {};
var name, result = {}, content = result;
if (gadget.key) {
content = result[gadget.key] = {};
}
for (i = 0; i < result_list.length; i += 1) {
for (name in result_list[i]) {
if (result_list[i].hasOwnProperty(name)) {
result[name] = result_list[i][name];
content[name] = result_list[i][name];
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment