-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.js
90 lines (79 loc) · 2.78 KB
/
dashboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(function ($) {
/**
* Move a block in the blocks table from one region to another via select list.
*
* This behavior is dependent on the tableDrag behavior, since it uses the
* objects initialized in that behavior to update the row.
*/
Drupal.behaviors.dashboard = {
attach: function (context, settings) {
// Make modal window height scaled automatically.
$('.ctools-modal-content, #modal-content', context).height('auto');
$('.ctools-use-modal:not(.ctools-use-modal-processed)').each(function(i, obj) {
var url = $(obj).attr('href');
// This is to pop up the modal as soon as the user clicks the element.
$(obj).click(Drupal.CTools.Modal.clickAjaxLink);
var element_settings = {};
element_settings.url = url;
element_settings.event = 'click';
element_settings.progress = { type: 'throbber' };
var base = url;
Drupal.ajax[base] = new Drupal.ajax(base, obj, element_settings);
$(obj).addClass('ctools-use-modal-processed');
});
}
};
$(document).ready(function() {
//check if we are in dashboard page
if($('#dashboard-refresh-time').length) {
//get the interval from dashboard page
var refresh_interval = parseInt($('#dashboard-refresh-time').html());
//interval in miliseconds
var interval = 1000 * 60 * refresh_interval;
//function to be called
var ajax_call = function() {
$.ajax({
type: 'GET',
url: "/dashboard/sections/refresh",
cache: false,
})
.success(function(data) {
var results = JSON.parse(data);
if(results.length > 0) {
for(var i = 0, len = results.length; i < len; i++) {
row = results[i];
if(row['command'] == 'invoke' && row['method'] == 'html') {
$(row['selector']).html(row['arguments'][0]);
}
}
}
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October","November", "December"];
var last_update = monthNames[month] + ' ' + day + ', ' + year + ' ' + hour + ':' + minute + ':' + second;
$('#dashboard-last-refresh-time').html(last_update);
//console.log(results);
console.log('Dashboard sections refreshed after '+refresh_interval+' minutes.');
})
};
//ajax called here at interval
if(refresh_interval > 0) {
setInterval(ajax_call, interval);
}
}
//datatable
if($('#dashboard-rx-links-list').length) {
$('#dashboard-rx-links-list').DataTable({
"searching": false,
"paging": false,
"lengthChange": false,
"info": false
});
}
});
})(jQuery);