Subversion Repositories cheapmusic

Rev

Rev 68 | Rev 77 | 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, '');
73 - 214
        var cond = parent.getElementsByTagName("td")[5].innerHTML;
215
        var format = parent.getElementsByTagName("td")[6].innerHTML;
216
        var price = parent.getElementsByTagName("td")[7].innerHTML;
52 - 217
 
218
        document.getElementById("wlMsg").innerHTML = "";
219
        document.getElementById("wlId").value = id;
220
        document.getElementById("wlArtist").value = artist;
221
        document.getElementById("wlTitle").value = title;
222
        document.getElementById("wlBarcode").value = barcode;
73 - 223
        document.getElementById("wlCond").value = cond;
52 - 224
        document.getElementById("wlFormat").value = format;
225
        document.getElementById("wlPrice").value = price;
226
    }
227
 
228
    $("#editWishlistModal").modal();
229
}
230
 
231
function saveEditedWishlist() {
232
    var id = document.getElementById("wlId").value;
233
    var field = document.getElementById("wlIdRow" + id);
234
    var parent = field.parentNode;
235
    var artist = document.getElementById("wlArtist").value;
236
    var title = document.getElementById("wlTitle").value;
237
    var barcode = document.getElementById("wlBarcode").value;
73 - 238
    var cond = document.getElementById("wlCond").value;
52 - 239
    var format = document.getElementById("wlFormat").value;
240
    var price = document.getElementById("wlPrice").value;
241
 
242
    var xhttp = new XMLHttpRequest();
243
    xhttp.onreadystatechange = function() {
65 - 244
        if (this.readyState == 4) {
245
            json = JSON.parse(this.responseText);
246
            switch (json.retval) {
247
                case 0:
248
                    parent.getElementsByTagName("td")[1].innerHTML = artist;
249
                    parent.getElementsByTagName("td")[2].innerHTML = title;
250
                    parent.getElementsByTagName("td")[3].innerHTML = barcode;
66 - 251
                    parent.getElementsByTagName("td")[4].innerHTML = barcode; // bugbug Format
73 - 252
                    parent.getElementsByTagName("td")[5].innerHTML = cond;
253
                    parent.getElementsByTagName("td")[6].innerHTML = format;
254
                    parent.getElementsByTagName("td")[7].innerHTML = price;
255
                    parent.getElementsByTagName("td")[8].innerHTML = '$' + Number(price).toFixed(2); // bugbug Format
65 - 256
                    $("#editWishlistModal").modal('hide');
257
                    break;
258
                case 1:
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>" + json.msg + "</div>";
260
                    editWishlist(id, null)
261
                    break;
262
                default:
263
                    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>";
264
                    break;
265
            }
52 - 266
        }
267
    };
268
    xhttp.open("POST", "wishlistDB.php", true);
269
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
73 - 270
    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 - 271
}
272
 
43 - 273
// Pagination
65 - 274
function paginationSetup() {
57 - 275
    $("[id^=masterModal]").modal("hide");
43 - 276
    $('#discogsDeck').paginate({
277
        paginateElement: '.card',
278
        elementsPerPage: paginationPerPage(),
279
        effect: 'default',
280
        firstButtonText: '<i class="fas fa-angle-double-left"></i>',
281
        lastButtonText: '<i class="fas fa-angle-double-right"></i>',
282
        prevButtonText: '<i class="fas fa-angle-left"></i>',
283
        nextButtonText: '<i class="fas fa-angle-right"></i>',
61 - 284
        extraButtonClasses: 'btn bg-primary px-2 shadow-sm'
43 - 285
    });
65 - 286
    $('[data-toggle="tooltip"]').tooltip({
287
        trigger: 'hover'
288
    });
289
    $('[data-toggle2="tooltip"]').tooltip({
290
        trigger: 'hover'
291
    });
43 - 292
}
293
 
