[3706] | 1 | /*global $, dotclear, jsToolBar */ |
---|
| 2 | 'use strict'; |
---|
| 3 | |
---|
[3781] | 4 | dotclear.dbCommentsCount = function() { |
---|
[3880] | 5 | const params = { |
---|
[3781] | 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 { |
---|
[3880] | 15 | const nb = $('rsp>count', data).attr('ret'); |
---|
[3781] | 16 | if (nb != dotclear.dbCommentsCount_Counter) { |
---|
| 17 | // First pass or counter changed |
---|
[3880] | 18 | const icon = $('#dashboard-main #icons p a[href="comments.php"]'); |
---|
[3781] | 19 | if (icon.length) { |
---|
| 20 | // Update count if exists |
---|
[3880] | 21 | const nb_label = icon.children('span.db-icon-title'); |
---|
[3781] | 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() { |
---|
[3880] | 33 | const params = { |
---|
[3781] | 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 { |
---|
[3880] | 43 | const nb = $('rsp>count', data).attr('ret'); |
---|
[3781] | 44 | if (nb != dotclear.dbPostsCount_Counter) { |
---|
| 45 | // First pass or counter changed |
---|
[3880] | 46 | const icon = $('#dashboard-main #icons p a[href="posts.php"]'); |
---|
[3781] | 47 | if (icon.length) { |
---|
| 48 | // Update count if exists |
---|
[3880] | 49 | const nb_label = icon.children('span.db-icon-title'); |
---|
[3781] | 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 | |
---|
[3880] | 66 | const params = { |
---|
[3706] | 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) { |
---|
[3880] | 82 | let msg; |
---|
[3706] | 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 | |
---|
[3880] | 110 | const f = $('#quick-entry'); |
---|
[3706] | 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 |
---|
[3880] | 145 | let params = { |
---|
[3706] | 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 |
---|
[3880] | 155 | const xml = $('rsp>update', data).attr('ret'); |
---|
[3706] | 156 | $('#content h2').after(xml); |
---|
[3819] | 157 | // manage outgoing links |
---|
[3820] | 158 | dotclear.outgoingLinks('#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 |
---|
[3880] | 174 | const xml = $('rsp>news', data).attr('ret'); |
---|
[3706] | 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 |
---|
[3820] | 185 | dotclear.outgoingLinks('#ajax-news a'); |
---|
[3706] | 186 | } |
---|
| 187 | } |
---|
| 188 | }); |
---|
[3781] | 189 | |
---|
| 190 | // run counters' update on some dashboard icons |
---|
| 191 | // Comments (including everything) |
---|
[3880] | 192 | if ($('#dashboard-main #icons p a[href="comments.php"]').length) { |
---|
[3781] | 193 | // Icon exists on dashboard |
---|
| 194 | // First pass |
---|
| 195 | dotclear.dbCommentsCount(); |
---|
| 196 | // Then fired every 60 seconds (1 minute) |
---|
| 197 | dotclear.dbCommentsCount_Timer = setInterval(dotclear.dbCommentsCount, 60 * 1000); |
---|
| 198 | } |
---|
| 199 | // Posts |
---|
[3880] | 200 | if ($('#dashboard-main #icons p a[href="posts.php"]').length) { |
---|
[3781] | 201 | // Icon exists on dashboard |
---|
| 202 | // First pass |
---|
| 203 | dotclear.dbPostsCount(); |
---|
| 204 | // Then fired every 600 seconds (10 minutes) |
---|
| 205 | dotclear.dbPostsCount_Timer = setInterval(dotclear.dbCommentsPost, 600 * 1000); |
---|
| 206 | } |
---|
[3833] | 207 | |
---|
[3901] | 208 | if (!dotclear.noDragDrop) { |
---|
| 209 | // Dashboard boxes and their children are sortable |
---|
| 210 | const set_positions = function(sel, id) { |
---|
| 211 | const list = $(sel).sortable("toArray").join(); |
---|
| 212 | // Save positions (via services) for id |
---|
| 213 | const params = { |
---|
| 214 | f: 'setDashboardPositions', |
---|
| 215 | xd_check: dotclear.nonce, |
---|
| 216 | id: id, |
---|
| 217 | list: list |
---|
| 218 | }; |
---|
| 219 | $.post('services.php', params, function() {}); |
---|
[3833] | 220 | }; |
---|
[3901] | 221 | const init_positions = function(sel, id) { |
---|
| 222 | $(sel).sortable({ |
---|
| 223 | cursor: 'move', |
---|
| 224 | opacity: 0.5, |
---|
[3905] | 225 | delay: 200, |
---|
| 226 | distance: 10, |
---|
[3901] | 227 | tolerance: "pointer", |
---|
| 228 | update: function() { |
---|
| 229 | set_positions(sel, id); |
---|
| 230 | }, |
---|
| 231 | start: function() { |
---|
| 232 | $(sel).addClass('sortable-area'); |
---|
| 233 | }, |
---|
| 234 | stop: function() { |
---|
| 235 | $(sel).removeClass('sortable-area'); |
---|
| 236 | } |
---|
| 237 | }); |
---|
| 238 | }; |
---|
[3906] | 239 | const reset_positions = function(sel) { |
---|
| 240 | $(sel).sortable('destroy'); |
---|
| 241 | }; |
---|
| 242 | // List of sortable areas |
---|
| 243 | const areas = [ |
---|
| 244 | ['#dashboard-main', 'main_order'], |
---|
| 245 | ['#dashboard-boxes', 'boxes_order'], |
---|
| 246 | ['#db-items', 'boxes_items_order'], |
---|
| 247 | ['#db-contents', 'boxes_contents_order'] |
---|
| 248 | ]; |
---|
| 249 | // Set or reset sortable depending on #dragndrop checbkox value |
---|
| 250 | $('#dragndrop').click(function() { |
---|
| 251 | if ($(this).is(':checked')) { |
---|
| 252 | // Activate sorting feature |
---|
| 253 | areas.forEach(element => init_positions(element[0], element[1])); |
---|
| 254 | $(this).prop('title', dotclear.dragndrop_on); |
---|
[3908] | 255 | $('#dragndrop-label').text(dotclear.dragndrop_on); |
---|
[3906] | 256 | } else { |
---|
| 257 | // Deactivate sorting feature |
---|
| 258 | areas.forEach(element => reset_positions(element[0])); |
---|
| 259 | $(this).prop('title', dotclear.dragndrop_off); |
---|
[3908] | 260 | $('#dragndrop-label').text(dotclear.dragndrop_off); |
---|
[3906] | 261 | } |
---|
| 262 | }); |
---|
[3901] | 263 | } |
---|
[234] | 264 | }); |
---|