| 1 |
/** |
| 2 |
* Javascript code needed to build tables in WordPress with jQuery DataTables. |
| 3 |
* |
| 4 |
* @author Peter Schulz |
| 5 |
* @since 1.0.0 |
| 6 |
*/ |
| 7 |
|
| 8 |
if (typeof Object.assign != 'function') { |
| 9 |
// IE |
| 10 |
Object.assign = function(target, varArgs) { // .length of function is 2 |
| 11 |
'use strict'; |
| 12 |
var to = Object(target); |
| 13 |
for (var index = 1; index < arguments.length; index++) { |
| 14 |
var nextSource = arguments[index]; |
| 15 |
if (nextSource != null) { // Skip over if undefined or null |
| 16 |
for (var nextKey in nextSource) { |
| 17 |
// Avoid bugs when hasOwnProperty is shadowed |
| 18 |
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { |
| 19 |
to[nextKey] = nextSource[nextKey]; |
| 20 |
} |
| 21 |
} |
| 22 |
} |
| 23 |
} |
| 24 |
return to; |
| 25 |
}; |
| 26 |
} |
| 27 |
|
| 28 |
function wpda_datatables_ajax_call( |
| 29 |
columnsvar, database, table_name, columns, |
| 30 |
responsive, responsive_popup_title, responsive_type, responsive_icon, |
| 31 |
language, sql_orderby, |
| 32 |
table_options_searching, table_options_ordering, table_options_paging, table_options_advanced, |
| 33 |
pub_id, pub_show_advanced_settings, modal_hyperlinks, |
| 34 |
filter_field_name, filter_field_value, |
| 35 |
nl2br, buttons, read_more, calc_estimate, geo_search, geo_search_options, |
| 36 |
wpnonce, pub_id_seq |
| 37 |
) { |
| 38 |
/* |
| 39 |
* display possible values: |
| 40 |
* childrow = user toggled |
| 41 |
* childrowimmediate = show |
| 42 |
* modal = show details in modal window |
| 43 |
*/ |
| 44 |
|
| 45 |
/* |
| 46 |
* type possible values: |
| 47 |
* column = no control element |
| 48 |
* inline = show control element |
| 49 |
*/ |
| 50 |
|
| 51 |
var show_more_text = 'SHOW MORE'; |
| 52 |
var end_of_list_text = 'END OF LIST'; |
| 53 |
if ( |
| 54 |
table_options_advanced !== null && |
| 55 |
table_options_advanced.show_more_text !== undefined |
| 56 |
) { |
| 57 |
show_more_text = table_options_advanced.show_more_text |
| 58 |
} |
| 59 |
if ( |
| 60 |
table_options_advanced !== null && |
| 61 |
table_options_advanced.end_of_list_text !== undefined |
| 62 |
) { |
| 63 |
end_of_list_text = table_options_advanced.end_of_list_text |
| 64 |
} |
| 65 |
|
| 66 |
var responsive_control_type = "inline"; |
| 67 |
if (responsive_icon !== "yes") { |
| 68 |
responsive_control_type = "column"; |
| 69 |
} |
| 70 |
|
| 71 |
var childrow = { |
| 72 |
details: { |
| 73 |
display: jQuery.fn.dataTable.Responsive.display.childRow, |
| 74 |
renderer: function (api, rowIdx, columns) { |
| 75 |
var data = jQuery.map( |
| 76 |
columns, function (col, i) { |
| 77 |
if (!col.hidden ) { |
| 78 |
return ''; |
| 79 |
} |
| 80 |
if (columnsvar[i].className==='wpda_select') { |
| 81 |
return ''; |
| 82 |
} |
| 83 |
if (pub_show_advanced_settings==='Never' && modal_hyperlinks.includes(i)) { |
| 84 |
return ''; |
| 85 |
} |
| 86 |
if (pub_show_advanced_settings==='If not listed' && modal_hyperlinks.includes(i) && !col.hidden) { |
| 87 |
return ''; |
| 88 |
} |
| 89 |
return '<tr class="' + columnsvar[i].className + '">' + |
| 90 |
'<td class="wpda-child-label">' + columnsvar[i].label + '</td>' + |
| 91 |
'<td class="wpda-child-value">' + col.data + '</td>' + |
| 92 |
'</tr>'; |
| 93 |
} |
| 94 |
).join( '' ); |
| 95 |
var datatable = '<table class="wpda-child-table display dataTable">' + data + '</table>'; |
| 96 |
var table = '<tr><td>' + datatable + '</td></tr>'; |
| 97 |
|
| 98 |
return jQuery( '<table class="wpda-child-expanded"/>' ).append( table ); |
| 99 |
}, |
| 100 |
type: responsive_control_type |
| 101 |
} |
| 102 |
}; |
| 103 |
|
| 104 |
var childrowimmediate = { |
| 105 |
details: { |
| 106 |
display: jQuery.fn.dataTable.Responsive.display.childRowImmediate, |
| 107 |
renderer: function (api, rowIdx, columns) { |
| 108 |
var data = jQuery.map( |
| 109 |
columns, function (col, i) { |
| 110 |
if (!col.hidden ) { |
| 111 |
return ''; |
| 112 |
} |
| 113 |
if (columnsvar[i].className==='wpda_select') { |
| 114 |
return ''; |
| 115 |
} |
| 116 |
if (pub_show_advanced_settings==='Never' && modal_hyperlinks.includes(i)) { |
| 117 |
return ''; |
| 118 |
} |
| 119 |
if (pub_show_advanced_settings==='If not listed' && modal_hyperlinks.includes(i) && !col.hidden) { |
| 120 |
return ''; |
| 121 |
} |
| 122 |
return '<tr class="' + columnsvar[i].className + '">' + |
| 123 |
'<td class="wpda-child-label">' + columnsvar[i].label + '</td>' + |
| 124 |
'<td class="wpda-child-value">' + col.data + '</td>' + |
| 125 |
'</tr>'; |
| 126 |
} |
| 127 |
).join( '' ); |
| 128 |
var datatable = '<table class="wpda-child-table display dataTable">' + data + '</table>'; |
| 129 |
var table = '<tr><td>' + datatable + '</td></tr>'; |
| 130 |
|
| 131 |
return jQuery( '<table class="wpda-child-expanded"/>' ).append( table ); |
| 132 |
}, |
| 133 |
type: responsive_control_type |
| 134 |
} |
| 135 |
}; |
| 136 |
|
| 137 |
var modal = { |
| 138 |
details: { |
| 139 |
display: jQuery.fn.dataTable.Responsive.display.modal( |
| 140 |
{ |
| 141 |
header: function (row) { |
| 142 |
if (table_options_advanced.css_classes) { |
| 143 |
return "<span class='" + table_options_advanced.css_classes + "'>" + responsive_popup_title + "</span>"; |
| 144 |
} else { |
| 145 |
return responsive_popup_title; |
| 146 |
} |
| 147 |
}, |
| 148 |
modal: { |
| 149 |
modal: true, |
| 150 |
draggable: false, |
| 151 |
resizable: false, |
| 152 |
width: "fit-content", |
| 153 |
position: { |
| 154 |
my: "left top", |
| 155 |
at: "left bottom" |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
), |
| 160 |
renderer: function (api, rowIdx, columns) { |
| 161 |
let data = jQuery.map( |
| 162 |
columns, function (col, i) { |
| 163 |
if (columnsvar[i].className==='wpda_select') { |
| 164 |
return ''; |
| 165 |
} |
| 166 |
if (pub_show_advanced_settings==='Never' && modal_hyperlinks.includes(i)) { |
| 167 |
return ''; |
| 168 |
} |
| 169 |
if (pub_show_advanced_settings==='If not listed' && modal_hyperlinks.includes(i) && !col.hidden) { |
| 170 |
return ''; |
| 171 |
} |
| 172 |
let html = |
| 173 |
`<tr class="${columnsvar[i].className}"> |
| 174 |
<td class="wpda-child-label">${columnsvar[i].label}</td> |
| 175 |
<td class="wpda-child-value">${col.data}</td> |
| 176 |
</tr>`; |
| 177 |
return html; |
| 178 |
} |
| 179 |
).join( '' ); |
| 180 |
if (table_options_advanced.primary_css_classes!==undefined) { |
| 181 |
cssClasses = table_options_advanced.primary_css_classes; |
| 182 |
} else { |
| 183 |
cssClasses = ""; |
| 184 |
if (window.top['wpda_publication_primary_css_classes']!==undefined) { |
| 185 |
// CSS added from style manager. |
| 186 |
cssClasses = window.top['wpda_publication_primary_css_classes']; |
| 187 |
} |
| 188 |
} |
| 189 |
let modalClasses = `wpda-child-table display dataTable ${cssClasses}`; |
| 190 |
let modalButtonClasses = "button dtr-modal-close"; |
| 191 |
if (jQueryDataTablesDefaultOptions.wpda_styling==="jqueryui") { |
| 192 |
modalClasses = "ui-widget-content"; |
| 193 |
modalButtonClasses = "ui-button fg-button uit-state-default wpda-close-button"; |
| 194 |
} |
| 195 |
if ( |
| 196 |
table_options_advanced.primary_add_modal_header===true || |
| 197 |
window.top['wpda_publication_primary_css_classes']!==undefined |
| 198 |
) { |
| 199 |
data = |
| 200 |
`<thead><tr><td> </td><td> </td></tr></tr></thead> |
| 201 |
${data} |
| 202 |
<tfoot><tr><td> </td><td> </td></tr></tr></tfoot>`; |
| 203 |
} |
| 204 |
let datatable = `<table class="${modalClasses}">${data}</table>`; |
| 205 |
let label = "Close"; |
| 206 |
if (api.settings()[0]?.oLanguage?.editor?.close!==undefined) { |
| 207 |
label = api.settings()[0]?.oLanguage.editor.close; |
| 208 |
} |
| 209 |
var footer = |
| 210 |
`<tr><td><div class="wpda-modal-footer"> |
| 211 |
<input type="button" value="${label}" class="${modalButtonClasses}" onclick="jQuery('.dtr-modal').remove()"/> |
| 212 |
</div></td></tr>`; |
| 213 |
var table = |
| 214 |
`<tr><td>${datatable}</td></tr>${footer}`; |
| 215 |
|
| 216 |
return jQuery( '<table class="wpda-child-modal ' + cssClasses + '"/>' ).append( table ); |
| 217 |
}, |
| 218 |
type: responsive_control_type |
| 219 |
} |
| 220 |
}; |
| 221 |
|
| 222 |
var responsive_value = false; |
| 223 |
if (responsive === 'yes') { |
| 224 |
switch (responsive_type) { |
| 225 |
case "modal": |
| 226 |
responsive_value = modal; |
| 227 |
break; |
| 228 |
case "expanded": |
| 229 |
responsive_value = childrowimmediate; |
| 230 |
break; |
| 231 |
default: |
| 232 |
/* collapsed */ |
| 233 |
responsive_value = childrow; |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
orderby = []; |
| 238 |
if ( sql_orderby != '') { |
| 239 |
sql_orderby.split("|").forEach(function (item) { |
| 240 |
orderby_array = item.split(","); |
| 241 |
orderby.push(orderby_array); |
| 242 |
}); |
| 243 |
} |
| 244 |
|
| 245 |
var jQueryDataTablesUserOptions = { |
| 246 |
searching: table_options_searching, |
| 247 |
ordering: table_options_ordering, |
| 248 |
paging: table_options_paging |
| 249 |
}; |
| 250 |
if (!table_options_paging) { |
| 251 |
jQueryDataTablesUserOptions.serverSide = false; |
| 252 |
} |
| 253 |
|
| 254 |
// Allow user to use more button to load additional rows |
| 255 |
var more_rows = []; |
| 256 |
var more_start = 0; |
| 257 |
var more_limit = 10; |
| 258 |
var more_new = true; |
| 259 |
|
| 260 |
// Prevent counting on each request to improve performance |
| 261 |
var wpda_paginationButtonPressed = false; |
| 262 |
|
| 263 |
if (table_options_advanced!==null && table_options_advanced.pageLength!==undefined && !isNaN(table_options_advanced.pageLength)) { |
| 264 |
more_limit = table_options_advanced.pageLength; |
| 265 |
} |
| 266 |
|
| 267 |
if ( |
| 268 |
table_options_advanced!==null && |
| 269 |
( |
| 270 |
table_options_advanced.wpda_use_estimates_only===true || |
| 271 |
table_options_advanced.wpda_use_estimates_only==="true" |
| 272 |
) |
| 273 |
) { |
| 274 |
table_options_advanced.pagingType = "simple_numbers"; |
| 275 |
jQuery.fn.DataTable.ext.pager.numbers_length = 7; |
| 276 |
} |
| 277 |
|
| 278 |
var jQueryDataTablesDefaultOptions = { |
| 279 |
responsive: responsive_value, |
| 280 |
processing: true, |
| 281 |
serverSide: true, |
| 282 |
stateSave: false, |
| 283 |
bAutoWidth: false, |
| 284 |
columnDefs: columnsvar, |
| 285 |
order: orderby, |
| 286 |
buttons: buttons, |
| 287 |
searchBuilder: { |
| 288 |
enterSearch: true, |
| 289 |
depthLimit: 2 |
| 290 |
}, |
| 291 |
ajax: { |
| 292 |
method: "POST", |
| 293 |
url: wpda_publication_vars.wpda_ajaxurl, |
| 294 |
data: function(data, event) { |
| 295 |
data.action ="wpda_datatables"; |
| 296 |
data.wpnonce = wpnonce; |
| 297 |
data.pubid = pub_id; |
| 298 |
if (pub_id=='0') { |
| 299 |
// For backward compatibility |
| 300 |
data.wpdasrc = database; |
| 301 |
data.wpdatabs = table_name; |
| 302 |
data.wpdacols = columns; |
| 303 |
} |
| 304 |
data.filter_field_name = filter_field_name; |
| 305 |
data.filter_field_value = filter_field_value; |
| 306 |
data.nl2br = nl2br; |
| 307 |
if (table_options_advanced!==null && table_options_advanced.wpda_use_estimates_only!==undefined) { |
| 308 |
data.wpda_use_estimates_only = table_options_advanced.wpda_use_estimates_only; |
| 309 |
} |
| 310 |
if (read_more==="true") { |
| 311 |
if (more_new) { |
| 312 |
more_start = 0; |
| 313 |
} else { |
| 314 |
more_start += more_limit; |
| 315 |
} |
| 316 |
data.more_start = more_start; |
| 317 |
data.more_limit = more_limit; |
| 318 |
} |
| 319 |
jQuery.each(window.location.search.replace('?','').split('&'), function(index, val) { |
| 320 |
var urlparam = val.split('='); |
| 321 |
if (urlparam.length===2) { |
| 322 |
if (urlparam[0].substring(0, 19) === 'wpda_search_column_') { |
| 323 |
urlParameterValue = urlparam[1].toString().replace(/%/g, "%25") |
| 324 |
urlParameterValue = urlParameterValue.replace(/%2525/g, "%25") |
| 325 |
data[urlparam[0]] = decodeURIComponent(urlParameterValue); |
| 326 |
} |
| 327 |
} |
| 328 |
}); |
| 329 |
var wpda_post_vars_name = table_name + "_" + pub_id + "_args"; |
| 330 |
if (window[wpda_post_vars_name] && Array.isArray(window[wpda_post_vars_name])) { |
| 331 |
for (let i=0; i<window[wpda_post_vars_name].length; i++) { |
| 332 |
for (var key in window[wpda_post_vars_name][i]) { |
| 333 |
if (key.substring(0, 19) === 'wpda_search_column_') { |
| 334 |
data[key] = window[wpda_post_vars_name][i][key]; |
| 335 |
} |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
// Add GET Params |
| 340 |
var wpda_url_get_params = table_name + "_" + pub_id + "_gets"; |
| 341 |
if (window[wpda_url_get_params] && Array.isArray(window[wpda_url_get_params])) { |
| 342 |
for (let i=0; i<window[wpda_url_get_params].length; i++) { |
| 343 |
for (var key in window[wpda_url_get_params][i]) { |
| 344 |
if (!data["get"]) { |
| 345 |
data["get"] = {}; |
| 346 |
} |
| 347 |
data["get"][key] = window[wpda_url_get_params][i][key]; |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
// Add POST Params |
| 352 |
var wpda_url_post_params = table_name + "_" + pub_id + "_posts"; |
| 353 |
if (window[wpda_url_post_params] && Array.isArray(window[wpda_url_post_params])) { |
| 354 |
for (let i=0; i<window[wpda_url_post_params].length; i++) { |
| 355 |
for (var key in window[wpda_url_post_params][i]) { |
| 356 |
if (!data["post"]) { |
| 357 |
data["post"] = {}; |
| 358 |
} |
| 359 |
data["post"][key] = window[wpda_url_post_params][i][key]; |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
var function_name = 'wpda_' + table_name + '_advanced_' + pub_id; |
| 364 |
if (typeof window[function_name] === "function") { |
| 365 |
var return_value = window[function_name](); |
| 366 |
if (Array.isArray(return_value)) { |
| 367 |
for (var key in return_value) { |
| 368 |
data[key] = return_value[key]; |
| 369 |
} |
| 370 |
} |
| 371 |
} |
| 372 |
if ( |
| 373 |
window['detailQuery']!==undefined && |
| 374 |
Array.isArray(window['detailQuery']) && |
| 375 |
window['detailQuery'].tableId===table_name+pub_id |
| 376 |
) { |
| 377 |
for (let i=0; i<window['detailQuery'].length; i++) { |
| 378 |
if ( |
| 379 |
window['detailQuery'][i].key!==undefined && |
| 380 |
window['detailQuery'][i].val!==undefined |
| 381 |
) { |
| 382 |
data[window['detailQuery'][i].key] = window['detailQuery'][i].val; |
| 383 |
} |
| 384 |
} |
| 385 |
} |
| 386 |
if (geo_search!=='') { |
| 387 |
if ( |
| 388 |
table_options_advanced.wpda_geo && |
| 389 |
table_options_advanced.wpda_geo.map_location==="user" |
| 390 |
) { |
| 391 |
map_location = "user"; |
| 392 |
if ( wpda_user_coords !== null ) { |
| 393 |
initial_lat = wpda_user_coords.latitude; |
| 394 |
initial_lng = wpda_user_coords.longitude; |
| 395 |
} else { |
| 396 |
initial_lat = undefined; |
| 397 |
initial_lng = undefined; |
| 398 |
} |
| 399 |
} else { |
| 400 |
map_location = "fixed"; |
| 401 |
initial_lat = geo_search_options.initial_lat; |
| 402 |
initial_lng = geo_search_options.initial_lng; |
| 403 |
} |
| 404 |
radius = geo_search_options.radius; |
| 405 |
if (jQuery("#" + table_name + pub_id + "_georange").val()) { |
| 406 |
radius = jQuery("#" + table_name + pub_id + "_georange").val(); |
| 407 |
} |
| 408 |
unit = geo_search_options.unit; |
| 409 |
if (jQuery("#" + table_name + pub_id + "_geounits").val()) { |
| 410 |
unit = jQuery("#" + table_name + pub_id + "_geounits").val(); |
| 411 |
} |
| 412 |
geosearch = { |
| 413 |
map_location: map_location, |
| 414 |
initial_lat: initial_lat, |
| 415 |
initial_lng: initial_lng, |
| 416 |
radius: radius, |
| 417 |
unit: unit |
| 418 |
} |
| 419 |
data.geosearch = geosearch; |
| 420 |
} |
| 421 |
|
| 422 |
// Prevent counting on each request to improve performance |
| 423 |
let table = jQuery("#" + table_name + pub_id + pub_id_seq).DataTable(); |
| 424 |
if (table.ajax.json()) { |
| 425 |
data.records_total = table.ajax.json().recordsTotal; |
| 426 |
if (wpda_paginationButtonPressed) { |
| 427 |
data.records_filtered = table.ajax.json().recordsFiltered; |
| 428 |
} |
| 429 |
} |
| 430 |
wpda_paginationButtonPressed = false; |
| 431 |
|
| 432 |
// console.log(data); |
| 433 |
}, |
| 434 |
dataSrc: function(data) { |
| 435 |
if (read_more==="true") { |
| 436 |
if (data.data.length<more_limit) { |
| 437 |
jQuery("#" + table_name + pub_id + "_more_button").prop('disabled', true).html(end_of_list_text); |
| 438 |
} else { |
| 439 |
jQuery("#" + table_name + pub_id + "_more_button").prop('disabled', false).html(show_more_text); |
| 440 |
} |
| 441 |
if (more_new) { |
| 442 |
more_rows = data.data; |
| 443 |
} else { |
| 444 |
more_rows = more_rows.concat(data.data); |
| 445 |
} |
| 446 |
more_new = true; |
| 447 |
|
| 448 |
return more_rows; |
| 449 |
} |
| 450 |
|
| 451 |
return data.data; |
| 452 |
} |
| 453 |
}, |
| 454 |
infoCallback: function( settings, start, end, max, total, pre ) { |
| 455 |
if (read_more==="true") { |
| 456 |
if (jQueryDataTablesDefaultOptions.wpda_search_more_info) { |
| 457 |
return jQueryDataTablesDefaultOptions |
| 458 |
.wpda_search_more_info |
| 459 |
.replaceAll("_START_", start) |
| 460 |
.replaceAll("_END_", end) |
| 461 |
.replaceAll("_MAX_", max) |
| 462 |
.replaceAll("_TOTAL_", total); |
| 463 |
} else { |
| 464 |
return end + " rows selected (from " + total + " entries)"; |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
return (calc_estimate === 'true' ? '~' : '') + pre; |
| 469 |
}, |
| 470 |
initComplete: function(settings, json) { |
| 471 |
if (jQueryDataTablesDefaultOptions.wpda_styling==="jqueryui") { |
| 472 |
jQuery("#" + table_name + pub_id + pub_id_seq + "_wrapper .dt-button").removeClass("dt-button").addClass("fg-button ui-button ui-state-default"); |
| 473 |
jQuery("#" + table_name + pub_id + pub_id_seq + "_wrapper .wpda_search_textbox").css("background-color", "transparent").css("color", "inherit"); |
| 474 |
} |
| 475 |
if (jQueryDataTablesDefaultOptions.wpda_geo) { |
| 476 |
if ( jQueryDataTablesDefaultOptions.wpda_geo.map_location==="user" ) { |
| 477 |
wpda_get_user_location(table_name, pub_id); |
| 478 |
} |
| 479 |
if ( |
| 480 |
jQueryDataTablesDefaultOptions.wpda_geo.geo_filter && |
| 481 |
'after' === jQueryDataTablesDefaultOptions.wpda_geo.geo_filter |
| 482 |
) { |
| 483 |
jQuery("#" + table_name + pub_id + "_filter").append(geo_search); |
| 484 |
} else { |
| 485 |
jQuery("#" + table_name + pub_id + "_filter").prepend(geo_search); |
| 486 |
} |
| 487 |
jQuery("#" + table_name + pub_id + "_wrapper").append(jQuery("#" + table_name + pub_id + "_geocontainer")); |
| 488 |
jQuery("#" + table_name + pub_id + "_georange").on("change", function() { |
| 489 |
update_table(table_name, pub_id); |
| 490 |
}); |
| 491 |
jQuery("#" + table_name + pub_id + "_geounits").on("change", function() { |
| 492 |
update_table(table_name, pub_id); |
| 493 |
}); |
| 494 |
jQuery("#" + table_name + pub_id + "_geobutton").on("click", function() { |
| 495 |
if ( |
| 496 |
jQueryDataTablesDefaultOptions.wpda_geo.map_location==="user" && |
| 497 |
wpda_user_coords === null |
| 498 |
) { |
| 499 |
alert("Missing user location information"); |
| 500 |
} else { |
| 501 |
if (jQuery("#" + table_name + pub_id + "_geocontainer").is(":visible")) { |
| 502 |
jQuery("#" + table_name + pub_id + "_geocontainer").hide(); |
| 503 |
} else { |
| 504 |
jQuery("#" + table_name + pub_id + "_geocontainer").css('display', 'inline-block') |
| 505 |
} |
| 506 |
|
| 507 |
wpdaproGeolocationRefreshMap(); |
| 508 |
} |
| 509 |
}); |
| 510 |
if ( |
| 511 |
jQueryDataTablesDefaultOptions.wpda_geo.map_init && |
| 512 |
'open' === jQueryDataTablesDefaultOptions.wpda_geo.map_init |
| 513 |
) { |
| 514 |
setTimeout(function(){ |
| 515 |
if (jQuery("#" + table_name + pub_id + "_geocontainer").is(":visible")) { |
| 516 |
jQuery("#" + table_name + pub_id + "_geocontainer").hide(); |
| 517 |
} else { |
| 518 |
jQuery("#" + table_name + pub_id + "_geocontainer").css('display', 'inline-block') |
| 519 |
} |
| 520 |
|
| 521 |
wpdaproGeolocationRefreshMap(); |
| 522 |
}, 100); |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
if (responsive === 'yes') { |
| 527 |
try { |
| 528 |
hiddenColumns = this.api().columns().responsiveHidden(); |
| 529 |
for (i=0; i<hiddenColumns.length; i++) { |
| 530 |
if (!hiddenColumns[i]) { |
| 531 |
hide_header_and_footer_of_hidden_column(table_name, pub_id, pub_id_seq, i); |
| 532 |
} |
| 533 |
} |
| 534 |
} catch(err) { |
| 535 |
console.log(err); |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
if ( |
| 540 |
jQueryDataTablesDefaultOptions.wpda_search_force_enter!==false && |
| 541 |
jQueryDataTablesDefaultOptions.wpda_search_force_enter!=="false" |
| 542 |
) { |
| 543 |
// Force press enter for global search and search builder |
| 544 |
jQueryDataTablesDefaultOptions.search = { |
| 545 |
return: true |
| 546 |
} |
| 547 |
// Force press enter for column search |
| 548 |
enterKeySearch(settings, jQueryDataTablesDefaultOptions); |
| 549 |
} else { |
| 550 |
// search on each key press |
| 551 |
noEnterKeySearch(settings, jQueryDataTablesDefaultOptions); |
| 552 |
} |
| 553 |
|
| 554 |
if (jQueryDataTablesDefaultOptions.userInitComplete) { |
| 555 |
jQueryDataTablesDefaultOptions.userInitComplete(settings, json); |
| 556 |
} |
| 557 |
|
| 558 |
if (jQuery.fn.tooltip) { |
| 559 |
// Add ui tooltip to jdt buttons |
| 560 |
jQuery(".wpda_tooltip").tooltip(); |
| 561 |
} |
| 562 |
|
| 563 |
// Prevent counting on each request to improve performance |
| 564 |
jQuery("#" + table_name + pub_id + pub_id_seq + "_wrapper .dataTables_paginate, #" + table_name + pub_id + "_wrapper .dataTables_length").on("mousedown", "a, select", function () { |
| 565 |
wpda_paginationButtonPressed = true; |
| 566 |
}); |
| 567 |
jQuery("#" + table_name + pub_id + pub_id_seq + "_wrapper .dataTables_paginate").on("click", "a", function () { |
| 568 |
wpda_paginationButtonPressed = false; |
| 569 |
}); |
| 570 |
jQuery("#" + table_name + pub_id + pub_id_seq + "_wrapper .dataTables_length").on("change", "select", function () { |
| 571 |
wpda_paginationButtonPressed = false; |
| 572 |
}); |
| 573 |
|
| 574 |
if (jQueryDataTablesOptions.wpda_seo_links!==undefined) { |
| 575 |
// Add SEO links |
| 576 |
wpdaTableSeo(settings, json, jQueryDataTablesOptions.wpda_seo_links); |
| 577 |
} |
| 578 |
}, |
| 579 |
drawCallback: function(settings) { |
| 580 |
// console.log(settings); |
| 581 |
|
| 582 |
table = jQuery("#" + table_name + pub_id + pub_id_seq).DataTable(); |
| 583 |
paging_start = table.page.info().start; |
| 584 |
paging_length = table.page.info().length; |
| 585 |
|
| 586 |
if (jQueryDataTablesDefaultOptions.wpda_geo) { |
| 587 |
showmap = true; |
| 588 |
if ( |
| 589 |
jQueryDataTablesDefaultOptions.wpda_geo.show_map !== undefined && |
| 590 |
jQueryDataTablesDefaultOptions.wpda_geo.show_map === false |
| 591 |
) { |
| 592 |
showmap = false; |
| 593 |
} |
| 594 |
|
| 595 |
if (showmap) { |
| 596 |
get_map_data = true; |
| 597 |
if ( |
| 598 |
jQueryDataTablesDefaultOptions.wpda_geo && |
| 599 |
jQueryDataTablesDefaultOptions.wpda_geo.map_location==="user" && |
| 600 |
wpda_user_coords === null |
| 601 |
) { |
| 602 |
get_map_data = false; |
| 603 |
} |
| 604 |
|
| 605 |
if (get_map_data) { |
| 606 |
radius = geo_search_options.radius; |
| 607 |
if (jQuery("#" + table_name + pub_id + "_georange").val()) { |
| 608 |
radius = jQuery("#" + table_name + pub_id + "_georange").val(); |
| 609 |
} |
| 610 |
unit = geo_search_options.unit; |
| 611 |
if (jQuery("#" + table_name + pub_id + "_geounits").val()) { |
| 612 |
unit = jQuery("#" + table_name + pub_id + "_geounits").val(); |
| 613 |
} |
| 614 |
|
| 615 |
if (typeof deleteAllMarkers==="function") { |
| 616 |
deleteAllMarkers(); |
| 617 |
} |
| 618 |
|
| 619 |
if (typeof popupClose==="function") { |
| 620 |
popupClose(); |
| 621 |
} |
| 622 |
|
| 623 |
args = {}; |
| 624 |
args.start = paging_start; |
| 625 |
args.step = paging_length; |
| 626 |
args.radius = radius; |
| 627 |
args.unit = unit; |
| 628 |
args.msg = settings.json.msg; |
| 629 |
if ( |
| 630 |
jQueryDataTablesDefaultOptions.wpda_geo && |
| 631 |
jQueryDataTablesDefaultOptions.wpda_geo.map_location==="user" && |
| 632 |
wpda_user_coords !== null |
| 633 |
) { |
| 634 |
args.user_latitude = wpda_user_coords.latitude; |
| 635 |
args.user_longitude = wpda_user_coords.longitude; |
| 636 |
} |
| 637 |
// Global search |
| 638 |
args.search = table.search(this.value); |
| 639 |
filter_args = {} |
| 640 |
// Column search |
| 641 |
var searchBoxes = jQuery("#" + table_name + pub_id + pub_id_seq + "_wrapper .wpda_search_boxes"); |
| 642 |
for (var i=0; i<searchBoxes.length; i++) { |
| 643 |
if (jQuery(searchBoxes[i]).val()!=="") { |
| 644 |
filter_args[jQuery(searchBoxes[i]).data("id")] = jQuery(searchBoxes[i]).val(); |
| 645 |
} |
| 646 |
} |
| 647 |
// Add Search Panes |
| 648 |
let sp = jQuery("div.dtsp-searchPane"); |
| 649 |
let searchPanes = []; |
| 650 |
for (let i=0; i<sp.length; i++) { |
| 651 |
let columnSearch = jQuery(sp[i]).find("table").DataTable().rows({selected: true}).data().toArray(); |
| 652 |
for (let j=0; j<columnSearch.length; j++) { |
| 653 |
let columnIndex = jQueryDataTablesDefaultOptions.searchPanes.columns[i]; |
| 654 |
let columnName = jQueryDataTablesDefaultOptions.columnDefs[columnIndex].name; |
| 655 |
if (columnSearch[j].filter) { |
| 656 |
searchPanes.push({ "key": columnName, "val": columnSearch[j].filter }); |
| 657 |
} |
| 658 |
} |
| 659 |
} |
| 660 |
// Add Search Builder |
| 661 |
let searchBuilder = []; |
| 662 |
if (jQuery(".dtsb-criteria").length>0) { |
| 663 |
let sb = table.searchBuilder.getDetails(); |
| 664 |
function updateColumnNames(obj) { |
| 665 |
for (const property in obj) { |
| 666 |
if (obj.criteria!==undefined && Array.isArray(obj.criteria)) { |
| 667 |
for (let i = 0; i < obj.criteria.length; i++) { |
| 668 |
let columnName = jQuery("div.dtsb-searchBuilder select.dtsb-data option:selected:contains(" + obj.criteria[i].data + ")").val(); |
| 669 |
if (columnName!==undefined) { |
| 670 |
columnName = jQueryDataTablesDefaultOptions.columnDefs[columnName].name; |
| 671 |
if (columnName!==undefined) { |
| 672 |
obj.criteria[i].origData = columnName; |
| 673 |
} |
| 674 |
} |
| 675 |
} |
| 676 |
} |
| 677 |
} |
| 678 |
return obj; |
| 679 |
} |
| 680 |
searchBuilder = updateColumnNames(sb); |
| 681 |
} |
| 682 |
|
| 683 |
args.msg = { |
| 684 |
filter_args: filter_args, |
| 685 |
searchPanes: searchPanes, |
| 686 |
searchBuilder: searchBuilder |
| 687 |
}; |
| 688 |
// console.log(args); |
| 689 |
|
| 690 |
if (typeof wpdaproGetGeoData==="function") { |
| 691 |
wpdaproGetGeoData(args); |
| 692 |
} |
| 693 |
|
| 694 |
if (unit==='mile') { |
| 695 |
jQuery(".wpda_geo_unit").html(" (mi)"); |
| 696 |
} else { |
| 697 |
jQuery(".wpda_geo_unit").html(" (km)"); |
| 698 |
} |
| 699 |
|
| 700 |
if ( |
| 701 |
jQueryDataTablesDefaultOptions.wpda_geo.geo_marker_column === 0 || |
| 702 |
( |
| 703 |
jQueryDataTablesDefaultOptions.wpda_geo.geo_marker_column && |
| 704 |
!isNaN(jQueryDataTablesDefaultOptions.wpda_geo.geo_marker_column) |
| 705 |
) |
| 706 |
) { |
| 707 |
var labelIndex = 0; |
| 708 |
for (var i=0; i<table.rows().data().length; i++) { |
| 709 |
node = jQuery(this.api().cell(i, jQueryDataTablesDefaultOptions.wpda_geo.geo_marker_column).node()); |
| 710 |
marker = '<div class="wpda_geo_map_marker_link"><a href="javascript:void(0)" onclick="popupMarker(\'' + String.fromCharCode(65+labelIndex) + '\')">' + String.fromCharCode(65+labelIndex) + '</a></div>'; |
| 711 |
node.append(marker); |
| 712 |
labelIndex++; |
| 713 |
} |
| 714 |
} |
| 715 |
} |
| 716 |
} |
| 717 |
} |
| 718 |
|
| 719 |
if (buttons.length > 0) { |
| 720 |
jQuery("#" + table_name + pub_id + pub_id_seq).find("td").on("click", function(e) { |
| 721 |
if (jQuery(this).hasClass("dtr-control")) { |
| 722 |
table = jQuery("#" + table_name + pub_id + pub_id_seq).DataTable(); |
| 723 |
if (!table.responsive.hasHidden()) { |
| 724 |
// Overwrite default icon behaviour |
| 725 |
selectedRows = table.row({selected : true}); |
| 726 |
if (selectedRows[0].includes(this._DT_CellIndex.row)) { |
| 727 |
table.row(':eq(' + this._DT_CellIndex.row + ')', { page: 'current' }).deselect(); |
| 728 |
} else { |
| 729 |
table.row(':eq(' + this._DT_CellIndex.row + ')', { page: 'current' }).select(); |
| 730 |
} |
| 731 |
} |
| 732 |
} |
| 733 |
}); |
| 734 |
} |
| 735 |
|
| 736 |
if ( |
| 737 |
jQueryDataTablesDefaultOptions.wpda_use_estimates_only===true || |
| 738 |
jQueryDataTablesDefaultOptions.wpda_use_estimates_only==="true" |
| 739 |
) { |
| 740 |
if (jQuery("#" + table_name + pub_id + pub_id_seq + "_paginate span a").length>0) { |
| 741 |
// default, compact, jQueryUI |
| 742 |
jQuery("#" + table_name + pub_id + pub_id_seq + "_paginate span a:last-child").hide(); |
| 743 |
} else if (jQuery("#" + table_name + pub_id + pub_id_seq + "_paginate ul").length>0) { |
| 744 |
// foundation, bootstrap3, bootstrap4 |
| 745 |
jQuery("#" + table_name + pub_id + pub_id_seq + "_paginate ul li:nth-last-child(2)").hide(); |
| 746 |
} else { |
| 747 |
// semantic |
| 748 |
jQuery("#" + table_name + pub_id + pub_id_seq + "_paginate a:nth-last-child(2)").hide(); |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
if (jQueryDataTablesDefaultOptions.userDrawCallback) { |
| 753 |
jQueryDataTablesDefaultOptions.userDrawCallback(settings); |
| 754 |
} |
| 755 |
|
| 756 |
var fncSetModalWidth = table_name + pub_id + pub_id_seq + "SetModalWidth"; |
| 757 |
if (typeof window[fncSetModalWidth] === "function") { |
| 758 |
window[fncSetModalWidth](); |
| 759 |
} |
| 760 |
} |
| 761 |
}; |
| 762 |
|
| 763 |
if ( typeof Object.assign != 'function' ) { |
| 764 |
var jQueryDataTablesOptions = jQueryDataTablesDefaultOptions; |
| 765 |
} else { |
| 766 |
var jQueryDataTablesOptions = Object.assign(jQueryDataTablesDefaultOptions, jQueryDataTablesUserOptions); |
| 767 |
} |
| 768 |
|
| 769 |
convert_string_to_function(table_options_advanced); |
| 770 |
jQueryDataTablesOptions = Object.assign(jQueryDataTablesOptions, table_options_advanced); |
| 771 |
|
| 772 |
if (jQueryDataTablesOptions.language==undefined) { |
| 773 |
jQueryDataTablesOptions.language = {}; |
| 774 |
} |
| 775 |
jQueryDataTablesOptions.language.url = "https://cdn.datatables.net/plug-ins/1.13.1/i18n/" + language + ".json"; |
| 776 |
|
| 777 |
// console.log(jQueryDataTablesOptions); |
| 778 |
|
| 779 |
jQuery("#" + table_name + pub_id + pub_id_seq).addClass('wpda-datatable'); |
| 780 |
jQuery("#" + table_name + pub_id + pub_id_seq).DataTable(jQueryDataTablesOptions); |
| 781 |
jQuery("#" + table_name + pub_id + pub_id_seq).on("click", "tr", function () { |
| 782 |
// Add actions to open modal |
| 783 |
jQuery(".dtr-modal-display").draggable(); |
| 784 |
jQuery(".dtr-modal-display").resizable(); |
| 785 |
jQuery("body div.dtr-modal div.dtr-modal-display").css("top", function() { |
| 786 |
var displayHeight = ( jQuery(window).height() - jQuery("body div.dtr-modal div.dtr-modal-display").height() ) / 2; |
| 787 |
if (displayHeight<0) { |
| 788 |
displayHeight = 0; // Just to be sure |
| 789 |
} |
| 790 |
return displayHeight + "px"; |
| 791 |
}); |
| 792 |
}); |
| 793 |
|
| 794 |
if (jQuery("#" + table_name + pub_id + "_more_button").length>0) { |
| 795 |
// Add load more rows action |
| 796 |
jQuery("#" + table_name + pub_id + "_more_button").on("click", function() { |
| 797 |
more_new = false; |
| 798 |
jQuery("#" + table_name + pub_id + pub_id_seq).DataTable().draw("page"); |
| 799 |
let scrolledHeight = jQuery("#" + table_name + pub_id + " tr").height() * 10; |
| 800 |
window.scrollBy(0,scrolledHeight); |
| 801 |
}); |
| 802 |
} |
| 803 |
|
| 804 |
if (window.top['wpda_publication_status']!==undefined) { |
| 805 |
window.top['wpda_publication_status']['completed'] = true; |
| 806 |
} |
| 807 |
} |
| 808 |
|
| 809 |
function convert_string_to_function(obj) { |
| 810 |
for (var prop in obj) { |
| 811 |
if (typeof obj[prop]=='string') { |
| 812 |
if (obj[prop].substr(0,8)=='function') { |
| 813 |
fnc = obj[prop]; |
| 814 |
delete obj[prop]; |
| 815 |
var f = new Function("return " + fnc); |
| 816 |
if (prop==="initComplete") { |
| 817 |
// Plugin users cannot overwrite initComplete |
| 818 |
prop = "userInitComplete"; |
| 819 |
} |
| 820 |
if (prop==="drawCallback") { |
| 821 |
// Plugin users cannot overwrite initComplete |
| 822 |
prop = "userDrawCallback"; |
| 823 |
} |
| 824 |
obj[prop] = f(); |
| 825 |
} |
| 826 |
} else { |
| 827 |
convert_string_to_function(obj[prop]); |
| 828 |
} |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
function hide_header_and_footer_of_hidden_column(table_name, pub_id, pub_id_seq, i) { |
| 833 |
// Hide labels of dynamic hyperlinks and double header rows |
| 834 |
var tr_head0 = jQuery("#" + table_name + pub_id + pub_id_seq).find('thead tr').eq(0); |
| 835 |
tr_head0.find('th').eq(i).hide(); |
| 836 |
tr_head0.find('td').eq(i).hide(); |
| 837 |
|
| 838 |
var tr_head1 = jQuery("#" + table_name + pub_id + pub_id_seq).find('thead tr').eq(1); |
| 839 |
tr_head1.find('th').eq(i).hide(); |
| 840 |
tr_head1.find('td').eq(i).hide(); |
| 841 |
|
| 842 |
var tr_foot = jQuery("#" + table_name + pub_id + pub_id_seq).find('tfoot tr').eq(0); |
| 843 |
tr_foot.find('th').eq(i).hide().find('td').eq(i).hide(); |
| 844 |
} |
| 845 |
|
| 846 |
function post_publication_widget(table_name, pub_id) { |
| 847 |
// responsive data table widgets do not rerender correctly with search box in header |
| 848 |
jQuery("#" + table_name + pub_id + ' thead tr:last-child th').each(function(i) { |
| 849 |
if (jQuery(this).is(":visible")) { |
| 850 |
jQuery("#" + table_name + pub_id + ' thead tr:first-child td:nth-child(' + i + ')').show(); |
| 851 |
} else { |
| 852 |
jQuery("#" + table_name + pub_id + ' thead tr:first-child td:nth-child(' + i + ')').hide(); |
| 853 |
} |
| 854 |
}); |
| 855 |
} |
| 856 |
|
| 857 |
function update_table(table_name, pub_id) { |
| 858 |
jQuery("#" + table_name + pub_id).DataTable().draw(); |
| 859 |
} |
| 860 |
|
| 861 |
var wpda_user_coords = null; |
| 862 |
function wpda_get_user_location(table_name, pub_id) { |
| 863 |
if (!navigator.geolocation) { |
| 864 |
alert("Geolocation is not supported by your browser"); |
| 865 |
} else { |
| 866 |
navigator.geolocation.getCurrentPosition( |
| 867 |
function(pos) { |
| 868 |
if (pos.coords===undefined) { |
| 869 |
wpda_user_coords = null; |
| 870 |
alert("ERROR - Could not determine user location"); |
| 871 |
} else { |
| 872 |
wpda_user_coords = pos.coords; |
| 873 |
update_table(table_name, pub_id); |
| 874 |
} |
| 875 |
}, |
| 876 |
function(err) { |
| 877 |
wpda_user_coords = null; |
| 878 |
alert("ERROR - " + err); |
| 879 |
}, |
| 880 |
{ |
| 881 |
enableHighAccuracy: true, |
| 882 |
timeout: 5000, |
| 883 |
maximumAge: 0 |
| 884 |
} |
| 885 |
); |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
/** |
| 890 |
* Author: Charles Godwin |
| 891 |
* @since 4.2.6 |
| 892 |
*/ |
| 893 |
function enterKeySearch(oSettings, options) { |
| 894 |
sTableID = "#" + oSettings.sTableId; |
| 895 |
|
| 896 |
jQuery(sTableID + "_filter input").off(); |
| 897 |
jQuery(sTableID + "_filter input").on("keyup", { sTableID: sTableID }, function (e) { |
| 898 |
if (e.keyCode == 13) { /* Enter key */ |
| 899 |
jQuery(e.data.sTableID).DataTable().search(this.value).draw(); |
| 900 |
} |
| 901 |
}); |
| 902 |
|
| 903 |
jQuery(sTableID + "_wrapper .wpda_search_textbox").off(); |
| 904 |
jQuery(sTableID + "_wrapper .wpda_search_textbox").on("keyup", { sTableID: sTableID }, function (e) { |
| 905 |
if (e.keyCode == 13) { /* Enter key */ |
| 906 |
if (options.serverSide) { |
| 907 |
jQuery(e.data.sTableID).DataTable().draw(); |
| 908 |
} else { |
| 909 |
let idx = jQuery(e.data.sTableID).DataTable().column(jQuery(this).data("id")+":name").index(); |
| 910 |
jQuery(e.data.sTableID).DataTable().column(idx).search(this.value).draw(); |
| 911 |
} |
| 912 |
} |
| 913 |
}); |
| 914 |
|
| 915 |
searchListbox(sTableID, options); |
| 916 |
} |
| 917 |
|
| 918 |
function noEnterKeySearch(oSettings, options) { |
| 919 |
sTableID = "#" + oSettings.sTableId; |
| 920 |
|
| 921 |
jQuery(sTableID + "_wrapper .wpda_search_textbox").off(); |
| 922 |
jQuery(sTableID + "_wrapper .wpda_search_textbox").on("keyup", {sTableID: sTableID}, function (e) { |
| 923 |
if (options.serverSide) { |
| 924 |
jQuery(e.data.sTableID).DataTable().draw(); |
| 925 |
} else { |
| 926 |
let idx = jQuery(e.data.sTableID).DataTable().column(jQuery(this).data("id") + ":name").index(); |
| 927 |
jQuery(e.data.sTableID).DataTable().column(idx).search(this.value).draw(); |
| 928 |
} |
| 929 |
}); |
| 930 |
|
| 931 |
searchListbox(sTableID, options); |
| 932 |
} |
| 933 |
|
| 934 |
function searchListbox(sTableID, options) { |
| 935 |
jQuery(sTableID + "_wrapper .wpda_search_listbox").off(); |
| 936 |
jQuery(sTableID + "_wrapper .wpda_search_listbox").on("change", { sTableID: sTableID }, function (e) { |
| 937 |
if (options.serverSide) { |
| 938 |
jQuery(e.data.sTableID).DataTable().draw(); |
| 939 |
} else { |
| 940 |
let idx = jQuery(e.data.sTableID).DataTable().column(jQuery(this).data("id")+":name").index(); |
| 941 |
jQuery(e.data.sTableID).DataTable().column(idx).search('\\b' + this.value + '\\b', true, false).draw(); |
| 942 |
} |
| 943 |
}); |
| 944 |
} |