| Revision 3880:e6d1f6d9d7df,
1.7 KB
checked in by franck <carnet.franck.paul@…>, 7 years ago
(diff) |
|
Use let and const rather than var (ES2015/ES6), use template string where is more efficient
|
| Rev | Line | |
|---|
| [3781] | 1 | /*global $, dotclear */ |
|---|
| 2 | 'use strict'; |
|---|
| 3 | |
|---|
| 4 | dotclear.dbSpamsCount = function() { |
|---|
| [3880] | 5 | const params = { |
|---|
| [3781] | 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 { |
|---|
| [3880] | 15 | const nb = $('rsp>count', data).attr('ret'); |
|---|
| [3781] | 16 | if (nb != dotclear.dbSpamsCount_Counter) { |
|---|
| 17 | // First pass or counter changed |
|---|
| [3880] | 18 | let icon = $('#dashboard-main #icons p a[href="comments.php?status=-2"]'); |
|---|
| [3781] | 19 | if (icon.length) { |
|---|
| 20 | // Update count if exists |
|---|
| [3880] | 21 | const nb_label = icon.children('span.db-icon-title-spam'); |
|---|
| [3781] | 22 | if (nb_label.length) { |
|---|
| 23 | nb_label.text(nb); |
|---|
| 24 | } |
|---|
| [3783] | 25 | } else { |
|---|
| [3786] | 26 | if (nb != '') { |
|---|
| 27 | // Add full element (link + counter) |
|---|
| [3880] | 28 | icon = $('#dashboard-main #icons p a[href="comments.php"]'); |
|---|
| [3786] | 29 | if (icon.length) { |
|---|
| [3880] | 30 | const xml = ` <a href="comments.php?status=-2"><span class="db-icon-title-spam">${nb}</span></a>`; |
|---|
| [3786] | 31 | icon.after(xml); |
|---|
| 32 | } |
|---|
| [3783] | 33 | } |
|---|
| [3781] | 34 | } |
|---|
| 35 | // Store current counter |
|---|
| 36 | dotclear.dbSpamsCount_Counter = nb; |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | }); |
|---|
| 40 | }; |
|---|
| 41 | |
|---|
| 42 | $(function() { |
|---|
| 43 | // run counters' update on some dashboard icons |
|---|
| 44 | // Spam comments |
|---|
| [3880] | 45 | const icon_spam = $('#dashboard-main #icons p a[href="comments.php"]'); |
|---|
| [3781] | 46 | if (icon_spam.length) { |
|---|
| 47 | // Icon exists on dashboard |
|---|
| 48 | // First pass |
|---|
| 49 | dotclear.dbSpamsCount(); |
|---|
| 50 | // Then fired every 60 seconds (1 minute) |
|---|
| 51 | dotclear.dbSpamsCount_Timer = setInterval(dotclear.dbSpamsCount, 60 * 1000); |
|---|
| 52 | } |
|---|
| 53 | }); |
|---|
Note: See
TracBrowser
for help on using the repository browser.