Add support for config hashes in the admin settings page.
This commit is contained in:
@@ -280,11 +280,11 @@ var rc = {
|
||||
|
||||
var line = $('<div>');
|
||||
line.attr('id', 'settings_'+id+'_line'+next.val());
|
||||
line.append($('<input type="text" class="settings_field_string" />'));
|
||||
line.append($('<input type="text" name="'+id+'[]" class="setting settings_field_string" />'));
|
||||
line.append(' ');
|
||||
var button = $('<input type="button" value="-" class="settings_field_remove"/>');
|
||||
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 = $('<div>');
|
||||
line.attr('id', 'settings_'+id+'_line'+next.val());
|
||||
|
||||
var hash_key = $('<input type="text" value="New" class="setting hash_key" />');
|
||||
var hash_value = $('<input type="text" id="setting_'+id+'_value'+next_value+'" name="'+id+'[New]" class="setting 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 = $('<input type="button" value="-" class="settings_field_remove"/>');
|
||||
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() {
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -22,4 +22,22 @@
|
||||
<input type="button" value="+" class="settings_field_add" onclick="rc.settings.add_stringlist_field('{$id}')" />
|
||||
</div>
|
||||
{/case}
|
||||
{case Sihnon_Config::TYPE_HASH}
|
||||
<div id="container_{$id}">
|
||||
{foreach from=$value item=hash_value key=hash_key name=settings}
|
||||
<div id="settings_{$id}_line{$smarty.foreach.settings.iteration}">
|
||||
<input type="text" value="{$hash_key}" class="setting hash_key" />
|
||||
<input type="text" name="{$id}[{$hash_key}]" value="{$hash_value}" class="setting hash_value" />
|
||||
<input type="button" value="-" class="settings_field_remove" onclick="rc.settings.remove_hash_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_hash_field('{$id}')" />
|
||||
</div>
|
||||
|
||||
{/case}
|
||||
{default}
|
||||
<em>Unsupported setting type!</em>
|
||||
{/switch}
|
||||
@@ -14,6 +14,7 @@
|
||||
<option value="bool">Boolean</option>
|
||||
<option value="string">String</option>
|
||||
<option value="string-list">String List</option>
|
||||
<option value="hash">Hash</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user