1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-22 00:02:28 +00:00

Fix bugs in Web UI parameters

* Fixes #49
* Slightly cleaner javascript code
This commit is contained in:
J. Fernando Sánchez 2017-12-13 14:53:02 +01:00
parent 869c00f709
commit aa54d1c9c8

View File

@ -43,23 +43,20 @@ $(document).ready(function() {
for (g in gplugins){
html += "<optgroup label=\""+g+"\">"
for (r in gplugins[g]){
plugin = plugins[r]
if (plugin["name"]){
plugin = plugins[gplugins[g][r]]
if (!plugin["name"]){
console.log("No name for plugin ", plugin);
continue;
}
html+= "<option value=\""+plugin["name"]+"\" "
if (plugin["name"] == defaultPlugin["name"]){
if (plugin["is_activated"]){
html+= "<option value=\""+plugin["name"]+"\" selected=\"selected\">"+plugin["name"]+"</option>"
}else{
html+= "<option value=\""+plugin["name"]+"\" selected=\"selected\" disabled=\"disabled\">"+plugin["name"]+"</option>"
}
}
else{
if (plugin["is_activated"]){
html+= "<option value=\""+plugin["name"]+"\">"+plugin["name"]+"</option>"
}
else{
html+= "<option value=\""+plugin["name"]+"\" disabled=\"disabled\">"+plugin["name"]+"</option>"
html+= " selected=\"selected\""
}
if (!plugin["is_activated"]){
html+= " disabled=\"disabled\" "
}
html+=">"+plugin["name"]+"</option>"
}
if (plugin["extra_params"]){
@ -76,7 +73,7 @@ $(document).ready(function() {
}
}
}
var pluginList = document.createElement('li');
var pluginEntry = document.createElement('li');
newHtml = ""
if(plugin.url) {
@ -85,11 +82,10 @@ $(document).ready(function() {
newHtml= plugin["name"];
}
newHtml += ": " + replaceURLWithHTMLLinks(plugin.description);
pluginList.innerHTML = newHtml;
availablePlugins.appendChild(pluginList)
pluginEntry.innerHTML = newHtml;
availablePlugins.appendChild(pluginEntry)
}
html += "</optgroup>"
}
document.getElementById('plugins').innerHTML = html;
change_params();
@ -154,10 +150,11 @@ function load_JSON(){
url += "?algo="+plugin+"&i="+input
for (param in plugins_params[plugin]){
if (param != null){
if (plugins_params[plugin].length > 0){
var param_value = encodeURIComponent(document.getElementById(param).options[document.getElementById(param).selectedIndex].text);
field = document.getElementById(param);
if (plugins_params[plugin][param].length > 0){
var param_value = encodeURIComponent(field.options[field.selectedIndex].text);
} else {
var param_value = encodeURIComponent(document.getElementById(param).value);
var param_value = encodeURIComponent(field.text);
}
if (param_value !== "undefined" && param_value.length > 0){
url+="&"+param+"="+param_value
@ -167,7 +164,7 @@ function load_JSON(){
for (param in default_params){
if ((param != null) && (default_params[param]['options']) && (['help','conversion'].indexOf(param) < 0)){
var param_value = encodeURIComponent(document.getElementById(param).options[document.getElementById(param).selectedIndex].text);
var param_value = encodeURIComponent(document.getElementById(param).options[document.getElementById(param).selectedIndex].value);
if (param_value){
url+="&"+param+"="+param_value
}