52 - 294
function filterWishlist() {
295
    var input, filter, table, tr, td, i, j, txtValue, flag;
296
    input = document.getElementById("tableFilter");
297
    filter = input.value.toUpperCase();
298
    table = document.getElementById("wishlistTable");
299
    tr = table.getElementsByTagName("tr");
300
    document.getElementById("tableFilterButton").style.display = (filter.length > 0 ? "" : "none");
301
 
302
    // Loop through all table rows, excluding the header, and hide those who don't match the search query
303
    for (i = 1; i < tr.length; i++) {
304
        td = tr[i].getElementsByTagName("td");
305
        flag = "none";
306
 
307
        for (j = 0; j < td.length; j++) {
308
            if (td[j]) {
309
                txtValue = td[j].textContent || td[j].innerText;
310
                if (txtValue.toUpperCase().indexOf(filter) > -1) {
311
                    flag = "";
312
                    break;
313
                }
314
            }
315
        }
316
 
317
        tr[i].style.display = flag;
318
    }
319
}
320
 
321
function mysqliHtmlDecode(str) {
322
    str = str.replace(/&amp;/g, '&');
323
    str = str.replace(/&lt;/g, '<');
324
    str = str.replace(/&gt;/g, '>');
325
    return str;
326
}
327
 
46 - 328
// number of discogs entries per page according to screen size
43 - 329
function paginationPerPage() {
65 - 330
    var width = $(window).width();
61 - 331
    var num = Math.floor(width / 210);
332
    if (num > 9) {
333
        num = 9;
334
    } else if (width < 576) {
335
        num = 1;
43 - 336
    }
61 - 337
    return num;
43 - 338
}
46 - 339
 
340
// sort table by column
341
function sortTable(table, col, colType) {
342
    var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
343
    table = document.getElementById(table);
344
    switching = true;
345
    // Set the sorting direction to ascending:
346
    dir = "asc";
347
    /* Make a loop that will continue until no switching has been done: */
348
    while (switching) {
349
        // Start by saying: no switching is done:
350
        switching = false;
351
        rows = table.rows;
352
        /* Loop through all table rows (except the first, which contains table headers): */
353
        for (i = 1; i < (rows.length - 1); i++) {
354
            // Start by saying there should be no switching:
355
            shouldSwitch = false;
356
            /* Get the two elements you want to compare, one from current row and one from the next: */
357
            x = rows[i].getElementsByTagName("TD")[col];
358
            y = rows[i + 1].getElementsByTagName("TD")[col];
359
            /* Check if the two rows should switch place, based on the direction, asc or desc: */
360
            if (dir == "asc") {
361
                if (colType == 'numeric') {
362
                    if (Number(x.innerHTML) > Number(y.innerHTML.toLowerCase)) {
363
                        // If so, mark as a switch and break the loop:
364
                        shouldSwitch = true;
365
                        break;
366
                    }
367
                } else /* if (colType == 'text') */ {
368
                    if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
369
                        // If so, mark as a switch and break the loop:
370
                        shouldSwitch = true;
371
                        break;
372
                    }
373
                }
374
            } else if (dir == "desc") {
375
                if (colType == 'numeric') {
376
                    if (Number(x.innerHTML) < Number(y.innerHTML)) {
377
                        // If so, mark as a switch and break the loop:
378
                        shouldSwitch = true;
379
                        break;
380
                    }
381
                } else /* if (colType == 'text') */ {
382
                    if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
383
                        // If so, mark as a switch and break the loop:
384
                        shouldSwitch = true;
385
                        break;
386
                    }
387
                }
388
            }
389
        }
390
        if (shouldSwitch) {
391
            /* If a switch has been marked, make the switch and mark that a switch has been done: */
392
            rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
393
            switching = true;
394
            // Each time a switch is done, increase this count by 1:
395
            switchcount++;
396
        } else {
397
            /* If no switching has been done AND the direction is "asc", set the direction to "desc" and run the while loop again. */
398
            if (switchcount == 0 && dir == "asc") {
399
                dir = "desc";
400
                switching = true;
401
            }
402
        }
403
    }
66 - 404
}