| 1 |
<?php |
| 2 |
/** |
| 3 |
* Declare view-js.php file |
| 4 |
* |
| 5 |
* @package view-js |
| 6 |
*/ |
| 7 |
|
| 8 |
?> |
| 9 |
<script> |
| 10 |
let interval_timeout_init = 10; |
| 11 |
let init_handle = setInterval(function () { |
| 12 |
// Check lasso_helper load already. |
| 13 |
if ( typeof lasso_lite_helper != "undefined") { |
| 14 |
// Clearing the interval. |
| 15 |
clearInterval(init_handle); |
| 16 |
// Call the initializing function init_lasso_view |
| 17 |
init_lasso_view(); |
| 18 |
} |
| 19 |
}, interval_timeout_init); |
| 20 |
|
| 21 |
/** |
| 22 |
* Init init_lasso_view |
| 23 |
*/ |
| 24 |
function init_lasso_view () { |
| 25 |
var monetize_id; |
| 26 |
jQuery(document).ready(function() { |
| 27 |
// At the begin, if search parameter available, set this value to search input |
| 28 |
let search_parameter = lasso_lite_helper.get_url_parameter( 'search' ); |
| 29 |
|
| 30 |
if ( search_parameter ) { |
| 31 |
jQuery('#search-links input').val( search_parameter ); |
| 32 |
} |
| 33 |
|
| 34 |
// Form submit disabled |
| 35 |
jQuery('form').submit(function() { |
| 36 |
return false; |
| 37 |
}); |
| 38 |
|
| 39 |
// ************************* |
| 40 |
// Pagination |
| 41 |
// ************************* |
| 42 |
var container = jQuery('#report-content'); |
| 43 |
var pagination = jQuery('.pagination'); |
| 44 |
var search_term = "<?php echo esc_js($_GET['search'] ?? ''); // phpcs:ignore ?>"; |
| 45 |
var tab_filter = "<?php echo esc_js( $_GET['filter'] ?? '' ) ; // phpcs:ignore ?>"; |
| 46 |
var url_page_number = lasso_lite_helper.get_page_from_current_url(); |
| 47 |
var limit = 10; |
| 48 |
|
| 49 |
function full_list_paginate(set_page) { |
| 50 |
lasso_lite_helper.set_pagination_cache(lasso_lite_helper.get_page_name(), set_page); |
| 51 |
|
| 52 |
var data = { |
| 53 |
items: jQuery('#total-posts').val(), |
| 54 |
displayedPages: 3, |
| 55 |
itemsOnPage: limit, |
| 56 |
cssStyle: 'light-theme', |
| 57 |
prevText: '<i class="far fa-angle-double-left"></i> Previous', |
| 58 |
nextText: 'Next <i class="far fa-angle-double-right"></i>', |
| 59 |
onPageClick: function(pageNumber, event) { |
| 60 |
var sortable = jQuery('.sortable-col.active'); |
| 61 |
var orderBy = ''; |
| 62 |
var orderType = ''; |
| 63 |
if(sortable) { |
| 64 |
orderBy = sortable.attr('data-order-by'); |
| 65 |
orderType = sortable.attr('data-order-type'); |
| 66 |
} |
| 67 |
|
| 68 |
lasso_lite_helper.set_pagination_cache(lasso_lite_helper.get_page_name(), pageNumber); |
| 69 |
lasso_lite_helper.remove_page_number_out_of_url(); |
| 70 |
|
| 71 |
if(['asc', 'desc'].includes(orderType) && orderBy !== '') { |
| 72 |
get_data_via_ajax(pageNumber, limit, orderBy, orderType); |
| 73 |
} else { |
| 74 |
get_data_via_ajax(pageNumber, limit); |
| 75 |
} |
| 76 |
} |
| 77 |
}; |
| 78 |
|
| 79 |
if(set_page > 0) { |
| 80 |
data.currentPage = set_page; |
| 81 |
} |
| 82 |
pagination.pagination(data); |
| 83 |
|
| 84 |
return pagination; |
| 85 |
} |
| 86 |
full_list_paginate(); |
| 87 |
|
| 88 |
// ************************* |
| 89 |
// Search |
| 90 |
// ************************* |
| 91 |
// Action when click search button |
| 92 |
jQuery('#search-icon').unbind().click(function(){ |
| 93 |
get_data_via_ajax(1, limit); |
| 94 |
}); |
| 95 |
|
| 96 |
// TYPE TO ADD TAGS TO SEARCH BAR |
| 97 |
jQuery('#search-links input').off('focusout'); |
| 98 |
jQuery('#search-links input') |
| 99 |
.on('focusout', function() { |
| 100 |
if(this) { |
| 101 |
var txt = this.value.replace(/[^a-zA-Z0-9\+\-\.\#]/g,' '); |
| 102 |
search_term = txt.trim(); |
| 103 |
} |
| 104 |
}) |
| 105 |
.on('keyup', function( e ) { |
| 106 |
// WHEN ENTER IS PRESSED, SEARCH |
| 107 |
if(e.which == 13) { |
| 108 |
jQuery(this).focusout(); |
| 109 |
lasso_lite_helper.clear_notifications(); |
| 110 |
lasso_lite_helper.remove_page_number_out_of_url(); |
| 111 |
get_data_via_ajax(1, limit); |
| 112 |
} |
| 113 |
}); |
| 114 |
|
| 115 |
// ************************* |
| 116 |
// Main Report Generation |
| 117 |
// ************************* |
| 118 |
|
| 119 |
// Get full url data via ajax |
| 120 |
function get_data_via_ajax(page, limit, order_by = undefined, order_type = undefined, container_name = '') { |
| 121 |
var link_type = '<?php echo $page; // phpcs:ignore ?>'; |
| 122 |
var t0 = performance.now(); |
| 123 |
var no_field_ids = []; |
| 124 |
|
| 125 |
// Push search to url parameter |
| 126 |
lasso_lite_helper.update_url_parameter('search', search_term); |
| 127 |
|
| 128 |
// Apply filter import plugin |
| 129 |
tab_filter = lasso_lite_helper.get_url_parameter( 'filter' ); |
| 130 |
container = jQuery('#report-content'); |
| 131 |
|
| 132 |
jQuery.ajax({ |
| 133 |
url: lassoLiteOptionsData.ajax_url, |
| 134 |
type: 'post', |
| 135 |
data: { |
| 136 |
action: 'lasso_lite_import', |
| 137 |
nonce: lassoLiteOptionsData.optionsNonce, |
| 138 |
post_id: '<?php echo esc_js( $_GET['post_id'] ?? '' ); // phpcs:ignore ?>', |
| 139 |
link_type: link_type, |
| 140 |
pageNumber: page, |
| 141 |
pageSize: limit, |
| 142 |
order_by: order_by, |
| 143 |
order_type: order_type, |
| 144 |
search: search_term, |
| 145 |
keyword: '<?php echo esc_js( $_GET['keyword'] ?? '' ); // phpcs:ignore ?>', |
| 146 |
filter: tab_filter, |
| 147 |
no_field_ids: no_field_ids |
| 148 |
}, |
| 149 |
beforeSend: function() { |
| 150 |
if(tab_filter != 'url-details') { |
| 151 |
// Loading image |
| 152 |
container.html(lasso_lite_helper.get_loading_image()); |
| 153 |
} |
| 154 |
|
| 155 |
if( -1 === jQuery.inArray(tab_filter, [ "opportunities", "out-of-stock", "broken-links" ] ) ) { |
| 156 |
tab_filter = ''; |
| 157 |
} |
| 158 |
pagination.pagination('disable'); |
| 159 |
} |
| 160 |
}) |
| 161 |
.done(function(response) { |
| 162 |
var t1 = performance.now(); |
| 163 |
// console.log("Query response took " + (t1 - t0) + " milliseconds."); |
| 164 |
if(response.success) { |
| 165 |
var post = response.data.post; |
| 166 |
var responseData = response.data; |
| 167 |
var order_icon = (post.order_type == 'asc') ? ' <i class="fas fa-caret-up green"></i> ': ' <i class="fas fa-caret-down green"></i> '; |
| 168 |
jQuery('table > thead').find('i').remove(); |
| 169 |
jQuery('table > thead').find('th[order-by="' + post.order_by + '"]') |
| 170 |
.attr('order-type', post.order_type).append(order_icon); |
| 171 |
|
| 172 |
var html = get_html(responseData.data, post); |
| 173 |
container.html(html); |
| 174 |
|
| 175 |
jQuery('.subsubsub').find('li.active').find('span').text(responseData.total.total); |
| 176 |
jQuery('#total-posts').val(responseData.total.total); |
| 177 |
if(jQuery("#js-report-result").length != 0) { |
| 178 |
jQuery('#js-report-result').html(responseData.total.total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " Found"); |
| 179 |
} |
| 180 |
|
| 181 |
// import view popup |
| 182 |
init_import_events(); |
| 183 |
render_filter_plugin_select(responseData.total.plugins); |
| 184 |
} else { |
| 185 |
container.html('Failed to load data.'); |
| 186 |
} |
| 187 |
}) |
| 188 |
.fail(function(xhr) { |
| 189 |
container.html('Failed to load data.'); |
| 190 |
}) |
| 191 |
.always(function(res) { |
| 192 |
var page = res && 'object' === typeof res && 'data' in res ? res.data.page : 1; |
| 193 |
|
| 194 |
// Don't change pagination if get custom fields of Lasso url |
| 195 |
if(container_name != 'custom-fields') { |
| 196 |
full_list_paginate(page); |
| 197 |
} |
| 198 |
|
| 199 |
pagination.pagination('enable'); |
| 200 |
}); |
| 201 |
} |
| 202 |
|
| 203 |
// Initial get data |
| 204 |
get_data_via_ajax(url_page_number, limit, undefined, undefined, ''); |
| 205 |
|
| 206 |
// Get html for full url data |
| 207 |
function get_html(data, post) { |
| 208 |
var html = ''; |
| 209 |
var default_image = ''; |
| 210 |
if(data.length > 0) { |
| 211 |
for (let index = 0; index < data.length; index++) { |
| 212 |
const element = data[index]; |
| 213 |
var collapse_id = index; |
| 214 |
var icon = (element.count > 0) ? '<i class="fas fa-caret-down green"></i>' : ''; |
| 215 |
var image_url = (!element.thumbnail) ? default_image : element.thumbnail; |
| 216 |
var image = `<img alt="${ element.post_title }" src="${ image_url }" loading="lazy" class="rounded border" width="50" height="50" />`; |
| 217 |
var display_type = 'text-link'; |
| 218 |
var type = `<a class="lasso-list-btn">${ element.type }</a>`; |
| 219 |
var status = `<a class="lasso-list-btn">${ element.status }</a>`; |
| 220 |
var create_link = `<a href="${ element.link_slug }" target="_blank" class="pl-2"><i class="far fa-external-link-alt green"></i></a><a class="trash-lasso-modal pl-2" href="#"><i class="far fa-trash-alt red"></i></a>`; |
| 221 |
var link_count = parseInt(element.count); |
| 222 |
var toggle_checked = element.link_report_color == 'green' ? 'checked' : ''; |
| 223 |
|
| 224 |
html += `<?php include SIMPLE_URLS_DIR . '/admin/views/rows/import-url.php'; ?>`; |
| 225 |
} |
| 226 |
} else { |
| 227 |
jQuery('#js-report-result').html("0 Found"); |
| 228 |
|
| 229 |
html = lasso_lite_helper.empty_html(); |
| 230 |
} |
| 231 |
|
| 232 |
return html; |
| 233 |
} |
| 234 |
|
| 235 |
// ************************* |
| 236 |
// Import Page |
| 237 |
// ************************* |
| 238 |
jQuery(document) |
| 239 |
.on('change', '#filter-plugin', filter_import_plugin_change); |
| 240 |
|
| 241 |
function filter_import_plugin_change() { |
| 242 |
var selected_value = jQuery(this).val(); |
| 243 |
|
| 244 |
lasso_lite_helper.update_url_parameter('filter', selected_value); // Push filter to url parameter |
| 245 |
lasso_lite_helper.clear_notifications(); |
| 246 |
lasso_lite_helper.remove_page_number_out_of_url(); |
| 247 |
get_data_via_ajax(1, limit); |
| 248 |
} |
| 249 |
|
| 250 |
function render_filter_plugin_select(plugins) { |
| 251 |
var filter_plugin_select = jQuery('#filter-plugin'); |
| 252 |
var options = '<option value="">All Plugins</option>'; |
| 253 |
|
| 254 |
plugins.forEach(function(plugin_source) { |
| 255 |
var selected = plugin_source == lasso_lite_helper.get_url_parameter( 'filter' ) ? 'selected' : ''; |
| 256 |
options += '<option '+ selected +' value="' + plugin_source + '">' + plugin_source + '</option>'; |
| 257 |
}); |
| 258 |
|
| 259 |
filter_plugin_select.html(options); |
| 260 |
} |
| 261 |
}); |
| 262 |
} |
| 263 |
</script> |
| 264 |
|