PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0
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 5.0, at assets/js/mainwp-posts.js

548 lines 19.3 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).prop("checked", false);
95 countReceived++;
96
97 if (countReceived == countSent) {
98 countReceived = 0;
99 countSent = 0;
100 setTimeout(function () {
101 jQuery('#mainwp-do-pages-bulk-actions').prop("disabled", false);
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').prop("disabled", false);
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 = response.trim();
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).prop("checked", false);
306 countReceived++;
307
308 if (countReceived == countSent) {
309 countReceived = 0;
310 countSent = 0;
311 setTimeout(function () {
312 jQuery('#mainwp-do-posts-bulk-actions').prop("disabled", false);
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 (response.redirect_to) {
346 location.href = response.redirect_to;
347 } else if (postType == 'post') {
348 location.href = 'admin.php?page=PostBulkEdit&post_id=' + response.id;
349 } else if (postType == 'page') {
350 location.href = 'admin.php?page=PageBulkEdit&post_id=' + response.id;
351 }
352 }
353 }
354 countReceived++;
355 if (countReceived == countSent) {
356 countReceived = 0;
357 countSent = 0;
358 jQuery('#mainwp-do-posts-bulk-actions').prop("disabled", false);
359 }
360 }, 'json');
361
362 return false;
363 };
364
365 mainwp_show_post = function (siteId, postId, userId) {
366 var siteElement = jQuery('input[name="selected_sites[]"][siteid="' + siteId + '"]');
367 siteElement.prop('checked', true);
368 siteElement.trigger("change");
369 mainwp_fetch_posts(postId, userId);
370 };
371 /* eslint-disable complexity */
372 mainwp_fetch_posts = function (postId, userId, start_sites) {
373 var errors = [];
374 var selected_sites = [];
375 var selected_groups = [];
376 var selected_clients = [];
377
378 var i = 0;
379 var num_sites = jQuery('#search-bulk-sites').attr('number-sites');
380 num_sites = parseInt(num_sites);
381
382 var bulk_search = num_sites > 0 ? true : false;
383
384 if (jQuery('#select_by').val() == 'site') {
385 if (start_sites == undefined) {
386 start_sites = 0;
387 }
388 jQuery("input[name='selected_sites[]']:checked").each(function () {
389 if (bulk_search) {
390 if (i >= start_sites && i < start_sites + num_sites) {
391 selected_sites.push(jQuery(this).val());
392 }
393 i++;
394 } else {
395 selected_sites.push(jQuery(this).val());
396 }
397 });
398 if (selected_sites.length == 0) {
399 if (!bulk_search || (bulk_search && start_sites == 0)) {
400 errors.push('<div class="ui yellow message">' + __('Please select at least one website or group or client.') + '</div>');
401 }
402 }
403
404 } else if (jQuery('#select_by').val() == 'client') {
405 jQuery("input[name='selected_clients[]']:checked").each(function () {
406 selected_clients.push(jQuery(this).val());
407 });
408 if (selected_clients.length == 0) {
409 errors.push('<div class="ui yellow message">' + __('Please select at least one client or website, group.') + '</div>');
410 }
411
412 } else if (jQuery('#select_by').val() == 'group') {
413 jQuery("input[name='selected_groups[]']:checked").each(function () {
414 selected_groups.push(jQuery(this).val());
415 });
416 if (selected_groups.length == 0) {
417 errors.push('<div class="ui yellow message">' + __('Please select at least one website or group or client.') + '</div>');
418 } else if (bulk_search) {
419
420 if (start_sites == undefined) {
421 console.log(num_sites);
422 start_sites = 0;
423 // get sites of groups.
424 var data = mainwp_secure_data({
425 action: 'mainwp_get_sites_of_groups',
426 'groups[]': selected_groups
427 });
428 jQuery('#mainwp-loading-posts-row').show();
429 jQuery.post(ajaxurl, data, function (response) {
430 var site_ids = response;
431 console.log(site_ids);
432 if (site_ids) {
433 jQuery("input[name='selected_sites[]'][bulk-search=true]").attr('bulk-search', false);
434 jQuery.each(site_ids, function (index, value) {
435 jQuery("input[name='selected_sites[]'][value=" + value + "]").attr('bulk-search', true);
436 });
437 }
438 mainwp_fetch_posts(postId, userId, start_sites);
439 }, 'json');
440 return;
441 }
442
443 console.log(jQuery("input[name='selected_sites[]'][bulk-search=true]").length);
444
445 jQuery("input[name='selected_sites[]'][bulk-search=true]").each(function () {
446 if (i >= start_sites && i < start_sites + num_sites) {
447 selected_sites.push(jQuery(this).val());
448 }
449 i++;
450 });
451 }
452 }
453 var _status = '';
454 var statuses = jQuery("#mainwp_post_search_type").dropdown("get value");
455 if (statuses == null)
456 errors.push('<div class="ui yellow message">' + __('Please select at least one post status.') + '</div>');
457 else {
458 _status = statuses.join(',');
459 }
460
461 if (errors.length > 0) {
462 jQuery('#mainwp-message-zone').html(errors);
463 jQuery('#mainwp-message-zone').show();
464 return;
465 } else {
466 jQuery('#mainwp-message-zone').html("");
467 jQuery('#mainwp-message-zone').hide();
468 }
469
470 var data = mainwp_secure_data({
471 action: 'mainwp_posts_search',
472 keyword: jQuery('#mainwp_post_search_by_keyword').val(),
473 dtsstart: jQuery('#mainwp_post_search_by_dtsstart').val(),
474 dtsstop: jQuery('#mainwp_post_search_by_dtsstop').val(),
475 status: _status,
476 'groups[]': selected_groups,
477 'sites[]': selected_sites,
478 'clients[]': selected_clients,
479 postId: (postId == undefined ? '' : postId),
480 userId: (userId == undefined ? '' : userId),
481 post_type: jQuery("#mainwp_get_custom_post_types_select").val(),
482 maximum: jQuery("#mainwp_maximumPosts").val(),
483 search_on: jQuery("#mainwp_post_search_on").val()
484 });
485
486 if (bulk_search) {
487 if (start_sites > 0) {
488 data.table_content = 1;
489 }
490 if (selected_sites.length == 0) {
491 mainwp_fetch_posts_done();
492 return;
493 }
494 }
495
496 jQuery('#mainwp-loading-posts-row').show();
497 jQuery.post(ajaxurl, data, function (response) {
498 response = response.trim();
499 if (bulk_search && start_sites > 0) {
500 jQuery('#mainwp-posts-list').append(response);
501 } else {
502 jQuery('#mainwp-posts-table-wrapper').html(response);
503 }
504
505 if (bulk_search) {
506 start_sites = start_sites + num_sites;
507 mainwp_fetch_posts(postId, userId, start_sites);
508 } else {
509 mainwp_fetch_posts_done();
510 }
511
512 });
513 };
514 /* eslint-enable complexity */
515
516 mainwp_fetch_posts_done = function () {
517 jQuery('#mainwp-loading-posts-row').hide();
518 jQuery('#mainwp_posts_main').show();
519 var responsive = true;
520 if (jQuery(window).width() > 1140) {
521 responsive = false;
522 }
523 // re-initialize datatable.
524 jQuery("#mainwp-posts-table").DataTable().destroy();
525 jQuery('#mainwp-posts-table').DataTable({
526 "responsive": responsive,
527 "colReorder": {
528 fixedColumnsLeft: 1,
529 fixedColumnsRight: 1
530 },
531 "stateSave": true,
532 "pagingType": "full_numbers",
533 "order": [],
534 "scrollX": true,
535 "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
536 "columnDefs": [{
537 "targets": 'no-sort',
538 "orderable": false
539 }],
540 "preDrawCallback": function () {
541 jQuery('#mainwp-posts-table-wrapper table .ui.dropdown').dropdown();
542 jQuery('#mainwp-posts-table-wrapper table .ui.checkbox').checkbox();
543 mainwp_datatable_fix_menu_overflow();
544 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
545 }
546 });
547 }
548