Subversion Repositories cheapmusic

Rev

Rev 81 | Rev 87 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15 - 1
$(document).ready(function() {
52 - 2
    var x;
23 - 3
 
65 - 4
    $('[data-toggle="tooltip"]').tooltip({
5
        trigger: 'hover'
6
    });
66 - 7
 
65 - 8
    $('[data-toggle2="tooltip"]').tooltip({
9
        trigger: 'hover'
10
    });
66 - 11
 
65 - 12
    $('[rel="tooltip"]').on('click', function() {
13
        $(this).tooltip('hide');
14
    });
15
 
20 - 16
    $('.flexdatalist').flexdatalist();
17
    $(function() {
18
        $("input[id='searchTerm-flexdatalist']").clearer();
19
    });
65 - 20
    $('.flexdatalist').flexdatalist({
21
        minLength: 0,
22
        searchContain: true,
23
        noResultsText: ""
24
    }); /* reset after running clearer */
6 - 25
 
15 - 26
    $(window).on('beforeunload', function() {
27
        $(":submit").attr('disabled', 'disabled');
47 - 28
        document.body.style.cursor = "progress";
15 - 29
    });
30
 
43 - 31
    $(window).bind('resize orientationchange', paginationSetup);
32
 
15 - 33
    tableFilterButtons();
66 - 34
    detailTableFilterButtons();
43 - 35
    paginationSetup();
66 - 36
    navTabs();
52 - 37
 
38
    x = document.getElementById("tableFilterButton")
39
    if (x) {
40
        x.style.display = "none";
41
    }
81 - 42
 
43
    // Floating Top Navigation Button:
44
    window.onscroll = function() {scrollFunction()};
6 - 45
});
11 - 46
 
15 - 47
function tableFilterButtons() {
66 - 48
    $(".filterButton,.filterButtonSmall").click(function() {
49
        $.post("filterTable.php",
50
            {
51
                submit: $(this).attr("value"),
52
                sessionTab: document.getElementById("sessionTab").value
53
            },
54
            function(data, status) {
55
                if (status == "success") {
56
                    document.getElementById("productTable").innerHTML = data;
57
                    tableFilterButtons();
58
                    detailTableFilterButtons();
59
                    navTabs();
60
                }
15 - 61
            }
66 - 62
        );
15 - 63
    });
64
}
65
 
66 - 66
function detailTableFilterButtons() {
67
    $("#detailFilterForm").on('submit',function(e){e.preventDefault();return false;});
68
    $(".detailFilterButton").click(function() {
69
        var formData = $("#detailFilterForm").serializeArray();
70
        formData.push({ name: this.name, value: this.value });
71
        $.post("filterTable.php",
72
            formData,
73
            function(data, status) {
74
                if (status == "success") {
75
                    document.getElementById("productTable").innerHTML = data;
76
                    detailTableFilterButtons();
77
                    tableFilterButtons();
78
                    navTabs();
79
                }
80
            }
81
        );
82
    });
83
}
84
 
85
function navTabs() {
86
    $('.nav-tabs a').click(function(e){
87
        e.preventDefault();
88
        $(this).tab('show');
89
        if ($(this).attr('id') == "quickTab") {
68 - 90
            $(this).attr('class', 'nav-link active bg-white');
91
            $('#detailTab').attr('class', 'nav-link bg-white invert');
66 - 92
        } else /* detailTab */ {
68 - 93
            $(this).attr('class', 'nav-link active bg-white');
94
            $('#quickTab').attr('class', 'nav-link bg-white invert');
66 - 95
        }
96
        navTabs();
97
    });
98
 
99
}
100
 
64 - 101
function alertAutoClose() {
102
    window.setTimeout(function() {
65 - 103
        $(".alert").fadeTo(1000, 0).slideUp(1000, function() {
64 - 104
            $(this).remove();
105
        });
106
    }, 3000);
107
}
108
 
15 - 109
function initProgressBarModal(title) {
110
    var elem = document.getElementById("progressBar");
111
    elem.style.width = '0%';
112
    elem.innerHTML = '0%';
113
 
114
    elem = document.getElementById("progressBarHeader");
115
    elem.innerHTML = title;
116
 
84 - 117
    elem = document.getElementById("progressBarMessage");
118
    elem.innerHTML = "";
119
 
65 - 120
    $("#progressBarDiv").modal({
121
        backdrop: "static"
122
    });
15 - 123
}
124
 
