Line | |
---|
1 | /*global $, dotclear */ |
---|
2 | 'use strict'; |
---|
3 | |
---|
4 | dotclear.dbSpamsCount = function() { |
---|
5 | var params = { |
---|
6 | f: 'getSpamsCount', |
---|
7 | xd_check: dotclear.nonce, |
---|
8 | }; |
---|
9 | $.get('services.php', params, function(data) { |
---|
10 | if ($('rsp[status=failed]', data).length > 0) { |
---|
11 | // For debugging purpose only: |
---|
12 | // console.log($('rsp',data).attr('message')); |
---|
13 | window.console.log('Dotclear REST server error'); |
---|
14 | } else { |
---|
15 | var nb = $('rsp>count', data).attr('ret'); |
---|
16 | if (nb != dotclear.dbSpamsCount_Counter) { |
---|
17 | // First pass or counter changed |
---|
18 | var icon = $('#dashboard-main #icons p a[href="comments.php?status=-2"]'); |
---|
19 | if (icon.length) { |
---|
20 | // Update count if exists |
---|
21 | var nb_label = icon.children('span.db-icon-title-spam'); |
---|
22 | if (nb_label.length) { |
---|
23 | nb_label.text(nb); |
---|
24 | } |
---|
25 | } else { |
---|
26 | // Add full element (link + counter) |
---|
27 | var icon = $('#dashboard-main #icons p a[href="comments.php"]'); |
---|
28 | if (icon.length) { |
---|
29 | var xml = ' <br /><a href="comments.php?status=-2"><span class="db-icon-title-spam">' + nb + '</span></a>'; |
---|
30 | icon.after(xml); |
---|
31 | } |
---|
32 | } |
---|
33 | // Store current counter |
---|
34 | dotclear.dbSpamsCount_Counter = nb; |
---|
35 | } |
---|
36 | } |
---|
37 | }); |
---|
38 | }; |
---|
39 | |
---|
40 | $(function() { |
---|
41 | // run counters' update on some dashboard icons |
---|
42 | // Spam comments |
---|
43 | var icon_spam = $('#dashboard-main #icons p a[href="comments.php"]'); |
---|
44 | if (icon_spam.length) { |
---|
45 | // Icon exists on dashboard |
---|
46 | // First pass |
---|
47 | dotclear.dbSpamsCount(); |
---|
48 | // Then fired every 60 seconds (1 minute) |
---|
49 | dotclear.dbSpamsCount_Timer = setInterval(dotclear.dbSpamsCount, 60 * 1000); |
---|
50 | } |
---|
51 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.