/* $Id: maketorrent.js 2874 2007-04-12 11:19:49Z munk $ */
// fields
var trackerState = 1;
var anlst = "(optional) announce_list = list of tracker URLs
\n";
anlst += " url[,url...][|url[,url...]...]
\n";
anlst += " URLs separated by commas are tried first
\n";
anlst += " before URLs separated by the pipe is checked.
\n";
anlst += "Examples:
\n";
anlst += " http://a.com|http://b.com|http://c.com
\n";
anlst += " (tries a-c in order)
\n";
anlst += " http://a.com,http://b.com,http://c.com
\n";
anlst += " (tries a-c in a randomly selected order)
\n";
anlst += " http://a.com|http://b.com,http://c.com
\n";
anlst += " (tries a first, then tries b-c randomly)
\n";
var annce = "tracker announce URL.
\n";
annce += "Example:
\n";
annce += " http://tracker.com/announce
\n";
var tornt = "torrent name to be saved as
\n";
tornt += "Example:
\n";
tornt += " gnome-livecd-2.10.torrent
\n";
var comnt = "add a comment to your torrent file (optional)
\n";
comnt += "";
var piece = "data piece size for torrent
\n";
piece += "power of 2 value to set the piece size to
\n";
piece += "(0 = automatic) (0 only option in this version)
\n";
var prvte = "private tracker support
\n";
prvte += "(disallows DHT if enabled)
\n";
var dhtbl = "DHT (Distributed Hash Table)
\n";
dhtbl += "can only be set abled if private flag is not set true
\n";
/**
* doSubmit
*/
function doSubmit(obj, client) {
// Basic check to see if maketorrent is already running
if (obj.value === "Creating...")
return false;
// Run some basic validation
var valid = true;
var tlength = document.maketorrent.torrent.value.length - 8;
var torrent = document.maketorrent.torrent.value.substr(tlength);
document.getElementById('output').innerHTML = "";
document.getElementById('ttag').innerHTML = "";
// torrent
if (torrent !== ".torrent") {
document.getElementById('ttag').innerHTML = "*";
document.getElementById('output').innerHTML += "* Torrent file must end in .torrent
";
valid = false;
}
// client-specific checks
if (client === "tornado") {
// tornado-special-checks
document.getElementById('atag').innerHTML = "";
// announce-url
if (document.maketorrent.announce.value === "http://") {
document.getElementById('atag').innerHTML = "*";
document.getElementById('output').innerHTML += "* Please enter a valid announce URL.
";
valid = false;
}
// For safety reason, let's force the property to false if it's disabled (private tracker)
if (document.maketorrent.DHT.disabled) {
document.maketorrent.DHT.checked = false;
}
} else {
// mainline-special-checks
document.getElementById('trtag').innerHTML = "";
/*
due to bugs (?) in mainlines maketorrent, this is disabled.
if (trackerState == 1) {
if ((document.maketorrent.tracker_name.value === "http://") || (document.maketorrent.tracker_name.value === "")) {
document.getElementById('trtag').innerHTML = "*";
document.getElementById('output').innerHTML += "* Please enter a valid Tracker Name.
";
valid = false;
}
} else {
if (document.maketorrent.tracker_name.value === "http://") {
document.getElementById('trtag').innerHTML = "*";
document.getElementById('output').innerHTML += "* Please enter a valid Node (<ip>:<port>) or an empty to pull some nodes from your routing table.
";
valid = false;
}
}
*/
if (trackerState == 1) {
if ((document.maketorrent.tracker_name.value === "http://") || (document.maketorrent.tracker_name.value === "")) {
document.getElementById('trtag').innerHTML = "*";
document.getElementById('output').innerHTML += "* Please enter a valid Tracker Name.
";
valid = false;
}
}
}
// If validation passed, submit form
if (valid === true) {
disableForm(client);
toggleLayer('progress');
document.getElementById('output').innerHTML += "Creating torrent...
";
document.getElementById('output').innerHTML += "* Note that larger folder/files will take some time to process,
";
document.getElementById('output').innerHTML += " do not close the window until it has been completed.
";
document.getElementById('output').innerHTML += " When completed, the torrent will show in your list
";
document.getElementById('output').innerHTML += " and a download link will be provided.
";
return true;
}
return false;
}
/**
* disableForm
*/
function disableForm(client) {
// Because of IE issue of disabling the submit button,
// we change the text and don't allow resubmitting
document.maketorrent.tsubmit.value = "Creating...";
document.maketorrent.torrent.readOnly = true;
if (client === "tornado")
document.maketorrent.announce.readOnly = true;
}
/**
* toggleDHT
*/
function toggleDHT(dhtstatus) {
document.maketorrent.DHT.disabled = dhtstatus;
}
/**
* toggleTracker
*/
function toggleTracker(tState) {
/*
trackerState = tState;
if (trackerState == 1) {
document.maketorrent.tracker_name.value = "http://";
} else {
document.maketorrent.tracker_name.value = "";
}
*/
trackerState = 1;
}
/**
* toggleLayer
*/
function toggleLayer(whichLayer) {
if (document.getElementById) {
// This is the way the standards work
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display ? "" : "block";
} else if (document.all) {
// This is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = style2.display ? "" : "block";
} else if (document.layers) {
// This is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = style2.display ? "" : "block";
}
}
/**
* completed
*/
function completed(downpath, alertme, timetaken) {
document.getElementById('output').innerHTML = "Creation completed!
";
document.getElementById('output').innerHTML += "Time taken: " + timetaken + "
";
document.getElementById('output').innerHTML += "The new torrent has been added to your list.
"
document.getElementById('output').innerHTML += "You can download the torrent here
";
if(alertme === 1)
alert('Creation of torrent completed!');
}
/**
* failed
*/
function failed(downpath, alertme) {
document.getElementById('output').innerHTML = "Creation failed!
";
document.getElementById('output').innerHTML += "An error occurred while trying to create the torrent.
";
if(alertme === 1)
alert('Creation of torrent failed!');
}