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

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