Added translation methods to JS and Python
Modified "Create"-form
This commit is contained in:
@ -7,28 +7,28 @@ window.onload = function () {
|
||||
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 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]
|
||||
@ -38,51 +38,38 @@ function setDropdownButtonText(text, dropdownButton) {
|
||||
function sortCategories(categories) {
|
||||
var sortedCategories = []
|
||||
for(var key in categories) {
|
||||
sortedCategories.push(key)
|
||||
sortedCategories.push(categories[key])
|
||||
}
|
||||
sortedCategories.sort()
|
||||
return sortedCategories
|
||||
}
|
||||
|
||||
// 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 = ""
|
||||
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;
|
||||
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(){ setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement) }
|
||||
newEntry.appendChild(newEntryLink)
|
||||
dropdownToFillUl.appendChild(newEntry)
|
||||
}
|
||||
}
|
||||
|
||||
// Hides the default browser-upload-form and replaces it by an button
|
||||
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();
|
||||
@ -91,19 +78,31 @@ function customizeUploadButton() {
|
||||
});
|
||||
}
|
||||
|
||||
// This sets the Uploadbutton to the filename of the uploaded file
|
||||
function setButtonToFilename(event) {
|
||||
$("input[name='Datei']").each(function() {
|
||||
$("input[name='torrentFile']").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
|
||||
button.innerHTML = chunk(fileName, 40)
|
||||
});
|
||||
}
|
||||
|
||||
// Sets the text of a given dropdown-button to a given value
|
||||
function setDropdownButtonText(text, dropdownButton) {
|
||||
var dropdownTextSpan = dropdownButton.getElementsByClassName("text")[0]
|
||||
dropdownTextSpan.innerHTML = text
|
||||
}
|
||||
|
||||
customizeUploadButton()
|
||||
function chunk(string, n) {
|
||||
var ret = "";
|
||||
for(var i=0, len=string.length; i < len; i += n) {
|
||||
if(i==0) {
|
||||
ret = string.substr(i, n)
|
||||
} else {
|
||||
ret += "<br/>" + string.substr(i, n)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
};
|
||||
|
Reference in New Issue
Block a user