Admin settings updated with add new setting feature

This commit is contained in:
2011-08-28 13:03:31 +01:00
parent 25449d4d3d
commit aec18cb810
7 changed files with 97 additions and 11 deletions

View File

@@ -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() {

View File

@@ -0,0 +1,50 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->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);
}
?>

View File

@@ -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)}
<tr>
<td>{$name}</td>
<td>
{include file="fragments/admin-setting-value.tpl"}
</td>
</tr>
{include file="fragments/admin-setting-row.tpl"}
{/foreach}
</tbody>
<tfoot>

View File

@@ -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}

View File

@@ -21,6 +21,10 @@
"close-dialog"
],
"cancel": "close-dialog"
},
"params": {
"name": "settings_add_name",
"type": "settings_add_type"
}
}
}

View File

@@ -0,0 +1,6 @@
<tr>
<td>{$name}</td>
<td>
{include file="fragments/admin-setting-value.tpl"}
</td>
</tr>

View File

@@ -9,11 +9,11 @@
<input type="text" id="settings_add_name" value="" />
</td>
<td>
<select id="settings_add_tpe">
<select id="settings_add_type">
<option value="int">Integer</option>
<option value="bool">Boolean</option>
<option value="string">String</option>
<option value="string_list">String List</option>
<option value="string-list">String List</option>
</select>
</td>
</tr>