Subversion Repositories cheapmusic

Rev

Rev 118 | Rev 121 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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