expandablefield set uses select-onChange method updateFieldSet to update the...

expandablefield set uses select-onChange method updateFieldSet to update the fieldSet according to the users Choice. AddField uses try-catch to resolve error. startService dropped.
parent 7a1c40de
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
.innerHTML, .innerHTML,
selected_option_template = Handlebars.compile(selected_option_source); selected_option_template = Handlebars.compile(selected_option_source);
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass gadget_klass
...@@ -29,70 +30,164 @@ ...@@ -29,70 +30,164 @@
// XXX node_id is added like a property so that one can change the node // XXX node_id is added like a property so that one can change the node
// id // id
var gadget = this, var gadget = this,
queue, j, len, ind, oneOf, value; queue, index, len, ind, oneOf, value, prop_name, prop_definition,
string_value;
console.log("EXPANDABLEFIELDSET RENDER 1"); console.log("EXPANDABLEFIELDSET RENDER 1");
console.log(options); console.log(options);
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, function addField(property_id, property_definition, value) {
value) {
console.log("ADDFIELD EXPANDABLEFIELDSET 1"); console.log("ADDFIELD EXPANDABLEFIELDSET 1");
var sub_gadget, temp_property_def; var sub_gadget, temp_property_def;
queue try {
.push(function () { queue
// XXX this is incorrect for recursive fieldsets. .push(function () {
// we should use nested fieldset with legend // XXX this is incorrect for recursive fieldsets.
console.log("EXPANDABLE insertingAdjacentHTML for:" + property_id); // we should use nested fieldset with legend
gadget.props.element.insertAdjacentHTML( console.log("EXPANDABLE insertingAdjacentHTML for:"
'beforeend', + property_id);
label_template({ gadget.props.element.insertAdjacentHTML(
"for": property_id, 'beforeend',
"name": (property_definition.name || property_id) label_template({
}) "for": property_id,
); "name": (property_definition.name || property_id)
if (property_definition.allOf) { })
if (property_definition.allOf[0].type) { );
delete property_definition.allOf[0].type; 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("../list_field/index.html");
}
if (property_definition.type === "object") {
// Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html");
}
if (property_definition.type === "number") {
return gadget.declareGadget("../number_field/index.html");
}
if (property_definition.enum) {
return gadget.declareGadget("../list_field/index.html");
}
return gadget.declareGadget("../string_field/index.html");
})
.push(function (gg) {
sub_gadget = gg;
if (temp_property_def) {
return sub_gadget.render({
key: property_id,
value: value,
property_definition: temp_property_def
});
} }
temp_property_def = property_definition.allOf[0];
return gadget.declareGadget("../list_field/index.html");
}
if (property_definition.type === "object") {
// Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html");
}
if (property_definition.type === "number") {
return gadget.declareGadget("../number_field/index.html");
}
if (property_definition.enum) {
return gadget.declareGadget("../list_field/index.html");
}
return gadget.declareGadget("../string_field/index.html");
})
.push(function (gg) {
sub_gadget = gg;
if (temp_property_def) {
return sub_gadget.render({ return sub_gadget.render({
key: property_id, key: property_id,
value: value, value: value,
property_definition: temp_property_def property_definition: property_definition
}); });
} })
return sub_gadget.render({ .push(function () {
key: property_id, return sub_gadget.getElement();
value: value, })
property_definition: property_definition .push(function (sub_element) {
gadget.props.element.appendChild(sub_element);
gadget.props.field_gadget_list.push(sub_gadget);
}); });
}) } catch (e) {
.push(function () { RSVP.Queue()
return sub_gadget.getElement(); .push(function () {
}) // XXX this is incorrect for recursive fieldsets.
.push(function (sub_element) { // we should use nested fieldset with legend
gadget.props.element.appendChild(sub_element); console.log("EXPANDABLE insertingAdjacentHTML for:"
gadget.props.field_gadget_list.push(sub_gadget); + property_id);
}); gadget.props.element.insertAdjacentHTML(
'beforeend',
label_template({
"for": property_id,
"name": (property_definition.name || property_id)
})
);
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("../list_field/index.html");
}
if (property_definition.type === "object") {
// Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html");
}
if (property_definition.type === "number") {
return gadget.declareGadget("../number_field/index.html");
}
if (property_definition.enum) {
return gadget.declareGadget("../list_field/index.html");
}
return gadget.declareGadget("../string_field/index.html");
})
.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,
property_definition: property_definition
});
})
.push(function () {
return sub_gadget.getElement();
})
.push(function (sub_element) {
gadget.props.element.appendChild(sub_element);
gadget.props.field_gadget_list.push(sub_gadget);
});
}
}
function updateFieldSet(gadget) {
var select = gadget.props.element.getElementsByTagName('select')[0],
update_value = select.options[select.selectedIndex].value,
i, select_index, child;
for (select_index = 0;
select_index <= gadget.props.element.childNodes.length-1;
select_index += 1) {
child = gadget.props.element.childNodes[select_index];
if (child.className === "ui-select") { select_index += 1; break; }
}
for (i = 0; i <= select_index; i += 1) {
gadget.props.element.removeChild(gadget.props.element.lastChild);
}
for (index = 0;
index <= options.property_definition.allOf.length - 1;
index += 1) {
if (options.property_definition.allOf[index].oneOf) {
break;
}
}
console.log(options.property_definition.allOf[index]);
for (i = 0;
i <= options.property_definition.allOf[index].oneOf.length - 1;
i += 1) {
if (options.property_definition.allOf[index].oneOf[i].title
=== update_value) {
addField(
options.property_definition.allOf[index].oneOf[i].title,
options.property_definition.allOf[index].oneOf[i],
options.property_definition.allOf[index].oneOf[i].default
);
break;
}
}
} }
function addListField(options) { function addListField(options) {
...@@ -115,28 +210,9 @@ ...@@ -115,28 +210,9 @@
}); });
} }
select.innerHTML += tmp; select.innerHTML += tmp;
} console.log("printing SELECT FIELD LIST");
select.onchange = function () {updateFieldSet(gadget); };
function createListField(index) { console.log(select);
console.log("CREATELISTFIELD EXPANDABLEFIELDSET 1");
var property_name, property_definition;//, temp_length, temp_value;
if ( Object.keys(options.property_definition.allOf[index].properties)
.length !== 1) {
console.log("the expandable property must be defined" +
"as a string with single string property");
}
property_name = Object.keys(options.property_definition
.allOf[index].properties)[0];
property_definition = options.property_definition.allOf[index]
.properties[property_name];
value = property_definition.default;
value = (options.value || {})[property_name] === undefined
? value : options.value[property_name];
addListField({
key: property_name,
value: value,
property_definition: property_definition
});
} }
queue = new RSVP.Queue() queue = new RSVP.Queue()
...@@ -147,23 +223,42 @@ ...@@ -147,23 +223,42 @@
if (!options.property_definition.allOf) { if (!options.property_definition.allOf) {
console.log("allOf must be used for expandable fields"); console.log("allOf must be used for expandable fields");
} }
console.log("RENDER EXPANDABLEFIELDSET 2");
len = options.property_definition.allOf.length; len = options.property_definition.allOf.length;
// console.log("the length is equal to " + len); for (index = 0; index <= len - 1; index += 1) {
for (j = 0; j <= len - 1; j += 1) { console.log("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
if (options.property_definition.allOf[j].oneOf) { console.log(options.property_definition.allOf[index]);
if (options.property_definition.allOf[index].oneOf) {
// XXX adding various hidden list fields // XXX adding various hidden list fields
// console.log("======== adding hidden list fields ========"); oneOf = options.property_definition.allOf[index].oneOf;
oneOf = options.property_definition.allOf[j].oneOf; // XX consider initiating only the one store ind option values
for (ind = 0; ind <= oneOf.length - 1; ind += 1) { for (ind = 0; ind <= oneOf.length - 1; ind += 1) {
value = oneOf[ind].default; if (oneOf[ind].title === string_value) {
value = (options.value || {})[oneOf[ind].title] === undefined value = (options.value || {})[oneOf[ind].title] === undefined
? value : options.value[oneOf[ind].title]; ? oneOf[ind].default : options.value[oneOf[ind].title];
addField(oneOf[ind].title, oneOf[ind], value); addField(oneOf[ind].title, oneOf[ind], value);
}
/*value = (options.value || {})[oneOf[ind].title] === undefined
? oneOf[ind].default : options.value[oneOf[ind].title];
addField(oneOf[ind].title, oneOf[ind], value); */
} }
} else { } else {
// XXX add a listfield // XXX add a listfield
createListField(j); if (Object.keys(options.property_definition
.allOf[index].properties).length !== 1) {
console.log("the expandable property must be defined" +
"as a string with single string property");
}
prop_name = Object.keys(options.property_definition
.allOf[index].properties)[0];
prop_definition = options.property_definition.allOf[index]
.properties[prop_name];
string_value = (options.value || {})[prop_name] === undefined
? prop_definition.default : options.value[prop_name];
addListField({
key: prop_name,
value: string_value,
property_definition: prop_definition
});
} }
} }
}); });
...@@ -195,7 +290,6 @@ ...@@ -195,7 +290,6 @@
return result; return result;
}) })
.push(function (results) { .push(function (results) {
// console.log(results);
if (Object.keys(results).length !== 1) { if (Object.keys(results).length !== 1) {
console.log("the expandable property results must contain" + console.log("the expandable property results must contain" +
"a single key of an object that can contain detailed results"); "a single key of an object that can contain detailed results");
...@@ -205,22 +299,6 @@ ...@@ -205,22 +299,6 @@
console.log(results); console.log(results);
return results; return results;
}); });
})
.declareMethod('startService', function () {
console.log("STARTSERVICE EXPANDFIELD");
var gadget = this;
function waitForListFieldSelection(gadget) {
console.log("OLA OMORFA OLA OMORFA");
console.log(gadget);
}
return RSVP.Queue()
.push(function () {
waitForListFieldSelection(gadget);
});
}); });
}(window, rJS, RSVP, Handlebars, initGadgetMixin)); }(window, rJS, RSVP, Handlebars, initGadgetMixin));//, loopEventListener));
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