Gazelle/static/functions/requests.js

201 lines
6.4 KiB
JavaScript
Raw Normal View History

2011-03-28 14:21:28 +00:00
function Vote(amount, requestid) {
2013-04-18 08:00:54 +00:00
if (typeof amount == 'undefined') {
2011-03-28 14:21:28 +00:00
amount = parseInt($('#amount').raw().value);
}
2013-04-18 08:00:54 +00:00
if (amount == 0) {
2011-03-28 14:21:28 +00:00
amount = 20 * 1024 * 1024;
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
var index;
var votecount;
2013-04-18 08:00:54 +00:00
if (!requestid) {
2011-03-28 14:21:28 +00:00
requestid = $('#requestid').raw().value;
votecount = $('#votecount').raw();
index = false;
} else {
votecount = $('#vote_count_' + requestid).raw();
bounty = $('#bounty_' + requestid).raw();
2011-03-28 14:21:28 +00:00
index = true;
}
2013-02-22 08:00:24 +00:00
2012-04-10 08:00:20 +00:00
if (amount > 20*1024*1024) {
2013-05-14 08:00:34 +00:00
upload = $('#current_uploaded').raw().value;
2012-04-10 08:00:20 +00:00
download = $('#current_downloaded').raw().value;
2013-04-18 08:00:54 +00:00
rr = $('#current_rr').raw().value;
2012-04-10 08:00:20 +00:00
if (amount > .3*(upload - rr * download)) {
2013-04-18 08:00:54 +00:00
if (!confirm('This vote is more than 30% of your buffer. Please confirm that you wish to place this large a vote.')) {
2012-04-10 08:00:20 +00:00
return false;
}
}
}
2013-02-22 08:00:24 +00:00
2013-02-20 08:00:33 +00:00
ajax.get('requests.php?action=takevote&id=' + requestid + '&auth=' + authkey + '&amount=' + amount, function (response) {
2013-04-18 08:00:54 +00:00
if (response == 'bankrupt') {
2011-03-28 14:21:28 +00:00
error_message("You do not have sufficient upload credit to add " + get_size(amount) + " to this request");
return;
} else if (response == 'dupesuccess') {
2011-03-28 14:21:28 +00:00
//No increment
} else if (response == 'success') {
2011-03-28 14:21:28 +00:00
votecount.innerHTML = (parseInt(votecount.innerHTML)) + 1;
}
2013-04-18 08:00:54 +00:00
if ($('#total_bounty').results() > 0) {
2011-03-28 14:21:28 +00:00
totalBounty = parseInt($('#total_bounty').raw().value);
totalBounty += (amount * (1 - $('#request_tax').raw().value));
$('#total_bounty').raw().value = totalBounty;
$('#formatted_bounty').raw().innerHTML = get_size(totalBounty);
save_message("Your vote of " + get_size(amount) + ", adding a " + get_size(amount * (1 - $('#request_tax').raw().value)) + " bounty, has been added");
$('#button').raw().disabled = true;
} else {
save_message("Your vote of " + get_size(amount) + " has been added");
}
}
);
}
function Calculate() {
var mul = (($('#unit').raw().options[$('#unit').raw().selectedIndex].value == 'mb') ? (1024*1024) : (1024*1024*1024));
var amt = Math.floor($('#amount_box').raw().value * mul);
2013-04-18 08:00:54 +00:00
if (amt > $('#current_uploaded').raw().value) {
2011-03-28 14:21:28 +00:00
$('#new_uploaded').raw().innerHTML = "You can't afford that request!";
$('#new_bounty').raw().innerHTML = "0.00 MB";
$('#button').raw().disabled = true;
2013-04-18 08:00:54 +00:00
} else if (isNaN($('#amount_box').raw().value)
2011-03-28 14:21:28 +00:00
|| (window.location.search.indexOf('action=new') != -1 && $('#amount_box').raw().value*mul < 100*1024*1024)
2012-08-28 08:00:14 +00:00
|| (window.location.search.indexOf('action=view') != -1 && $('#amount_box').raw().value*mul < 20*1024*1024)) {
2011-03-28 14:21:28 +00:00
$('#new_uploaded').raw().innerHTML = get_size(($('#current_uploaded').raw().value));
$('#new_bounty').raw().innerHTML = "0.00 MB";
$('#button').raw().disabled = true;
} else {
$('#button').raw().disabled = false;
$('#amount').raw().value = amt;
$('#new_uploaded').raw().innerHTML = get_size(($('#current_uploaded').raw().value) - amt);
$('#new_ratio').raw().innerHTML = ratio($('#current_uploaded').raw().value - amt, $('#current_downloaded').raw().value);
2011-03-28 14:21:28 +00:00
$('#new_bounty').raw().innerHTML = get_size(mul * $('#amount_box').raw().value);
}
}
function AddArtistField() {
var ArtistCount = document.getElementsByName("artists[]").length;
2013-04-18 08:00:54 +00:00
if (ArtistCount >= 200) {
return;
}
2011-03-28 14:21:28 +00:00
var ArtistField = document.createElement("input");
ArtistField.type = "text";
ArtistField.id = "artist";
ArtistField.name = "artists[]";
ArtistField.size = 45;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
var ImportanceField = document.createElement("select");
ImportanceField.id = "importance";
ImportanceField.name = "importance[]";
ImportanceField.options[0] = new Option("Main", "1");
ImportanceField.options[1] = new Option("Guest", "2");
2011-11-20 08:00:18 +00:00
ImportanceField.options[2] = new Option("Composer", "4");
ImportanceField.options[3] = new Option("Conductor", "5");
ImportanceField.options[4] = new Option("DJ / Compiler", "6");
ImportanceField.options[5] = new Option("Remixer", "3");
2012-02-19 08:00:19 +00:00
ImportanceField.options[6] = new Option("Producer", "7");
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
var x = $('#artistfields').raw();
x.appendChild(document.createElement("br"));
x.appendChild(ArtistField);
2013-04-18 08:00:54 +00:00
x.appendChild(document.createTextNode('\n'));
2011-03-28 14:21:28 +00:00
x.appendChild(ImportanceField);
ArtistCount++;
}
function RemoveArtistField() {
var ArtistCount = document.getElementsByName("artists[]").length;
if (ArtistCount == 1) { return; }
var x = $('#artistfields').raw();
2013-02-22 08:00:24 +00:00
2013-04-18 08:00:54 +00:00
while (x.lastChild.tagName != "INPUT") {
2013-02-22 08:00:24 +00:00
x.removeChild(x.lastChild);
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
x.removeChild(x.lastChild);
2013-04-18 08:00:54 +00:00
x.removeChild(x.lastChild); //Remove trailing new line.
2011-03-28 14:21:28 +00:00
ArtistCount--;
}
function Categories() {
var cat = $('#categories').raw().options[$('#categories').raw().selectedIndex].value;
2013-04-18 08:00:54 +00:00
if (cat == "Music") {
2013-06-17 08:01:02 +00:00
$('#artist_tr').gshow();
$('#releasetypes_tr').gshow();
$('#formats_tr').gshow();
$('#bitrates_tr').gshow();
$('#media_tr').gshow();
2011-03-28 14:21:28 +00:00
ToggleLogCue();
2013-06-17 08:01:02 +00:00
$('#year_tr').gshow();
$('#cataloguenumber_tr').gshow();
2013-04-18 08:00:54 +00:00
} else if (cat == "Audiobooks" || cat == "Comedy") {
2013-06-17 08:01:02 +00:00
$('#year_tr').gshow();
$('#artist_tr').ghide();
$('#releasetypes_tr').ghide();
$('#formats_tr').ghide();
$('#bitrates_tr').ghide();
$('#media_tr').ghide();
$('#logcue_tr').ghide();
$('#cataloguenumber_tr').ghide();
2011-03-28 14:21:28 +00:00
} else {
2013-06-17 08:01:02 +00:00
$('#artist_tr').ghide();
$('#releasetypes_tr').ghide();
$('#formats_tr').ghide();
$('#bitrates_tr').ghide();
$('#media_tr').ghide();
$('#logcue_tr').ghide();
$('#year_tr').ghide();
$('#cataloguenumber_tr').ghide();
2011-03-28 14:21:28 +00:00
}
}
function add_tag() {
if ($('#tags').raw().value == "") {
$('#tags').raw().value = $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
} else if ($('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value == "---") {
} else {
$('#tags').raw().value = $('#tags').raw().value + ", " + $('#genre_tags').raw().options[$('#genre_tags').raw().selectedIndex].value;
}
}
function Toggle(id, disable) {
var arr = document.getElementsByName(id + '[]');
var master = $('#toggle_' + id).raw().checked;
for (var x in arr) {
arr[x].checked = master;
2013-04-18 08:00:54 +00:00
if (disable == 1) {
2011-03-28 14:21:28 +00:00
arr[x].disabled = master;
}
}
2013-02-22 08:00:24 +00:00
2013-04-18 08:00:54 +00:00
if (id == "formats") {
2011-03-28 14:21:28 +00:00
ToggleLogCue();
}
}
function ToggleLogCue() {
var formats = document.getElementsByName('formats[]');
var flac = false;
2013-02-22 08:00:24 +00:00
2013-04-18 08:00:54 +00:00
if (formats[1].checked) {
2011-03-28 14:21:28 +00:00
flac = true;
}
2013-02-22 08:00:24 +00:00
2013-04-18 08:00:54 +00:00
if (flac) {
2013-06-17 08:01:02 +00:00
$('#logcue_tr').gshow();
2011-03-28 14:21:28 +00:00
} else {
2013-06-17 08:01:02 +00:00
$('#logcue_tr').ghide();
2011-03-28 14:21:28 +00:00
}
ToggleLogScore();
}
function ToggleLogScore() {
2013-04-18 08:00:54 +00:00
if ($('#needlog').raw().checked) {
2013-06-17 08:01:02 +00:00
$('#minlogscore_span').gshow();
2011-03-28 14:21:28 +00:00
} else {
2013-06-17 08:01:02 +00:00
$('#minlogscore_span').ghide();
2011-03-28 14:21:28 +00:00
}
}