changed create dialog

This commit is contained in:
sqozz 2015-02-21 04:29:47 +01:00
parent ebc7da1d05
commit 3092c2e615
5 changed files with 61 additions and 18 deletions

View File

@ -115,4 +115,4 @@ if __name__ == "__main__":
app.jinja_env.globals.update(getLocalString=getLocalString) app.jinja_env.globals.update(getLocalString=getLocalString)
app.jinja_env.globals.update(json=json) app.jinja_env.globals.update(json=json)
app.jinja_env.globals.update(sorted=sorted) app.jinja_env.globals.update(sorted=sorted)
app.run(debug=True) app.run(debug=False, host="0.0.0.0")

View File

@ -117,6 +117,10 @@ body {
display: inline; display: inline;
} }
.detectedInfosGroup {
display: none;
}
.row { .row {
margin-bottom: 10px; margin-bottom: 10px;
} }

View File

@ -28,35 +28,71 @@ function fillDetectedFilelist(file) {
fileList = document.querySelectorAll(".detectedFiles ul")[0] fileList = document.querySelectorAll(".detectedFiles ul")[0]
fileList.innerHTML = "" fileList.innerHTML = ""
reader.onload = function() { reader.onload = function() {
autodetectSuccess = false
b = new bencode() b = new bencode()
torrentObject = b.decode(reader.result) try {
for(var fileIndex = 0; fileIndex < torrentObject.info.files.length; fileIndex++){ torrentObject = b.decode(reader.result)
newListElement = document.createElement("li") } catch(err) {
newListElement.innerHTML = torrentObject.info.files[fileIndex].path[0]
fileList.appendChild(newListElement)
} }
document.querySelectorAll("input.name")[0].value = torrentObject.info.name if(torrentObject.info.name) {
document.querySelectorAll("input.name")[0].value = torrentObject.info.name
}
sizeGroup = document.querySelectorAll(".sizeGroup")[0] sizeGroup = document.querySelectorAll(".sizeGroup")[0]
if(torrentObject.info.pieces.length && torrentObject.info["piece length"]){ if(torrentObject.info.pieces.length && torrentObject.info["piece length"]) {
sizeGroup.style.display = "" sizeGroup.style.display = ""
document.querySelectorAll(".detectedSize")[0].innerHTML = ((Math.round((torrentObject.info.pieces.length / 20) * torrentObject.info["piece length"]) / 1024 / 1024 * 100) / 100) + " MB" size = (torrentObject.info.pieces.length / 20) * torrentObject.info["piece length"]
size = getNextUnit(size)
document.querySelectorAll(".detectedSize")[0].innerHTML = ((Math.round(size[0] * 100)) / 100) + " " + size[1]
autodetectSuccess = true
} else { } else {
sizeGroup.style.display = "none" sizeGroup.style.display = "none"
} }
trackerGroup = document.querySelectorAll(".trackerGroup")[0] trackerGroup = document.querySelectorAll(".trackerGroup")[0]
if(torrentObject.announce){ if(torrentObject.announce) {
trackerGroup.style.display = "" trackerGroup.style.display = ""
document.querySelectorAll(".detectedTracker")[0].innerHTML = torrentObject.announce document.querySelectorAll(".detectedTracker")[0].innerHTML = torrentObject.announce
autodetectSuccess = true
} else { } else {
trackerGroup.style.display = "none" trackerGroup.style.display = "none"
} }
filesGroup = document.querySelectorAll(".filesGroup")[0]
if(torrentObject.info.files.length > 0) {
autodetectSuccess = true
for(var fileIndex = 0; fileIndex < torrentObject.info.files.length; fileIndex++){
newListElement = document.createElement("li")
newListElement.innerHTML = torrentObject.info.files[fileIndex].path[0]
fileList.appendChild(newListElement)
}
}
var detectInfosGroup = document.querySelectorAll(".detectedInfosGroup")[0]
if(autodetectSuccess) {
detectInfosGroup.style.display = "block"
} else {
detectInfosGroup.style.display = "none"
}
} }
reader.readAsArrayBuffer(file) reader.readAsArrayBuffer(file)
} }
function getNextUnit(bSize) {
units = ["B", "kB", "MB", "GB", "TB", "PB", "To damn high"]
iters = 0
size = bSize
do {
size /= 1024
iters++
} while(size >= 1)
size *= 1024
if(iters > units.length) { iters = units.length }
return [size, units[iters - 1]]
}
// Fill a defined dropdown with values. // Fill a defined dropdown with values.
// These values will be generated out of the categories.json // These values will be generated out of the categories.json
function fillDropdownByValue(value, dropdownToFill) { function fillDropdownByValue(value, dropdownToFill) {

View File

@ -38,6 +38,9 @@
"create_new_torrent" : "Create a new torrent", "create_new_torrent" : "Create a new torrent",
"description" : "Description", "description" : "Description",
"audio_quality" : "Audio quality", "audio_quality" : "Audio quality",
"video_quality" : "Video quality" "video_quality" : "Video quality",
"size" : "Size",
"tracker" : "Tracker",
"detected_files" : "Detected files"
} }
} }

View File

@ -21,22 +21,22 @@ vim: ts=2 noexpandtab
<div class="form-group"> <div class="form-group">
<label for="inputTorrentFile" class="col-sm-3 control-label">{{ getLocalString(language, "torrent_file") }}</label> <label for="inputTorrentFile" class="col-sm-3 control-label">{{ getLocalString(language, "torrent_file") }}</label>
<div class="col-sm-9"> <div class="col-sm-9">
<input name="torrentFile" class="file" type="file" size="50" maxlength="100000" accept="text/*" onchange="setButtonToFilename(event)"> <input name="torrentFile" class="file" type="file" size="50" maxlength="100000" accept="application/x-bittorrent" onchange="setButtonToFilename(event)">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group detectedInfosGroup">
<label for="inputTorrentFile" class="col-sm-3 control-label">File info</label> <label for="inputTorrentFile" class="col-sm-3 control-label">File info</label>
<div class="col-sm-9 detectedInfos"> <div class="col-sm-9 detectedInfos">
<div class="detectedGroup sizeGroup"> <div class="detectedGroup sizeGroup">
<h5>Size:</h5> <h5>{{ getLocalString(language, "size") }}:</h5>
<p class="detectedSize">123MB</p> <p class="detectedSize"></p>
</div> </div>
<div class="detectedGroup trackerGroup"> <div class="detectedGroup trackerGroup">
<h5>Tracker:</h5> <h5>{{ getLocalString(language, "tracker") }}:</h5>
<p class="detectedTracker">http://foo.bar/tracker</p> <p class="detectedTracker"></p>
</div> </div>
<div class="detectedGroup filesGroup"> <div class="detectedGroup filesGroup">
<h5>Detected files:</h5> <h5>{{ getLocalString(language, "detected_files") }}:</h5>
<div class="detectedFiles"> <div class="detectedFiles">
<ul> <ul>
</ul> </ul>