Commit 76649640 authored by Ad Schellevis's avatar Ad Schellevis

(dashboard) make widgets draggable and sortable again

still need to add a selectable number of columns (col-md-6 fixed now)
parent 6c1fe153
......@@ -34,7 +34,6 @@ ini_set('output_buffering', 'true');
// Start buffering with a cache size of 100000
ob_start(null, "1000");
// Load Essential Includes
require_once('guiconfig.inc');
......@@ -65,11 +64,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$widgetItem['display_name'] = ucwords(str_replace("_", " ", $widgetItem['name']));
$widgetItem['filename'] = $php_file;
$widgetItem['state'] = "none";
$widgetItem['sortKey'] = $widgetItem['name'] == 'system_information' ? "" : $widgetItem['name'];
/// default sort order
$widgetItem['sortKey'] = $widgetItem['name'] == 'system_information' ? "00000000" : "99999999";
foreach ($widgetSeqParts as $seqPart) {
$tmp = explode(':', $seqPart);
if (count($tmp) == 3 && explode('-', $tmp[0])[0] == $widgetItem['name']) {
$widgetItem['state'] = $tmp[2];
$widgetItem['sortKey'] = $tmp[1];
}
}
$widgetCollection[] = $widgetItem;
......@@ -94,7 +95,6 @@ foreach (glob("/usr/local/www/widgets/include/*.inc") as $filename) {
include("head.inc");
?>
<body>
<?php
include("fbegin.inc");?>
......@@ -113,7 +113,6 @@ include("fbegin.inc");?>
<h1><?= gettext("Starting initial configuration!") ?></h1>
</div>
</header>
<section class="page-content-main">
<div class="container-fluid col-xs-12 col-sm-10 col-md-9">
<div class="row">
......@@ -142,63 +141,93 @@ include("fbegin.inc");?>
else:?>
<script src='/javascript/index/ajax.js'></script>
<script src='/ui/js/jquery-sortable.js'></script>
<script type="text/javascript">
//<![CDATA[
function addWidget(selectedDiv) {
function addWidget(selectedDiv) {
$('#'+selectedDiv).show();
$('#'+selectedDiv+'-config').val('show');
showSave();
}
}
function configureWidget(selectedDiv) {
function configureWidget(selectedDiv) {
selectIntLink = '#' + selectedDiv + "-settings";
if ($(selectIntLink).css('display') == "none") {
$(selectIntLink).show();
} else {
$(selectIntLink).hide();
}
}
}
function showWidget(selectedDiv,swapButtons) {
function showWidget(selectedDiv,swapButtons) {
$('#'+selectedDiv+'-container').show();
$('#'+selectedDiv+'-min').show();
$('#'+selectedDiv+'-max').hide();
$('#'+selectedDiv+'-config').val('show');
showSave();
}
}
function minimizeWidget(selectedDiv,swapButtons) {
function minimizeWidget(selectedDiv, swapButtons) {
$('#'+selectedDiv+'-container').hide();
$('#'+selectedDiv+'-min').hide();
$('#'+selectedDiv+'-max').show();
$('#'+selectedDiv+'-config').val('hide');
showSave();
}
}
function closeWidget(selectedDiv) {
function closeWidget(selectedDiv) {
$('#'+selectedDiv).hide();
$('#'+selectedDiv+'-config').val('close');
showSave();
}
}
function showSave() {
function showSave() {
$('#updatepref').show();
}
}
function updatePref() {
function updatePref() {
var widgetInfo = [];
var index = 0;
$('.widgetdiv').each(function(key) {
widgetInfo.push($(this).attr('id')+'-container:col1:'+$('input[name='+$(this).attr('id')+'-config]').val());
if ($(this).is(':visible')) {
// only capture visible widgets
var index_str = "0000000" + index;
index_str = index_str.substr(index_str.length-8);
widgetInfo.push($(this).attr('id')+'-container:'+index_str+':'+$('input[name='+$(this).attr('id')+'-config]').val());
index++;
}
});
$("#sequence").val(widgetInfo.join(','));
$("#iform").submit();
return false;
}
//]]>
}
</script>
<script type="text/javascript">
$( document ).ready(function() {
// move non visible items to bottom
$(".widgetdiv").each(function(){
if (!$(this).is(':visible')) {
$(this).insertBefore($("#end_of_block"));
}
});
// sortable widgets
$(".sortable").sortable({
handle: '.content-box-head',
itemSelector: '.widgetdiv',
containerSelector: '.sortable',
placeholder: '<div class="placeholder"><i class="fa fa-hand-o-right" aria-hidden="true"></i></div>',
afterMove: function (placeholder, container, closestItemOrContainer) {
showSave();
}
});
});
</script>
<section class="page-content-main">
<form method="post" id="iform">
<input type="hidden" value="" name="sequence" id="sequence" />
<div class="container-fluid">
<div class="row">
<div class="row sortable">
<?php
$crash_report = get_crash_report();
if ($crash_report != '') {
......@@ -236,8 +265,6 @@ function updatePref() {
}?>
<section class="col-xs-12 col-md-6 widgetdiv" id="<?= $widgetItem['name'] ?>" style="display:<?= $divdisplay ?>;">
<div class="content-box">
<form method="post" id="iform">
<input type="hidden" value="" name="sequence" id="sequence" />
<header class="content-box-head container-fluid">
<ul class="list-inline __nomb">
<li><h3>
......@@ -246,7 +273,7 @@ function updatePref() {
<u><span onclick="location.href='/<?= $$widgettitlelink ?>'" style="cursor:pointer">
<?php
endif;
echo !empty($$widgettitle) ? $$widgettitle : $widgetItem['display_name'];
echo empty($$widgettitle) ? $widgetItem['display_name'] : $$widgettitle;
if (isset($$widgettitlelink)):?>
</span></u>
<?php
......@@ -262,8 +289,7 @@ function updatePref() {
</li>
</ul>
</header>
</form>
<div class="content-box-main collapse in" id="<?= $widgetItem['name'] ?>-container" style="display:<?= $mindiv ?>">
<div class="content-box-main collapse in container" id="<?= $widgetItem['name'] ?>-container" style="display:<?= $mindiv ?>">
<input type="hidden" value="<?= $inputdisplay ?>" id="<?= $widgetItem['name'] ?>-config" name="<?= $widgetItem['name'] ?>-config" />
<?php
if ($divdisplay != "block"):?>
......@@ -274,9 +300,7 @@ function updatePref() {
</div>
<?php
else:
if ($divdisplay == 'block') {
include($widgetItem['filename']);
}
endif;
?>
</div>
......@@ -284,10 +308,13 @@ function updatePref() {
</section>
<?php
endforeach;?>
<section id="end_of_block"></section>
</div>
</div>
</form>
</section>
<?php
// include widget javascripts
foreach (glob("/usr/local/www/widgets/javascript/*.js") as $filename):?>
<script src="/widgets/javascript/<?=basename($filename);?>" type="text/javascript"></script>
<?php
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment