Added support for dropdown to tables in domain settings

This commit is contained in:
seefo 2017-06-13 15:40:37 -07:00
parent dadbf445a1
commit 2f307f418c
2 changed files with 58 additions and 4 deletions

View file

@ -1360,8 +1360,19 @@
{
"name": "server_type",
"label": "Server Type",
"type": "select",
"placeholder": "Audio Mixer",
"can_set": true
"can_set": true,
"options": [
{
"value": "Audio Mixer",
"label": "Audio Mixer"
},
{
"value": "Avatar Mixer",
"label": "Avatar Mixer"
}
]
}
]
}

View file

@ -1163,6 +1163,8 @@ function makeTable(setting, keypath, setting_value) {
var isNonDeletableRow = !setting.can_add_new_rows;
// console.log(setting);
_.each(setting.columns, function(col) {
var colValue, colName;
@ -1183,6 +1185,24 @@ function makeTable(setting, keypath, setting_value) {
"<input type='checkbox' class='form-control table-checkbox' " +
"name='" + colName + "'" + (colValue ? " checked" : "") + "/>" +
"</td>";
} else if (isArray && col.type === "select" ) {
//console.log("adding row");
//console.log(col);
//console.log(setting);
html +=
"<td class='" + Settings.DATA_COL_CLASS + "'name='" + col.name + "'>" +
"<select class='form-control' data-hidden-input='" + setting.key + "'>'";
for(var i in col.options) {
var option = col.options[i];
html += "<option value='" + option.value + "' " + (option.value == colValue ? 'selected' : '') + ">" + option.label + "</option>";
}
html += "</select>";
html += "<input type='hidden' value='" + option.value + "'></td>";
} else if (isArray && col.type === "time" && col.editable) {
html +=
"<td class='" + Settings.DATA_COL_CLASS + "'name='" + col.name + "'>" +
@ -1281,6 +1301,23 @@ function makeTableHiddenInputs(setting, initialValues, categoryValue) {
"<input type='checkbox' style='display: none;' class='form-control table-checkbox' " +
"name='" + col.name + "'" + (defaultValue ? " checked" : "") + "/>" +
"</td>";
} else if (col.type === "select") {
console.log(col);
console.log(setting);
console.log(categoryValue);
html += "<td class='" + Settings.DATA_COL_CLASS + "'name='" + col.name + "'>"
html += "<select class='form-control' data-hidden-input='" + col.name + "'>'"
for(var i in col.options) {
var option = col.options[i];
html += "<option value='" + option.value + "' " + (option.value == defaultValue ? 'selected' : '') + ">" + option.label + "</option>";
}
html += "</select>";
html += "<input type='hidden' class='table-dropdown' name='" + col.name + "' value='" + option.value + "'></td>";
} else {
html +=
"<td " + (col.hidden ? "style='display: none;'" : "") + " class='" + Settings.DATA_COL_CLASS + "' " +
@ -1408,6 +1445,7 @@ function addTableRow(row) {
input.show();
var isCheckbox = input.hasClass("table-checkbox");
var isDropdown = input.hasClass("table-dropdown");
if (isArray) {
var row_index = row.siblings('.' + Settings.DATA_ROW_CLASS).length
@ -1416,15 +1454,20 @@ function addTableRow(row) {
// are there multiple columns or just one?
// with multiple we have an array of Objects, with one we have an array of whatever the value type is
var num_columns = row.children('.' + Settings.DATA_COL_CLASS).length
var newName = setting_name + "[" + row_index + "]" + (num_columns > 1 ? "." + key : "");
if (isCheckbox) {
input.attr("name", setting_name + "[" + row_index + "]" + (num_columns > 1 ? "." + key : ""))
input.attr("name", newName)
} else {
input.attr("name", setting_name + "[" + row_index + "]" + (num_columns > 1 ? "." + key : ""))
if(isDropdown) {
$(element).children("select").attr("data-hidden-input", newName);
}
input.attr("name", newName);
}
} else {
// because the name of the setting in question requires the key
// setup a hook to change the HTML name of the element whenever the key changes
var colName = $(element).attr("name");
keyInput.on('change', function(){
input.attr("name", setting_name + "." + $(this).val() + "." + colName);