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

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