From 553c256574da9aaa598a15c7c774dc8add5f69ec Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sat, 24 Sep 2011 16:14:10 +0100 Subject: [PATCH] Add support for config hashes in the admin settings page. --- webui/scripts/main.js | 39 +++++++++++++++++-- webui/source/pages/ajax/admin/add-setting.php | 4 ++ .../fragments/admin-setting-value.tpl | 18 +++++++++ .../fragments/new-setting-dialog.tpl | 1 + webui/styles/normal.css | 6 +++ 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/webui/scripts/main.js b/webui/scripts/main.js index e45dd74..a3296cf 100644 --- a/webui/scripts/main.js +++ b/webui/scripts/main.js @@ -280,11 +280,11 @@ var rc = { var line = $('
'); line.attr('id', 'settings_'+id+'_line'+next.val()); - line.append($('')); + line.append($('')); line.append(' '); var button = $(''); button.click(function() { - rc.settings.remove_field(id, next_value); + rc.settings.remove_stringlist_field(id, next_value); }); line.append(button); @@ -293,12 +293,43 @@ var rc = { // Increment the next counter next.val(parseInt(next_value)+1); - }, remove_stringlist_field: function(id, line) { $("#settings_"+id+"_line"+line).remove(); - }, + }, + + add_hash_field: function(id) { + var container = $('#container_'+id); + var next = $('#settings_'+id+'_next'); + var next_value = next.val(); + + var line = $('
'); + line.attr('id', 'settings_'+id+'_line'+next.val()); + + var hash_key = $(''); + var hash_value = $(''); + hash_key.change(function() { + $('#setting_'+id+'_value'+next_value).attr('name', id+'['+$(this).val()+']'); + }) + + line.append(hash_key).append(' ').append(hash_value).append(' '); + var button = $(''); + button.click(function() { + rc.settings.remove_hash_field(id, next_value); + }); + line.append(button); + + // Add the new item + container.append(line); + + // Increment the next counter + next.val(parseInt(next_value)+1); + }, + + remove_hash_field: function(id, line) { + $("#settings_"+id+"_line"+line).remove(); + }, save: function() { diff --git a/webui/source/pages/ajax/admin/add-setting.php b/webui/source/pages/ajax/admin/add-setting.php index 191c00d..1cc591c 100644 --- a/webui/source/pages/ajax/admin/add-setting.php +++ b/webui/source/pages/ajax/admin/add-setting.php @@ -30,6 +30,10 @@ try { $type = Sihnon_Config::TYPE_STRING_LIST; $value = array(); } break; + case 'hash': { + $type = Sihnon_Config::TYPE_HASH; + $value = array(); + } break; } // Add the new (empty) value. This is because no suitable UI has been presented yet. diff --git a/webui/source/templates/fragments/admin-setting-value.tpl b/webui/source/templates/fragments/admin-setting-value.tpl index 7ffcf9a..16a3dc1 100644 --- a/webui/source/templates/fragments/admin-setting-value.tpl +++ b/webui/source/templates/fragments/admin-setting-value.tpl @@ -22,4 +22,22 @@
{/case} + {case Sihnon_Config::TYPE_HASH} +
+ {foreach from=$value item=hash_value key=hash_key name=settings} +
+ + + +
+ {/foreach} +
+
+ + +
+ + {/case} + {default} + Unsupported setting type! {/switch} \ No newline at end of file diff --git a/webui/source/templates/fragments/new-setting-dialog.tpl b/webui/source/templates/fragments/new-setting-dialog.tpl index 59f67a0..fcea745 100644 --- a/webui/source/templates/fragments/new-setting-dialog.tpl +++ b/webui/source/templates/fragments/new-setting-dialog.tpl @@ -14,6 +14,7 @@ + diff --git a/webui/styles/normal.css b/webui/styles/normal.css index 773ab72..295a321 100644 --- a/webui/styles/normal.css +++ b/webui/styles/normal.css @@ -155,6 +155,12 @@ table#settings td { table#settings input[type=text] { width: 40em; } +table#settings input.hash_key { + width: 10em; +} +table#settings input.hash_value { + width: 25em; +} .settings_addfieldcontainer { text-align: right; }