PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.3
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / assets / js / mainwp-posts.js

mainwp-posts.js in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.3, at assets/js/mainwp-posts.js

547 lines 19.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 /**
3 * MainWP_Page.page
4 */
5 jQuery(document).ready(function () {
6
7 // to fix issue not loaded calendar js library
8 if (jQuery('.ui.calendar').length > 0) {
9 if (mainwpParams.use_wp_datepicker == 1) {
10 jQuery('#mainwp-manage-pages .ui.calendar input[type=text],#mainwp-manage-posts .ui.calendar input[type=text]').datepicker({ dateFormat: "yy-mm-dd" });
11 } else {
12 jQuery('#mainwp-manage-pages .ui.calendar, #mainwp-manage-posts .ui.calendar').calendar({
13 type: 'date',
14 monthFirst: false,
15 today: true,
16 touchReadonly: false,
17 formatter: {
18 date: function (date) {
19 if (!date) return '';
20 var day = date.getDate();
21 var month = date.getMonth() + 1;
22 var year = date.getFullYear();
23
24 if (month < 10) {
25 month = '0' + month;
26 }
27 if (day < 10) {
28 day = '0' + day;
29 }
30 return year + '-' + month + '-' + day;
31 }
32 }
33 });
34 }
35 }
36
37 jQuery(document).on('click', '#mainwp_show_pages', function () {
38 mainwp_fetch_pages();
39 });
40 jQuery(document).on('click', '.page_submitpublish', function () {
41 mainwppage_postAction(jQuery(this), 'publish');
42 return false;
43 });
44 jQuery(document).on('click', '.page_submitdelete', function () {
45 mainwppage_postAction(jQuery(this), 'trash');
46 return false;
47 });
48 jQuery(document).on('click', '.page_submitdelete_perm', function () {
49 mainwppage_postAction(jQuery(this), 'delete');
50 return false;
51 });
52 jQuery(document).on('click', '.page_submitrestore', function () {
53 mainwppage_postAction(jQuery(this), 'restore');
54 return false;
55 });
56 jQuery(document).on('click', '#mainwp-do-pages-bulk-actions', function () {
57 var action = jQuery('#mainwp-bulk-actions').val();
58 if (action != 'trash' && action != 'restore' && action != 'delete') {
59 return false;
60 }
61
62 var tmp = jQuery("input[name='page[]']:checked");
63 countSent = tmp.length;
64
65 if (countSent == 0)
66 return false;
67
68 var _callback = function () {
69 jQuery('#mainwp-do-pages-bulk-actions').attr('disabled', 'true');
70 tmp.each(
71 function (index, elem) {
72 mainwppage_postAction(elem, action);
73 }
74 );
75 };
76
77 if (action == 'delete') {
78 var msg = __('You are about to delete %1 page(s). Are you sure you want to proceed?', countSent);
79 mainwp_confirm(msg, _callback);
80 return false;
81 }
82 _callback();
83 return false;
84 });
85 });
86
87
88 mainwppage_postAction = function (elem, what) {
89 var rowElement = jQuery(elem).closest('tr');
90 var pageId = rowElement.find('.pageId').val();
91 var websiteId = rowElement.find('.websiteId').val();
92
93 if (rowElement.find('.allowedBulkActions').val().indexOf('|' + what + '|') == -1) {
94 jQuery(elem).removeAttr('checked');
95 countReceived++;
96
97 if (countReceived == countSent) {
98 countReceived = 0;
99 countSent = 0;
100 setTimeout(function () {
101 jQuery('#mainwp-do-pages-bulk-actions').removeAttr('disabled');
102 }, 50);
103 }
104
105 return;
106 }
107
108 var data = mainwp_secure_data({
109 action: 'mainwp_page_' + what,
110 postId: pageId,
111 websiteId: websiteId
112 });
113
114 rowElement.html('<td colspan="99"><i class="notched circle loading icon"></i> Please wait...</td>');
115 jQuery.post(ajaxurl, data, function (response) {
116 if (response.error) {
117 rowElement.html('<td colspan="99"><i class="times circle red icon"></i>' + response.error + '</td>');
118 } else if (response.result) {
119 rowElement.html('<td colspan="99"><i class="check circle green icon"></i> ' + response.result + '</td>');
120 if (jQuery(rowElement).hasClass('child')) {
121 jQuery(rowElement).prev().hide();
122 }
123 }
124 countReceived++;
125
126 if (countReceived == countSent) {
127 countReceived = 0;
128 countSent = 0;
129 jQuery('#mainwp-do-pages-bulk-actions').removeAttr('disabled');
130 }
131 }, 'json');
132
133 return false;
134 };
135
136 mainwp_fetch_pages = function () {
137 var errors = [];
138 var selected_sites = [];
139 var selected_groups = [];
140 var selected_clients = [];
141
142 if (jQuery('#select_by').val() == 'site') {
143 jQuery("input[name='selected_sites[]']:checked").each(function () {
144 selected_sites.push(jQuery(this).val());
145 });
146 if (selected_sites.length == 0) {
147 errors.push('<div class="mainwp-notice mainwp-notice-red">' + __('Please select websites or groups or clients.') + '</div>');
148 }
149 } else if( jQuery('#select_by').val() == 'client' ) {
150 jQuery("input[name='selected_clients[]']:checked").each(function () {
151 selected_clients.push(jQuery(this).val());
152 });
153 if (selected_clients.length == 0) {
154 errors.push('<div class="mainwp-notice mainwp-notice-red">' + __('Please select websites or groups or clients.') + '</div>');
155 }
156 } else {
157 jQuery("input[name='selected_groups[]']:checked").each(function () {
158 selected_groups.push(jQuery(this).val());
159 });
160 if (selected_groups.length == 0) {
161 errors.push('<div class="mainwp-notice mainwp-notice-red">' + __('Please select websites or groups or clients.') + '</div>');
162 }
163 }
164
165 var _status = '';
166 var statuses = jQuery("#mainwp_page_search_type").dropdown("get value");
167 if (statuses == null)
168 errors.push('Please select a page status.');
169 else {
170 _status = statuses.join(',');
171 }
172
173 if (errors.length > 0) {
174 jQuery('#mainwp_pages_error').html(errors.join('<br />'));
175 jQuery('#mainwp_pages_error').show();
176 return;
177 } else {
178 jQuery('#mainwp_pages_error').html("");
179 jQuery('#mainwp_pages_error').hide();
180 }
181
182 var data = mainwp_secure_data({
183 action: 'mainwp_pages_search',
184 keyword: jQuery('#mainwp_page_search_by_keyword').val(),
185 dtsstart: jQuery('#mainwp_page_search_by_dtsstart').val(),
186 dtsstop: jQuery('#mainwp_page_search_by_dtsstop').val(),
187 status: _status,
188 'groups[]': selected_groups,
189 'sites[]': selected_sites,
190 'clients[]': selected_clients,
191 maximum: jQuery("#mainwp_maximumPages").val(),
192 search_on: jQuery("#mainwp_page_search_on").val(),
193 });
194
195 jQuery('#mainwp-loading-pages-row').show();
196 jQuery.post(ajaxurl, data, function (response) {
197 response = jQuery.trim(response);
198 jQuery('#mainwp-loading-pages-row').hide();
199 jQuery('#mainwp_pages_main').show();
200 jQuery('#mainwp_pages_wrap_table').html(response);
201 // re-initialize datatable
202 jQuery("#mainwp-pages-table").DataTable().destroy();
203 jQuery('#mainwp-pages-table').DataTable({
204 "responsive": true,
205 "colReorder": {
206 fixedColumnsLeft: 1,
207 fixedColumnsRight: 1
208 },
209 "stateSave": true,
210 "pagingType": "full_numbers",
211 "scrollX": true,
212 "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
213 "order": [],
214 "columnDefs": [{
215 "targets": 'no-sort',
216 "orderable": false
217 }],
218 "preDrawCallback": function () {
219 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
220 mainwp_datatable_fix_menu_overflow();
221 }
222 });
223 });
224 };
225
226 /**
227 * MainWP_Post.page
228 */
229 var countSent = 0;
230 var countReceived = 0;
231 jQuery(document).ready(function () {
232 jQuery(document).on('click', '#mainwp_show_posts', function () {
233 mainwp_fetch_posts();
234 });
235 jQuery(document).on('click', '.post_submitdelete', function () {
236 mainwppost_postAction(jQuery(this), 'trash');
237 return false;
238 });
239 jQuery(document).on('click', '.post_submitpublish', function () {
240 mainwppost_postAction(jQuery(this), 'publish');
241 return false;
242 });
243 jQuery(document).on('click', '.post_submitunpublish', function () {
244 mainwppost_postAction(jQuery(this), 'unpublish');
245 return false;
246 });
247 jQuery(document).on('click', '.post_submitapprove', function () {
248 mainwppost_postAction(jQuery(this), 'approve');
249 return false;
250 });
251 jQuery(document).on('click', '.post_submitdelete_perm', function () {
252 mainwppost_postAction(jQuery(this), 'delete');
253 return false;
254 });
255 jQuery(document).on('click', '.post_submitrestore', function () {
256 mainwppost_postAction(jQuery(this), 'restore');
257 return false;
258 });
259
260 jQuery(document).on('click', '.post_getedit', function () {
261 mainwppost_postAction(jQuery(this), 'get_edit', 'post');
262 return false;
263 });
264
265 jQuery(document).on('click', '.page_getedit', function () {
266 mainwppost_postAction(jQuery(this), 'get_edit', 'page');
267 return false;
268 });
269
270 jQuery(document).on('click', '#mainwp-do-posts-bulk-actions', function () {
271 var action = jQuery('#mainwp-bulk-actions').val();
272 if (action != 'publish' && action != 'unpublish' && action != 'trash' && action != 'restore' && action != 'delete') {
273 return false;
274 }
275
276 var tmp = jQuery("input[name='post[]']:checked");
277 countSent = tmp.length;
278
279 if (countSent == 0)
280 return false;
281
282 var _callback = function () {
283 jQuery('#mainwp-do-posts-bulk-actions').attr('disabled', 'true');
284 tmp.each(
285 function (index, elem) {
286 mainwppost_postAction(elem, action);
287 }
288 );
289 }
290 if (action == 'delete') {
291 var msg = __('You are about to delete %1 post(s). Are you sure you want to proceed?', countSent);
292 mainwp_confirm(msg, _callback);
293 return false;
294 }
295 _callback();
296 return false;
297 });
298 });
299
300 mainwppost_postAction = function (elem, what, postType) {
301 var rowElement = jQuery(elem).closest('tr');
302 var postId = rowElement.find('.postId').val();
303 var websiteId = rowElement.find('.websiteId').val();
304 if (rowElement.find('.allowedBulkActions').val().indexOf('|' + what + '|') == -1) {
305 jQuery(elem).removeAttr('checked');
306 countReceived++;
307
308 if (countReceived == countSent) {
309 countReceived = 0;
310 countSent = 0;
311 setTimeout(function () {
312 jQuery('#mainwp-do-posts-bulk-actions').removeAttr('disabled');
313 }, 50);
314 }
315
316 return;
317 }
318
319 if ( what == 'get_edit' && postType === 'page' ) {
320 postId = rowElement.find( '.pageId' ).val();
321 }
322
323 var data = {
324 action: 'mainwp_post_' + what,
325 postId: postId,
326 websiteId: websiteId
327 };
328 if (typeof postType !== "undefined") {
329 data['postType'] = postType;
330 }
331 data = mainwp_secure_data(data);
332
333 rowElement.html('<td colspan="99"><i class="notched circle loading icon"></i> Please wait...</td>');
334 jQuery.post(ajaxurl, data, function (response) {
335 if (response.error) {
336 rowElement.html('<td colspan="99"><i class="times circle red icon"></i>' + response.error + '</td>');
337 } else if (response.result) {
338 rowElement.html('<td colspan="99"><i class="check circle green icon"></i> ' + response.result + '</td>');
339 if (jQuery(rowElement).hasClass('child')) {
340 jQuery(rowElement).prev().hide();
341 }
342 } else {
343 rowElement.hide();
344 if (what == 'get_edit' && response.id) {
345 if (postType == 'post') {
346 location.href = 'admin.php?page=PostBulkEdit&post_id=' + response.id;
347 } else if (postType == 'page') {
348 location.href = 'admin.php?page=PageBulkEdit&post_id=' + response.id;
349 }
350 }
351 }
352 countReceived++;
353 if (countReceived == countSent) {
354 countReceived = 0;
355 countSent = 0;
356 jQuery('#mainwp-do-posts-bulk-actions').removeAttr('disabled');
357 }
358 }, 'json');
359
360 return false;
361 };
362
363 mainwp_show_post = function (siteId, postId, userId) {
364 var siteElement = jQuery('input[name="selected_sites[]"][siteid="' + siteId + '"]');
365 siteElement.prop('checked', true);
366 siteElement.trigger("change");
367 mainwp_fetch_posts(postId, userId);
368 };
369 /* eslint-disable complexity */
370 mainwp_fetch_posts = function (postId, userId, start_sites) {
371 var errors = [];
372 var selected_sites = [];
373 var selected_groups = [];
374 var selected_clients = [];
375
376 var i = 0;
377 var num_sites = jQuery('#search-bulk-sites').attr('number-sites');
378 num_sites = parseInt(num_sites);
379
380 var bulk_search = num_sites > 0 ? true : false;
381
382 if (jQuery('#select_by').val() == 'site') {
383 if (start_sites == undefined) {
384 start_sites = 0;
385 }
386 jQuery("input[name='selected_sites[]']:checked").each(function () {
387 if (bulk_search) {
388 if (i >= start_sites && i < start_sites + num_sites) {
389 selected_sites.push(jQuery(this).val());
390 }
391 i++;
392 } else {
393 selected_sites.push(jQuery(this).val());
394 }
395 });
396 if (selected_sites.length == 0) {
397 if (!bulk_search || (bulk_search && start_sites == 0)) {
398 errors.push('<div class="ui yellow message">' + __('Please select at least one website or group or client.') + '</div>');
399 }
400 }
401
402 } else if (jQuery('#select_by').val() == 'client') {
403 jQuery("input[name='selected_clients[]']:checked").each(function () {
404 selected_clients.push(jQuery(this).val());
405 });
406 if (selected_clients.length == 0) {
407 errors.push('<div class="ui yellow message">' + __('Please select at least one client or website, group.') + '</div>');
408 }
409
410 } else if(jQuery('#select_by').val() == 'group' ) {
411 jQuery("input[name='selected_groups[]']:checked").each(function () {
412 selected_groups.push(jQuery(this).val());
413 });
414 if (selected_groups.length == 0) {
415 errors.push('<div class="ui yellow message">' + __('Please select at least one website or group or client.') + '</div>');
416 } else if (bulk_search) {
417
418 if (start_sites == undefined) {
419 console.log(num_sites);
420 start_sites = 0;
421 // get sites of groups.
422 var data = mainwp_secure_data({
423 action: 'mainwp_get_sites_of_groups',
424 'groups[]': selected_groups
425 });
426 jQuery('#mainwp-loading-posts-row').show();
427 jQuery.post(ajaxurl, data, function (response) {
428 var site_ids = response;
429 console.log(site_ids);
430 if (site_ids) {
431 jQuery("input[name='selected_sites[]'][bulk-search=true]").attr('bulk-search', false);
432 jQuery.each(site_ids, function (index, value) {
433 jQuery("input[name='selected_sites[]'][value=" + value + "]").attr('bulk-search', true);
434 });
435 }
436 mainwp_fetch_posts(postId, userId, start_sites);
437 }, 'json');
438 return;
439 }
440
441 console.log(jQuery("input[name='selected_sites[]'][bulk-search=true]").length);
442
443 jQuery("input[name='selected_sites[]'][bulk-search=true]").each(function () {
444 if (i >= start_sites && i < start_sites + num_sites) {
445 selected_sites.push(jQuery(this).val());
446 }
447 i++;
448 });
449 console.log(selected_sites);
450 }
451 }
452 var _status = '';
453 var statuses = jQuery("#mainwp_post_search_type").dropdown("get value");
454 if (statuses == null)
455 errors.push('<div class="ui yellow message">' + __('Please select at least one post status.') + '</div>');
456 else {
457 _status = statuses.join(',');
458 }
459
460 if (errors.length > 0) {
461 jQuery('#mainwp-message-zone').html(errors);
462 jQuery('#mainwp-message-zone').show();
463 return;
464 } else {
465 jQuery('#mainwp-message-zone').html("");
466 jQuery('#mainwp-message-zone').hide();
467 }
468
469 var data = mainwp_secure_data({
470 action: 'mainwp_posts_search',
471 keyword: jQuery('#mainwp_post_search_by_keyword').val(),
472 dtsstart: jQuery('#mainwp_post_search_by_dtsstart').val(),
473 dtsstop: jQuery('#mainwp_post_search_by_dtsstop').val(),
474 status: _status,
475 'groups[]': selected_groups,
476 'sites[]': selected_sites,
477 'clients[]': selected_clients,
478 postId: (postId == undefined ? '' : postId),
479 userId: (userId == undefined ? '' : userId),
480 post_type: jQuery("#mainwp_get_custom_post_types_select").val(),
481 maximum: jQuery("#mainwp_maximumPosts").val(),
482 search_on: jQuery("#mainwp_post_search_on").val()
483 });
484
485 if (bulk_search) {
486 if (start_sites > 0) {
487 data.table_content = 1;
488 }
489 if (selected_sites.length == 0) {
490 mainwp_fetch_posts_done();
491 return;
492 }
493 }
494
495 jQuery('#mainwp-loading-posts-row').show();
496 jQuery.post(ajaxurl, data, function (response) {
497 response = jQuery.trim(response);
498 if (bulk_search && start_sites > 0) {
499 jQuery('#mainwp-posts-list').append(response);
500 } else {
501 jQuery('#mainwp-posts-table-wrapper').html(response);
502 }
503
504 if (bulk_search) {
505 start_sites = start_sites + num_sites;
506 mainwp_fetch_posts(postId, userId, start_sites);
507 } else {
508 mainwp_fetch_posts_done();
509 }
510
511 });
512 };
513 /* eslint-enable complexity */
514
515 mainwp_fetch_posts_done = function () {
516 jQuery('#mainwp-loading-posts-row').hide();
517 jQuery('#mainwp_posts_main').show();
518 var responsive = true;
519 if( jQuery( window ).width() > 1140 ) {
520 responsive = false;
521 }
522 // re-initialize datatable.
523 jQuery("#mainwp-posts-table").DataTable().destroy();
524 jQuery('#mainwp-posts-table').DataTable({
525 "responsive": responsive,
526 "colReorder": {
527 fixedColumnsLeft: 1,
528 fixedColumnsRight: 1
529 },
530 "stateSave": true,
531 "pagingType": "full_numbers",
532 "order": [],
533 "scrollX": true,
534 "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
535 "columnDefs": [{
536 "targets": 'no-sort',
537 "orderable": false
538 }],
539 "preDrawCallback": function () {
540 jQuery('#mainwp-posts-table-wrapper table .ui.dropdown').dropdown();
541 jQuery('#mainwp-posts-table-wrapper table .ui.checkbox').checkbox();
542 mainwp_datatable_fix_menu_overflow();
543 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
544 }
545 });
546 }
547