<?php defined('KOBLOG') or die('Koblog CMS.'); ?>

<?php echo Bootstrap::formOpen(array('id'=>'jsform', 'class'=>'tab-content')); ?>

<div class="d-flex justify-content-between mb-2">
<?php echo Bootstrap::pageTitle(array('title'=>$L->g('Reorder sidebar'), 'icon'=>'list')); ?>
	<div>
		<button type="button" class="btn btn-primary jsbuttonSave" name="save"><?php $L->p('Save') ?></button>
		<a class="btn btn-secondary" href="<?php echo HTML_PATH_ADMIN_ROOT.'sidebar' ?>" role="button"><?php $L->p('Cancel') ?></a>
	</div>
</div>

<div class="alert alert-primary"><?php $L->p('Drag and Drop to sort the plugins') ?></div>

<?php
	// Token CSRF
	echo Bootstrap::formInputHidden(array(
		'name'=>'tokenCSRF',
		'value'=>$security->getTokenCSRF()
	));

	echo Bootstrap::formInputHidden(array(
		'name'=>'plugin-list',
		'value'=>''
	));

	echo '<ul class="list-group list-group-sortable">';
	foreach ($plugins['siteSidebar'] as $Plugin) {
		echo '<li class="list-group-item" data-plugin="'.$Plugin->className().'"><span class="fa fa-arrows-v"></span> '.$Plugin->name().'</li>';
	}
	echo '</ul>';
?>

<?php echo Bootstrap::formClose(); ?>

<script>
$(document).ready(function() {
	$('.list-group-sortable').sortable({
		placeholderClass: 'list-group-item'
	});

	$(".jsbuttonSave").on("click", function() {
		var tmp = [];
		$("li.list-group-item").each(function() {
			tmp.push( $(this).attr("data-plugin") );
		});
		$("#jsplugin-list").attr("value", tmp.join(",") );
		$("#jsform").submit();
	});
});
</script>