Merge branch 'feature-settings' into develop
This commit is contained in:
@@ -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) {
|
||||
@@ -63,6 +64,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() {
|
||||
@@ -84,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');
|
||||
}
|
||||
|
||||
},
|
||||
@@ -124,6 +141,14 @@ var rc = {
|
||||
|
||||
'delete-source-confirm': function(params) {
|
||||
rc.sources.remove_confirmed(params['plugin'], params['id']);
|
||||
},
|
||||
|
||||
'add-setting': function(params) {
|
||||
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);
|
||||
}
|
||||
|
||||
},
|
||||
@@ -145,14 +170,28 @@ var rc = {
|
||||
}
|
||||
},
|
||||
|
||||
trigger_all: function(params) {
|
||||
if (params.actions) {
|
||||
for (var action in params.actions) {
|
||||
rc.trigger(action, params.actions[action]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
settings: {
|
||||
|
||||
init: function() {
|
||||
$("#settings_save").click(
|
||||
function() {
|
||||
rc.settings.save();
|
||||
}
|
||||
);
|
||||
$("#settings_save").click(function() {
|
||||
rc.settings.save();
|
||||
});
|
||||
|
||||
$("#settings_new").click(function() {
|
||||
rc.settings.new_setting();
|
||||
});
|
||||
},
|
||||
|
||||
new_setting: function() {
|
||||
rc.ajax.get(base_url + "ajax/admin/new-setting/");
|
||||
},
|
||||
|
||||
add_stringlist_field: function(id) {
|
||||
|
||||
50
webui/source/pages/ajax/admin/add-setting.php
Normal file
50
webui/source/pages/ajax/admin/add-setting.php
Normal 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);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -10,42 +10,15 @@
|
||||
{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>
|
||||
{switch $type}
|
||||
{case Sihnon_Config::TYPE_BOOL}
|
||||
<input type="checkbox" id="setting_{$id}" name="{$id}" value="1" {if $value}checked="checked" {/if} class="setting" />
|
||||
{/case}
|
||||
{case Sihnon_Config::TYPE_INT}
|
||||
<input type="text" id="setting_{$id}" name="{$id}" value="{$value}" class="setting settings_field_numeric" />
|
||||
{/case}
|
||||
{case Sihnon_Config::TYPE_STRING}
|
||||
<input type="text" id="setting_{$id}" name="{$id}" value="{$value}" class="setting settings_field_string" />
|
||||
{/case}
|
||||
{case Sihnon_Config::TYPE_STRING_LIST}
|
||||
<div id="container_{$id}">
|
||||
{foreach from=$value item=line name=settings}
|
||||
<div id="settings_{$id}_line{$smarty.foreach.settings.iteration}">
|
||||
<input type="text" name="{$id}[]" value="{$line}" class="setting settings_field_string" />
|
||||
<input type="button" value="-" class="settings_field_remove" onclick="rc.settings.remove_stringlist_field('{$id}', '{$smarty.foreach.settings.iteration}')" />
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
<div class="settings_addfieldcontainer">
|
||||
<input type="hidden" id="settings_{$id}_next" value="{$smarty.foreach.settings.iteration+1}" />
|
||||
<input type="button" value="+" class="settings_field_add" onclick="rc.settings.add_stringlist_field('{$id}')" />
|
||||
</div>
|
||||
{/case}
|
||||
{/switch}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{include file="fragments/admin-setting-row.tpl"}
|
||||
{/foreach}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<input type="button" id="settings_save" name="save" value="Save" />
|
||||
<input type="button" id="settings_new" name="new_setting" value="New Setting" />
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
11
webui/source/templates/ajax/admin/add-setting.tpl
Normal file
11
webui/source/templates/ajax/admin/add-setting.tpl
Normal 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}
|
||||
|
||||
30
webui/source/templates/ajax/admin/new-setting.tpl
Normal file
30
webui/source/templates/ajax/admin/new-setting.tpl
Normal file
@@ -0,0 +1,30 @@
|
||||
"page_replacements": {
|
||||
|
||||
"dialogheadertitle": {
|
||||
"content": "Add Setting"
|
||||
},
|
||||
|
||||
"dialogcontent": {
|
||||
{include file="fragments/new-setting-dialog.tpl" assign=new_setting_dialog_content}
|
||||
"content": {$new_setting_dialog_content|json_encode}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
"dialog": {
|
||||
"show": true,
|
||||
"buttons": {
|
||||
"type": "okcancel",
|
||||
"actions": {
|
||||
"ok": [
|
||||
"add-setting",
|
||||
"close-dialog"
|
||||
],
|
||||
"cancel": "close-dialog"
|
||||
},
|
||||
"params": {
|
||||
"name": "settings_add_name",
|
||||
"type": "settings_add_type"
|
||||
}
|
||||
}
|
||||
}
|
||||
6
webui/source/templates/fragments/admin-setting-row.tpl
Normal file
6
webui/source/templates/fragments/admin-setting-row.tpl
Normal file
@@ -0,0 +1,6 @@
|
||||
<tr>
|
||||
<td>{$name}</td>
|
||||
<td>
|
||||
{include file="fragments/admin-setting-value.tpl"}
|
||||
</td>
|
||||
</tr>
|
||||
25
webui/source/templates/fragments/admin-setting-value.tpl
Normal file
25
webui/source/templates/fragments/admin-setting-value.tpl
Normal file
@@ -0,0 +1,25 @@
|
||||
{switch $type}
|
||||
{case Sihnon_Config::TYPE_BOOL}
|
||||
<input type="checkbox" id="setting_{$id}" name="{$id}" value="1" {if $value}checked="checked" {/if} class="setting" />
|
||||
{/case}
|
||||
{case Sihnon_Config::TYPE_INT}
|
||||
<input type="text" id="setting_{$id}" name="{$id}" value="{$value}" class="setting settings_field_numeric" />
|
||||
{/case}
|
||||
{case Sihnon_Config::TYPE_STRING}
|
||||
<input type="text" id="setting_{$id}" name="{$id}" value="{$value}" class="setting settings_field_string" />
|
||||
{/case}
|
||||
{case Sihnon_Config::TYPE_STRING_LIST}
|
||||
<div id="container_{$id}">
|
||||
{foreach from=$value item=line name=settings}
|
||||
<div id="settings_{$id}_line{$smarty.foreach.settings.iteration}">
|
||||
<input type="text" name="{$id}[]" value="{$line}" class="setting settings_field_string" />
|
||||
<input type="button" value="-" class="settings_field_remove" onclick="rc.settings.remove_stringlist_field('{$id}', '{$smarty.foreach.settings.iteration}')" />
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
<div class="settings_addfieldcontainer">
|
||||
<input type="hidden" id="settings_{$id}_next" value="{$smarty.foreach.settings.iteration+1}" />
|
||||
<input type="button" value="+" class="settings_field_add" onclick="rc.settings.add_stringlist_field('{$id}')" />
|
||||
</div>
|
||||
{/case}
|
||||
{/switch}
|
||||
21
webui/source/templates/fragments/new-setting-dialog.tpl
Normal file
21
webui/source/templates/fragments/new-setting-dialog.tpl
Normal file
@@ -0,0 +1,21 @@
|
||||
<table>
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="settings_add_name" value="" />
|
||||
</td>
|
||||
<td>
|
||||
<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>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -69,6 +69,12 @@
|
||||
<input type="button" class="dialogbutton" id="dialogfooterok" value="Ok" />
|
||||
</fieldset>
|
||||
</div>
|
||||
<div id="dialogfooterokcancel" class="dialogfooterbuttonset">
|
||||
<fieldset>
|
||||
<input type="button" class="dialogbutton" id="dialogfooterokcancel_ok" value="Ok" />
|
||||
<input type="button" class="dialogbutton" id="dialogfooterokcancel_cancel" value="Cancel" />
|
||||
</fieldset>
|
||||
</div>
|
||||
<div id="dialogfooteryesno" class="dialogfooterbuttonset">
|
||||
<fieldset>
|
||||
<input type="button" class="dialogbutton" id="dialogfooteryes" value="Yes" />
|
||||
|
||||
Reference in New Issue
Block a user