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