From 5807af8b8f05204431d133c296060674111a288d Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sat, 27 Aug 2011 19:53:35 +0100 Subject: [PATCH 1/4] Move admin settings value into dedicated template file --- webui/source/templates/admin/settings.tpl | 26 +------------------ .../fragments/admin-setting-value.tpl | 25 ++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 webui/source/templates/fragments/admin-setting-value.tpl diff --git a/webui/source/templates/admin/settings.tpl b/webui/source/templates/admin/settings.tpl index 7cf3361..874a6d3 100644 --- a/webui/source/templates/admin/settings.tpl +++ b/webui/source/templates/admin/settings.tpl @@ -13,31 +13,7 @@ {$name} - {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} -
-
- - -
- {/case} - {/switch} + {include file="fragments/admin-setting-value.tpl"} {/foreach} diff --git a/webui/source/templates/fragments/admin-setting-value.tpl b/webui/source/templates/fragments/admin-setting-value.tpl new file mode 100644 index 0000000..7ffcf9a --- /dev/null +++ b/webui/source/templates/fragments/admin-setting-value.tpl @@ -0,0 +1,25 @@ +{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} +
+
+ + +
+ {/case} +{/switch} \ No newline at end of file From cab3a513235a7dd5320168e7b33b9338571cad01 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sat, 27 Aug 2011 20:25:48 +0100 Subject: [PATCH 2/4] Add initial support for adding settings. Adds "Add Setting" button to table, and shows a popup with form elements for adding a new setting. Does not yet add setting to the db. --- webui/scripts/main.js | 30 +++++++++++++++---- webui/source/templates/admin/add-setting.tpl | 21 +++++++++++++ webui/source/templates/admin/settings.tpl | 1 + .../templates/ajax/admin/add-setting.tpl | 26 ++++++++++++++++ webui/source/templates/index.tpl | 6 ++++ 5 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 webui/source/templates/admin/add-setting.tpl create mode 100644 webui/source/templates/ajax/admin/add-setting.tpl diff --git a/webui/scripts/main.js b/webui/scripts/main.js index 6bb6edc..e149041 100644 --- a/webui/scripts/main.js +++ b/webui/scripts/main.js @@ -63,6 +63,15 @@ var rc = { ); $("#dialogfooterok").show(); break; + case 'okcancel': + $("#dialogfooterokcancel_ok").click(function() { + rc.trigger(d.dialog.buttons.actions.ok, d.dialog.buttons.params); + }); + $("#dialogfooterokcancel_cancel").click(function() { + rc.trigger(d.dialog.buttons.actions.cancel, d.dialog.buttons.params); + }); + $("#dialogfooterokcancel").show(); + break; case 'yesno': $("#dialogfooteryes").click( function() { @@ -124,6 +133,11 @@ var rc = { 'delete-source-confirm': function(params) { rc.sources.remove_confirmed(params['plugin'], params['id']); + }, + + 'add-setting': function(params) { + // TODO + console.log('todo'); } }, @@ -148,11 +162,17 @@ var rc = { settings: { init: function() { - $("#settings_save").click( - function() { - rc.settings.save(); - } - ); + $("#settings_save").click(function() { + rc.settings.save(); + }); + + $("#settings_add").click(function() { + rc.settings.add(); + }); + }, + + add: function() { + rc.ajax.get(base_url + "ajax/admin/add-setting/"); }, add_stringlist_field: function(id) { diff --git a/webui/source/templates/admin/add-setting.tpl b/webui/source/templates/admin/add-setting.tpl new file mode 100644 index 0000000..ebc88a5 --- /dev/null +++ b/webui/source/templates/admin/add-setting.tpl @@ -0,0 +1,21 @@ + + + + + + + + + + + +
NameType
+ + + +
diff --git a/webui/source/templates/admin/settings.tpl b/webui/source/templates/admin/settings.tpl index 874a6d3..8ce9e2a 100644 --- a/webui/source/templates/admin/settings.tpl +++ b/webui/source/templates/admin/settings.tpl @@ -22,6 +22,7 @@ + diff --git a/webui/source/templates/ajax/admin/add-setting.tpl b/webui/source/templates/ajax/admin/add-setting.tpl new file mode 100644 index 0000000..90b3524 --- /dev/null +++ b/webui/source/templates/ajax/admin/add-setting.tpl @@ -0,0 +1,26 @@ +"page_replacements": { + + "dialogheadertitle": { + "content": "Add Setting" + }, + + "dialogcontent": { + {include file="admin/add-setting.tpl" assign=add_setting_content} + "content": {$add_setting_content|json_encode} + } + +}, + +"dialog": { + "show": true, + "buttons": { + "type": "okcancel", + "actions": { + "ok": [ + "add-setting", + "close-dialog" + ], + "cancel": "close-dialog" + } + } +} \ No newline at end of file diff --git a/webui/source/templates/index.tpl b/webui/source/templates/index.tpl index 412f558..5c8d460 100644 --- a/webui/source/templates/index.tpl +++ b/webui/source/templates/index.tpl @@ -69,6 +69,12 @@ +
+
+ + +
+
From 25449d4d3d870ccf0c24612ffa79f0f1d1219d9c Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 28 Aug 2011 10:32:54 +0100 Subject: [PATCH 3/4] Rename add-setting to new-setting. Will reuse name for the backend --- webui/scripts/main.js | 8 ++++---- webui/source/templates/admin/settings.tpl | 2 +- .../ajax/admin/{add-setting.tpl => new-setting.tpl} | 4 ++-- .../add-setting.tpl => fragments/new-setting-dialog.tpl} | 0 4 files changed, 7 insertions(+), 7 deletions(-) rename webui/source/templates/ajax/admin/{add-setting.tpl => new-setting.tpl} (71%) rename webui/source/templates/{admin/add-setting.tpl => fragments/new-setting-dialog.tpl} (100%) diff --git a/webui/scripts/main.js b/webui/scripts/main.js index e149041..5cf4fad 100644 --- a/webui/scripts/main.js +++ b/webui/scripts/main.js @@ -166,13 +166,13 @@ var rc = { rc.settings.save(); }); - $("#settings_add").click(function() { - rc.settings.add(); + $("#settings_new").click(function() { + rc.settings.new_setting(); }); }, - add: function() { - rc.ajax.get(base_url + "ajax/admin/add-setting/"); + new_setting: function() { + rc.ajax.get(base_url + "ajax/admin/new-setting/"); }, add_stringlist_field: function(id) { diff --git a/webui/source/templates/admin/settings.tpl b/webui/source/templates/admin/settings.tpl index 8ce9e2a..4aaae90 100644 --- a/webui/source/templates/admin/settings.tpl +++ b/webui/source/templates/admin/settings.tpl @@ -22,7 +22,7 @@ - + diff --git a/webui/source/templates/ajax/admin/add-setting.tpl b/webui/source/templates/ajax/admin/new-setting.tpl similarity index 71% rename from webui/source/templates/ajax/admin/add-setting.tpl rename to webui/source/templates/ajax/admin/new-setting.tpl index 90b3524..1b7e1cf 100644 --- a/webui/source/templates/ajax/admin/add-setting.tpl +++ b/webui/source/templates/ajax/admin/new-setting.tpl @@ -5,8 +5,8 @@ }, "dialogcontent": { - {include file="admin/add-setting.tpl" assign=add_setting_content} - "content": {$add_setting_content|json_encode} + {include file="fragments/new-setting-dialog.tpl" assign=new_setting_dialog_content} + "content": {$new_setting_dialog_content|json_encode} } }, diff --git a/webui/source/templates/admin/add-setting.tpl b/webui/source/templates/fragments/new-setting-dialog.tpl similarity index 100% rename from webui/source/templates/admin/add-setting.tpl rename to webui/source/templates/fragments/new-setting-dialog.tpl From aec18cb810ec1fdbe0b8b2854746e3320872d399 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 28 Aug 2011 13:03:31 +0100 Subject: [PATCH 4/4] Admin settings updated with add new setting feature --- webui/scripts/main.js | 25 ++++++++-- webui/source/pages/ajax/admin/add-setting.php | 50 +++++++++++++++++++ webui/source/templates/admin/settings.tpl | 8 +-- .../templates/ajax/admin/add-setting.tpl | 11 ++++ .../templates/ajax/admin/new-setting.tpl | 4 ++ .../templates/fragments/admin-setting-row.tpl | 6 +++ .../fragments/new-setting-dialog.tpl | 4 +- 7 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 webui/source/pages/ajax/admin/add-setting.php create mode 100644 webui/source/templates/ajax/admin/add-setting.tpl create mode 100644 webui/source/templates/fragments/admin-setting-row.tpl diff --git a/webui/scripts/main.js b/webui/scripts/main.js index 5cf4fad..77ad51c 100644 --- a/webui/scripts/main.js +++ b/webui/scripts/main.js @@ -36,6 +36,7 @@ var rc = { success: function(d, s, x) { rc.page.update(d); rc.dialog.prepare(d); + rc.trigger_all(d); }, failure: function(x, s, e) { @@ -93,9 +94,16 @@ var rc = { }, close: function() { + // Hide the dialog $("#dialog").hide(); - $(".dialogfooterbuttonset").hide(); + + // Remove the dialog content $("#dialogcontent").html(); + + // Hide all buttons + $(".dialogfooterbuttonset").hide(); + // Strip all event handlers + $(".dialogfooterbuttonset input[type='button']").unbind('click'); } }, @@ -136,8 +144,11 @@ var rc = { }, 'add-setting': function(params) { - // TODO - console.log('todo'); + rc.ajax.post(base_url + 'ajax/admin/add-setting/name/' + $('#'+params.name).val() + '/type/' + $('#'+params.type).val() + '/'); + }, + + 'add_setting_row': function(params) { + $("#settings tbody").append(params.content); } }, @@ -159,6 +170,14 @@ var rc = { } }, + trigger_all: function(params) { + if (params.actions) { + for (var action in params.actions) { + rc.trigger(action, params.actions[action]); + } + } + }, + settings: { init: function() { diff --git a/webui/source/pages/ajax/admin/add-setting.php b/webui/source/pages/ajax/admin/add-setting.php new file mode 100644 index 0000000..882aabc --- /dev/null +++ b/webui/source/pages/ajax/admin/add-setting.php @@ -0,0 +1,50 @@ +request(); +$config = $main->config(); + +$messages = array(); +$result = false; + +try { + $name = $req->get('name', 'RippingCluster_Exception_InvalidParameters'); + $type = $req->get('type', 'RippingCluster_Exception_InvalidParameters'); + + // Convert the web-friendly type field into the correct internal name + $value = null; + switch($type) { + case 'bool': { + $type = Sihnon_Config::TYPE_BOOL; + $value = false; + } break; + case 'int': { + $type = Sihnon_Config::TYPE_INT; + $value = 0; + } break; + case 'string': { + $type = Sihnon_Config::TYPE_STRING; + $value = ''; + } break; + case 'string-list': { + $type = Sihnon_Config::TYPE_STRING_LIST; + $value = array(); + } break; + } + + // Add the new (empty) value. This is because no suitable UI has been presented yet. + // Possible future fix, to insert intermediate dialog to capture the value using the correct UI. + $result = $config->add($name, $type, $value); + $this->smarty->assign('success', $result); + + $this->smarty->assign('name', $name); + $this->smarty->assign('type', $type); + $this->smarty->assign('value', ''); + +} catch(RippingCluster_Exception $e) { + $messages[] = get_class($e) . ':' . $e->getMessage(); + $this->smarty->assign('messages', $messages); + $this->smarty->assign('success', false); +} + +?> \ No newline at end of file diff --git a/webui/source/templates/admin/settings.tpl b/webui/source/templates/admin/settings.tpl index 4aaae90..3640b03 100644 --- a/webui/source/templates/admin/settings.tpl +++ b/webui/source/templates/admin/settings.tpl @@ -10,12 +10,8 @@ {assign var='value' value=$config->get($name)} {assign var='type' value=$config->type($name)} {assign var='id' value=str_replace('.', '-',$name)} - - {$name} - - {include file="fragments/admin-setting-value.tpl"} - - + + {include file="fragments/admin-setting-row.tpl"} {/foreach} diff --git a/webui/source/templates/ajax/admin/add-setting.tpl b/webui/source/templates/ajax/admin/add-setting.tpl new file mode 100644 index 0000000..0fcbcff --- /dev/null +++ b/webui/source/templates/ajax/admin/add-setting.tpl @@ -0,0 +1,11 @@ +{if $success} + "actions": { + "add_setting_row": { + {include file="fragments/admin-setting-row.tpl" assign=content} + "content": {$content|json_encode} + } + }, +{/if} + +"success": {$success|json_encode} + diff --git a/webui/source/templates/ajax/admin/new-setting.tpl b/webui/source/templates/ajax/admin/new-setting.tpl index 1b7e1cf..743a360 100644 --- a/webui/source/templates/ajax/admin/new-setting.tpl +++ b/webui/source/templates/ajax/admin/new-setting.tpl @@ -21,6 +21,10 @@ "close-dialog" ], "cancel": "close-dialog" + }, + "params": { + "name": "settings_add_name", + "type": "settings_add_type" } } } \ No newline at end of file diff --git a/webui/source/templates/fragments/admin-setting-row.tpl b/webui/source/templates/fragments/admin-setting-row.tpl new file mode 100644 index 0000000..6886a32 --- /dev/null +++ b/webui/source/templates/fragments/admin-setting-row.tpl @@ -0,0 +1,6 @@ + + {$name} + + {include file="fragments/admin-setting-value.tpl"} + + \ 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 ebc88a5..59f67a0 100644 --- a/webui/source/templates/fragments/new-setting-dialog.tpl +++ b/webui/source/templates/fragments/new-setting-dialog.tpl @@ -9,11 +9,11 @@ - - +