Subversion Repositories cheapmusic

Rev

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