mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
only post changed values to settings.json, fix for bool values
This commit is contained in:
parent
13169fa664
commit
5cd2dc594f
4 changed files with 35 additions and 9 deletions
|
@ -15,9 +15,19 @@ function reloadSettings() {
|
|||
|
||||
var SETTINGS_ERROR_MESSAGE = "There was a problem saving domain settings. Please try again!";
|
||||
|
||||
$('#settings').on('click', 'button', function(e){
|
||||
$('#settings').on('click', 'button', function(e){
|
||||
// disable any inputs not changed
|
||||
$("input:not([data-changed])").each(function(){
|
||||
$(this).prop('disabled', true);
|
||||
});
|
||||
|
||||
// grab a JSON representation of the form via form2js
|
||||
var formJSON = form2js('settings-form', ".", false, null, true);
|
||||
var formJSON = form2js('settings-form', ".", false, cleanupFormValues, true);
|
||||
|
||||
// re-enable all inputs
|
||||
$("input").each(function(){
|
||||
$(this).prop('disabled', false);
|
||||
});
|
||||
|
||||
// POST the form JSON to the domain-server settings.json endpoint so the settings are saved
|
||||
$.ajax('/settings.json', {
|
||||
|
@ -40,6 +50,19 @@ $('#settings').on('click', 'button', function(e){
|
|||
return false;
|
||||
});
|
||||
|
||||
$('#settings').on('change', 'input', function(){
|
||||
// this input was changed, add the changed data attribute to it
|
||||
$(this).attr('data-changed', true);
|
||||
});
|
||||
|
||||
function cleanupFormValues(node) {
|
||||
if (node.type && node.type === 'checkbox') {
|
||||
return { name: node.id, value: node.checked ? true : false };
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function showAlertMessage(message, isSuccess) {
|
||||
var alertBox = $('.alert');
|
||||
alertBox.attr('class', 'alert');
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"type": "checkbox",
|
||||
"label": "Dynamic Jitter Buffers",
|
||||
"help": "Dynamically buffer client audio based on perceived jitter in packet receipt timing",
|
||||
"default": "false"
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,13 +13,15 @@
|
|||
<div class="panel-body">
|
||||
<% _.each(group.settings, function(setting, setting_key){ %>
|
||||
<div class="form-group">
|
||||
<label for="{{=group}}.{{=setting}}" class="col-sm-2 control-label"><%- setting.label %></label>
|
||||
<% var setting_id = group_key + "." + setting_key %>
|
||||
<label for="<%- setting_id %>" class="col-sm-2 control-label"><%- setting.label %></label>
|
||||
<div class="col-sm-10">
|
||||
<% if(setting.type) %>
|
||||
<% if (setting.type === "checkbox") { %>
|
||||
<input type="checkbox">
|
||||
<% var checked_box = (_.isUndefined(values[group_key][setting_key]) ? setting.default : values[group_key][setting_key]) %>
|
||||
<input type="checkbox" id="<%- setting_id %>" <%- checked_box ? "checked" : "" %>>
|
||||
<% } else { %>
|
||||
<input type="text" class="form-control" id="<%- group %>.<%- setting %>" placeholder="<%- setting.placeholder %>" value="<%- values[group_key][setting_key] %>">
|
||||
<input type="text" class="form-control" id="<%- setting_id %>" placeholder="<%- setting.placeholder %>" value="<%- values[group_key][setting_key] %>">
|
||||
<% } %>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -81,10 +81,11 @@ void DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJ
|
|||
// we don't continue if this key is not present in our descriptionObject
|
||||
if (descriptionObject.contains(key)) {
|
||||
if (rootValue.isString()) {
|
||||
// if this is a string then just set it in our settingsVariant
|
||||
settingsVariant[key] = rootValue.toString();
|
||||
} else if (rootValue.isBool()) {
|
||||
settingsVariant[key] = rootValue.toBool();
|
||||
} else if (rootValue.isObject()) {
|
||||
|
||||
// there's a JSON Object to explore, so attempt to recurse into it
|
||||
QJsonObject nextDescriptionObject = descriptionObject[key].toObject();
|
||||
|
||||
if (nextDescriptionObject.contains(DESCRIPTION_SETTINGS_KEY)) {
|
||||
|
@ -93,7 +94,7 @@ void DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJ
|
|||
settingsVariant[key] = QVariantMap();
|
||||
}
|
||||
|
||||
// there's a JSON Object to explore, so recurse into it
|
||||
|
||||
recurseJSONObjectAndOverwriteSettings(rootValue.toObject(),
|
||||
*reinterpret_cast<QVariantMap*>(settingsVariant[key].data()),
|
||||
nextDescriptionObject[DESCRIPTION_SETTINGS_KEY].toObject());
|
||||
|
|
Loading…
Reference in a new issue