fieldset: first step towards dynamic expansion of fields according to the user input

parent e08f9da8
......@@ -23,15 +23,20 @@
var gadget = this,
queue;
console.log("FIELDSET RENDER 1");
console.log(options);
console.log(node_id);
gadget.props.key = options.key; // used for recursive fieldsets
gadget.props.field_gadget_list = [];
function addField(property_id, property_definition, value) {
var sub_gadget;
function addField(property_id, property_definition,
value) {
var sub_gadget, temp_property_def;
queue
.push(function () {
// XXX this is incorrect for recursive fieldsets.
// we should use nested fieldset with legend
console.log("insertingAdjacentHTML for:" + property_id);
gadget.props.element.insertAdjacentHTML(
'beforeend',
label_template({
......@@ -39,6 +44,16 @@
"name": (property_definition.name || property_id)
})
);
console.log("....................");
console.log(property_id);
console.log(property_definition);
console.log(value);
if (property_definition.allOf) {
if (property_definition.allOf[0].type) {
delete property_definition.allOf[0].type;
}
temp_property_def = property_definition.allOf[0];
return gadget.declareGadget("../fieldset/index.html");
if (property_definition.type === "object") {
// Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html");
......@@ -53,6 +68,13 @@
})
.push(function (gg) {
sub_gadget = gg;
if (temp_property_def) {
return sub_gadget.render({
key: property_id,
value: value,
property_definition: temp_property_def
});
}
return sub_gadget.render({
key: property_id,
value: value,
......@@ -77,11 +99,34 @@
).forEach(function (property_name) {
var property_definition =
options.property_definition.properties[property_name],
value = (options.value || {})[property_name] === undefined
? property_definition._default : options.value[property_name];
value = property_definition.default,
i=0, property;
// XXX some properties are not editable
if (property_name !== 'coordinate' && property_name !== '_class') {
addField(property_name, property_definition, value);
console.log("******************");
console.log(property_name);
console.log(property_definition);
if (property_definition.allOf) {
if (property_definition.allOf[0].properties) {
for (property in property_definition
.allOf[0].properties) {
if (property_definition.allOf[0].properties
.hasOwnProperty(property)) {
i += 1;
if (i > 1) {console.log("something is wrong!");}
value = property_definition.allOf[0]
.properties[property].default;
}
}
}
}
value = (options.value || {})[property_name] === undefined
? value : options.value[property_name];
if (property_name !== 'coordinate'
&& property_name !== '_class'
&& property_name !== 'id') {
addField(property_name, property_definition, value);
}
});
});
......
......@@ -316,6 +316,10 @@
function updateElementData(gadget, node_id, data) {
console.log("updateELEMENTDATA 1");
console.log("updateELEMENTDATA 1");
console.log(gadget);
console.log(node_id);
console.log(data);
var element_id = gadget.props.node_id_to_dom_element_id[node_id],
new_id = data.id;
if (data.data.name) {
......@@ -433,16 +437,16 @@
full_schema.class_definition[ref_word],
full_schema);
}
console.log(full_schema.class_definition.definitions);
// console.log(full_schema.class_definition.definitions);
if (referenced.properties) {
console.log("[[[[[[[[[[]]]]]]]]]]");
console.log(referenced.properties);
// console.log("[[[[[[[[[[]]]]]]]]]]");
// console.log(referenced.properties);
for (property in referenced.properties) {
if (referenced.properties.hasOwnProperty(property)) {
if (referenced.properties[property].type ||
referenced.properties[property].$ref) {
console.log("..");
console.log(property);
// console.log("..");
// console.log(property);
if (referenced.properties[property].$ref) {
ref_definition_list
= referenced.properties[property].$ref.split("/");
......@@ -451,26 +455,26 @@
ref_definition
= full_schema.class_definition
.definitions[ref_definition_word];
console.log("(((((((())))))))");
console.log(ref_definition);
// console.log("(((((((())))))))");
// console.log(ref_definition);
if (ref_definition.allOf) {
if (ref_definition.allOf[1].oneOf) {
len = ref_definition.allOf[1].oneOf.length - 1;
for (j = 0; j <= len; j += 1) {
console.log("--------- " + j);
console.log(ref_definition.allOf[1].oneOf[j]);
// console.log("--------- " + j);
// console.log(ref_definition.allOf[1].oneOf[j]);
if (ref_definition.allOf[1]
.oneOf[j].$ref) {
sub_ref_def_list = ref_definition.allOf[1]
.oneOf[j].$ref.split("/");
console.log(">>>>>>");
// console.log(">>>>>>");
sub_ref_def_word
= sub_ref_def_list[sub_ref_def_list.length-1];
sub_ref_def_root
= sub_ref_def_list[sub_ref_def_list.length-2];
sub_ref_def = full_schema.class_definition
.definitions[sub_ref_def_root][sub_ref_def_word];
console.log(sub_ref_def);
// console.log(sub_ref_def);
ref_definition.allOf[1].oneOf[j] = sub_ref_def;
}
}
......@@ -478,8 +482,8 @@
}
expanded_class_definition.properties[property]
= ref_definition;
console.log("for property " + property + ", definition:");
console.log(ref_definition);
//console.log("for property " + property + ", definition:");
//console.log(ref_definition);
} else {
expanded_class_definition.properties[property]
= referenced.properties[property];
......@@ -490,8 +494,8 @@
}
}
}
console.log("expandSCHEMA 2");
console.log(expanded_class_definition);
// console.log("expandSCHEMA 2");
// console.log(expanded_class_definition);
return expanded_class_definition;
}
......@@ -659,6 +663,13 @@
"data": {}
};
return fieldset_gadget.getContent().then(function (r) {
console.log("******");
console.log("******");
console.log("******");
console.log(r);
console.log("******");
console.log("******");
console.log("******");
$.extend(data.data, r);
updateElementData(gadget, node_id, data);
});
......@@ -684,6 +695,13 @@
scope: 'fieldset'
})
.push(function (fieldset_gadget) {
console.log("^^^^^^^^^^^^^^^^^^^");
console.log("^^^^^^^^^^^^^^^^^^^");
console.log("^^^^^^^^^^^^^^^^^^^");
console.log(node_data);
console.log("^^^^^^^^^^^^^^^^^^^");
console.log("^^^^^^^^^^^^^^^^^^^");
console.log("^^^^^^^^^^^^^^^^^^^");
return RSVP.all([fieldset_gadget,
fieldset_gadget.render({value: node_data,
property_definition: schema},
......@@ -919,6 +937,13 @@
})
.declareMethod('getContent', function () {
console.log("£££££££");
console.log("£££££££");
console.log("£££££££");
console.log(this.props.data);
console.log("£££££££");
console.log("£££££££");
console.log("£££££££");
return JSON.stringify(this.props.data);
})
......
......@@ -43,7 +43,8 @@
});
}
select.innerHTML += tmp;
}).declareMethod('getContent', function () {
})
.declareMethod('getContent', function () {
var select = this.element.getElementsByTagName('select')[0],
result = {};
result[select.getAttribute("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