Subversion Repositories cheapmusic

Rev

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