125
function updateProgressBar(width, message) {
126
    var elem = document.getElementById("progressBar");
84 - 127
    if (elem && width) {
128
        elem.style.width = width + '%';
129
        elem.innerHTML = width.toFixed(0) + '%';
130
        // bugbug document.getElementById("progressBarMessage").innerHTML = message;
131
    }
15 - 132
}
133
 
134
function endProgressBarModal() {
135
    $("#progressBarDiv").modal("hide");
136
}
137
 
138
// Refresh the progress bar.
139
function refreshProgress() {
140
    $.ajax({
141
        url: "pbChecker.php?file=" + document.getElementById("sessionId").value + "_" + document.getElementById("sessionTab").value,
142
        success: function(data) {
143
            updateProgressBar(data.percent, data.message);
77 - 144
            if (data.percent >= 100) {
15 - 145
                window.clearInterval(timer);
146
                timer = window.setInterval(completeProgress, 1000);
147
            }
148
        }
149
    });
150
}
151
 
152
// End the progress bar.
153
function completeProgress() {
154
    updateProgressBar(100, "Completed");
155
    window.clearInterval(timer);
39 - 156
    endProgressBarModal();
15 - 157
}
158
 
159
// Start the progress bar.
160
function progressBar(title) {
161
    initProgressBarModal(title);
162
    timer = window.setInterval(refreshProgress, 1000);
28 - 163
}
164
 
52 - 165
function saveTransfer(url) {
28 - 166
    var xhttp = new XMLHttpRequest();
167
    xhttp.open("POST", "savetransfer.php", true);
168
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
52 - 169
    xhttp.send("target=" + btoa(url) + "&sessionTab=" + document.getElementById("sessionTab").value);
43 - 170
}
171
 
52 - 172
function addWishlist(id, field, cnt, wl) {
173
    $(field).tooltip('hide');
174
    $(field).remove();
175
    var xhttp = new XMLHttpRequest();
176
    xhttp.onreadystatechange = function() {
177
        if (this.readyState == 4) {
65 - 178
            json = JSON.parse(this.responseText);
179
            switch (json.retval) {
52 - 180
                case 0:
181
                    msg = "Added to wishlist.";
182
                    alert = "alert-success";
183
                    break;
184
                case 1:
185
                    msg = "Already on the wishlist.";
186
                    alert = "alert-warning";
187
                    break;
188
                default:
189
                    msg = "ERROR! Could not add to the wishlist.";
190
                    alert = "alert-dangere";
191
                    break;
192
            }
65 - 193
            document.getElementById("wishlistAdd" + cnt).innerHTML = "<div class=\"alert " + alert + " alert-dismissible mt-2 mb-0\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" + msg + "</div>";;
194
            alertAutoClose();
195
        }
196
    };
52 - 197
    xhttp.open("POST", "wishlistDB.php", true);
198
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
199
    xhttp.send("id=" + id + "&function=add&wl=" + wl + "&sessionTab=" + document.getElementById("sessionTab").value);
200
}
201
 
202
function deleteWishlist(id, field, title, artist) {
203
    $(field).tooltip('hide');
68 - 204
    if (confirm('Remove ' + title + ' by ' + artist + ' from wishlist?')) {
58 - 205
        var parent = field.parentNode.parentNode.parentNode;
52 - 206
        var xhttp = new XMLHttpRequest();
207
        xhttp.open("POST", "wishlistDB.php", true);
208
        xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
209
        xhttp.send("function=delete&id=" + id + "&sessionTab=" + document.getElementById("sessionTab").value);
210
        parent.parentNode.removeChild(parent);
211
    }
212
}
213
 
214
function editWishlist(id, field) {
215
    if (field !== null) {
216
        $(field).tooltip('hide');
58 - 217
        var parent = field.parentNode.parentNode.parentNode;
52 - 218
 
219
        var artist = mysqliHtmlDecode(parent.getElementsByTagName("td")[1].innerHTML);
220
        var title = mysqliHtmlDecode(parent.getElementsByTagName("td")[2].innerHTML);
221
        var barcode = parent.getElementsByTagName("td")[3].innerHTML.replace(/-/g, '');
73 - 222
        var cond = parent.getElementsByTagName("td")[5].innerHTML;
223
        var format = parent.getElementsByTagName("td")[6].innerHTML;
224
        var price = parent.getElementsByTagName("td")[7].innerHTML;
52 - 225
 
226
        document.getElementById("wlMsg").innerHTML = "";
227
        document.getElementById("wlId").value = id;
228
        document.getElementById("wlArtist").value = artist;
229
        document.getElementById("wlTitle").value = title;
230
        document.getElementById("wlBarcode").value = barcode;
73 - 231
        document.getElementById("wlCond").value = cond;
52 - 232
        document.getElementById("wlFormat").value = format;
233
        document.getElementById("wlPrice").value = price;
234
    }
235
 
236
    $("#editWishlistModal").modal();
237
}
238
 
