Fix drag'n drop in plugin configs
As discussed in #65. Uses a simpler approach to detect the order of the items and their activation at the same time
This commit is contained in:
parent
ec864e6b71
commit
daa3afe812
@ -90,25 +90,18 @@ if (isset($_GET['serendipity']['plugin_to_conf'])) {
|
||||
$value = $_POST['serendipity']['plugin'][$config_item];
|
||||
|
||||
$validate = $plugin->validate($config_item, $cbag, $value);
|
||||
|
||||
if ($validate === true) {
|
||||
// echo $config_item . " validated: $validate<br />\n";
|
||||
|
||||
if (!empty($_POST['serendipity']['plugin']['override'][$config_item])) {
|
||||
$value = $_POST['serendipity']['plugin']['override'][$config_item];
|
||||
}
|
||||
|
||||
if (is_array($_POST['serendipity']['plugin']['activate'][$config_item])) {
|
||||
$values = explode(',', $value);
|
||||
$out_values = array();
|
||||
foreach($values AS $out_value) {
|
||||
if (!isset($_POST['serendipity']['plugin']['activate'][$config_item][$out_value])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$out_values[] = $out_value;
|
||||
$active_values = array();
|
||||
foreach($_POST['serendipity']['plugin']['activate'][$config_item] as $ordered_item_value) {
|
||||
$ordered_item_value;
|
||||
$active_values[] = $ordered_item_value;
|
||||
}
|
||||
$value = implode(',', $out_values);
|
||||
$value = implode(',', $active_values);
|
||||
}
|
||||
|
||||
$plugin->set_config($config_item, $value);
|
||||
|
1
templates/2k11/admin/js/dragdrop.js
vendored
1
templates/2k11/admin/js/dragdrop.js
vendored
@ -1,6 +1,7 @@
|
||||
$("document").ready(function() {
|
||||
$('.pluginmanager_sidebar .pluginmanager_container').sortable(getDragdropConfiguration('plugins_sidebar'));
|
||||
$('.pluginmanager_event .pluginmanager_container').sortable(getDragdropConfiguration('plugins_event'));
|
||||
$('.configuration_group .pluginmanager_container').sortable(getDragdropConfiguration('plugins_event'));
|
||||
|
||||
function getDragdropConfiguration(group) {
|
||||
return {
|
||||
|
@ -27,6 +27,11 @@
|
||||
{/foreach}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{* Those are only needed if the plugin contains a config item of type sequence, liek the entryproperty-plugin *}
|
||||
<script src="{serendipity_getFile file="admin/js/jquery.autoscroll.js"}"></script>
|
||||
<script src="{serendipity_getFile file="admin/js/jquery.sortable.js"}"></script>
|
||||
<script src="{serendipity_getFile file="admin/js/dragdrop.js"}"></script>
|
||||
{foreach $OUT_STACK_REST as $out_stack_config_item}
|
||||
<div class="configuration_group {cycle values='odd,even'}">
|
||||
{$out_stack_config_item}
|
||||
|
@ -63,15 +63,12 @@
|
||||
{if $cdesc != ''}<span id="{$postKey}_{$config_item}_info" class="field_info additional_info">{$cdesc}</span>{/if}
|
||||
</div>
|
||||
{elseif $ctype == 'sequence'}
|
||||
{if !$sequencejs_output}
|
||||
<script src="{serendipity_getFile file="admin/js/dragdrop.js"}"></script>
|
||||
{/if}
|
||||
<fieldset>
|
||||
<legend><span>{$cname}{if $cdesc != ''} <button class="toggle_info button_link" type="button" data-href="#{$config_item}_info"><span class="icon-info-circled"></span><span class="visuallyhidden"> More</span></button>{/if}</span></legend>
|
||||
<input id="{$config_item}_value" name="serendipity[{$postKey}][{$config_item}]" type="hidden" value="{$value}">
|
||||
|
||||
<noscript>
|
||||
<!-- Replace standard submit button when using up/down submits -->
|
||||
{* Replace standard submit button when using up/down submits *}
|
||||
<input name="SAVECONF" type="hidden" value="Save">
|
||||
</noscript>
|
||||
|
||||
@ -83,7 +80,7 @@
|
||||
</div>
|
||||
{if $checkable}
|
||||
<div class="form_check">
|
||||
<input id="activate_{$orid['id']}" name="serendipity[{$postKey}][activate][{$config_item}][{$orid['id']}]" {(in_array($orid['id'], $store_order)) ? ' checked="checked" ' : ''} type="checkbox" onclick="sort_{$config_item}_Sequence();" value="true">
|
||||
<input id="activate_{$orid['id']}" name="serendipity[{$postKey}][activate][{$config_item}][{$orid['id']}]" {(in_array($orid['id'], $store_order)) ? ' checked="checked" ' : ''} type="checkbox" value="{$orid['id']}">
|
||||
<label for="activate_{$orid['id']}" class="visuallyhidden">Activate</label> {* i18n *}
|
||||
</div>
|
||||
{/if}
|
||||
@ -113,36 +110,4 @@
|
||||
{/if}
|
||||
{if $cdesc != ''}<span id="{$config_item}_info" class="field_info additional_info">{$cdesc}</span>{/if}
|
||||
</fieldset>
|
||||
<script>
|
||||
function sort_{$config_item}_Sequence() {
|
||||
//var seq = DragDrop.serData('{$config_item}_group', null);
|
||||
var seq = DragDrop.serData(null, '{$config_item}');
|
||||
var start = seq.indexOf("(");
|
||||
var end = seq.indexOf(")");
|
||||
seq = seq.slice((start + 1), end);
|
||||
checkable_seq = seq.split(",");
|
||||
out_seq = '';
|
||||
for (i in checkable_seq) {
|
||||
if (document.getElementById('activate_' + checkable_seq[i]) && !document.getElementById('activate_' + checkable_seq[i]).checked) {
|
||||
continue;
|
||||
} else {
|
||||
if (out_seq != '') {
|
||||
out_seq += ',';
|
||||
}
|
||||
out_seq += checkable_seq[i];
|
||||
}
|
||||
}
|
||||
var order = document.getElementById("{$config_item}_value");
|
||||
order.value = out_seq;
|
||||
}
|
||||
|
||||
function init_{$config_item}_Sequence() {
|
||||
var lst = document.getElementById("{$config_item}");
|
||||
DragDrop.makeListContainer(lst, '{$config_item}_group');
|
||||
lst.onDragOut = function() {
|
||||
sort_{$config_item}_Sequence();
|
||||
};
|
||||
}
|
||||
addLoadEvent(init_{$config_item}_Sequence);
|
||||
</script>
|
||||
{/if}
|
||||
|
Loading…
x
Reference in New Issue
Block a user