From f884e930213d71702981626c7946965f63e3a031 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Fri, 26 Aug 2011 18:41:40 +0100 Subject: [PATCH] Complete settings update including success dialog --- webui/scripts/main.js | 21 ++++++++++++++++-- webui/source/pages/ajax/update-settings.php | 7 ++++++ webui/source/templates/admin/settings.tpl | 8 +++---- webui/source/templates/ajax.tpl | 9 ++++---- .../source/templates/ajax/update-settings.tpl | 22 +++++++++++++++++++ webui/source/templates/fragments/messages.tpl | 7 ++++++ .../fragments/update-settings-dialog.tpl | 10 +++++++++ webui/source/templates/index.tpl | 5 +++++ 8 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 webui/source/templates/fragments/messages.tpl create mode 100644 webui/source/templates/fragments/update-settings-dialog.tpl diff --git a/webui/scripts/main.js b/webui/scripts/main.js index 195656f..718e849 100644 --- a/webui/scripts/main.js +++ b/webui/scripts/main.js @@ -55,6 +55,14 @@ var rc = { if (d.dialog.buttons) { switch (d.dialog.buttons.type) { + case 'ok': + $("#dialogfooterok").click( + function() { + rc.trigger(d.dialog.buttons.actions.ok, d.dialog.buttons.params); + } + ); + $("#dialogfooterok").show(); + break; case 'yesno': $("#dialogfooteryes").click( function() { @@ -182,14 +190,23 @@ var rc = { for (var i in fields) { var setting = fields[i]; var name = setting.name; + var value; + + switch(setting.type) { + case 'checkbox': + value = $(setting).is(':checked') ? 1 : 0; + break; + default: + value = setting.value; + } if (/\[\]$/.test(name)) { if (! settings[name]) { settings[name] = []; } - settings[name].push(setting.value); + settings[name].push(value); } else { - settings[name] = setting.value; + settings[name] = value; } } diff --git a/webui/source/pages/ajax/update-settings.php b/webui/source/pages/ajax/update-settings.php index 7401e48..a58875c 100644 --- a/webui/source/pages/ajax/update-settings.php +++ b/webui/source/pages/ajax/update-settings.php @@ -3,10 +3,17 @@ $main = RippingCluster_Main::instance(); $config = $main->config(); +$messages = array(); + // Iterate over the settings and store each one back to the backend foreach($_POST as $key => $value) { + // Convert - to . (to work around the PHP register global backwards compatibility that renames input variables) + $key = str_replace("-", ".", $key); + if ($config->exists($key)) { $config->set($key, $value); + } else { + $messages[] = "Unknown config key '{$key}', value not updated."; } } diff --git a/webui/source/templates/admin/settings.tpl b/webui/source/templates/admin/settings.tpl index c202081..ea646de 100644 --- a/webui/source/templates/admin/settings.tpl +++ b/webui/source/templates/admin/settings.tpl @@ -15,19 +15,19 @@ {switch $type} {case Sihnon_Config::TYPE_BOOL} - + {/case} {case Sihnon_Config::TYPE_INT} - + {/case} {case Sihnon_Config::TYPE_STRING} - + {/case} {case Sihnon_Config::TYPE_STRING_LIST}
{foreach from=$value item=line name=settings}
- +
{/foreach} diff --git a/webui/source/templates/ajax.tpl b/webui/source/templates/ajax.tpl index 093d88b..7c0aecf 100644 --- a/webui/source/templates/ajax.tpl +++ b/webui/source/templates/ajax.tpl @@ -1,11 +1,12 @@ { {if $messages} - messages: [ - {foreach from=$messages item=message} - '{$message|json_encode}', + "messages": [ + {foreach from=$messages item=message name=messages} + {$message|json_encode}{if ! $smarty.foreach.messages.last},{/if} {/foreach} - ], + ]{if $page_content},{/if} {/if} {$page_content} + } \ No newline at end of file diff --git a/webui/source/templates/ajax/update-settings.tpl b/webui/source/templates/ajax/update-settings.tpl index e69de29..3fa938f 100644 --- a/webui/source/templates/ajax/update-settings.tpl +++ b/webui/source/templates/ajax/update-settings.tpl @@ -0,0 +1,22 @@ +"page_replacements": { + + "dialogheadertitle": { + "content": "Update Settings" + }, + + "dialogcontent": { + {include file="fragments/update-settings-dialog.tpl" assign=dialog_content} + "content": {$dialog_content|json_encode} + } + +}, + +"dialog": { + "show": true, + "buttons": { + "type": "ok", + "actions": { + "ok": "close-dialog" + } + } +} diff --git a/webui/source/templates/fragments/messages.tpl b/webui/source/templates/fragments/messages.tpl new file mode 100644 index 0000000..6f3f273 --- /dev/null +++ b/webui/source/templates/fragments/messages.tpl @@ -0,0 +1,7 @@ +{if $messages} + +{/if} diff --git a/webui/source/templates/fragments/update-settings-dialog.tpl b/webui/source/templates/fragments/update-settings-dialog.tpl new file mode 100644 index 0000000..d0c2214 --- /dev/null +++ b/webui/source/templates/fragments/update-settings-dialog.tpl @@ -0,0 +1,10 @@ +

+ Settings have been saved. +

+ +{if $messages} +

+ Some messages were generated during this operation: + {include file="fragments/messages.tpl"} +

+{/if} diff --git a/webui/source/templates/index.tpl b/webui/source/templates/index.tpl index 559f0f9..412f558 100644 --- a/webui/source/templates/index.tpl +++ b/webui/source/templates/index.tpl @@ -64,6 +64,11 @@
+
+
+ +
+