Complete settings update including success dialog
This commit is contained in:
@@ -55,6 +55,14 @@ var rc = {
|
|||||||
|
|
||||||
if (d.dialog.buttons) {
|
if (d.dialog.buttons) {
|
||||||
switch (d.dialog.buttons.type) {
|
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':
|
case 'yesno':
|
||||||
$("#dialogfooteryes").click(
|
$("#dialogfooteryes").click(
|
||||||
function() {
|
function() {
|
||||||
@@ -182,14 +190,23 @@ var rc = {
|
|||||||
for (var i in fields) {
|
for (var i in fields) {
|
||||||
var setting = fields[i];
|
var setting = fields[i];
|
||||||
var name = setting.name;
|
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 (/\[\]$/.test(name)) {
|
||||||
if (! settings[name]) {
|
if (! settings[name]) {
|
||||||
settings[name] = [];
|
settings[name] = [];
|
||||||
}
|
}
|
||||||
settings[name].push(setting.value);
|
settings[name].push(value);
|
||||||
} else {
|
} else {
|
||||||
settings[name] = setting.value;
|
settings[name] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,17 @@
|
|||||||
$main = RippingCluster_Main::instance();
|
$main = RippingCluster_Main::instance();
|
||||||
$config = $main->config();
|
$config = $main->config();
|
||||||
|
|
||||||
|
$messages = array();
|
||||||
|
|
||||||
// Iterate over the settings and store each one back to the backend
|
// Iterate over the settings and store each one back to the backend
|
||||||
foreach($_POST as $key => $value) {
|
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)) {
|
if ($config->exists($key)) {
|
||||||
$config->set($key, $value);
|
$config->set($key, $value);
|
||||||
|
} else {
|
||||||
|
$messages[] = "Unknown config key '{$key}', value not updated.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,19 +15,19 @@
|
|||||||
<td>
|
<td>
|
||||||
{switch $type}
|
{switch $type}
|
||||||
{case Sihnon_Config::TYPE_BOOL}
|
{case Sihnon_Config::TYPE_BOOL}
|
||||||
<input type="checkbox" id="setting_{$id}" name="{$name}" value="1" {if $value}checked="checked" {/if} class="setting" />
|
<input type="checkbox" id="setting_{$id}" name="{$id}" value="1" {if $value}checked="checked" {/if} class="setting" />
|
||||||
{/case}
|
{/case}
|
||||||
{case Sihnon_Config::TYPE_INT}
|
{case Sihnon_Config::TYPE_INT}
|
||||||
<input type="text" id="setting_{$id}" name="{$name}" value="{$value}" class="setting settings_field_numeric" />
|
<input type="text" id="setting_{$id}" name="{$id}" value="{$value}" class="setting settings_field_numeric" />
|
||||||
{/case}
|
{/case}
|
||||||
{case Sihnon_Config::TYPE_STRING}
|
{case Sihnon_Config::TYPE_STRING}
|
||||||
<input type="text" id="setting_{$id}" name="{$name}" value="{$value}" class="setting settings_field_string" />
|
<input type="text" id="setting_{$id}" name="{$id}" value="{$value}" class="setting settings_field_string" />
|
||||||
{/case}
|
{/case}
|
||||||
{case Sihnon_Config::TYPE_STRING_LIST}
|
{case Sihnon_Config::TYPE_STRING_LIST}
|
||||||
<div id="container_{$id}">
|
<div id="container_{$id}">
|
||||||
{foreach from=$value item=line name=settings}
|
{foreach from=$value item=line name=settings}
|
||||||
<div id="settings_{$id}_line{$smarty.foreach.settings.iteration}">
|
<div id="settings_{$id}_line{$smarty.foreach.settings.iteration}">
|
||||||
<input type="text" name="{$name}[]" value="{$line}" class="setting settings_field_string" />
|
<input type="text" name="{$id}[]" value="{$line}" class="setting settings_field_string" />
|
||||||
<input type="button" value="-" class="settings_field_remove" onclick="rc.settings.remove_field('{$id}', '{$smarty.foreach.settings.iteration}')" />
|
<input type="button" value="-" class="settings_field_remove" onclick="rc.settings.remove_field('{$id}', '{$smarty.foreach.settings.iteration}')" />
|
||||||
</div>
|
</div>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
{if $messages}
|
{if $messages}
|
||||||
messages: [
|
"messages": [
|
||||||
{foreach from=$messages item=message}
|
{foreach from=$messages item=message name=messages}
|
||||||
'{$message|json_encode}',
|
{$message|json_encode}{if ! $smarty.foreach.messages.last},{/if}
|
||||||
{/foreach}
|
{/foreach}
|
||||||
],
|
]{if $page_content},{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{$page_content}
|
{$page_content}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
7
webui/source/templates/fragments/messages.tpl
Normal file
7
webui/source/templates/fragments/messages.tpl
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{if $messages}
|
||||||
|
<ul>
|
||||||
|
{foreach from=$messages item=message}
|
||||||
|
<li>{$message|escape}</li>
|
||||||
|
{/foreach}
|
||||||
|
</ul>
|
||||||
|
{/if}
|
||||||
10
webui/source/templates/fragments/update-settings-dialog.tpl
Normal file
10
webui/source/templates/fragments/update-settings-dialog.tpl
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<p>
|
||||||
|
Settings have been saved.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{if $messages}
|
||||||
|
<p>
|
||||||
|
Some messages were generated during this operation:
|
||||||
|
{include file="fragments/messages.tpl"}
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
@@ -64,6 +64,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="dialogcontent"></div>
|
<div id="dialogcontent"></div>
|
||||||
<div id="dialogfooter">
|
<div id="dialogfooter">
|
||||||
|
<div id="dialogfooterok" class="dialogfooterbuttonset">
|
||||||
|
<fieldset>
|
||||||
|
<input type="button" class="dialogbutton" id="dialogfooterok" value="Ok" />
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
<div id="dialogfooteryesno" class="dialogfooterbuttonset">
|
<div id="dialogfooteryesno" class="dialogfooterbuttonset">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<input type="button" class="dialogbutton" id="dialogfooteryes" value="Yes" />
|
<input type="button" class="dialogbutton" id="dialogfooteryes" value="Yes" />
|
||||||
|
|||||||
Reference in New Issue
Block a user