Subversion Repositories cheapmusic

Rev

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