Subversion Repositories cheapmusic

Rev

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