Rework categories and stuff
This commit is contained in:
		@@ -1,19 +1,12 @@
 | 
			
		||||
window.onload = function () {
 | 
			
		||||
	$('.dropdown li > a').click(function(e){
 | 
			
		||||
		setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement) //set the display-text to the selected value
 | 
			
		||||
		fillDropdownByValue(this.innerHTML, $(".dropdown")["1"])
 | 
			
		||||
		this.parentElement.parentElement.parentElement.classList.remove("open");
 | 
			
		||||
		return false;
 | 
			
		||||
	$('#subcategory').prop('disabled', true);
 | 
			
		||||
	$('#category').change(function() {
 | 
			
		||||
		fillSubcategory(this.value)
 | 
			
		||||
	});
 | 
			
		||||
	
 | 
			
		||||
	customizeUploadButton()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function setDropdownButtonText(text, dropdownButton) {
 | 
			
		||||
	var dropdownTextSpan = dropdownButton.getElementsByClassName("text")[0]
 | 
			
		||||
	dropdownTextSpan.innerHTML = text
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function sortCategories(categories) {
 | 
			
		||||
	var sortedCategories = []
 | 
			
		||||
	for(var key in categories) {
 | 
			
		||||
@@ -80,33 +73,28 @@ function fillDetectedFilelist(file) {
 | 
			
		||||
	reader.readAsArrayBuffer(file)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Fill a defined dropdown with values.
 | 
			
		||||
// These values will be generated out of the categories.json
 | 
			
		||||
function fillDropdownByValue(value, dropdownToFill) {
 | 
			
		||||
	dropdownToFill.getElementsByTagName("button")[0].disabled = false
 | 
			
		||||
	dropdownToFill.getElementsByClassName("text")[0].innerHTML = "Subcategorie"
 | 
			
		||||
	var dropdownToFillUl = dropdownToFill.getElementsByClassName("dropdown-menu")[0]
 | 
			
		||||
	dropdownToFillUl.innerHTML = ""
 | 
			
		||||
	valueDescriptor = getDescriptorByLocalString("english", value)
 | 
			
		||||
	subcategories = global_categories[valueDescriptor]
 | 
			
		||||
	subcategories = sortCategories(subcategories)
 | 
			
		||||
	for(subcategoryIndex in subcategories) {
 | 
			
		||||
		subcategoryLocalString = getLocalString("english", subcategories[subcategoryIndex])
 | 
			
		||||
		var newEntry = document.createElement("li")
 | 
			
		||||
		var newEntryLink = document.createElement("a")
 | 
			
		||||
		newEntry.setAttribute("role", "presentation")
 | 
			
		||||
		newEntryLink.setAttribute("role", "menuitem")
 | 
			
		||||
		newEntryLink.tabIndex = -1
 | 
			
		||||
		newEntryLink.href = "#"
 | 
			
		||||
		newEntryLink.innerHTML = subcategoryLocalString
 | 
			
		||||
		newEntryLink.onclick = function(e){
 | 
			
		||||
			setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement)
 | 
			
		||||
			this.parentElement.parentElement.parentElement.classList.remove("open");
 | 
			
		||||
			return false;
 | 
			
		||||
function fillSubcategory(value) {
 | 
			
		||||
	var subSelect = $('#subcategory')
 | 
			
		||||
	subSelect.empty();
 | 
			
		||||
	subSelect.append($('<option value="-1" selected>--- Select Subcategory ---</selected>'))
 | 
			
		||||
	if (value >= 0) {
 | 
			
		||||
		var subcategories = null
 | 
			
		||||
		for(var i = 0; i < global_categories.length; i++) {
 | 
			
		||||
			if (global_categories[i]["id"] == value) {
 | 
			
		||||
				subcategories = global_categories[i]["subcategories"]
 | 
			
		||||
				break
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if(subcategories) {
 | 
			
		||||
			for(subcategoryIndex in subcategories) {
 | 
			
		||||
				var subcategoryId = subcategories[subcategoryIndex]["id"]
 | 
			
		||||
				var subcategoryLocalString = subcategories[subcategoryIndex]["label"]
 | 
			
		||||
				var node = $('<option value="'+subcategoryId+'">'+subcategoryLocalString+'</string>')
 | 
			
		||||
				subSelect.append(node)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		newEntry.appendChild(newEntryLink)
 | 
			
		||||
		dropdownToFillUl.appendChild(newEntry)
 | 
			
		||||
	}
 | 
			
		||||
	subSelect.prop('disabled', value < 0)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Hides the default browser-upload-form and replaces it by an button
 | 
			
		||||
@@ -129,19 +117,11 @@ function setButtonToFilename(event) {
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Sets the text of a given dropdown-button to a given value
 | 
			
		||||
function setDropdownButtonText(text, dropdownButton) {
 | 
			
		||||
	var dropdownTextSpan = dropdownButton.getElementsByClassName("text")[0]
 | 
			
		||||
	dropdownHiddenValue = dropdownButton.getElementsByTagName("input")[0]
 | 
			
		||||
	dropdownHiddenValue.setAttribute("value", getDescriptorByLocalString("english", text))
 | 
			
		||||
	dropdownTextSpan.innerHTML = text
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function validateForm() {
 | 
			
		||||
	valid = true
 | 
			
		||||
	file = document.querySelectorAll("input.file")[0]
 | 
			
		||||
	category = document.querySelectorAll("input.category")[0]
 | 
			
		||||
	subcategory = document.querySelectorAll("input.subcategory")[0]
 | 
			
		||||
	category = document.querySelectorAll("#category")[0]
 | 
			
		||||
	subcategory = document.querySelectorAll("#subcategory")[0]
 | 
			
		||||
	torrentname = document.querySelectorAll("input.name")[0]
 | 
			
		||||
	description = document.querySelectorAll("textarea.description")[0]
 | 
			
		||||
	if(file.value.length <= 0) {
 | 
			
		||||
@@ -153,7 +133,7 @@ function validateForm() {
 | 
			
		||||
		file.parentElement.parentElement.classList.remove("has-error")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if(category.value.length <= 0) {
 | 
			
		||||
	if(category.value < 0) {
 | 
			
		||||
		valid = false
 | 
			
		||||
		category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.add("has-error")
 | 
			
		||||
		category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-success")
 | 
			
		||||
@@ -162,7 +142,7 @@ function validateForm() {
 | 
			
		||||
		category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-error")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if(subcategory.value.length <= 0) {
 | 
			
		||||
	if(subcategory.value < 0) {
 | 
			
		||||
		valid = false
 | 
			
		||||
		category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.add("has-error")
 | 
			
		||||
		category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-success")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user