Commit 1dd08722 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_web: set default values on selection boxes and comment debug logs.

parent 64175d1c
...@@ -140,20 +140,25 @@ ...@@ -140,20 +140,25 @@
);\n );\n
}\n }\n
\n \n
function render_selection(json_field) {\n function render_selection(json_field, default_value) {\n
var input = document.createElement("select"),\n var input = document.createElement("select"),\n
option = document.createElement("option"),\n option = document.createElement("option"),\n
option_index,\n option_index,\n
optionz;\n optionz;\n
input.size = 1;\n input.size = 1;\n
option.selected = "selected";\n
option.value = "";\n option.value = "";\n
if (default_value === undefined) {\n
option.selected = "selected";\n
}\n
input.appendChild(option);\n input.appendChild(option);\n
for (option_index in json_field.enum) {\n for (option_index in json_field.enum) {\n
if (json_field.enum.hasOwnProperty(option_index)) {\n if (json_field.enum.hasOwnProperty(option_index)) {\n
optionz = document.createElement("option");\n optionz = document.createElement("option");\n
optionz.value = json_field.enum[option_index];\n optionz.value = json_field.enum[option_index];\n
optionz.textContent = json_field.enum[option_index];\n optionz.textContent = json_field.enum[option_index];\n
if (json_field.enum[option_index] === default_value) {\n
optionz.selected = "selected";\n
}\n
input.appendChild(optionz);\n input.appendChild(optionz);\n
}\n }\n
}\n }\n
...@@ -163,12 +168,12 @@ ...@@ -163,12 +168,12 @@
function render_field(json_field, default_value) {\n function render_field(json_field, default_value) {\n
\n \n
if (json_field.enum !== undefined) {\n if (json_field.enum !== undefined) {\n
return render_selection(json_field);\n return render_selection(json_field, default_value);\n
}\n }\n
\n \n
if (json_field.type === "boolean") {\n if (json_field.type === "boolean") {\n
json_field.enum = [true, false];\n json_field.enum = [true, false];\n
return render_selection(json_field);\n return render_selection(json_field, default_value);\n
}\n }\n
\n \n
var input = document.createElement("input");\n var input = document.createElement("input");\n
...@@ -254,7 +259,8 @@ ...@@ -254,7 +259,8 @@
}\n }\n
root.appendChild(div);\n root.appendChild(div);\n
\n \n
return root;\n \n
return div;\n
}\n }\n
}\n }\n
\n \n
...@@ -313,7 +319,7 @@ ...@@ -313,7 +319,7 @@
}\n }\n
}\n }\n
});\n });\n
console.log(json_dict);\n // console.log(json_dict);\n
\n \n
function convertOnMultiLevel(key, value, d) {\n function convertOnMultiLevel(key, value, d) {\n
var i,\n var i,\n
...@@ -376,7 +382,7 @@ ...@@ -376,7 +382,7 @@
i,\n i,\n
promise_list = [];\n promise_list = [];\n
\n \n
console.log("INITIATING A LOOP EVENT LISTENER");\n // console.log("INITIATING A LOOP EVENT LISTENER");\n
\n \n
for (i = 0; i < field_list.length; i = i + 1) {\n for (i = 0; i < field_list.length; i = i + 1) {\n
promise_list.push(loopEventListener(\n promise_list.push(loopEventListener(\n
...@@ -477,7 +483,7 @@ ...@@ -477,7 +483,7 @@
xml_output = jsonDictToParameterXML(json_dict);\n xml_output = jsonDictToParameterXML(json_dict);\n
}\n }\n
parameter_hash_input.value = btoa(xml_output);\n parameter_hash_input.value = btoa(xml_output);\n
console.log(parameter_hash_input.value);\n // console.log(parameter_hash_input.value);\n
if (validation.valid) {\n if (validation.valid) {\n
return xml_output;\n return xml_output;\n
}\n }\n
...@@ -554,11 +560,16 @@ ...@@ -554,11 +560,16 @@
if (options.json_url === undefined) {\n if (options.json_url === undefined) {\n
throw new Error("undefined json_url");\n throw new Error("undefined json_url");\n
}\n }\n
console.log("CALLED RENDER");\n // console.log("CALLED RENDER");\n
var g = this,\n var g = this,\n
softwaretype;\n softwaretype;\n
\n \n
this.options = options;\n this.options = options;\n
\n
function updateParameterForm(evt) {\n
options.parameter.softwaretype = evt.srcElement.value;\n
return g.render(options);\n
}\n
\n \n
return g.loadSoftwareJSON(g.options.json_url).push(function (json) {\n return g.loadSoftwareJSON(g.options.json_url).push(function (json) {\n
var option_index,\n var option_index,\n
...@@ -636,17 +647,17 @@ ...@@ -636,17 +647,17 @@
prefix = options.json_url.split(json_url_uri.path())[0] + prefix.join("/");\n prefix = options.json_url.split(json_url_uri.path())[0] + prefix.join("/");\n
parameter_json_schema_url = prefix + "/" + parameter_json_schema_url;\n parameter_json_schema_url = prefix + "/" + parameter_json_schema_url;\n
}\n }\n
console.log("GOING TO RENDER FORM");\n // console.log("GOING TO RENDER FORM");\n
return g.renderParameterForm(parameter_json_schema_url, parameter_dict);\n return g.renderParameterForm(parameter_json_schema_url, parameter_dict);\n
})\n })\n
.push(function () {\n .push(function () {\n
console.log("FINISHED TO RENDER, RETURNING THE GADGET");\n // console.log("FINISHED TO RENDER, RETURNING THE GADGET");\n
return g;\n return g;\n
})\n })\n
\n \n
.fail(function (error) {\n .fail(function (error) {\n
var parameter_xml = \'\';\n var parameter_xml = \'\';\n
console.log("FAIL CALLED");\n // console.log("FAIL CALLED");\n
console.log(error.stack);\n console.log(error.stack);\n
if (g.options.parameter.parameter_hash !== undefined) {\n if (g.options.parameter.parameter_hash !== undefined) {\n
parameter_xml = atob(g.options.parameter.parameter_hash);\n parameter_xml = atob(g.options.parameter.parameter_hash);\n
...@@ -674,7 +685,7 @@ ...@@ -674,7 +685,7 @@
});\n });\n
}\n }\n
\n \n
console.log("INITIATING A LOOP EVENT LISTENER FOR OPTION CHANGE");\n // console.log("INITIATING A LOOP EVENT LISTENER FOR OPTION CHANGE");\n
return loopEventListener(\n return loopEventListener(\n
element,\n element,\n
\'change\',\n \'change\',\n
...@@ -690,7 +701,7 @@ ...@@ -690,7 +701,7 @@
return g.processValidation(g.options.json_url)\n return g.processValidation(g.options.json_url)\n
.fail(function (error) {\n .fail(function (error) {\n
var parameter_xml = \'\';\n var parameter_xml = \'\';\n
console.log("FAIL CALLED");\n // console.log("FAIL CALLED");\n
console.log(error.stack);\n console.log(error.stack);\n
if (g.options.parameter.parameter_hash !== undefined) {\n if (g.options.parameter.parameter_hash !== undefined) {\n
parameter_xml = atob(g.options.parameter.parameter_hash);\n parameter_xml = atob(g.options.parameter.parameter_hash);\n
...@@ -840,7 +851,7 @@ ...@@ -840,7 +851,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>942.10806.29939.62481</string> </value> <value> <string>942.12751.5721.43315</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -858,7 +869,7 @@ ...@@ -858,7 +869,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1428362362.95</float> <float>1428479010.83</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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