fix population of multi-column array from values in settings

This commit is contained in:
Stephen Birarda 2014-10-09 14:26:39 -07:00
parent 6d01724568
commit e1b64275c9
2 changed files with 57 additions and 6 deletions

View file

@ -59,6 +59,20 @@
"type": "password",
"help": "Password used for basic HTTP authentication. Leave this blank if you do not want to change it.",
"value-hidden": true
},
{
"name": "allowed_users",
"type": "table",
"label": "Allowed Users",
"help": "A list of usernames for the High Fidelity users you want to allow into your domain. Users not found in this list will not be allowed to connect.",
"numbered": false,
"columns": [
{
"name": "username",
"label": "Username",
"can_set": true
}
]
}
]
},
@ -99,6 +113,33 @@
}
]
},
{
"name": "attenuation_coefficients",
"type": "table",
"label": "Attenuation Coefficients",
"help": "In this table you can set custom attenuation coefficients between audio zones",
"numbered": false,
"columns": [
{
"name": "source",
"label": "Source",
"can_set": true,
"placeholder": "Zone_A"
},
{
"name": "listener",
"label": "Listener",
"can_set": true,
"placeholder": "Zone_B"
},
{
"name": "coefficient",
"label": "Attenuation coefficient",
"can_set": true,
"placeholder": "0.18"
}
]
},
{
"name": "enable_filter",
"type": "checkbox",

View file

@ -210,7 +210,7 @@ function makeTable(setting, setting_name, setting_value) {
var html = "<label class='control-label'>" + setting.label + "</label>"
html += "<span class='help-block'>" + setting.help + "</span>"
html += "<table class='table table-bordered' data-short-name='" + setting.name + "' name='" + setting_name + (isArray ? "[]" : "")
html += "<table class='table table-bordered' data-short-name='" + setting.name + "' name='" + setting_name
+ "' data-setting-type='" + (isArray ? 'array' : 'hash') + "'>"
// Column names
@ -248,9 +248,15 @@ function makeTable(setting, setting_name, setting_value) {
html += "<td class='row-data'>"
if (isArray) {
html += row
colIsArray = _.isArray(row)
colValue = colIsArray ? row : row[col.name]
html += colValue
// for arrays we add a hidden input to this td so that values can be posted appropriately
html += "<input type='hidden' name='" + setting_name + "[]' value='" + row + "'/>"
html += "<input type='hidden' name='" + setting_name + "[" + indexOrName + "]"
+ (colIsArray ? "" : "." + col.name) + "' value='" + colValue + "'/>"
} else if (row.hasOwnProperty(col.name)) {
html += row[col.name]
}
@ -260,6 +266,7 @@ function makeTable(setting, setting_name, setting_value) {
html += "<td class='buttons'><span class='glyphicon glyphicon-remove del-row'></span></td>"
html += "</tr>"
row_num++
})
@ -358,11 +365,12 @@ function addTableRow(add_glyphicon) {
return
}
})
if (empty) {
showErrorMessage("Error", "Empty field(s)")
return
}
var input_clone = row.clone()
// Change input row to data row
@ -384,7 +392,7 @@ function addTableRow(add_glyphicon) {
} else if ($(element).hasClass("buttons")) {
// Change buttons
var span = $(element).children("span")
span.removeClass("glyphicon-ok add-row")
span.removeClass("glyphicon-plus add-row")
span.addClass("glyphicon-remove del-row")
} else if ($(element).hasClass("key")) {
var input = $(element).children("input")
@ -396,7 +404,9 @@ function addTableRow(add_glyphicon) {
input.attr("type", "hidden")
if (isArray) {
input.attr("name", setting_name)
var row_index = row.siblings('tr.row-data').length
input.attr("name", setting_name + "[" + row_index + "]")
} else {
input.attr("name", full_name + "." + $(element).attr("name"))
}