[3706] | 1 | /*global $, dotclear, jsToolBar */ |
---|
| 2 | 'use strict'; |
---|
| 3 | |
---|
[3781] | 4 | dotclear.dbCommentsCount = function() { |
---|
| 5 | var params = { |
---|
| 6 | f: 'getCommentsCount', |
---|
| 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.dbCommentsCount_Counter) { |
---|
| 17 | // First pass or counter changed |
---|
| 18 | var icon = $('#dashboard-main #icons p a[href="comments.php"]'); |
---|
| 19 | if (icon.length) { |
---|
| 20 | // Update count if exists |
---|
| 21 | var nb_label = icon.children('span.db-icon-title'); |
---|
| 22 | if (nb_label.length) { |
---|
| 23 | nb_label.text(nb); |
---|
| 24 | } |
---|
| 25 | } |
---|
| 26 | // Store current counter |
---|
| 27 | dotclear.dbCommentsCount_Counter = nb; |
---|
| 28 | } |
---|
| 29 | } |
---|
| 30 | }); |
---|
| 31 | }; |
---|
| 32 | dotclear.dbPostsCount = function() { |
---|
| 33 | var params = { |
---|
| 34 | f: 'getPostsCount', |
---|
| 35 | xd_check: dotclear.nonce, |
---|
| 36 | }; |
---|
| 37 | $.get('services.php', params, function(data) { |
---|
| 38 | if ($('rsp[status=failed]', data).length > 0) { |
---|
| 39 | // For debugging purpose only: |
---|
| 40 | // console.log($('rsp',data).attr('message')); |
---|
| 41 | window.console.log('Dotclear REST server error'); |
---|
| 42 | } else { |
---|
| 43 | var nb = $('rsp>count', data).attr('ret'); |
---|
| 44 | if (nb != dotclear.dbPostsCount_Counter) { |
---|
| 45 | // First pass or counter changed |
---|
| 46 | var icon = $('#dashboard-main #icons p a[href="posts.php"]'); |
---|
| 47 | if (icon.length) { |
---|
| 48 | // Update count if exists |
---|
| 49 | var nb_label = icon.children('span.db-icon-title'); |
---|
| 50 | if (nb_label.length) { |
---|
| 51 | nb_label.text(nb); |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | // Store current counter |
---|
| 55 | dotclear.dbPostsCount_Counter = nb; |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | }); |
---|
| 59 | }; |
---|
[0] | 60 | $(function() { |
---|
[3706] | 61 | function quickPost(f, status) { |
---|
| 62 | if ($.isFunction('jsToolBar') && (contentTb.getMode() == 'wysiwyg')) { |
---|
| 63 | contentTb.syncContents('iframe'); |
---|
| 64 | } |
---|
[234] | 65 | |
---|
[3706] | 66 | var params = { |
---|
| 67 | f: 'quickPost', |
---|
| 68 | xd_check: dotclear.nonce, |
---|
| 69 | post_title: $('#post_title', f).val(), |
---|
| 70 | post_content: $('#post_content', f).val(), |
---|
| 71 | cat_id: $('#cat_id', f).val(), |
---|
| 72 | post_status: status, |
---|
| 73 | post_format: $('#post_format', f).val(), |
---|
| 74 | post_lang: $('#post_lang', f).val(), |
---|
| 75 | new_cat_title: $('#new_cat_title', f).val(), |
---|
| 76 | new_cat_parent: $('#new_cat_parent', f).val() |
---|
| 77 | }; |
---|
[234] | 78 | |
---|
[3706] | 79 | $('p.qinfo', f).remove(); |
---|
[234] | 80 | |
---|
[3706] | 81 | $.post('services.php', params, function(data) { |
---|
| 82 | var msg; |
---|
| 83 | if ($('rsp[status=failed]', data).length > 0) { |
---|
| 84 | msg = '<p class="qinfo"><strong>' + dotclear.msg.error + |
---|
| 85 | '</strong> ' + $('rsp', data).text() + '</p>'; |
---|
| 86 | } else { |
---|
| 87 | msg = '<p class="qinfo">' + dotclear.msg.entry_created + |
---|
| 88 | ' - <a href="post.php?id=' + $('rsp>post', data).attr('id') + '">' + |
---|
| 89 | dotclear.msg.edit_entry + '</a>'; |
---|
| 90 | if ($('rsp>post', data).attr('post_status') == 1) { |
---|
| 91 | msg += ' - <a href="' + $('rsp>post', data).attr('post_url') + '">' + |
---|
| 92 | dotclear.msg.view_entry + '</a>'; |
---|
| 93 | } |
---|
| 94 | msg += '</p>'; |
---|
| 95 | $('#post_title', f).val(''); |
---|
| 96 | $('#post_content', f).val(''); |
---|
| 97 | $('#post_content', f).change(); |
---|
| 98 | if ($.isFunction('jsToolBar') && (contentTb.getMode() == 'wysiwyg')) { |
---|
| 99 | contentTb.syncContents('textarea'); |
---|
| 100 | } |
---|
| 101 | $('#cat_id', f).val('0'); |
---|
| 102 | $('#new_cat_title', f).val(''); |
---|
| 103 | $('#new_cat_parent', f).val('0'); |
---|
| 104 | } |
---|
[234] | 105 | |
---|
[3706] | 106 | $('fieldset', f).prepend(msg); |
---|
| 107 | }); |
---|
| 108 | } |
---|
[234] | 109 | |
---|
[3706] | 110 | var f = $('#quick-entry'); |
---|
| 111 | if (f.length > 0) { |
---|
| 112 | if ($.isFunction(jsToolBar)) { |
---|
| 113 | var contentTb = new jsToolBar($('#post_content', f)[0]); |
---|
| 114 | contentTb.switchMode($('#post_format', f).val()); |
---|
| 115 | } |
---|
[234] | 116 | |
---|
[3706] | 117 | $('input[name=save]', f).click(function() { |
---|
| 118 | quickPost(f, -2); |
---|
| 119 | return false; |
---|
| 120 | }); |
---|
[234] | 121 | |
---|
[3706] | 122 | if ($('input[name=save-publish]', f).length > 0) { |
---|
| 123 | var btn = $('<input type="submit" value="' + $('input[name=save-publish]', f).val() + '" />'); |
---|
| 124 | $('input[name=save-publish]', f).remove(); |
---|
| 125 | $('input[name=save]', f).after(btn).after(' '); |
---|
| 126 | btn.click(function() { |
---|
| 127 | quickPost(f, 1); |
---|
| 128 | return false; |
---|
| 129 | }); |
---|
| 130 | } |
---|
[234] | 131 | |
---|
[3706] | 132 | $('#new_cat').toggleWithLegend($('#new_cat').parent().children().not('#new_cat'), { |
---|
| 133 | // no cookie on new category as we don't use this every day |
---|
| 134 | legend_click: true |
---|
| 135 | }); |
---|
| 136 | } |
---|
[3613] | 137 | |
---|
[3706] | 138 | // allow to hide quick entry div, and remember choice |
---|
| 139 | $('#quick h3').toggleWithLegend($('#quick').children().not('h3'), { |
---|
| 140 | legend_click: true, |
---|
| 141 | user_pref: 'dcx_quick_entry' |
---|
| 142 | }); |
---|
[3613] | 143 | |
---|
[3706] | 144 | // check if core update available |
---|
| 145 | var params = { |
---|
| 146 | f: 'checkCoreUpdate', |
---|
| 147 | xd_check: dotclear.nonce |
---|
| 148 | }; |
---|
| 149 | $.post('services.php', params, function(data) { |
---|
| 150 | if ($('rsp[status=failed]', data).length > 0) { |
---|
| 151 | // Silently fail as a forced checked my be done with admin update page |
---|
| 152 | } else { |
---|
| 153 | if ($('rsp>update', data).attr('check') == 1) { |
---|
| 154 | // Something has to be displayed |
---|
| 155 | var xml = $('rsp>update', data).attr('ret'); |
---|
| 156 | $('#content h2').after(xml); |
---|
[3819] | 157 | // manage outgoing links |
---|
| 158 | dotclear.outgoingLink('#ajax-update a'); |
---|
[3706] | 159 | } |
---|
| 160 | } |
---|
| 161 | }); |
---|
| 162 | |
---|
| 163 | // check if some news are available |
---|
| 164 | params = { |
---|
| 165 | f: 'checkNewsUpdate', |
---|
| 166 | xd_check: dotclear.nonce |
---|
| 167 | }; |
---|
| 168 | $.post('services.php', params, function(data) { |
---|
| 169 | if ($('rsp[status=failed]', data).length > 0) { |
---|
| 170 | // Silently fail |
---|
| 171 | } else { |
---|
| 172 | if ($('rsp>news', data).attr('check') == 1) { |
---|
| 173 | // Something has to be displayed |
---|
| 174 | var xml = $('rsp>news', data).attr('ret'); |
---|
| 175 | if ($('#dashboard-boxes').length == 0) { |
---|
| 176 | // Create the #dashboard-boxes container |
---|
| 177 | $('#dashboard-main').append('<div id="dashboard-boxes"></div>'); |
---|
| 178 | } |
---|
| 179 | if ($('#dashboard-boxes div.db-items').length == 0) { |
---|
| 180 | // Create the #dashboard-boxes div.db-items container |
---|
| 181 | $('#dashboard-boxes').prepend('<div class="db-items"></div>'); |
---|
| 182 | } |
---|
| 183 | $('#dashboard-boxes div.db-items').prepend(xml); |
---|
[3819] | 184 | // manage outgoing links |
---|
| 185 | dotclear.outgoingLink('#ajax-news a'); |
---|
[3706] | 186 | } |
---|
| 187 | } |
---|
| 188 | }); |
---|
[3781] | 189 | |
---|
| 190 | // run counters' update on some dashboard icons |
---|
| 191 | // Comments (including everything) |
---|
| 192 | var icon_com = $('#dashboard-main #icons p a[href="comments.php"]'); |
---|
| 193 | if (icon_com.length) { |
---|
| 194 | // Icon exists on dashboard |
---|
| 195 | // First pass |
---|
| 196 | dotclear.dbCommentsCount(); |
---|
| 197 | // Then fired every 60 seconds (1 minute) |
---|
| 198 | dotclear.dbCommentsCount_Timer = setInterval(dotclear.dbCommentsCount, 60 * 1000); |
---|
| 199 | } |
---|
| 200 | // Posts |
---|
| 201 | var icon_com = $('#dashboard-main #icons p a[href="posts.php"]'); |
---|
| 202 | if (icon_com.length) { |
---|
| 203 | // Icon exists on dashboard |
---|
| 204 | // First pass |
---|
| 205 | dotclear.dbPostsCount(); |
---|
| 206 | // Then fired every 600 seconds (10 minutes) |
---|
| 207 | dotclear.dbPostsCount_Timer = setInterval(dotclear.dbCommentsPost, 600 * 1000); |
---|
| 208 | } |
---|
[234] | 209 | }); |
---|