Rev 46 | Rev 57 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip({trigger : 'hover'});
$('[data-toggle2="tooltip"]').tooltip({trigger : 'hover'});
$('[rel="tooltip"]').on('click', function() {$(this).tooltip('hide');});
$('.flexdatalist').flexdatalist();
$(function() {
$("input[id='searchTerm-flexdatalist']").clearer();
});
$('.flexdatalist').flexdatalist({minLength: 0, searchContain : true, noResultsText: ""}); /* reset after running clearer */
$(window).on('beforeunload', function() {
$(":submit").attr('disabled', 'disabled');
document.body.style.cursor = "progress";
});
$(window).bind('resize orientationchange', paginationSetup);
tableFilterButtons();
paginationSetup();
});
function tableFilterButtons() {
$(".filterButton").click(function() {
$.post("filterTable.php", {
submit: $(this).attr("value"),
sessionTab: document.getElementById("sessionTab").value
}, function(data, status) {
if (status == "success") {
document.getElementById("productTable").innerHTML = data;
tableFilterButtons();
}
});
});
}
function initProgressBarModal(title) {
var elem = document.getElementById("progressBar");
elem.style.width = '0%';
elem.innerHTML = '0%';
elem = document.getElementById("progressBarHeader");
elem.innerHTML = title;
$("#progressBarDiv").modal({backdrop: "static"});
}
function updateProgressBar(width, message) {
var elem = document.getElementById("progressBar");
elem.style.width = width + '%';
elem.innerHTML = width.toFixed(0) + '%';
// bugbug document.getElementById("progressBarMessage").innerHTML = message;
}
function endProgressBarModal() {
$("#progressBarDiv").modal("hide");
}
// Refresh the progress bar.
function refreshProgress() {
$.ajax({
url: "pbChecker.php?file=" + document.getElementById("sessionId").value + "_" + document.getElementById("sessionTab").value,
success: function(data) {
updateProgressBar(data.percent, data.message);
if (data.percent == 100) {
window.clearInterval(timer);
timer = window.setInterval(completeProgress, 1000);
}
}
});
}
// End the progress bar.
function completeProgress() {
updateProgressBar(100, "Completed");
window.clearInterval(timer);
endProgressBarModal();
}
// Start the progress bar.
function progressBar(title) {
initProgressBarModal(title);
timer = window.setInterval(refreshProgress, 1000);
}
function saveTransfer($url) {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "savetransfer.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("target=" + btoa($url) + "&sessionTab=" + document.getElementById("sessionTab").value);
}
// Pagination
function paginationSetup(){
$('#discogsDeck').paginate({
paginateElement: '.card',
elementsPerPage: paginationPerPage(),
effect: 'default',
firstButtonText: '<i class="fas fa-angle-double-left"></i>',
lastButtonText: '<i class="fas fa-angle-double-right"></i>',
prevButtonText: '<i class="fas fa-angle-left"></i>',
nextButtonText: '<i class="fas fa-angle-right"></i>',
extraButtonClasses: 'btn btn-primary px-2 shadow-sm'
});
$('[data-toggle="tooltip"]').tooltip({trigger : 'hover'});
$('[data-toggle2="tooltip"]').tooltip({trigger : 'hover'});
}
// number of discogs entries per page according to screen size
function paginationPerPage() {
width = $( document ).width();
if (width < 576){
return 1;
} else if (width < 768){
return 2;
} else if (width < 992){
return 3;
} else if (width < 1200){
return 4;
} else {
return 6;
}
}
// sort table by column
function sortTable(table, col, colType) {
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
table = document.getElementById(table);
switching = true;
// Set the sorting direction to ascending:
dir = "asc";
/* Make a loop that will continue until no switching has been done: */
while (switching) {
// Start by saying: no switching is done:
switching = false;
rows = table.rows;
/* Loop through all table rows (except the first, which contains table headers): */
for (i = 1; i < (rows.length - 1); i++) {
// Start by saying there should be no switching:
shouldSwitch = false;
/* Get the two elements you want to compare, one from current row and one from the next: */
x = rows[i].getElementsByTagName("TD")[col];
y = rows[i + 1].getElementsByTagName("TD")[col];
/* Check if the two rows should switch place, based on the direction, asc or desc: */
if (dir == "asc") {
if (colType == 'numeric') {
if (Number(x.innerHTML) > Number(y.innerHTML.toLowerCase)) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
} else /* if (colType == 'text') */ {
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
}
} else if (dir == "desc") {
if (colType == 'numeric') {
if (Number(x.innerHTML) < Number(y.innerHTML)) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
} else /* if (colType == 'text') */ {
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
}
}
}
if (shouldSwitch) {
/* If a switch has been marked, make the switch and mark that a switch has been done: */
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
// Each time a switch is done, increase this count by 1:
switchcount++;
} else {
/* If no switching has been done AND the direction is "asc", set the direction to "desc" and run the while loop again. */
if (switchcount == 0 && dir == "asc") {
dir = "desc";
switching = true;
}
}
}
}