Subversion Repositories cheapmusic

Rev

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