-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchdog_live.js
78 lines (64 loc) · 2.33 KB
/
watchdog_live.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
// $Id: watchdog_live.js,v 1.3 2009/04/21 14:17:16 naxoc Exp $
Drupal.watchdog = {
// Attach functionality.
autoAttach: function() {
// Grab settings.
Drupal.watchdog.interval = $('#edit-watchdog-live-interval').val();
Drupal.watchdog.disabled = $('#edit-watchdog-live-disabled').attr('checked') || 0;
// Interval setting.
$('#edit-watchdog-live-interval').bind('change', function(event) {
Drupal.watchdog.saveSetting('interval', this.value);
});
// Disabled state.
$('#edit-watchdog-live-disabled').bind('click', function(event) {
Drupal.watchdog.saveSetting('disabled', this.checked);
if (!this.checked) {
Drupal.watchdog.start();
}
});
// Handle updating.
Drupal.watchdog.start();
},
// Check callback for update and display new content if any.
load: function() {
$.get(Drupal.settings.watchdogLive.callback_url, function(data) {
var result = Drupal.parseJson(data);
// Only if we get content back.
if (result.content) {
var animated = false;
$('#dblog-filter-form').parent().children().not('#dblog-filter-form').fadeOut('fast', function() {
// Since we have multiple children, the callback will be called multiple times.
// Force a stop.
if (animated) {
return false;
}
animated = true;
// Remove old table.
$('#dblog-filter-form').parent().children().not('#dblog-filter-form').remove();
// Bring in new content.
$('#dblog-filter-form').parent().append(result.content);
$('#dblog-filter-form').parent().children().not('#dblog-filter-form').fadeIn('fast');
});
}
// Continue the loop.
Drupal.watchdog.start();
});
},
// Save a setting for the configurable options.
saveSetting: function(name, value) {
var setting = {};
setting[name] = value;
$.post(Drupal.settings.watchdogLive.setting_url, setting);
Drupal.watchdog[name] = value;
},
// Start the process.
start: function() {
if (!Drupal.watchdog.disabled) {
Drupal.watchdog.timeoutId = setTimeout(Drupal.watchdog.load, Drupal.watchdog.interval);
}
}
};
// Global Killswitch.
if (Drupal.jsEnabled) {
$(document).ready(Drupal.watchdog.autoAttach);
}