From 5cd2dc594fff6f168c29b3f84844619e3530751e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 26 Jun 2014 08:45:12 -0700 Subject: [PATCH] only post changed values to settings.json, fix for bool values --- domain-server/resources/web/js/settings.js | 27 +++++++++++++++++-- .../resources/web/settings/describe.json | 2 +- .../resources/web/settings/index.shtml | 8 +++--- .../src/DomainServerSettingsManager.cpp | 7 ++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/domain-server/resources/web/js/settings.js b/domain-server/resources/web/js/settings.js index 293ccce36d..487ec5b296 100644 --- a/domain-server/resources/web/js/settings.js +++ b/domain-server/resources/web/js/settings.js @@ -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'); diff --git a/domain-server/resources/web/settings/describe.json b/domain-server/resources/web/settings/describe.json index 5e810baa12..2c0440ac01 100644 --- a/domain-server/resources/web/settings/describe.json +++ b/domain-server/resources/web/settings/describe.json @@ -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 } } } diff --git a/domain-server/resources/web/settings/index.shtml b/domain-server/resources/web/settings/index.shtml index d95bd65d44..15ce842f30 100644 --- a/domain-server/resources/web/settings/index.shtml +++ b/domain-server/resources/web/settings/index.shtml @@ -13,13 +13,15 @@
<% _.each(group.settings, function(setting, setting_key){ %>
- + <% var setting_id = group_key + "." + setting_key %> +
<% if(setting.type) %> <% if (setting.type === "checkbox") { %> - + <% var checked_box = (_.isUndefined(values[group_key][setting_key]) ? setting.default : values[group_key][setting_key]) %> + > <% } else { %> - + <% } %>
diff --git a/domain-server/src/DomainServerSettingsManager.cpp b/domain-server/src/DomainServerSettingsManager.cpp index fabd26c8e0..4229e45191 100644 --- a/domain-server/src/DomainServerSettingsManager.cpp +++ b/domain-server/src/DomainServerSettingsManager.cpp @@ -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(settingsVariant[key].data()), nextDescriptionObject[DESCRIPTION_SETTINGS_KEY].toObject());