2015-07-21 23:01:57 +01:00
<? php
2015-07-21 23:11:48 +01:00
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
2015-07-26 11:25:54 +00:00
/*
* Code for Gridster.sort_by_row_and_col_asc(serialization) call is from http://gridster.net/demos/grid-from-serialize.html
*/
2015-12-13 19:39:12 +00:00
$no_refresh = true ;
2017-04-01 16:18:00 -05:00
$default_dash = get_user_pref ( 'dashboard' , 0 );
2017-01-26 22:38:14 +00:00
2017-04-01 16:18:00 -05:00
// get all dashboards this user can access and put them into two lists user_dashboards and shared_dashboards
$dashboards = get_dashboards ();
list ( $user_dashboards , $shared_dashboards ) = array_reduce ( $dashboards , function ( $ret , $dash ) {
if ( $dash [ 'user_id' ] == $_SESSION [ 'user_id' ]) {
$ret [ 0 ][] = $dash ;
} else {
$ret [ 1 ][] = $dash ;
2017-01-26 22:38:14 +00:00
}
2017-04-01 16:18:00 -05:00
return $ret ;
}, array ());
2017-01-26 22:38:14 +00:00
2017-04-01 16:18:00 -05:00
// if the default dashboard doesn't exist, set it to the global default or to 0
if ( ! isset ( $dashboards [ $default_dash ])) {
$global_default = ( int ) $config [ 'webui' ][ 'default_dashboard_id' ];
2017-04-04 11:55:18 -05:00
$default_dash = isset ( $dashboards [ $global_default ]) ? $global_default : 0 ;
2016-08-23 12:37:12 -06:00
}
2017-01-26 22:38:14 +00:00
2017-04-01 16:18:00 -05:00
// if there are no possible dashboards, add one
if ( $default_dash == 0 && empty ( $user_dashboards )) {
$new_dash = array (
'dashboard_name' => 'Default' ,
'user_id' => $_SESSION [ 'user_id' ],
);
$dashboard_id = dbInsert ( $new_dash , 'dashboards' );
$new_dash [ 'dashboard_id' ] = $dashboard_id ;
$new_dash [ 'username' ] = $_SESSION [ 'username' ];
$vars [ 'dashboard' ] = $new_dash ;
2016-08-18 20:28:22 -05:00
if ( dbFetchCell ( 'select 1 from users_widgets where user_id = ? && dashboard_id = ?' , array ( $_SESSION [ 'user_id' ], 0 )) == 1 ) {
2017-04-01 16:18:00 -05:00
dbUpdate ( array ( 'dashboard_id' => $dashboard_id ), 'users_widgets' , 'user_id = ? && dashboard_id = ?' , array ( $_SESSION [ 'user_id' ], 0 ));
2015-09-09 20:19:13 +01:00
}
2017-04-01 16:18:00 -05:00
} else {
// load a dashboard
2015-09-11 19:20:10 +01:00
$orig = $vars [ 'dashboard' ];
2017-04-01 16:18:00 -05:00
if ( ! empty ( $orig ) && isset ( $dashboards [ $orig ])) {
// specific dashboard
$vars [ 'dashboard' ] = $dashboards [ $orig ];
2016-08-18 20:28:22 -05:00
} else {
2017-04-01 16:18:00 -05:00
// load a default dashboard
$vars [ 'dashboard' ] = $default_dash == 0 ? current ( $user_dashboards ) : $dashboards [ $default_dash ];
// $dashboard was requested, but doesn't exist
if ( ! empty ( $orig )) {
$msg_box [] = array ( 'type' => 'error' , 'message' => 'Dashboard <code>#' . $orig .
'</code> does not exist! Loaded <code>' . $vars [ 'dashboard' ][ 'dashboard_name' ] .
'</code> instead.' , 'title' => 'Requested Dashboard Not Found!' );
}
2015-09-11 19:20:10 +01:00
}
2015-09-09 20:06:10 +01:00
}
2017-01-26 22:38:14 +00:00
2017-04-01 16:18:00 -05:00
$data = dbFetchRows (
'SELECT user_widget_id,users_widgets.widget_id,title,widget,col,row,size_x,size_y,refresh FROM `users_widgets`
LEFT JOIN `widgets` ON `widgets`.`widget_id`=`users_widgets`.`widget_id` WHERE `dashboard_id`=?' ,
array ( $vars [ 'dashboard' ][ 'dashboard_id' ])
);
2015-09-09 20:19:13 +01:00
if ( empty ( $data )) {
2015-10-02 07:21:37 +00:00
$data [] = array ( 'user_widget_id' => '0' , 'widget_id' => 1 , 'title' => 'Add a widget' , 'widget' => 'placeholder' , 'col' => 1 , 'row' => 1 , 'size_x' => 6 , 'size_y' => 2 , 'refresh' => 60 );
2015-09-09 20:19:13 +01:00
}
2017-04-01 16:18:00 -05:00
2015-09-09 20:19:13 +01:00
$data = serialize ( json_encode ( $data ));
2015-07-21 23:01:57 +01:00
$dash_config = unserialize ( stripslashes ( $data ));
2015-10-29 17:00:56 +00:00
if ( empty ( $vars [ 'bare' ]) || $vars [ 'bare' ] == "no" ) {
?>
2015-09-10 19:24:44 +01:00
<div class="row">
<div class="col-md-6">
<div class="btn-group btn-lg">
2015-09-12 09:51:58 +01:00
<button class="btn btn-default disabled" style="min-width:160px;"><span class="pull-left">Dashboards</span></button>
2015-09-10 19:24:44 +01:00
<div class="btn-group">
2015-09-12 09:51:58 +01:00
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="min-width:160px;"><span class="pull-left"><?php echo ($vars['dashboard']['user_id'] != $_SESSION['user_id'] ? $vars['dashboard']['username'].':' : ''); ?><?php echo $vars['dashboard']['dashboard_name']; ?></span>
2015-09-10 19:24:44 +01:00
<span class="pull-right">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</span>
</button>
<ul class="dropdown-menu">
2015-09-09 20:06:10 +01:00
<?php
2017-04-01 16:18:00 -05:00
$nodash = true;
foreach ($user_dashboards as $dash) {
if ($dash['dashboard_id'] != $vars['dashboard']['dashboard_id']) {
echo ' <li><a href="'.rtrim($config['base_url'], '/').'/overview/dashboard='.$dash['dashboard_id'].'">'.$dash['dashboard_name'].'</a></li>';
$nodash = false;
2015-09-09 20:06:10 +01:00
}
2015-09-11 19:20:10 +01:00
}
2017-04-01 16:18:00 -05:00
if ($nodash) {
2015-09-10 19:24:44 +01:00
echo ' <li><a>No other Dashboards</a></li>';
2015-09-09 20:06:10 +01:00
}
2017-04-01 16:18:00 -05:00
2015-09-11 19:20:10 +01:00
if (!empty($shared_dashboards)) {
echo ' <li role="separator" class="divider"></li>';
echo ' <li class="dropdown-header">Shared Dashboards</li>';
foreach ($shared_dashboards as $dash) {
if ($dash['dashboard_id'] != $vars['dashboard']['dashboard_id']) {
2016-08-18 20:28:22 -05:00
echo ' <li><a href="'.rtrim($config['base_url'], '/').'/overview/dashboard='.$dash['dashboard_id'].'"> '.$dash['username'].':'.$dash['dashboard_name'].($dash['access'] == 1 ? ' (Read)' : '').'</a></li>';
2015-09-11 19:20:10 +01:00
}
}
}
2015-09-09 20:06:10 +01:00
?>
2015-09-10 19:24:44 +01:00
</ul>
</div>
2016-08-22 14:09:22 -04:00
<button class="btn btn-default edit-dash-btn" href="#edit_dash" onclick="dashboard_collapse($(this).attr('href'))" data-toggle="tooltip" data-container="body" data-placement="top" title="Edit Dashboard"><i class="fa fa-pencil-square-o fa-fw"></i></button>
<button class="btn btn-danger" href="#del_dash" onclick="dashboard_collapse($(this).attr('href'))" data-toggle="tooltip" data-container="body" data-placement="top" title="Remove Dashboard"><i class="fa fa-trash fa-fw"></i></button>
<button class="btn btn-success" href="#add_dash" onclick="dashboard_collapse($(this).attr('href'))" data-toggle="tooltip" data-container="body" data-placement="top" title="New Dashboard"><i class="fa fa-plus fa-fw"></i></button>
2015-09-10 19:24:44 +01:00
</div>
</div>
2015-07-23 22:55:37 +01:00
</div>
2015-09-10 19:24:44 +01:00
<div class="dash-collapse" id="add_dash">
2015-09-11 21:14:25 +01:00
<div class="row" style="margin-top:5px;">
2015-09-10 19:24:44 +01:00
<div class="col-md-6">
2016-11-15 03:54:12 +00:00
<form class="form-inline" onsubmit="dashboard_add(this); return false;" name="add_form" id="add_form">
2015-09-09 20:06:10 +01:00
<div class="col-sm-3 col-sx-6">
<div class="input-group">
<span class="input-group-btn">
2015-09-12 09:51:58 +01:00
<a class="btn btn-default disabled" type="button" style="min-width:160px;"><span class="pull-left">New Dashboard</span></a>
2015-09-09 20:06:10 +01:00
</span>
2016-11-15 03:54:12 +00:00
<input class="form-control" type="text" placeholder="Name" name="dashboard_name" id="dashboard_name" style="min-width:160px;">
2015-09-09 20:06:10 +01:00
<span class="input-group-btn">
2015-09-11 21:14:25 +01:00
<button class="btn btn-primary" type="submit">Add</button>
2015-09-09 20:06:10 +01:00
</span>
</div>
</div>
</form>
</div>
</div>
2015-09-11 21:14:25 +01:00
<hr>
2015-09-09 20:06:10 +01:00
</div>
2015-09-10 19:24:44 +01:00
<div class="dash-collapse" id="edit_dash">
2015-09-11 21:14:25 +01:00
<!-- Start Dashboard-Settings -->
2015-09-11 19:20:10 +01:00
<div class="row" style="margin-top:5px;">
<div class="col-md-12">
<div class="col-md-12">
2015-09-09 20:06:10 +01:00
<form class="form-inline" onsubmit="dashboard_edit(this); return false;">
2015-09-11 19:20:10 +01:00
<div class="form-group">
2015-09-09 20:06:10 +01:00
<div class="input-group">
<span class="input-group-btn">
2015-09-12 09:51:58 +01:00
<a class="btn btn-default disabled" type="button" style="min-width:160px;"><span class="pull-left">Dashboard Name</span></a>
2015-09-09 20:06:10 +01:00
</span>
2015-09-10 19:24:44 +01:00
<input class="form-control" type="text" placeholder="Dashbord Name" name="dashboard_name" value="<?php echo $vars['dashboard']['dashboard_name']; ?>" style="width:160px;">
2015-09-11 19:20:10 +01:00
<select class="form-control" name="access" style="width:160px;">
<?php
2016-08-18 20:28:22 -05:00
foreach (array('Private','Shared (Read)','Shared') as $k => $v) {
2015-09-11 19:20:10 +01:00
echo ' <option value="'.$k.'"'.($vars['dashboard']['access'] == $k ? 'selected' : '').'>'.$v.'</option>';
}
?>
</select>
<span class="input-group-btn pull-left">
2015-09-11 21:14:25 +01:00
<button class="btn btn-primary" type="submit">Update</button>
2015-09-09 20:06:10 +01:00
</span>
</div>
</div>
</form>
</div>
2015-09-10 19:24:44 +01:00
</div>
2015-09-11 19:20:10 +01:00
</div>
2015-09-11 21:14:25 +01:00
<!-- End Dashboard-Settings -->
<!-- Start Widget-Select -->
2015-09-11 19:20:10 +01:00
<div class="row" style="margin-top:5px;">
<div class="col-md-12">
2015-09-10 19:24:44 +01:00
<div class="col-md-12">
2015-09-11 19:20:10 +01:00
<div class="btn-group" role="group">
2015-09-12 09:51:58 +01:00
<a class="btn btn-default disabled" role="button" style="min-width:160px;"><span class="pull-left">Add Widgets</span></a>
2015-09-11 21:14:25 +01:00
<div class="btn-group">
2015-09-12 09:51:58 +01:00
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="min-width:160px;"><span class="pull-left">Select Widget</span>
2015-09-11 21:14:25 +01:00
<span class="pull-right">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</span>
</button>
<ul class="dropdown-menu">
2015-07-21 23:01:57 +01:00
<?php
2015-07-23 17:09:18 +01:00
foreach (dbFetchRows("SELECT * FROM `widgets` ORDER BY `widget_title`") as $widgets) {
2016-05-27 09:20:33 -05:00
echo ' <li><a href="#" onsubmit="return false;" class="place_widget" data-widget_id="'.$widgets['widget_id'] .'">'. $widgets['widget_title'] .'</a></li>';
2015-07-23 17:09:18 +01:00
}
?>
2015-09-11 21:14:25 +01:00
</ul>
</div>
</div>
2015-09-10 19:24:44 +01:00
</div>
</div>
</div>
2015-09-11 21:14:25 +01:00
<!-- End Widget-Select -->
<hr>
2015-09-10 19:24:44 +01:00
</div>
<div class="dash-collapse" id="del_dash">
<div class="row" style="margin-top:5px;">
<div class="col-md-6">
<div class="col-md-6">
2015-09-12 09:51:58 +01:00
<button class="btn btn-danger" type="button" id="clear_widgets" name="clear_widgets" style="min-width:160px;"><span class="pull-left">Remove</span><strong class="pull-right">Widgets</strong></button>
2015-09-09 20:06:10 +01:00
</div>
</div>
2015-07-23 17:09:18 +01:00
</div>
2015-09-11 21:14:25 +01:00
<div class="row" style="margin-top:5px;">
<div class="col-md-6">
<div class="col-md-6">
2015-09-12 09:51:58 +01:00
<button class="btn btn-danger" type="button" onclick="dashboard_delete(this); return false;" data-dashboard="<?php echo $vars['dashboard']['dashboard_id']; ?>" style="min-width:160px;"><span class="pull-left">Delete</span><strong class="pull-right">Dashboard</strong></button>
2015-09-11 21:14:25 +01:00
</div>
</div>
</div>
<hr>
2015-07-23 17:09:18 +01:00
</div>
2017-06-03 08:02:50 +12:00
<?php } //End Vars['bare'] If
if (strpos($dash_config, 'globe') !== false) {
echo "<script src='https://www.google.com/jsapi'></script>";
}
?>
2015-07-21 23:01:57 +01:00
<script src="js/jquery.gridster.min.js"></script>
2015-07-22 22:04:33 +01:00
2015-07-21 23:01:57 +01:00
<span class="message" id="message"></span>
2015-07-22 22:04:33 +01:00
2015-07-21 23:01:57 +01:00
<div class="gridster grid">
<ul>
</ul>
</div>
2015-07-22 22:04:33 +01:00
<script type="text/javascript">
2015-07-23 17:09:18 +01:00
2015-07-22 22:04:33 +01:00
var gridster;
2015-07-21 23:01:57 +01:00
2015-07-22 22:04:33 +01:00
var serialization = <?php echo $dash_config; ?>;
2015-07-21 23:01:57 +01:00
2015-07-22 22:04:33 +01:00
serialization = Gridster.sort_by_row_and_col_asc(serialization);
2015-07-21 23:01:57 +01:00
2015-07-22 22:04:33 +01:00
function updatePos(gridster) {
var s = JSON.stringify(gridster.serialize());
2016-11-15 03:54:12 +00:00
<?php
if ($vars['dashboard']['dashboard_id'] > 0) {
echo "var dashboard_id = " . $vars['dashboard']['dashboard_id'] . ";";
} else {
echo "var dashboard_id = 0;";
}
?>
if (dashboard_id > 0) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {
type: "update-dashboard-config",
data: s,
dashboard_id: dashboard_id
},
dataType: "json",
success: function (data) {
if (data.status == 'ok') {
}
else {
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
}
},
error: function () {
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
2015-07-21 23:01:57 +01:00
}
2016-11-15 03:54:12 +00:00
});
}
2015-07-22 22:04:33 +01:00
}
2015-07-21 23:01:57 +01:00
2015-10-02 05:06:48 +00:00
var gridster_state = 0;
2015-07-22 22:04:33 +01:00
$(function(){
2016-11-15 03:54:12 +00:00
<?php
if ($vars['dashboard']['dashboard_id'] > 0) {
echo "var dashboard_id = " . $vars['dashboard']['dashboard_id'] . ";";
} else {
echo "var dashboard_id = 0;";
}
?>
2015-10-02 05:06:48 +00:00
$('[data-toggle="tooltip"]').tooltip();
2015-09-10 19:24:44 +01:00
dashboard_collapse();
2015-07-21 23:01:57 +01:00
gridster = $(".gridster ul").gridster({
2015-11-11 08:49:07 +00:00
widget_base_dimensions: ['auto', 100],
autogenerate_stylesheet: true,
2015-07-22 22:04:33 +01:00
widget_margins: [5, 5],
avoid_overlapped_widgets: true,
2015-11-11 08:49:07 +00:00
min_cols: 1,
max_cols: 20,
2015-07-22 22:04:33 +01:00
draggable: {
2015-09-06 13:37:48 +01:00
handle: 'header, span',
2015-07-22 22:04:33 +01:00
stop: function(e, ui, $widget) {
2015-07-21 23:01:57 +01:00
updatePos(gridster);
2015-07-22 22:04:33 +01:00
},
2015-07-21 23:01:57 +01:00
},
2015-07-22 22:04:33 +01:00
resize: {
enabled: true,
2015-09-06 13:18:54 +01:00
stop: function(e, ui, widget) {
2015-07-21 23:01:57 +01:00
updatePos(gridster);
2015-09-06 13:18:54 +01:00
widget_reload(widget.attr('id'),widget.data('type'));
2015-07-21 23:01:57 +01:00
}
},
2015-09-06 13:18:54 +01:00
serialize_params: function(w, wgd) {
return {
id: $(w).attr('id'),
col: wgd.col,
row: wgd.row,
size_x: wgd.size_x,
size_y: wgd.size_y
2015-07-22 22:04:33 +01:00
};
2015-07-21 23:01:57 +01:00
}
2015-07-22 22:04:33 +01:00
}).data('gridster');
2015-11-11 08:49:07 +00:00
$('.gridster ul').css({'width': $(window).width()});
2015-07-21 23:01:57 +01:00
2015-07-22 22:04:33 +01:00
gridster.remove_all_widgets();
2015-10-02 05:06:48 +00:00
gridster.disable();
gridster.disable_resize();
2015-07-22 22:04:33 +01:00
$.each(serialization, function() {
2015-09-06 13:18:54 +01:00
widget_dom(this);
2015-07-22 22:04:33 +01:00
});
2015-10-02 05:06:48 +00:00
$(document).on('click','.edit-dash-btn', function() {
if (gridster_state == 0) {
gridster.enable();
gridster.enable_resize();
gridster_state = 1;
$('.fade-edit').fadeIn();
}
else {
gridster.disable();
gridster.disable_resize();
gridster_state = 0;
$('.fade-edit').fadeOut();
}
});
2015-07-21 23:01:57 +01:00
2015-07-23 21:27:33 +01:00
$(document).on('click','#clear_widgets', function() {
var widget_id = $(this).data('widget-id');
2016-11-15 03:54:12 +00:00
if (dashboard_id > 0) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {
type: "update-dashboard-config",
sub_type: 'remove-all',
dashboard_id: dashboard_id
},
dataType: "json",
success: function (data) {
if (data.status == 'ok') {
gridster.remove_all_widgets();
}
else {
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
}
},
error: function () {
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
2015-07-23 21:27:33 +01:00
}
2016-11-15 03:54:12 +00:00
});
}
2015-07-23 21:27:33 +01:00
});
2016-05-26 09:44:41 -05:00
$('.place_widget').on('click', function(event, state) {
2015-07-23 17:09:18 +01:00
var widget_id = $(this).data('widget_id');
2016-08-30 14:56:28 +02:00
event.preventDefault();
2016-11-15 03:54:12 +00:00
if (dashboard_id > 0) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {
type: "update-dashboard-config",
sub_type: 'add',
widget_id: widget_id,
dashboard_id: dashboard_id
},
dataType: "json",
success: function (data) {
if (data.status == 'ok') {
widget_dom(data.extra);
updatePos(gridster);
}
else {
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
}
},
error: function () {
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
2015-07-22 22:04:33 +01:00
}
2016-11-15 03:54:12 +00:00
});
}
2015-07-21 23:01:57 +01:00
});
2015-07-23 17:09:18 +01:00
$(document).on( "click", ".close-widget", function() {
var widget_id = $(this).data('widget-id');
2015-07-22 22:04:33 +01:00
$.ajax({
type: 'POST',
2015-08-11 14:54:05 -07:00
url: 'ajax_form.php',
2016-11-15 03:54:12 +00:00
data: {type: "update-dashboard-config", sub_type: 'remove', widget_id: widget_id, dashboard_id: dashboard_id},
2015-07-22 22:04:33 +01:00
dataType: "json",
success: function (data) {
2015-07-23 17:09:18 +01:00
if (data.status == 'ok') {
gridster.remove_widget($('#'+widget_id));
updatePos(gridster);
}
else {
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
}
},
error: function () {
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
}
});
});
2015-09-06 13:18:54 +01:00
$(document).on("click",".edit-widget",function() {
2015-10-02 05:06:48 +00:00
obj = $(this).parent().parent().parent();
2015-09-06 13:18:54 +01:00
if( obj.data('settings') == 1 ) {
obj.data('settings','0');
} else {
obj.data('settings','1');
}
widget_reload(obj.attr('id'),obj.data('type'));
});
2015-07-22 22:04:33 +01:00
});
2015-09-10 19:24:44 +01:00
function dashboard_collapse(target) {
if (target !== undefined) {
$('.dash-collapse:not('+target+')').each(function() {
2015-09-11 19:20:10 +01:00
$(this).fadeOut(0);
2015-09-10 19:24:44 +01:00
});
2015-09-11 19:20:10 +01:00
$(target).fadeToggle(300);
2015-10-02 05:06:48 +00:00
if (target != "#edit_dash") {
gridster.disable();
gridster.disable_resize();
gridster_state = 0;
$('.fade-edit').fadeOut();
}
2015-09-10 19:24:44 +01:00
} else {
$('.dash-collapse').fadeOut(0);
}
}
2015-09-09 20:06:10 +01:00
function dashboard_delete(data) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: 'delete-dashboard', dashboard_id: $(data).data('dashboard')},
dataType: "json",
success: function (data) {
if( data.status == "ok" ) {
2015-09-11 21:14:25 +01:00
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
2016-08-18 20:28:22 -05:00
window.location.href="<?php echo rtrim($config['base_url'], '/'); ?>/overview";
2015-09-09 20:06:10 +01:00
}
2015-09-11 21:14:25 +01:00
else {
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
}
2015-09-09 20:06:10 +01:00
}
});
}
function dashboard_edit(data) {
2016-11-15 03:54:12 +00:00
<?php
if ($vars['dashboard']['dashboard_id'] > 0) {
echo "var dashboard_id = " . $vars['dashboard']['dashboard_id'] . ";";
} else {
echo "var dashboard_id = 0;";
}
?>
2015-09-09 20:06:10 +01:00
datas = $(data).serializeArray();
data = [];
for( var field in datas ) {
data[datas[field].name] = datas[field].value;
}
2016-11-15 03:54:12 +00:00
if (dashboard_id > 0) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {
type: 'edit-dashboard',
dashboard_name: data['dashboard_name'],
dashboard_id: dashboard_id,
access: data['access']
},
dataType: "json",
success: function (data) {
if (data.status == "ok") {
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
window.location.href = "<?php echo rtrim($config['base_url'], '/'); ?>/overview/dashboard=" + dashboard_id;
}
else {
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
}
2015-09-11 21:14:25 +01:00
}
2016-11-15 03:54:12 +00:00
});
}
2015-09-09 20:06:10 +01:00
}
function dashboard_add(data) {
datas = $(data).serializeArray();
data = [];
for( var field in datas ) {
data[datas[field].name] = datas[field].value;
}
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: 'add-dashboard', dashboard_name: data['dashboard_name']},
dataType: "json",
success: function (data) {
if( data.status == "ok" ) {
2015-09-11 21:14:25 +01:00
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
2016-08-18 20:28:22 -05:00
window.location.href="<?php echo rtrim($config['base_url'], '/'); ?>/overview/dashboard="+data.dashboard_id;
2015-09-09 20:06:10 +01:00
}
2015-09-11 21:14:25 +01:00
else {
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
}
2015-09-09 20:06:10 +01:00
}
});
}
2015-09-06 13:18:54 +01:00
function widget_dom(data) {
2015-09-07 19:30:22 +01:00
dom = '<li id="'+data.user_widget_id+'" data-type="'+data.widget+'" data-settings="0">'+
2015-10-02 05:06:48 +00:00
'<header class="widget_header"><span id="widget_title_'+data.user_widget_id+'">'+data.title+
'</span>'+
2015-10-02 07:21:37 +00:00
'<span class="fade-edit pull-right">'+
2017-05-05 22:22:01 +01:00
<?php
if (($vars['dashboard']['access'] == 1 && $_SESSION['user_id'] === $vars['dashboard']['user_id']) ||
($vars['dashboard']['access'] == 0 || $vars['dashboard']['access'] == 2)) {
echo "'<i class=\"fa fa-pencil-square-o edit-widget\" data-widget-id=\"'+data.user_widget_id+'\" aria-label=\"Settings\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"Settings\"> </i> '+";
}
?>
2016-05-26 09:44:41 -05:00
'<i class="text-danger fa fa-times close-widget" data-widget-id="'+data.user_widget_id+'" aria-label="Close" data-toggle="tooltip" data-placement="top" title="Remove"> </i> '+
2015-10-02 07:21:37 +00:00
'</span>'+
2015-09-06 13:18:54 +01:00
'</header>'+
2016-05-26 09:44:41 -05:00
'<div class="widget_body" id="widget_body_'+data.user_widget_id+'">'+data.widget+'</div>'+
2015-09-06 13:18:54 +01:00
'\<script\>var timeout'+data.user_widget_id+' = grab_data('+data.user_widget_id+','+data.refresh+',\''+data.widget+'\');\<\/script\>'+
'</li>';
if (data.hasOwnProperty('col') && data.hasOwnProperty('row')) {
gridster.add_widget(dom, parseInt(data.size_x), parseInt(data.size_y), parseInt(data.col), parseInt(data.row));
} else {
gridster.add_widget(dom, parseInt(data.size_x), parseInt(data.size_y));
}
2015-10-02 05:06:48 +00:00
if (gridster_state == 0) {
$('.fade-edit').fadeOut(0);
}
2015-10-02 07:21:37 +00:00
$('[data-toggle="tooltip"]').tooltip();
2015-09-06 13:18:54 +01:00
}
2015-09-05 16:15:11 +01:00
2015-09-06 13:18:54 +01:00
function widget_settings(data) {
var widget_settings = {};
var widget_id = 0;
datas = $(data).serializeArray();
for( var field in datas ) {
widget_settings[datas[field].name] = datas[field].value;
}
$('.gridster').find('div[id^=widget_body_]').each(function() {
if(this.contains(data)) {
widget_id = $(this).parent().attr('id');
widget_type = $(this).parent().data('type');
$(this).parent().data('settings','0');
}
});
if( widget_id > 0 && widget_settings != {} ) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: 'widget-settings', id: widget_id, settings: widget_settings},
dataType: "json",
success: function (data) {
if( data.status == "ok" ) {
widget_reload(widget_id,widget_type);
}
2015-09-11 21:14:25 +01:00
else {
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
}
2015-09-06 13:18:54 +01:00
}
});
}
2016-08-18 20:28:22 -05:00
return false;
2015-09-06 13:18:54 +01:00
}
2015-09-05 16:15:11 +01:00
2015-09-06 13:18:54 +01:00
function widget_reload(id,data_type) {
2017-09-22 00:06:49 -06:00
$("#widget_body_"+id+" .bootgrid-table").bootgrid("destroy");
2017-09-01 10:27:01 -06:00
$("#widget_body_"+id+" *").off();
$("#widget_body_"+id).empty();
2015-09-06 13:18:54 +01:00
if( $("#widget_body_"+id).parent().data('settings') == 1 ) {
settings = 1;
} else {
settings = 0;
}
$.ajax({
type: 'POST',
url: 'ajax_dash.php',
2017-04-05 15:14:21 +00:00
data: {type: data_type, id: id, dimensions: {x:$("#widget_body_"+id).innerWidth()-50, y:$("#widget_body_"+id).innerHeight()-50}, settings:settings},
2015-09-06 13:18:54 +01:00
dataType: "json",
success: function (data) {
if (data.status == 'ok') {
$("#widget_title_"+id).html(data.title);
$("#widget_body_"+id).html(data.html);
}
else {
$("#widget_body_"+id).html('<div class="alert alert-info">' + data.message + '</div>');
}
},
error: function () {
$("#widget_body_"+id).html('<div class="alert alert-info">Problem with backend</div>');
}
});
}
2015-07-23 17:09:18 +01:00
2015-09-06 13:18:54 +01:00
function grab_data(id,refresh,data_type) {
2015-09-07 19:30:22 +01:00
if( $("#widget_body_"+id).parent().data('settings') == 0 ) {
widget_reload(id,data_type);
}
2015-09-06 13:18:54 +01:00
new_refresh = refresh * 1000;
setTimeout(function() {
grab_data(id,refresh,data_type);
},
new_refresh);
}
$('#new-widget').popover();
2016-11-15 03:54:12 +00:00
<?php
2017-01-26 22:38:14 +00:00
if (empty($vars['dashboard']['dashboard_id']) && $default_dash == 0) {
2016-11-15 03:54:12 +00:00
echo "\$('#dashboard_name').val('Default');\n";
echo "dashboard_add(\$('#add_form'));\n";
}
?>
2015-07-22 22:04:33 +01:00
</script>