110 lines
4.1 KiB
JavaScript
110 lines
4.1 KiB
JavaScript
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"])
|
|
});
|
|
|
|
customizeUploadButton()
|
|
}
|
|
|
|
function fillDropdownByValue(value, dropdownToFill) {
|
|
dropdownToFill.getElementsByClassName("text")[0].innerHTML = "Subcategory"
|
|
var dropdownToFillUl = dropdownToFill.getElementsByClassName("dropdown-menu")[0]
|
|
dropdownToFillUl.innerHTML = ""
|
|
|
|
subCategory = getDescriptorByLocalString("english", value)
|
|
catList = document.getElementById("subcategory_list")
|
|
catList.innerHTML = ""
|
|
categories = global_categories[subCategory].sort()
|
|
for(var key in categories) {
|
|
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 = getLocalString("english", categories[key])
|
|
newEntryLink.onclick = function(){ setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement) }
|
|
newEntry.appendChild(newEntryLink)
|
|
dropdownToFillUl.appendChild(newEntry)
|
|
}
|
|
}
|
|
|
|
function setDropdownButtonText(text, dropdownButton) {
|
|
var dropdownTextSpan = dropdownButton.getElementsByClassName("text")[0]
|
|
dropdownTextSpan.innerHTML = text
|
|
}
|
|
|
|
function sortCategories(categories) {
|
|
var sortedCategories = []
|
|
for(var key in categories) {
|
|
sortedCategories.push(key)
|
|
}
|
|
sortedCategories.sort()
|
|
return sortedCategories
|
|
}
|
|
|
|
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 = ""
|
|
switch(value) {
|
|
case "Action":
|
|
for(i = 0; i < 10; i++) {
|
|
// <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
|
|
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 = "foo" + i
|
|
newEntryLink.onclick = function(){ setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement) }
|
|
newEntry.appendChild(newEntryLink)
|
|
dropdownToFillUl.appendChild(newEntry)
|
|
}
|
|
break;
|
|
case "Another action":
|
|
for(i = 0; i < 10; i++) {
|
|
// <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
|
|
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 = "bar" + i
|
|
newEntryLink.onclick = function(){ setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement) }
|
|
newEntry.appendChild(newEntryLink)
|
|
dropdownToFillUl.appendChild(newEntry)
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
function customizeUploadButton() {
|
|
$(".tfile").before('<button id="button-file" type="button" class="btn btn-default"><span class="text">Upload...</span><span class="glyphicon glyphicon-open-file" aria-hidden="true"></span></button>');
|
|
$(".tfile").hide();
|
|
$('body').on('click', '#button-file', function() {
|
|
$(".tfile").trigger('click');
|
|
});
|
|
}
|
|
|
|
function setButtonToFilename(event) {
|
|
$("input[name='Datei']").each(function() {
|
|
var fileName = $(this).val().split('/').pop().split('\\').pop();
|
|
console.log(event["target"]);
|
|
targetInput = event["target"]
|
|
button = targetInput.previousSibling.getElementsByClassName("text")[0]
|
|
button.innerHTML = fileName
|
|
});
|
|
}
|
|
|
|
function setDropdownButtonText(text, dropdownButton) {
|
|
var dropdownTextSpan = dropdownButton.getElementsByClassName("text")[0]
|
|
dropdownTextSpan.innerHTML = text
|
|
}
|
|
|
|
customizeUploadButton()
|