| 1 |
function wpda_show_table_actions( schema_name, table_name, rownum, wpnonce, dbo_type, loading ) { |
| 2 |
jQuery('#wpda_admin_menu_actions_' + rownum).toggle(); |
| 3 |
wpda_toggle_row_actions(rownum); |
| 4 |
if (jQuery('#wpda_admin_menu_actions_' + rownum).html()===loading) { |
| 5 |
url = location.pathname + '?action=wpda_show_table_actions'; |
| 6 |
jQuery.ajax({ |
| 7 |
method: 'POST', |
| 8 |
url: url, |
| 9 |
data: { |
| 10 |
wpdaschema_name: schema_name, |
| 11 |
table_name: table_name, |
| 12 |
_wpnonce: wpnonce, |
| 13 |
dbo_type: dbo_type, |
| 14 |
rownum: rownum |
| 15 |
} |
| 16 |
}).done( |
| 17 |
function(msg) { |
| 18 |
jQuery('#wpda_admin_menu_actions_' + rownum).html(msg); |
| 19 |
} |
| 20 |
); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
function wpda_toggle_row_actions( rownum ) { |
| 25 |
if (jQuery('#wpda_admin_menu_actions_' + rownum).is(":visible")) { |
| 26 |
jQuery("#rownum_" + rownum + " td div").removeClass("row-actions"); |
| 27 |
} else { |
| 28 |
jQuery("#rownum_" + rownum + " td div").addClass("row-actions"); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
function wpda_list_table_favourite( schema_name, table_name ) { |
| 33 |
if (jQuery('#span_favourites_'+ table_name).hasClass('dashicons-star-empty')) { |
| 34 |
action = 'wpda_add_favourite'; |
| 35 |
} else { |
| 36 |
action = 'wpda_rem_favourite'; |
| 37 |
} |
| 38 |
url = location.pathname + '?action=' + action; |
| 39 |
jQuery.ajax({ |
| 40 |
method: 'POST', |
| 41 |
url: url, |
| 42 |
data: { |
| 43 |
wpdaschema_name: schema_name, |
| 44 |
table_name: table_name |
| 45 |
} |
| 46 |
}).done( |
| 47 |
function (msg) { |
| 48 |
if (msg === '1') { |
| 49 |
if (jQuery('#span_favourites_' + table_name).hasClass('dashicons-star-empty')) { |
| 50 |
jQuery('#span_favourites_' + table_name) |
| 51 |
.removeClass('dashicons-star-empty') |
| 52 |
.addClass('dashicons-star-filled') |
| 53 |
.prop('title', 'Remove from favourites'); |
| 54 |
} else { |
| 55 |
jQuery('#span_favourites_' + table_name) |
| 56 |
.removeClass('dashicons-star-filled') |
| 57 |
.addClass('dashicons-star-empty') |
| 58 |
.prop('title', 'Add to favourites'); |
| 59 |
} |
| 60 |
if (jQuery('#wpda_main_favourites_list').val()!=='') { |
| 61 |
jQuery("#wpda_main_form :input[name='action']").val('-1'); |
| 62 |
jQuery("#wpda_main_form :input[name='action2']").val('-1'); |
| 63 |
jQuery('#wpda_main_form').submit(); |
| 64 |
} |
| 65 |
} else { |
| 66 |
alert('Adding to favourites failed!'); |
| 67 |
} |
| 68 |
} |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
function wpda_main_export_start() { |
| 73 |
jQuery("#wpda_main_export_form").submit(); |
| 74 |
jQuery("#wpda_row_export_anchor").empty(); |
| 75 |
|
| 76 |
return false; |
| 77 |
} |
| 78 |
|
| 79 |
function wpda_main_export(schemaName, wpnonce, selectedRows) { |
| 80 |
jQuery("#wpda_main_export_form__schema_name").val(schemaName); |
| 81 |
jQuery("#wpda_main_export_form__wpnonce").val(wpnonce); |
| 82 |
|
| 83 |
rows = JSON.parse(selectedRows); |
| 84 |
for (var i=0; i<rows.length; i++) { |
| 85 |
jQuery("#wpda_main_export_form").append("<input type='hidden' name='table_names[]' value='" + rows[i] + "' />"); |
| 86 |
} |
| 87 |
|
| 88 |
jQuery("#wpda_row_export_anchor").append( |
| 89 |
"<button class='button button-primary wpda_row_export_button' onclick='return wpda_main_export_start();'>Download export</button>" |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
function wpda_table_export(schemaName, tableNames, wpnonce, formatType, includeTableSettings) { |
| 94 |
jQuery("#wpda_table_export_form__schema_name").val(schemaName); |
| 95 |
jQuery("#wpda_table_export_form__table_names").val(tableNames); |
| 96 |
jQuery("#wpda_table_export_form__format_type").val(formatType); |
| 97 |
jQuery("#wpda_table_export_form__wpnonce").val(wpnonce); |
| 98 |
jQuery("#wpda_table_export_form__include_table_settings").val(includeTableSettings); |
| 99 |
|
| 100 |
jQuery("#wpda_table_export_form").submit(); |
| 101 |
} |
| 102 |
|
| 103 |
function wpda_row_export_start() { |
| 104 |
jQuery("#wpda_row_export_form").submit(); |
| 105 |
jQuery("#wpda_row_export_anchor").empty(); |
| 106 |
|
| 107 |
return false; |
| 108 |
} |
| 109 |
|
| 110 |
function wpda_row_export(pid, schemaName, tableNames, wpnonce, formatType, mysqlSet, showCreate, showComments, selectedRows) { |
| 111 |
jQuery("#wpda_row_export_form__pid").val(pid); |
| 112 |
jQuery("#wpda_row_export_form__schema_name").val(schemaName); |
| 113 |
jQuery("#wpda_row_export_form__table_names").val(tableNames); |
| 114 |
jQuery("#wpda_row_export_form__mysql_set").val(mysqlSet); |
| 115 |
jQuery("#wpda_row_export_form__show_create").val(showCreate); |
| 116 |
jQuery("#wpda_row_export_form__show_comments").val(showComments); |
| 117 |
jQuery("#wpda_row_export_form__format_type").val(formatType); |
| 118 |
jQuery("#wpda_row_export_form__wpnonce").val(wpnonce); |
| 119 |
|
| 120 |
rows = JSON.parse(selectedRows); |
| 121 |
for (var column in rows) { |
| 122 |
for (var i=0; i<rows[column].length; i++) { |
| 123 |
jQuery("#wpda_row_export_form").append("<input type='hidden' name='" + column + "[]' value='" + rows[column][i] + "' />"); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
jQuery("#wpda_row_export_anchor").append( |
| 128 |
"<button class='button button-primary wpda_row_export_button' onclick='return wpda_row_export_start();'>Download " + (formatType==='' ? 'SQL' : formatType) + " export</button>" |
| 129 |
); |
| 130 |
} |
| 131 |
|
| 132 |
function wpda_show_notice( value ) { |
| 133 |
if ( |
| 134 |
value==='bulk-delete' || |
| 135 |
value==='bulk-drop' || |
| 136 |
value==='bulk-truncate' |
| 137 |
) { |
| 138 |
return confirm('You are about to permanently delete these items from your site.\nThis action cannot be undone.\n\'Cancel\' to stop, \'OK\' to delete.'); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
function wpda_action_button() { |
| 143 |
action1 = jQuery("#wpda_main_form :input[name='action']").val(); |
| 144 |
if (action1!=="-1") { |
| 145 |
return wpda_show_notice(action1); |
| 146 |
} |
| 147 |
action2 = jQuery("#wpda_main_form :input[name='action2']").val(); |
| 148 |
if (action2!=="-1") { |
| 149 |
return wpda_show_notice(action2); |
| 150 |
} |
| 151 |
return true; |
| 152 |
} |
| 153 |
|
| 154 |
// Source: https://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery |
| 155 |
var entityMap = { |
| 156 |
'&': '&', |
| 157 |
'<': '<', |
| 158 |
'>': '>', |
| 159 |
'"': '"', |
| 160 |
"'": ''', |
| 161 |
'/': '/', |
| 162 |
'`': '`', |
| 163 |
'=': '=' |
| 164 |
}; |
| 165 |
|
| 166 |
// Source: https://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery |
| 167 |
function escapeHtml(string) { |
| 168 |
return String(string).replace(/[&<>"'`=\/]/g, function (s) { |
| 169 |
return entityMap[s]; |
| 170 |
}); |
| 171 |
} |
| 172 |
|
| 173 |
function submit_table_settings(rownum, schema_name, table_name) { |
| 174 |
table_settings = {}; |
| 175 |
|
| 176 |
if (jQuery("input:radio[name ='" + table_name + "_row_count_estimate']:checked").val() === "true") { |
| 177 |
table_settings['row_count_estimate'] = true; |
| 178 |
} else if (jQuery("input:radio[name ='" + table_name + "_row_count_estimate']:checked").val() === "false") { |
| 179 |
table_settings['row_count_estimate'] = false; |
| 180 |
} else { |
| 181 |
table_settings['row_count_estimate'] = null; |
| 182 |
} |
| 183 |
|
| 184 |
table_settings['row_count_estimate_value'] = jQuery("input:radio[name ='" + table_name + "_row_count_estimated_value']:checked").val(); |
| 185 |
table_settings['row_count_estimate_value_hard'] = jQuery("#" + table_name + "_row_count_estimated_value_hard").val(); |
| 186 |
|
| 187 |
table_settings['query_buffer_size'] = |
| 188 |
jQuery('#' + table_name + '_query_buffer_size').val(); |
| 189 |
|
| 190 |
table_settings['row_level_security'] = |
| 191 |
jQuery('#' + table_name + '_row_level_security').is(':checked') ? 'true' : 'false'; |
| 192 |
|
| 193 |
table_settings['hyperlink_definition'] = |
| 194 |
jQuery('#' + table_name + 'table_top_setting_hyperlink_definition_json').is(':checked') ? 'json' : 'text'; |
| 195 |
|
| 196 |
jsonData = {}; |
| 197 |
jsonData['request_type'] = 'table_settings'; |
| 198 |
jsonData['table_settings'] = table_settings; |
| 199 |
jsonData['unused'] = jQuery('#wpda_' + rownum + '_sql_dml').val(); |
| 200 |
|
| 201 |
// console.log(jsonData); |
| 202 |
// console.log(JSON.stringify(jsonData)); |
| 203 |
|
| 204 |
// Submit |
| 205 |
wpda_rest_api( |
| 206 |
'save-settings', |
| 207 |
{ |
| 208 |
action: 'table_settings', |
| 209 |
dbs: schema_name, |
| 210 |
tbl: table_name, |
| 211 |
settings: JSON.stringify(jsonData), |
| 212 |
}, |
| 213 |
(function(data) { |
| 214 |
submitSettingsCallbackOk(data, rownum); |
| 215 |
}), |
| 216 |
submitSettingsCallbackError |
| 217 |
); |
| 218 |
|
| 219 |
return false; |
| 220 |
} |
| 221 |
|
| 222 |
function submitSettingsCallbackOk(response, rownum) { |
| 223 |
if (response.code!==undefined && response.message!==undefined) { |
| 224 |
switch(response.code) { |
| 225 |
case "ok": |
| 226 |
jQuery("#wpda_" + rownum + "_sql_dml").val("UPDATE"); |
| 227 |
jQuery.notify(response.message, "success"); |
| 228 |
break; |
| 229 |
case "error": |
| 230 |
jQuery.notify(response.message, "error"); |
| 231 |
break; |
| 232 |
default: |
| 233 |
jQuery.notify("Application error! Please contact the plugin development team.", "error"); |
| 234 |
} |
| 235 |
} else { |
| 236 |
submitSettingsCallbackError(response); |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
function submitSettingsCallbackError(response) { |
| 241 |
if (response.code!==undefined && response.message!==undefined) { |
| 242 |
switch(response.code) { |
| 243 |
case "error": |
| 244 |
jQuery.notify(response.message, "error"); |
| 245 |
break; |
| 246 |
default: |
| 247 |
jQuery.notify("Application error! Please contact the plugin development team.", "error"); |
| 248 |
} |
| 249 |
} else { |
| 250 |
jQuery.notify("Application error! Please contact the plugin development team.", "error"); |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
function submit_column_settings(rownum, schema_name, table_name ) { |
| 255 |
custom_settings = {}; |
| 256 |
list_labels = {}; |
| 257 |
form_labels = {}; |
| 258 |
column_media = {}; |
| 259 |
unused = {}; |
| 260 |
|
| 261 |
jQuery('#wpda_table_settings_' + rownum + ' .wpda_table_setting_item').each(function () { |
| 262 |
element_id = jQuery(this).attr('id'); |
| 263 |
element_value = jQuery(this).val(); |
| 264 |
element_type = jQuery(this).attr('type'); |
| 265 |
is_custom_element = false; |
| 266 |
for (i=0; i<custom_column_settings.length; i++) { |
| 267 |
if (element_id.startsWith(custom_column_settings[i])) { |
| 268 |
element_name = element_id.substr(custom_column_settings[i].length); |
| 269 |
if (element_type==="checkbox") { |
| 270 |
element_value = jQuery(this).is(':checked'); |
| 271 |
} |
| 272 |
custom_settings[element_id] = element_value; |
| 273 |
is_custom_element = true; |
| 274 |
} |
| 275 |
} |
| 276 |
if (!is_custom_element) { |
| 277 |
if (element_id.startsWith("list_label_")) { |
| 278 |
element_name = element_id.substr(11); |
| 279 |
list_labels[element_name] = element_value; |
| 280 |
} else if (element_id.startsWith("form_label_")) { |
| 281 |
element_name = element_id.substr(11); |
| 282 |
form_labels[element_name] = element_value; |
| 283 |
} else if (element_id.startsWith("column_media_")) { |
| 284 |
element_name = element_id.substr(13); |
| 285 |
element_old_value = jQuery('#column_media_' + element_name + '_old').val(); |
| 286 |
if (element_value !== element_old_value) { |
| 287 |
media_dml = jQuery('#column_media_' + element_name + '_dml').val(); |
| 288 |
column_media[element_name] = {'value': element_value, 'dml': media_dml}; |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
}); |
| 293 |
|
| 294 |
unused["sql_dml"] = jQuery('#wpda_' + rownum + '_sql_dml').val(); |
| 295 |
|
| 296 |
jsonData = {}; |
| 297 |
jsonData['request_type'] = 'column_settings'; |
| 298 |
jsonData['custom_settings'] = custom_settings; |
| 299 |
jsonData['list_labels'] = list_labels; |
| 300 |
jsonData['form_labels'] = form_labels; |
| 301 |
jsonData['column_media'] = column_media; |
| 302 |
jsonData['unused'] = unused; |
| 303 |
|
| 304 |
// console.log(jsonData); |
| 305 |
// console.log(JSON.stringify(jsonData)); |
| 306 |
|
| 307 |
// Submit |
| 308 |
wpda_rest_api( |
| 309 |
'save-settings', |
| 310 |
{ |
| 311 |
action: 'column_settings', |
| 312 |
dbs: schema_name, |
| 313 |
tbl: table_name, |
| 314 |
settings: JSON.stringify(jsonData), |
| 315 |
}, |
| 316 |
(function(data) { |
| 317 |
submitSettingsCallbackOk(data, rownum); |
| 318 |
}), |
| 319 |
submitSettingsCallbackError |
| 320 |
); |
| 321 |
|
| 322 |
return false; |
| 323 |
} |
| 324 |
|
| 325 |
function submit_hyperlinks(rownum, schema_name, table_name) { |
| 326 |
hyperlinks = []; |
| 327 |
unused = {}; |
| 328 |
isvalid = true; |
| 329 |
|
| 330 |
jQuery("#wpda_" + rownum + "_add_hyperlink_body tr").each(function() { |
| 331 |
let hyperlink_label, hyperlink_list, hyperlink_form, hyperlink_target, hyperlink_html; |
| 332 |
jQuery(this).find("td .wpda_action_font").each(function() { |
| 333 |
switch(jQuery(this).data("id")) { |
| 334 |
case "hyperlink_label": |
| 335 |
hyperlink_label = jQuery(this).val(); |
| 336 |
break; |
| 337 |
case "hyperlink_list": |
| 338 |
hyperlink_list = jQuery(this).is(':checked'); |
| 339 |
break; |
| 340 |
case "hyperlink_form": |
| 341 |
hyperlink_form = jQuery(this).is(':checked'); |
| 342 |
break; |
| 343 |
case "hyperlink_target": |
| 344 |
hyperlink_target = jQuery(this).is(':checked'); |
| 345 |
break; |
| 346 |
case "hyperlink_html": |
| 347 |
hyperlink_html = jQuery(this).val(); |
| 348 |
break; |
| 349 |
} |
| 350 |
}); |
| 351 |
|
| 352 |
if (hyperlink_label===""||hyperlink_html==="") { |
| 353 |
alert('Hyperlink label and HTML must be entered'); |
| 354 |
isvalid = false; |
| 355 |
} else { |
| 356 |
let hyperlink_item = { |
| 357 |
'hyperlink_label': hyperlink_label, |
| 358 |
'hyperlink_list': hyperlink_list, |
| 359 |
'hyperlink_form': hyperlink_form, |
| 360 |
'hyperlink_target': hyperlink_target, |
| 361 |
'hyperlink_html': escapeHtml(hyperlink_html) |
| 362 |
}; |
| 363 |
hyperlinks.push(hyperlink_item); |
| 364 |
} |
| 365 |
}); |
| 366 |
|
| 367 |
if (!isvalid) { |
| 368 |
return false; |
| 369 |
} |
| 370 |
|
| 371 |
unused["sql_dml"] = jQuery('#wpda_' + rownum + '_sql_dml').val(); |
| 372 |
|
| 373 |
jsonData = {}; |
| 374 |
jsonData['request_type'] = 'column_settings'; |
| 375 |
jsonData['hyperlinks'] = hyperlinks; |
| 376 |
jsonData['unused'] = unused; |
| 377 |
|
| 378 |
// console.log(jsonData); |
| 379 |
// console.log(JSON.stringify(jsonData)); |
| 380 |
|
| 381 |
// Submit |
| 382 |
wpda_rest_api( |
| 383 |
'save-settings', |
| 384 |
{ |
| 385 |
action: 'column_settings', |
| 386 |
dbs: schema_name, |
| 387 |
tbl: table_name, |
| 388 |
settings: JSON.stringify(jsonData), |
| 389 |
}, |
| 390 |
(function(data) { |
| 391 |
submitSettingsCallbackOk(data, rownum); |
| 392 |
}), |
| 393 |
submitSettingsCallbackError |
| 394 |
); |
| 395 |
|
| 396 |
return false; |
| 397 |
} |
| 398 |
|
| 399 |
function submit_dashboard_menus(rownum, schema_name, table_name) { |
| 400 |
menu = []; |
| 401 |
isvalid = true; |
| 402 |
|
| 403 |
jQuery("#wpda_" + rownum + "_add_dashboard_menu_body tr").each(function() { |
| 404 |
let menu_name, menu_slug, menu_role, menu_id; |
| 405 |
jQuery(this).find("td .wpda_action_font").each(function() { |
| 406 |
switch(jQuery(this).data("id")) { |
| 407 |
case "menu_name": |
| 408 |
menu_name = jQuery(this).val(); |
| 409 |
break; |
| 410 |
case "menu_slug": |
| 411 |
menu_slug = jQuery(this).val(); |
| 412 |
break; |
| 413 |
case "menu_role": |
| 414 |
menu_role = jQuery(this).val(); |
| 415 |
break; |
| 416 |
case "menu_id": |
| 417 |
menu_id = jQuery(this).val(); |
| 418 |
break; |
| 419 |
} |
| 420 |
}); |
| 421 |
|
| 422 |
if (menu_name===""||menu_slug==="") { |
| 423 |
alert('Menu name and slug must be entered'); |
| 424 |
isvalid = false; |
| 425 |
} else { |
| 426 |
let menu_item = { |
| 427 |
'menu_name': menu_name, |
| 428 |
'menu_slug': menu_slug, |
| 429 |
'menu_role': menu_role, |
| 430 |
'menu_id': menu_id |
| 431 |
}; |
| 432 |
menu.push(menu_item); |
| 433 |
} |
| 434 |
}); |
| 435 |
|
| 436 |
if (!isvalid) { |
| 437 |
return false; |
| 438 |
} |
| 439 |
|
| 440 |
jsonData = {}; |
| 441 |
jsonData['request_type'] = 'dashboard_menus'; |
| 442 |
jsonData['menu'] = menu; |
| 443 |
|
| 444 |
if (wpdaDeletedDashboardMenus[rownum]!==undefined) { |
| 445 |
jsonData['delete'] = wpdaDeletedDashboardMenus[rownum]; |
| 446 |
} |
| 447 |
|
| 448 |
// console.log(jsonData); |
| 449 |
// console.log(JSON.stringify(jsonData)); |
| 450 |
|
| 451 |
// Submit |
| 452 |
wpda_rest_api( |
| 453 |
'save-settings', |
| 454 |
{ |
| 455 |
action: 'dashboard_menus', |
| 456 |
dbs: schema_name, |
| 457 |
tbl: table_name, |
| 458 |
settings: JSON.stringify(jsonData), |
| 459 |
}, |
| 460 |
(function(data) { |
| 461 |
submitMenusCallbackOk(data, rownum); |
| 462 |
}), |
| 463 |
submitSettingsCallbackError |
| 464 |
); |
| 465 |
|
| 466 |
return false; |
| 467 |
} |
| 468 |
|
| 469 |
function submitMenusCallbackOk(response, rownum) { |
| 470 |
if (response.code!==undefined && response.message!==undefined) { |
| 471 |
switch(response.code) { |
| 472 |
case "ok": |
| 473 |
jQuery.notify(response.message, "success"); |
| 474 |
wpdaDeletedDashboardMenus[rownum] = []; |
| 475 |
if (response.data!==undefined && Array.isArray(response.data)) { |
| 476 |
for (let i=0; i<response.data.length; i++) { |
| 477 |
jQuery("#wpda_" + rownum + "_add_dashboard_menu_body tr .wpda_dashboard_menu_id").each(function() { |
| 478 |
if (jQuery(this).val()==="") { |
| 479 |
jQuery(this).val(response.data[i].menu_id); |
| 480 |
} |
| 481 |
}); |
| 482 |
} |
| 483 |
} |
| 484 |
break; |
| 485 |
case "error": |
| 486 |
jQuery.notify(response.message, "error"); |
| 487 |
break; |
| 488 |
default: |
| 489 |
jQuery.notify("Application error! Please contact the plugin development team.", "error"); |
| 490 |
} |
| 491 |
} else { |
| 492 |
submitSettingsCallbackError(response); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
function settab(rownum, tab) { |
| 497 |
for (i = 1; i <= 6; i++) { |
| 498 |
jQuery("#" + rownum + "-sel-" + i.toString()).removeClass('nav-tab-active'); |
| 499 |
jQuery("#" + rownum + "-tab-" + i.toString()).hide(); |
| 500 |
} |
| 501 |
jQuery("#" + rownum + "-sel-" + tab).addClass('nav-tab-active'); |
| 502 |
jQuery("#" + rownum + "-tab-" + tab).show(); |
| 503 |
} |
| 504 |
|
| 505 |
function backup_respository_tables( |
| 506 |
app_table_name, |
| 507 |
app_container_table_name, |
| 508 |
app_apps_table_name, |
| 509 |
table_settings_table_name, |
| 510 |
media_table_name, |
| 511 |
design_table_name, |
| 512 |
data_projects_project_name, |
| 513 |
data_projects_page_name, |
| 514 |
data_projects_table_name, |
| 515 |
data_publication_table_name, |
| 516 |
menus_table_name, |
| 517 |
csv_import_table_name, |
| 518 |
logging_table_name |
| 519 |
) { |
| 520 |
jQuery('#app_table_name').val(app_table_name); |
| 521 |
jQuery('#app_container_table_name').val(app_container_table_name); |
| 522 |
jQuery('#app_apps_table_name').val(app_apps_table_name); |
| 523 |
jQuery('#table_settings_table_name').val(table_settings_table_name); |
| 524 |
jQuery('#media_table_name').val(media_table_name); |
| 525 |
jQuery('#design_table_name').val(design_table_name); |
| 526 |
jQuery('#data_projects_project_name').val(data_projects_project_name); |
| 527 |
jQuery('#data_projects_page_name').val(data_projects_page_name); |
| 528 |
jQuery('#data_projects_table_name').val(data_projects_table_name); |
| 529 |
jQuery('#data_publication_table_name').val(data_publication_table_name); |
| 530 |
jQuery('#menus_table_name').val(menus_table_name); |
| 531 |
jQuery('#csv_import_table_name').val(csv_import_table_name); |
| 532 |
jQuery('#logging_table_name').val(logging_table_name); |
| 533 |
|
| 534 |
jQuery('#wpda-download-backup').submit(); |
| 535 |
} |
| 536 |
|
| 537 |
function restore_respository_tables() { |
| 538 |
if (!confirm("Restore repository tables? This action cannot be undone!\n\nIt might be wise to backup your actual repository tables first...")) { |
| 539 |
return; |
| 540 |
} |
| 541 |
|
| 542 |
jQuery('#restore_app_table_name').val(jQuery("input[name='restore_app_table_name']:checked").val()); |
| 543 |
jQuery('#restore_app_container_table_name').val(jQuery("input[name='restore_app_container_table_name']:checked").val()); |
| 544 |
jQuery('#restore_app_apps_table_name').val(jQuery("input[name='restore_app_apps_table_name']:checked").val()); |
| 545 |
jQuery('#restore_table_settings_table_name').val(jQuery("input[name='restore_table_settings_table_name']:checked").val()); |
| 546 |
jQuery('#restore_media_table_name').val(jQuery("input[name='restore_media_table_name']:checked").val()); |
| 547 |
jQuery('#restore_design_table_name').val(jQuery("input[name='restore_design_table_name']:checked").val()); |
| 548 |
jQuery('#restore_data_projects_project_name').val(jQuery("input[name='restore_data_projects_project_name']:checked").val()); |
| 549 |
jQuery('#restore_data_projects_page_name').val(jQuery("input[name='restore_data_projects_project_name']:checked").val()); |
| 550 |
jQuery('#restore_data_projects_table_name').val(jQuery("input[name='restore_data_projects_table_name']:checked").val()); |
| 551 |
jQuery('#restore_data_publication_table_name').val(jQuery("input[name='restore_data_publication_table_name']:checked").val()); |
| 552 |
jQuery('#restore_menus_table_name').val(jQuery("input[name='restore_menus_table_name']:checked").val()); |
| 553 |
jQuery('#restore_csv_import_table_name').val(jQuery("input[name='restore_csv_import_table_name']:checked").val()); |
| 554 |
jQuery('#restore_logging_table_name').val(jQuery("input[name='restore_logging_table_name']:checked").val()); |
| 555 |
|
| 556 |
jQuery('#restore_date').val(jQuery('.wpda-restore-repository-backup-selected').data('backupDate')); |
| 557 |
|
| 558 |
jQuery('#wpda-restore-respository').submit(); |
| 559 |
} |
| 560 |
|
| 561 |
function get_table_row_count(wpnonce, schema_name, table_name) { |
| 562 |
url = location.pathname + '?action=wpda_get_table_row_count'; |
| 563 |
jQuery.ajax({ |
| 564 |
method: 'POST', |
| 565 |
url: url, |
| 566 |
data: { |
| 567 |
wpda_wpnonce: wpnonce, |
| 568 |
wpdaschema_name: schema_name, |
| 569 |
wpdatable_name: table_name |
| 570 |
} |
| 571 |
}).done( |
| 572 |
function(msg) { |
| 573 |
try { |
| 574 |
json = JSON.parse(msg); |
| 575 |
if (json[0].row_count === undefined) { |
| 576 |
alert('Ajax error: row count failed'); |
| 577 |
} else { |
| 578 |
jQuery("#" + table_name + "_row_count_estimated_value_hard").val(json[0].row_count); |
| 579 |
} |
| 580 |
} catch (e) { |
| 581 |
alert('Ajax error: ' + e.message); |
| 582 |
} |
| 583 |
} |
| 584 |
); |
| 585 |
} |
| 586 |
|
| 587 |
function expandFieldset(id) { |
| 588 |
if (jQuery("#wpda_table_expand_" + id).is(":visible")) { |
| 589 |
jQuery("#wpda_field_expand_" + id).removeClass("fa-minus-circle"); |
| 590 |
jQuery("#wpda_field_expand_" + id).addClass("fa-plus-circle"); |
| 591 |
jQuery("#wpda_fieldset_expand_" + id).val("off"); |
| 592 |
jQuery("#wpda_table_expand_" + id).css("display", "none"); |
| 593 |
} else { |
| 594 |
jQuery("#wpda_field_expand_" + id).removeClass("fa-plus-circle"); |
| 595 |
jQuery("#wpda_field_expand_" + id).addClass("fa-minus-circle"); |
| 596 |
jQuery("#wpda_fieldset_expand_" + id).val("on"); |
| 597 |
jQuery("#wpda_table_expand_" + id).css("display", "table"); |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
function wpda_add_icons_to_dialog_buttons() { |
| 602 |
jQuery("div.ui-dialog div.ui-dialog-buttonset button").each(function() { |
| 603 |
switch(jQuery(this).text()) { |
| 604 |
case "OK": |
| 605 |
case "Select": |
| 606 |
case "Close": |
| 607 |
jQuery(this).prepend('<i class="fas fa-check wpda_icon_on_button"></i> '); |
| 608 |
break; |
| 609 |
case "Apply": |
| 610 |
jQuery(this).prepend('<i class="fas fa-code-commit wpda_icon_on_button"></i> '); |
| 611 |
break; |
| 612 |
case "Delete": |
| 613 |
jQuery(this).prepend('<i class="fas fa-trash wpda_icon_on_button"></i> '); |
| 614 |
break; |
| 615 |
case "Keep": |
| 616 |
jQuery(this).prepend('<i class="fas fa-eraser wpda_icon_on_button"></i> '); |
| 617 |
break; |
| 618 |
case "Cancel": |
| 619 |
jQuery(this).prepend('<i class="fas fa-times-circle wpda_icon_on_button"></i> '); |
| 620 |
break; |
| 621 |
} |
| 622 |
}); |
| 623 |
} |
| 624 |
|
| 625 |
function wpda_dbinit_admin( schema_name, wpnonce ) { |
| 626 |
jQuery.ajax({ |
| 627 |
method: 'POST', |
| 628 |
url: wpda_admin_vars.wpda_ajaxurl + '?action=wpda_dbinit_admin', |
| 629 |
data: { |
| 630 |
wpdaschema_name: schema_name, |
| 631 |
wpnonce: wpnonce, |
| 632 |
} |
| 633 |
}).done( |
| 634 |
function(data) { |
| 635 |
if (typeof data === "string") { |
| 636 |
msg = JSON.parse(data); |
| 637 |
} else { |
| 638 |
msg = data; |
| 639 |
} |
| 640 |
if (msg.status==="OK") { |
| 641 |
jQuery.notify('Database function wpda_get_wp_user_id() created', 'success'); |
| 642 |
} else { |
| 643 |
console.log(msg); |
| 644 |
jQuery.notify(msg.msg, 'error'); |
| 645 |
} |
| 646 |
} |
| 647 |
); |
| 648 |
} |
| 649 |
|
| 650 |
function wpda_toggle_password(id, e) { |
| 651 |
// Change input type |
| 652 |
let elm = document.getElementById(id); |
| 653 |
if (elm.type === "password") { |
| 654 |
elm.type = "text"; |
| 655 |
} else { |
| 656 |
elm.type = "password"; |
| 657 |
} |
| 658 |
|
| 659 |
// Change icon if applicable |
| 660 |
let icn = jQuery(e.target); |
| 661 |
if (icn.hasClass("fa-eye")) { |
| 662 |
icn.addClass("fa-eye-slash").removeClass("fa-eye"); |
| 663 |
} else if (icn.hasClass("fa-eye-slash")) { |
| 664 |
icn.addClass("fa-eye").removeClass("fa-eye-slash"); |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
function wpda_alert(title, txt) { |
| 669 |
jQuery("<p></p>").append(txt).dialog({ |
| 670 |
title: title, |
| 671 |
modal: true, |
| 672 |
buttons: { |
| 673 |
OK: function() { |
| 674 |
jQuery(this).dialog("close"); |
| 675 |
} |
| 676 |
} |
| 677 |
}); |
| 678 |
} |
| 679 |
|
| 680 |
function wpda_confirm(title, txt) { |
| 681 |
var defer = jQuery.Deferred(); |
| 682 |
|
| 683 |
jQuery("<p></p>").append(txt).dialog({ |
| 684 |
title: title, |
| 685 |
modal: true, |
| 686 |
buttons: { |
| 687 |
OK: function() { |
| 688 |
defer.resolve(true); |
| 689 |
jQuery(this).dialog("close"); |
| 690 |
}, |
| 691 |
CANCEL: function() { |
| 692 |
defer.resolve(false); |
| 693 |
jQuery(this).dialog("close"); |
| 694 |
} |
| 695 |
} |
| 696 |
}); |
| 697 |
|
| 698 |
return defer.promise(); |
| 699 |
} |
| 700 |
|
| 701 |
function restApiPanelOnChange(elem, panel) { |
| 702 |
if (elem.is(":checked")) { |
| 703 |
panel.show(); |
| 704 |
} else { |
| 705 |
panel.hide(); |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
function restApiAccessOnChange(elem, access) { |
| 710 |
if (elem.val() === "anonymous") { |
| 711 |
access.hide(); |
| 712 |
} else { |
| 713 |
access.show(); |
| 714 |
} |
| 715 |
} |
| 716 |
|
| 717 |
function submit_rest_api(schema_name, table_name, settings ) { |
| 718 |
// Submit |
| 719 |
wpda_rest_api( |
| 720 |
'save-settings', |
| 721 |
{ |
| 722 |
action: 'rest_api', |
| 723 |
dbs: schema_name, |
| 724 |
tbl: table_name, |
| 725 |
settings: JSON.stringify(settings), |
| 726 |
}, |
| 727 |
(function(data) { |
| 728 |
submitSettingsCallbackOk(data, "norownum"); |
| 729 |
}), |
| 730 |
submitSettingsCallbackError |
| 731 |
); |
| 732 |
|
| 733 |
return false; |
| 734 |
} |
| 735 |
|
| 736 |
function restApiTestCallbackOk(response, rownum) { |
| 737 |
if (response.code!==undefined && response.message!==undefined) { |
| 738 |
switch(response.code) { |
| 739 |
case "ok": |
| 740 |
jQuery.notify("Please check your console...", "success"); |
| 741 |
console.log(response); |
| 742 |
break; |
| 743 |
default: |
| 744 |
jQuery.notify("Please check your console...", "error"); |
| 745 |
console.error(response); |
| 746 |
} |
| 747 |
} else { |
| 748 |
restApiTestCallbackError(response); |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
function restApiTestCallbackError(response) { |
| 753 |
if (response.code!==undefined && response.message!==undefined) { |
| 754 |
jQuery.notify("Please check your console...", "error"); |
| 755 |
console.error(response); |
| 756 |
} else { |
| 757 |
jQuery.notify("Please check your console...", "error"); |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
var wpdaDeletedDashboardMenus = []; |
| 762 |
function deleteDashboardMenu(element, rownum) { |
| 763 |
let menu_id = jQuery(element).closest("tr").find(".wpda_dashboard_menu_id").val(); |
| 764 |
if (wpdaDeletedDashboardMenus[rownum]===undefined) { |
| 765 |
wpdaDeletedDashboardMenus[rownum] = []; |
| 766 |
} |
| 767 |
wpdaDeletedDashboardMenus[rownum].push(menu_id); |
| 768 |
jQuery(element).closest("tr").remove(); |
| 769 |
} |
| 770 |
|
| 771 |
wpdaMediaFrames = []; |
| 772 |
function wpdaInitMediaItem(mediaId, mediaContainer, mediaItem, mediaType, dataType, title, buttonText, mediaTypes) { |
| 773 |
wpdaMediaFrames[mediaId] = null; |
| 774 |
|
| 775 |
jQuery("#media_" + mediaId + "_upload_button").on("click", function (e) { |
| 776 |
e.preventDefault(); |
| 777 |
|
| 778 |
if (wpdaMediaFrames[mediaId]!==null) { |
| 779 |
wpdaMediaFrames[mediaId].open(); |
| 780 |
wpdaSetMediaSelection( |
| 781 |
mediaItem, |
| 782 |
wpdaMediaFrames[mediaId] |
| 783 |
); |
| 784 |
} else { |
| 785 |
wpdaMediaFrames[mediaId] = wp.media({ |
| 786 |
title: title, |
| 787 |
button: { |
| 788 |
text: buttonText |
| 789 |
}, |
| 790 |
library: { |
| 791 |
type: mediaTypes |
| 792 |
}, |
| 793 |
multiple: dataType==="number" ? "false" : "true", |
| 794 |
render: false |
| 795 |
}); |
| 796 |
|
| 797 |
wpdaMediaFrames[mediaId].on("select", function () { |
| 798 |
if ('number' === dataType) { |
| 799 |
attachment = wpdaMediaFrames[mediaId].state().get('selection').first().toJSON(); |
| 800 |
} else { |
| 801 |
attachment = wpdaMediaFrames[mediaId].state().get('selection').toJSON(); |
| 802 |
} |
| 803 |
|
| 804 |
wpdaGetMedia( |
| 805 |
mediaContainer, |
| 806 |
mediaItem, |
| 807 |
dataType, |
| 808 |
attachment, |
| 809 |
mediaType |
| 810 |
); |
| 811 |
}); |
| 812 |
|
| 813 |
wpdaMediaFrames[mediaId].open(); |
| 814 |
wpdaSetMediaSelection( |
| 815 |
mediaItem, |
| 816 |
wpdaMediaFrames[mediaId] |
| 817 |
); |
| 818 |
} |
| 819 |
}); |
| 820 |
|
| 821 |
jQuery("#media_" + mediaId + "_remove_button").on("click", function (e) { |
| 822 |
e.preventDefault(); |
| 823 |
mediaContainer.empty(); |
| 824 |
mediaItem.val(''); |
| 825 |
}); |
| 826 |
} |
| 827 |
|
| 828 |
function wpdaGetMedia(mediaContainer, mediaItem, dataType, attachment, attachmentType) { |
| 829 |
mediaContainer.empty(); |
| 830 |
if ('number' === dataType) { |
| 831 |
mediaItem.val(attachment.id); |
| 832 |
mediaContainer.append( |
| 833 |
wpdaGetMediaContent(attachment, attachmentType) |
| 834 |
); |
| 835 |
} else { |
| 836 |
mediaItem.val(''); |
| 837 |
for (var i = 0; i < attachment.length; ++i) { |
| 838 |
if (attachment[i].id !== '') { |
| 839 |
if (mediaItem.val() === '') { |
| 840 |
mediaItem.val(attachment[i].id); |
| 841 |
} else { |
| 842 |
mediaItem.val( |
| 843 |
mediaItem.val() + ',' + attachment[i].id |
| 844 |
); |
| 845 |
} |
| 846 |
mediaContainer.append( |
| 847 |
wpdaGetMediaContent(attachment[i], attachmentType) |
| 848 |
); |
| 849 |
} |
| 850 |
} |
| 851 |
} |
| 852 |
} |
| 853 |
|
| 854 |
function wpdaGetMediaContent(attachment, attachmentType) { |
| 855 |
switch(attachmentType) { |
| 856 |
case 'image': |
| 857 |
return wpdaGetMediaImage(attachment) |
| 858 |
case 'video': |
| 859 |
return wpdaGetMediaVideo(attachment) |
| 860 |
case 'audio': |
| 861 |
return wpdaGetMediaAudio(attachment) |
| 862 |
default: |
| 863 |
return wpdaGetMediaItem(attachment) |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
function wpdaGetMediaItem(attachment) { |
| 868 |
return ` |
| 869 |
<span class="wpda_media_container wpda_media"> |
| 870 |
<a href="${attachment.url}" target="_blank"> |
| 871 |
<img src="${attachment.icon}"> |
| 872 |
<br/> |
| 873 |
${attachment.title} |
| 874 |
</a> |
| 875 |
</span> |
| 876 |
`; |
| 877 |
} |
| 878 |
|
| 879 |
function wpdaGetMediaImage(attachment) { |
| 880 |
return ` |
| 881 |
<span class="wpda_media_container wpda_image"> |
| 882 |
<img src="${attachment.url}"/> |
| 883 |
</span> |
| 884 |
`; |
| 885 |
} |
| 886 |
|
| 887 |
function wpdaGetMediaAudio(attachment) { |
| 888 |
return ` |
| 889 |
<span class="wpda_media_container wpda_audio"> |
| 890 |
<audio src="${attachment.url}" controls></audio> |
| 891 |
</span> |
| 892 |
`; |
| 893 |
} |
| 894 |
|
| 895 |
function wpdaGetMediaVideo(attachment) { |
| 896 |
return ` |
| 897 |
<span class="wpda_media_container wpda_video"> |
| 898 |
<video controls> |
| 899 |
<source src="${attachment.url}"> |
| 900 |
</video> |
| 901 |
</span> |
| 902 |
`; |
| 903 |
} |
| 904 |
|
| 905 |
function wpdaSetMediaSelection(mediaItem, frame) { |
| 906 |
// Selects selected media in media uploader. |
| 907 |
selection = frame.state().get('selection'); |
| 908 |
media_ids = mediaItem.val(); |
| 909 |
media_ids = media_ids.split(','); |
| 910 |
media_ids.forEach( |
| 911 |
function (id) { |
| 912 |
attachment = wp.media.attachment(id); |
| 913 |
attachment.fetch(); |
| 914 |
selection.add(attachment ? [attachment] : []); |
| 915 |
} |
| 916 |
); |
| 917 |
} |
| 918 |
|
| 919 |
const setLegacyTools = () => { |
| 920 |
jQuery("#wpda-legacy-tool-settings-panel").toggle(); |
| 921 |
} |
| 922 |
|
| 923 |
const setLegacyToolStatus = (element) => { |
| 924 |
if (jQuery(element).find("i.fas.fa-toggle-off").length === 1) { |
| 925 |
// Turn on |
| 926 |
jQuery(element).html('<i class="fas fa-toggle-on" style="font-size: 28px;"></i>'); |
| 927 |
} else { |
| 928 |
// Turn off |
| 929 |
jQuery(element).html('<i class="fas fa-toggle-off" style="font-size: 28px;"></i>'); |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
const updateLegacyTools = () => { |
| 934 |
const toolStatus = {} |
| 935 |
|
| 936 |
jQuery.each( |
| 937 |
jQuery("#wpda-legacy-tool-settings-panel table td.status"), |
| 938 |
function(key, value) { |
| 939 |
const tool = jQuery(value).data("tool"); |
| 940 |
const status = jQuery(value).find("i.fas.fa-toggle-off").length === 0 |
| 941 |
toolStatus[tool] = status; |
| 942 |
} |
| 943 |
); |
| 944 |
|
| 945 |
jQuery("#wpda-legacy-tool-settings-legacy-tool-data").val(JSON.stringify(toolStatus)); |
| 946 |
jQuery("#wpda-legacy-tool-settings-form-data").submit(); |
| 947 |
} |
| 948 |
|
| 949 |
const submitMailCallbackOk = (response, debug) => { |
| 950 |
if (response.code!==undefined && response.message!==undefined) { |
| 951 |
switch(response.code) { |
| 952 |
case "ok": |
| 953 |
jQuery("#debugInfoContainer").parent().parent().hide() |
| 954 |
jQuery.notify(response.message, "success"); |
| 955 |
break; |
| 956 |
case "error": |
| 957 |
jQuery.notify(response.message, "error"); |
| 958 |
break; |
| 959 |
default: |
| 960 |
jQuery.notify("Application error! Please contact the plugin development team.", "error"); |
| 961 |
} |
| 962 |
|
| 963 |
if (debug === true) { |
| 964 |
jQuery("#debugInfoContainer").html(response.debug) |
| 965 |
jQuery("#debugInfoContainer").parent().parent().show() |
| 966 |
} |
| 967 |
} else { |
| 968 |
submitSettingsCallbackError(response); |
| 969 |
} |
| 970 |
|
| 971 |
jQuery('#mailSpinner').hide(); |
| 972 |
} |
| 973 |
|
| 974 |
const submitMailCallbackError = (response) => { |
| 975 |
if (response.code!==undefined && response.message!==undefined) { |
| 976 |
switch(response.code) { |
| 977 |
case "error": |
| 978 |
jQuery.notify(response.message, "error"); |
| 979 |
break; |
| 980 |
default: |
| 981 |
jQuery.notify("Application error! Please contact the plugin development team.", "error"); |
| 982 |
} |
| 983 |
} else { |
| 984 |
jQuery.notify("Application error! Please contact the plugin development team.", "error"); |
| 985 |
} |
| 986 |
|
| 987 |
jQuery('#mailSpinner').hide(); |
| 988 |
} |
| 989 |
|
| 990 |
const sendMail = (to, subject, message, debug) => { |
| 991 |
if (to.trim() === "" || subject.trim() === "" || message.trim() === "") { |
| 992 |
jQuery.notify("Invalid function call! Missing arguments.", "error"); |
| 993 |
jQuery('#mailSpinner').hide(); |
| 994 |
} else { |
| 995 |
wpda_rest_api( |
| 996 |
"action/mail", |
| 997 |
{ |
| 998 |
to: to, |
| 999 |
subject: subject, |
| 1000 |
message: message, |
| 1001 |
}, |
| 1002 |
function(response) { |
| 1003 |
submitMailCallbackOk(response, debug) |
| 1004 |
}, |
| 1005 |
submitSettingsCallbackError |
| 1006 |
); |
| 1007 |
} |
| 1008 |
} |