239
function saveEditedWishlist() {
240
    var id = document.getElementById("wlId").value;
241
    var field = document.getElementById("wlIdRow" + id);
242
    var parent = field.parentNode;
243
    var artist = document.getElementById("wlArtist").value;
244
    var title = document.getElementById("wlTitle").value;
245
    var barcode = document.getElementById("wlBarcode").value;
73 - 246
    var cond = document.getElementById("wlCond").value;
52 - 247
    var format = document.getElementById("wlFormat").value;
248
    var price = document.getElementById("wlPrice").value;
249
 
250
    var xhttp = new XMLHttpRequest();
251
    xhttp.onreadystatechange = function() {
65 - 252
        if (this.readyState == 4) {
253
            json = JSON.parse(this.responseText);
254
            switch (json.retval) {
255
                case 0:
256
                    parent.getElementsByTagName("td")[1].innerHTML = artist;
257
                    parent.getElementsByTagName("td")[2].innerHTML = title;
258
                    parent.getElementsByTagName("td")[3].innerHTML = barcode;
66 - 259
                    parent.getElementsByTagName("td")[4].innerHTML = barcode; // bugbug Format
73 - 260
                    parent.getElementsByTagName("td")[5].innerHTML = cond;
261
                    parent.getElementsByTagName("td")[6].innerHTML = format;
262
                    parent.getElementsByTagName("td")[7].innerHTML = price;
263
                    parent.getElementsByTagName("td")[8].innerHTML = '$' + Number(price).toFixed(2); // bugbug Format
65 - 264
                    $("#editWishlistModal").modal('hide');
265
                    break;
266
                case 1:
267
                    document.getElementById("wlMsg").innerHTML = "<div class=\"alert alert-danger alert-dismissible mt-0 mb-0\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" + json.msg + "</div>";
268
                    editWishlist(id, null)
269
                    break;
270
                default:
271
                    document.getElementById("wlMsg").innerHTML = "<div class=\"alert alert-danger alert-dismissible mt-0 mb-0\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>Unknown Error. Please reload page.</div>";
272
                    break;
273
            }
52 - 274
        }
275
    };
276
    xhttp.open("POST", "wishlistDB.php", true);
277
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
73 - 278
    xhttp.send("function=update&id=" + id + "&artist=" + encodeURIComponent(artist) + "&title=" + encodeURIComponent(title) + "&barcode=" + encodeURIComponent(barcode) + "&cond=" + encodeURIComponent(cond) + "&format=" + encodeURIComponent(format) + "&price=" + encodeURIComponent(price) + "&sessionTab=" + document.getElementById("sessionTab").value);
52 - 279
}
280
 
43 - 281
// Pagination
65 - 282
function paginationSetup() {
57 - 283
    $("[id^=masterModal]").modal("hide");
43 - 284
    $('#discogsDeck').paginate({
285
        paginateElement: '.card',
286
        elementsPerPage: paginationPerPage(),
287
        effect: 'default',
288
        firstButtonText: '<i class="fas fa-angle-double-left"></i>',
289
        lastButtonText: '<i class="fas fa-angle-double-right"></i>',
290
        prevButtonText: '<i class="fas fa-angle-left"></i>',
291
        nextButtonText: '<i class="fas fa-angle-right"></i>',
61 - 292
        extraButtonClasses: 'btn bg-primary px-2 shadow-sm'
43 - 293
    });
65 - 294
    $('[data-toggle="tooltip"]').tooltip({
295
        trigger: 'hover'
296
    });
297
    $('[data-toggle2="tooltip"]').tooltip({
298
        trigger: 'hover'
299
    });
43 - 300
}
301
 
