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 @@
.innerHTML,
selected_option_template = Handlebars.compile(selected_option_source);
initGadgetMixin(gadget_klass);
gadget_klass
......@@ -29,70 +30,164 @@
// XXX node_id is added like a property so that one can change the node
// id
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(options);
gadget.props.key = options.key; // used for recursive fieldsets
gadget.props.field_gadget_list = [];
function addField(property_id, property_definition,
value) {
function addField(property_id, property_definition, value) {
console.log("ADDFIELD EXPANDABLEFIELDSET 1");
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("EXPANDABLE insertingAdjacentHTML for:" + 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;
try {
queue
.push(function () {
// XXX this is incorrect for recursive fieldsets.
// we should use nested fieldset with legend
console.log("EXPANDABLE insertingAdjacentHTML for:"
+ 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
});
}
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
property_definition: property_definition
});
}
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);
});
})
.push(function () {
return sub_gadget.getElement();
})
.push(function (sub_element) {
gadget.props.element.appendChild(sub_element);
gadget.props.field_gadget_list.push(sub_gadget);
});
} catch (e) {
RSVP.Queue()
.push(function () {
// XXX this is incorrect for recursive fieldsets.
// we should use nested fieldset with legend
console.log("EXPANDABLE insertingAdjacentHTML for:"
+ 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) {
......@@ -115,28 +210,9 @@
});
}
select.innerHTML += tmp;
}
function createListField(index) {
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
});
console.log("printing SELECT FIELD LIST");
select.onchange = function () {updateFieldSet(gadget); };
console.log(select);
}
queue = new RSVP.Queue()
......@@ -147,23 +223,42 @@
if (!options.property_definition.allOf) {
console.log("allOf must be used for expandable fields");
}
console.log("RENDER EXPANDABLEFIELDSET 2");
len = options.property_definition.allOf.length;
// console.log("the length is equal to " + len);
for (j = 0; j <= len - 1; j += 1) {
if (options.property_definition.allOf[j].oneOf) {
for (index = 0; index <= len - 1; index += 1) {
console.log("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
console.log(options.property_definition.allOf[index]);
if (options.property_definition.allOf[index].oneOf) {
// XXX adding various hidden list fields
// console.log("======== adding hidden list fields ========");
oneOf = options.property_definition.allOf[j].oneOf;
oneOf = options.property_definition.allOf[index].oneOf;
// XX consider initiating only the one store ind option values
for (ind = 0; ind <= oneOf.length - 1; ind += 1) {
value = oneOf[ind].default;
value = (options.value || {})[oneOf[ind].title] === undefined
? value : options.value[oneOf[ind].title];
addField(oneOf[ind].title, oneOf[ind], value);
if (oneOf[ind].title === string_value) {
value = (options.value || {})[oneOf[ind].title] === undefined
? oneOf[ind].default : options.value[oneOf[ind].title];
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 {
// 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 @@
return result;
})
.push(function (results) {
// console.log(results);
if (Object.keys(results).length !== 1) {
console.log("the expandable property results must contain" +
"a single key of an object that can contain detailed results");
......@@ -205,22 +299,6 @@
console.log(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