Subversion Repositories cheapmusic

Rev

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