52 - 302
function filterWishlist() {
303
    var input, filter, table, tr, td, i, j, txtValue, flag;
304
    input = document.getElementById("tableFilter");
305
    filter = input.value.toUpperCase();
306
    table = document.getElementById("wishlistTable");
307
    tr = table.getElementsByTagName("tr");
308
    document.getElementById("tableFilterButton").style.display = (filter.length > 0 ? "" : "none");
309
 
310
    // Loop through all table rows, excluding the header, and hide those who don't match the search query
311
    for (i = 1; i < tr.length; i++) {
312
        td = tr[i].getElementsByTagName("td");
313
        flag = "none";
314
 
315
        for (j = 0; j < td.length; j++) {
316
            if (td[j]) {
317
                txtValue = td[j].textContent || td[j].innerText;
318
                if (txtValue.toUpperCase().indexOf(filter) > -1) {
319
                    flag = "";
320
                    break;
321
                }
322
            }
323
        }
324
 
325
        tr[i].style.display = flag;
326
    }
327
}
328
 
329
function mysqliHtmlDecode(str) {
330
    str = str.replace(/&amp;/g, '&');
331
    str = str.replace(/&lt;/g, '<');
332
    str = str.replace(/&gt;/g, '>');
333
    return str;
334
}
335
 
46 - 336
// number of discogs entries per page according to screen size
43 - 337
function paginationPerPage() {
65 - 338
    var width = $(window).width();
61 - 339
    var num = Math.floor(width / 210);
340
    if (num > 9) {
341
        num = 9;
342
    } else if (width < 576) {
343
        num = 1;
43 - 344
    }
61 - 345
    return num;
43 - 346
}
46 - 347
 
348
// sort table by column
349
function sortTable(table, col, colType) {
350
    var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
351
    table = document.getElementById(table);
352
    switching = true;
353
    // Set the sorting direction to ascending:
354
    dir = "asc";
355
    /* Make a loop that will continue until no switching has been done: */
356
    while (switching) {
357
        // Start by saying: no switching is done:
358
        switching = false;
359
        rows = table.rows;
360
        /* Loop through all table rows (except the first, which contains table headers): */
361
        for (i = 1; i < (rows.length - 1); i++) {
362
            // Start by saying there should be no switching:
363
            shouldSwitch = false;
364
            /* Get the two elements you want to compare, one from current row and one from the next: */
365
            x = rows[i].getElementsByTagName("TD")[col];
366
            y = rows[i + 1].getElementsByTagName("TD")[col];
367
            /* Check if the two rows should switch place, based on the direction, asc or desc: */
368
            if (dir == "asc") {
369
                if (colType == 'numeric') {
370
                    if (Number(x.innerHTML) > Number(y.innerHTML.toLowerCase)) {
371
                        // If so, mark as a switch and break the loop:
372
                        shouldSwitch = true;
373
                        break;
374
                    }
375
                } else /* if (colType == 'text') */ {
376
                    if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
377
                        // If so, mark as a switch and break the loop:
378
                        shouldSwitch = true;
379
                        break;
380
                    }
381
                }
382
            } else if (dir == "desc") {
383
                if (colType == 'numeric') {
384
                    if (Number(x.innerHTML) < Number(y.innerHTML)) {
385
                        // If so, mark as a switch and break the loop:
386
                        shouldSwitch = true;
387
                        break;
388
                    }
389
                } else /* if (colType == 'text') */ {
390
                    if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
391
                        // If so, mark as a switch and break the loop:
392
                        shouldSwitch = true;
393
                        break;
394
                    }
395
                }
396
            }
397
        }
398
        if (shouldSwitch) {
399
            /* If a switch has been marked, make the switch and mark that a switch has been done: */
400
            rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
401
            switching = true;
402
            // Each time a switch is done, increase this count by 1:
403
            switchcount++;
404
        } else {
405
            /* If no switching has been done AND the direction is "asc", set the direction to "desc" and run the while loop again. */
406
            if (switchcount == 0 && dir == "asc") {
407
                dir = "desc";
408
                switching = true;
409
            }
410
        }
411
    }
66 - 412
}
81 - 413
 
414
function scrollFunction() {
415
    var topButton = document.getElementById("topBtn");
416
 
417
    if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
418
        topButton.style.display = "block";
419
    } else {
420
        topButton.style.display = "none";
421
    }
422
}
423
 
424
function topFunction() {
425
    document.body.scrollTop = document.documentElement.scrollTop = 0;
426
}