recursive expandable field syncs properly according to the new expanded...

recursive expandable field syncs properly according to the new expanded schema. getContenct needs to be corrected
parent 8d494d02
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
selected_option_template = Handlebars.compile(selected_option_source); selected_option_template = Handlebars.compile(selected_option_source);
function syncField(gadget) { function syncField(gadget) {
console.log("SYNCFIELD EXPANDABLEFIELDSET 1");
var i, properties_dict, var i, properties_dict,
sub_title, sub_type, in_type, default_value, previous_value, sub_title, sub_type, in_type, default_value, previous_value,
labels, inps, j, labels = [], lbls, inps = [], inputs, j,
recent_occupied = [], recent_occupied = [],
recent_occupied_labels = [],
prop_name = gadget.props.definition.property_def.title; prop_name = gadget.props.definition.property_def.title;
console.log("for prop_name"); console.log("for prop_name syncField");
console.log(prop_name); console.log(prop_name);
// set the title of the field // set the title of the field
...@@ -46,23 +46,51 @@ ...@@ -46,23 +46,51 @@
if (gadget.props.definition.property_def.properties) { if (gadget.props.definition.property_def.properties) {
properties_dict = gadget.props.definition.property_def.properties; properties_dict = gadget.props.definition.property_def.properties;
gadget.props.element.children[2].style.display = ''; gadget.props.element.children[2].style.display = '';
// XXX assuming that the number of labels inputs = gadget.props.element.children[2]
// is the same as the number of inputs
inps = gadget.props.element.children[2]
.getElementsByTagName("input"); .getElementsByTagName("input");
labels = gadget.props.element.children[2] for (i = 0; i <= inputs.length-1; i += 1) {
if (inputs[i].parentNode.parentNode.parentNode ===
gadget.props.element.children[2]) {
inps.push(inputs[i]);
}
}
lbls = gadget.props.element.children[2]
.getElementsByTagName("label"); .getElementsByTagName("label");
for (i = 0; i <= lbls.length-1; i += 1) {
if (lbls[i].parentNode ===
gadget.props.element.children[2]) {
labels.push(lbls[i]);
}
}
for (i = 0; i <= Object.keys(properties_dict).length-1; i += 1) { for (i = 0; i <= Object.keys(properties_dict).length-1; i += 1) {
sub_title = Object.keys(properties_dict)[i]; sub_title = Object.keys(properties_dict)[i];
console.log("sub_title"); console.log("sub_title");
console.log(sub_title); console.log(sub_title);
sub_type = properties_dict[sub_title].type; sub_type = properties_dict[sub_title].type;
// if the gadget contains expandable inputs (allOf)
// find the labels of that inputs
if (properties_dict[sub_title].allOf) {
for (j = 0; j <= labels.length-1; j += 1) {
if (labels[j].getAttribute("for").split("_")[0] === "allOf") {
if (!(recent_occupied_labels.indexOf(labels[j]) > -1)) {
labels[j].innerHTML = sub_title;
recent_occupied_labels.push(labels[j]);
break;
}
}
}
}
default_value = properties_dict[sub_title].default; default_value = properties_dict[sub_title].default;
// previous value // previous value
if (gadget.props.options.value[prop_name]) { if (gadget.props.options.value[prop_name]) {
previous_value = gadget.props.options.value[prop_name][sub_title]; previous_value = gadget.props.options.value[prop_name][sub_title];
} }
for (j = 0; j <= inps.length-1; j += 1) { for (j = 0; j <= inps.length-1; j += 1) {
// check if the input is one of a sub-gadget
// do not proceed if yes
if (inps[j].parentNode.parentNode.parentNode ===
gadget.props.element.children[2]) {
// if the element is not already occupied // if the element is not already occupied
if (!(recent_occupied.indexOf(inps[j]) > -1)) { if (!(recent_occupied.indexOf(inps[j]) > -1)) {
if (inps[j].getAttribute("type")) { if (inps[j].getAttribute("type")) {
...@@ -84,22 +112,33 @@ ...@@ -84,22 +112,33 @@
? default_value ? default_value
: previous_value : previous_value
); );
labels[j].innerHTML = sub_title;
labels[j].setAttribute('for', sub_title);
recent_occupied.push(inps[j]); recent_occupied.push(inps[j]);
// find the label for that input
inps[j].parentNode.parentNode
.previousSibling.previousSibling.innerHTML = sub_title;
recent_occupied_labels.push(inps[j].parentNode.parentNode
.previousSibling.previousSibling);
// present them // present them
inps[j].parentNode.parentNode
.previousSibling.previousSibling.style.display = '';
inps[j].parentNode.parentNode.style.display = ''; inps[j].parentNode.parentNode.style.display = '';
labels[j].style.display = '';
break; break;
} }
} }
} }
} }
} }
}
// hiding the inps that are not occupied
for (j = 0; j <= inps.length-1; j += 1) { for (j = 0; j <= inps.length-1; j += 1) {
if (!(recent_occupied.indexOf(inps[j]) > -1)) { if (!(recent_occupied.indexOf(inps[j]) > -1)) {
inps[j].parentNode.parentNode.style.display = 'block'; inps[j].parentNode.parentNode.style.display = 'block';
inps[j].parentNode.parentNode.style.display = 'none'; inps[j].parentNode.parentNode.style.display = 'none';
}
}
// hiding the labels that are not occupied
for (j = 0; j <= labels.length-1; j += 1) {
if (!(recent_occupied_labels.indexOf(labels[j]) > -1)) {
labels[j].style.display = 'block'; labels[j].style.display = 'block';
labels[j].style.display = 'none'; labels[j].style.display = 'none';
} }
...@@ -192,6 +231,13 @@ ...@@ -192,6 +231,13 @@
"name": (property_definition.name || property_id) "name": (property_definition.name || property_id)
}) })
); );
if (property_definition.allOf) {
// if there is type property then remove it
if (property_definition.allOf[0].type) {
delete property_definition.allOf[0].type;
}
return gadget.declareGadget("../expandable_field/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");
...@@ -251,7 +297,7 @@ ...@@ -251,7 +297,7 @@
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
function findRequestedTypes(oneOf_list) { function findRequestedTypes(oneOf_list) {
var prop_dict, prop_list, var prop_dict, prop_list,
prop_type_list, x, search_item, prop_type_list, x, search_item, search_item_def,
req_props_dlist = [], req_props_dlist = [],
req_props_slist = [], req_props_slist = [],
// req_props_sdict = {}, // req_props_sdict = {},
...@@ -277,31 +323,40 @@ ...@@ -277,31 +323,40 @@
// the same definition // the same definition
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
for (x = 0; x <= prop_list.length-1; x += 1) { for (x = 0; x <= prop_list.length-1; x += 1) {
search_item = prop_dict[prop_list[x]].type; search_item = prop_dict[prop_list[x]].allOf ?
prop_type_list.push(search_item); "allOf" : prop_dict[prop_list[x]].type;
search_item_def = prop_dict[prop_list[x]] || "";
prop_type_list.push([search_item, search_item_def]);
if (req_props_slist.indexOf(search_item) === -1) { if (req_props_slist.indexOf(search_item) === -1) {
// list of unique requested properties // list of unique requested properties
req_props_slist.push(prop_dict[prop_list[x]].type); req_props_slist.push(search_item);
} }
} }
// array of requested type-arrays for each different item // array of requested type-arrays for each different item
req_props_dlist.push(prop_type_list); req_props_dlist.push(prop_type_list);
} }
} }
console.log("array of requested type-arrays for each item");
console.log(req_props_dlist);
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// find the maximum number of appearances // find the maximum number of appearances
// for each requested type within req_props_dlist // for each requested type within req_props_dlist
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
for (x = 0; x <= req_props_slist.length-1; x += 1){ for (x = 0; x <= req_props_slist.length-1; x += 1){
req_props_sdict[req_props_slist[x]] = []; req_props_sdict[req_props_slist[x]] = {
"number" : [],
"definition" : {}};
for (ind = 0; ind <= req_props_dlist.length-1; ind += 1) { for (ind = 0; ind <= req_props_dlist.length-1; ind += 1) {
counter = 0; counter = 0;
for (y = 0; y <= req_props_dlist[ind].length-1; y += 1) { for (y = 0; y <= req_props_dlist[ind].length-1; y += 1) {
if (req_props_slist[x] === req_props_dlist[ind][y]) { if (req_props_slist[x] === req_props_dlist[ind][y][0]) {
counter += 1; counter += 1;
search_item_def = req_props_dlist[ind][y][1];
} }
} }
req_props_sdict[req_props_slist[x]].push(counter); req_props_sdict[req_props_slist[x]].number.push(counter);
req_props_sdict[req_props_slist[x]].definition
= search_item_def;
} }
} }
for (ind = 0; for (ind = 0;
...@@ -314,8 +369,8 @@ ...@@ -314,8 +369,8 @@
// find the maximum number within the array // find the maximum number within the array
// and replace the array itself // and replace the array itself
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
req_props_sdict[Object.keys(req_props_sdict)[ind]] = req_props_sdict[Object.keys(req_props_sdict)[ind]].number =
req_props_sdict[Object.keys(req_props_sdict)[ind]].reduce( req_props_sdict[Object.keys(req_props_sdict)[ind]].number.reduce(
handleReduce handleReduce
); );
} }
...@@ -361,9 +416,19 @@ ...@@ -361,9 +416,19 @@
ind += 1) { ind += 1) {
// create an abstract property definition (updated later) // create an abstract property definition (updated later)
for (w = 0; for (w = 0;
w <= req_props_sdict[Object.keys(req_props_sdict)[ind]]-1; w <= req_props_sdict[
Object.keys(req_props_sdict)[ind]
].number-1;
w += 1) { w += 1) {
ab_title = Object.keys(req_props_sdict)[ind] + "_" + w; ab_title = Object.keys(req_props_sdict)[ind] + "_" + w;
if (req_props_sdict[
Object.keys(req_props_sdict)[ind]
].definition.allOf) {
ab_definition.properties[ab_title]
= req_props_sdict[
Object.keys(req_props_sdict)[ind]
].definition;
} else {
ab_definition.properties[ab_title] = { ab_definition.properties[ab_title] = {
type: Object.keys(req_props_sdict)[ind], type: Object.keys(req_props_sdict)[ind],
default: "", default: "",
...@@ -372,6 +437,7 @@ ...@@ -372,6 +437,7 @@
}; };
} }
} }
}
console.log("abstract_definition for " + index); console.log("abstract_definition for " + index);
console.log(ab_definition); console.log(ab_definition);
// add a field with abstract definition // add a field with abstract definition
...@@ -525,7 +591,7 @@ ...@@ -525,7 +591,7 @@
for (ind = sel_ind; for (ind = sel_ind;
ind <= gadget.props.element.children.length-1; ind <= gadget.props.element.children.length-1;
ind += 1) { ind += 1) {
console.log("hiding :"); console.log("hiding all the children as the service starts:");
gadget.props.element.children[ind].style.display = "block"; gadget.props.element.children[ind].style.display = "block";
gadget.props.element.children[ind].style.display = "none"; gadget.props.element.children[ind].style.display = "none";
} }
...@@ -534,6 +600,19 @@ ...@@ -534,6 +600,19 @@
console.log("STARTSERVICE EXPANDFIELD 1"); console.log("STARTSERVICE EXPANDFIELD 1");
syncField(gadget); syncField(gadget);
}) })
.push(function () {
var i,
promise_list = [];
for (i = 0; i < gadget.props.field_gadget_list.length; i += 1) {
if (gadget.props.field_gadget_list[i].startService) {
promise_list.push(
gadget.props.field_gadget_list[i].startService()
);
}
}
console.log("thr r " + promise_list.length + " subgadget promises");
return RSVP.all(promise_list);
})
.push(function () { .push(function () {
waitForListFieldSelection(gadget); waitForListFieldSelection(gadget);
}); });
......
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