mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-22 08:12:27 +00:00
Fix bugs in Web UI parameters
* Fixes #49 * Slightly cleaner javascript code
This commit is contained in:
parent
869c00f709
commit
aa54d1c9c8
@ -28,74 +28,70 @@ function hashchanged(){
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var response = JSON.parse($.ajax({type: "GET", url: "/api/plugins/" , async: false}).responseText);
|
var response = JSON.parse($.ajax({type: "GET", url: "/api/plugins/" , async: false}).responseText);
|
||||||
var defaultPlugin= JSON.parse($.ajax({type: "GET", url: "/api/plugins/default" , async: false}).responseText);
|
var defaultPlugin= JSON.parse($.ajax({type: "GET", url: "/api/plugins/default" , async: false}).responseText);
|
||||||
html="";
|
html="";
|
||||||
var availablePlugins = document.getElementById('availablePlugins');
|
var availablePlugins = document.getElementById('availablePlugins');
|
||||||
plugins = response.plugins;
|
plugins = response.plugins;
|
||||||
gplugins = {};
|
gplugins = {};
|
||||||
for (r in plugins){
|
for (r in plugins){
|
||||||
ptype = plugins[r]['@type'];
|
ptype = plugins[r]['@type'];
|
||||||
if(gplugins[ptype] == undefined){
|
if(gplugins[ptype] == undefined){
|
||||||
gplugins[ptype] = [r]
|
gplugins[ptype] = [r]
|
||||||
}else{
|
}else{
|
||||||
gplugins[ptype].push(r)
|
gplugins[ptype].push(r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
for (g in gplugins){
|
||||||
for (g in gplugins){
|
html += "<optgroup label=\""+g+"\">"
|
||||||
html += "<optgroup label=\""+g+"\">"
|
for (r in gplugins[g]){
|
||||||
for (r in gplugins[g]){
|
plugin = plugins[gplugins[g][r]]
|
||||||
plugin = plugins[r]
|
if (!plugin["name"]){
|
||||||
if (plugin["name"]){
|
console.log("No name for plugin ", plugin);
|
||||||
if (plugin["name"] == defaultPlugin["name"]){
|
continue;
|
||||||
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>"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin["extra_params"]){
|
}
|
||||||
plugins_params[plugin["name"]]={};
|
html+= "<option value=\""+plugin["name"]+"\" "
|
||||||
for (param in plugin["extra_params"]){
|
if (plugin["name"] == defaultPlugin["name"]){
|
||||||
if (typeof plugin["extra_params"][param] !="string"){
|
html+= " selected=\"selected\""
|
||||||
var params = new Array();
|
}
|
||||||
var alias = plugin["extra_params"][param]["aliases"][0];
|
if (!plugin["is_activated"]){
|
||||||
params[alias]=new Array();
|
html+= " disabled=\"disabled\" "
|
||||||
for (option in plugin["extra_params"][param]["options"]){
|
}
|
||||||
params[alias].push(plugin["extra_params"][param]["options"][option])
|
html+=">"+plugin["name"]+"</option>"
|
||||||
}
|
}
|
||||||
plugins_params[plugin["name"]][alias] = (params[alias])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var pluginList = document.createElement('li');
|
|
||||||
|
|
||||||
newHtml = ""
|
if (plugin["extra_params"]){
|
||||||
if(plugin.url) {
|
plugins_params[plugin["name"]]={};
|
||||||
newHtml= "<a href="+plugin.url+">" + plugin.name + "</a>";
|
for (param in plugin["extra_params"]){
|
||||||
}else {
|
if (typeof plugin["extra_params"][param] !="string"){
|
||||||
newHtml= plugin["name"];
|
var params = new Array();
|
||||||
}
|
var alias = plugin["extra_params"][param]["aliases"][0];
|
||||||
newHtml += ": " + replaceURLWithHTMLLinks(plugin.description);
|
params[alias]=new Array();
|
||||||
pluginList.innerHTML = newHtml;
|
for (option in plugin["extra_params"][param]["options"]){
|
||||||
availablePlugins.appendChild(pluginList)
|
params[alias].push(plugin["extra_params"][param]["options"][option])
|
||||||
}
|
}
|
||||||
html += "</optgroup>"
|
plugins_params[plugin["name"]][alias] = (params[alias])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var pluginEntry = document.createElement('li');
|
||||||
|
|
||||||
|
newHtml = ""
|
||||||
|
if(plugin.url) {
|
||||||
|
newHtml= "<a href="+plugin.url+">" + plugin.name + "</a>";
|
||||||
|
}else {
|
||||||
|
newHtml= plugin["name"];
|
||||||
|
}
|
||||||
|
newHtml += ": " + replaceURLWithHTMLLinks(plugin.description);
|
||||||
|
pluginEntry.innerHTML = newHtml;
|
||||||
|
availablePlugins.appendChild(pluginEntry)
|
||||||
|
}
|
||||||
|
html += "</optgroup>"
|
||||||
document.getElementById('plugins').innerHTML = html;
|
document.getElementById('plugins').innerHTML = html;
|
||||||
change_params();
|
change_params();
|
||||||
|
|
||||||
$(window).on('hashchange', hashchanged);
|
$(window).on('hashchange', hashchanged);
|
||||||
hashchanged();
|
hashchanged();
|
||||||
$('.tooltip-form').tooltip();
|
$('.tooltip-form').tooltip();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -154,10 +150,11 @@ function load_JSON(){
|
|||||||
url += "?algo="+plugin+"&i="+input
|
url += "?algo="+plugin+"&i="+input
|
||||||
for (param in plugins_params[plugin]){
|
for (param in plugins_params[plugin]){
|
||||||
if (param != null){
|
if (param != null){
|
||||||
if (plugins_params[plugin].length > 0){
|
field = document.getElementById(param);
|
||||||
var param_value = encodeURIComponent(document.getElementById(param).options[document.getElementById(param).selectedIndex].text);
|
if (plugins_params[plugin][param].length > 0){
|
||||||
|
var param_value = encodeURIComponent(field.options[field.selectedIndex].text);
|
||||||
} else {
|
} else {
|
||||||
var param_value = encodeURIComponent(document.getElementById(param).value);
|
var param_value = encodeURIComponent(field.text);
|
||||||
}
|
}
|
||||||
if (param_value !== "undefined" && param_value.length > 0){
|
if (param_value !== "undefined" && param_value.length > 0){
|
||||||
url+="&"+param+"="+param_value
|
url+="&"+param+"="+param_value
|
||||||
@ -167,7 +164,7 @@ function load_JSON(){
|
|||||||
|
|
||||||
for (param in default_params){
|
for (param in default_params){
|
||||||
if ((param != null) && (default_params[param]['options']) && (['help','conversion'].indexOf(param) < 0)){
|
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){
|
if (param_value){
|
||||||
url+="&"+param+"="+param_value
|
url+="&"+param+"="+param_value
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user