Gazelle/static/functions/torrent.js

323 lines
10 KiB
JavaScript
Raw Normal View History

2011-11-20 08:00:18 +00:00
function ChangeCategory(catid) {
2013-04-19 08:00:55 +00:00
if (catid == 1) {
2013-06-17 08:01:02 +00:00
$('#split_releasetype').gshow();
$('#split_artist').gshow();
$('#split_year').gshow();
2013-04-19 08:00:55 +00:00
} else if (catid == 4 || catid == 6) {
2013-06-17 08:01:02 +00:00
$('#split_releasetype').ghide();
$('#split_year').gshow();
$('#split_artist').ghide();
2011-11-20 08:00:18 +00:00
} else {
2013-06-17 08:01:02 +00:00
$('#split_releasetype').ghide();
$('#split_artist').ghide();
$('#split_year').ghide();
2011-11-20 08:00:18 +00:00
}
}
function ArtistManager() {
var GroupID = window.location.search.match(/[?&]id=(\d+)/);
2013-04-19 08:00:55 +00:00
if (typeof GroupID == 'undefined') {
2011-11-20 08:00:18 +00:00
return;
} else {
GroupID = GroupID[1];
}
var ArtistList;
2013-04-19 08:00:55 +00:00
if (!(ArtistList = $('#artist_list').raw())) {
2011-11-20 08:00:18 +00:00
return false;
2013-04-19 08:00:55 +00:00
} else if ($('#artistmanager').raw()) {
2013-06-17 08:01:02 +00:00
$('#artistmanager').gtoggle();
$('#artist_list').gtoggle();
2011-11-20 08:00:18 +00:00
} else {
MainArtistCount = 0;
var elArtistManager = document.createElement('div');
elArtistManager.id = 'artistmanager';
var elArtistList = ArtistList.cloneNode(true);
elArtistList.id = 'artistmanager_list';
2013-04-30 18:18:07 +00:00
for (var i = 0; i < elArtistList.children.length; i++) {
2011-11-20 08:00:18 +00:00
switch (elArtistList.children[i].className) {
case 'artist_main':
importance = 1;
break;
case 'artists_with':
importance = 2;
break;
case 'artists_remix':
importance = 3;
break;
case 'artists_composers':
importance = 4;
break;
case 'artists_conductors':
importance = 5;
break;
case 'artists_dj':
importance = 6;
break;
2012-02-19 08:00:19 +00:00
case 'artists_producer':
importance = 7;
break;
2011-11-20 08:00:18 +00:00
}
2013-04-19 08:00:55 +00:00
if (elArtistList.children[i].children[0].tagName.toUpperCase() == 'A') {
2011-11-20 08:00:18 +00:00
var ArtistID = elArtistList.children[i].children[0].href.match(/[?&]id=(\d+)/)[1];
var elBox = document.createElement('input');
elBox.type = 'checkbox';
elBox.id = 'artistmanager_box'+(i-importance+1);
elBox.name = 'artistmanager_box';
2012-02-23 08:00:18 +00:00
elBox.value = importance+';'+ArtistID;
2011-11-20 08:00:18 +00:00
elBox.onclick = function(e) { SelectArtist(e,this); };
elArtistList.children[i].insertBefore(elBox, elArtistList.children[i].children[0]);
2013-04-19 08:00:55 +00:00
if (importance == 1 || importance == 4 || importance == 6) {
2011-11-20 08:00:18 +00:00
MainArtistCount++;
}
}
}
elArtistManager.appendChild(elArtistList);
var elArtistForm = document.createElement('form');
elArtistForm.id = 'artistmanager_form';
elArtistForm.method = 'post';
var elGroupID = document.createElement('input');
elGroupID.type = 'hidden';
elGroupID.name = 'groupid';
elGroupID.value = GroupID;
elArtistForm.appendChild(elGroupID);
var elAction = document.createElement('input');
elAction.type = 'hidden';
elAction.name = 'manager_action';
elAction.id = 'manager_action';
elAction.value = 'manage';
elArtistForm.appendChild(elAction);
var elAction = document.createElement('input');
elAction.type = 'hidden';
elAction.name = 'action';
elAction.value = 'manage_artists';
elArtistForm.appendChild(elAction);
var elAuth = document.createElement('input');
elAuth.type = 'hidden';
elAuth.name = 'auth';
elAuth.value = authkey;
elArtistForm.appendChild(elAuth);
var elSelection = document.createElement('input');
elSelection.type = 'hidden';
elSelection.id = 'artists_selection';
elSelection.name = 'artists';
elArtistForm.appendChild(elSelection);
var elSubmitDiv = document.createElement('div');
var elImportance = document.createElement('select');
elImportance.name = 'importance';
elImportance.id = 'artists_importance';
var elOpt = document.createElement('option');
elOpt.value = 1;
elOpt.innerHTML = 'Main artist';
elImportance.appendChild(elOpt);
elOpt = document.createElement('option');
elOpt.value = 2;
elOpt.innerHTML = 'Guest artist';
elImportance.appendChild(elOpt);
elOpt = document.createElement('option');
elOpt.value = 4;
elOpt.innerHTML = 'Composer';
elImportance.appendChild(elOpt);
elOpt = document.createElement('option');
elOpt.value = 5;
elOpt.innerHTML = 'Conductor';
elImportance.appendChild(elOpt);
elOpt = document.createElement('option');
elOpt.value = 6;
elOpt.innerHTML = 'DJ / Compiler';
elImportance.appendChild(elOpt);
elOpt = document.createElement('option');
elOpt.value = 3;
elOpt.innerHTML = 'Remixer';
elImportance.appendChild(elOpt);
2012-02-19 08:00:19 +00:00
elOpt = document.createElement('option');
elOpt.value = 7;
elOpt.innerHTML = 'Producer';
elImportance.appendChild(elOpt);
2011-11-20 08:00:18 +00:00
elSubmitDiv.appendChild(elImportance);
elSubmitDiv.appendChild(document.createTextNode(' '));
elSubmitDiv.className = 'body';
var elSubmit = document.createElement('input');
elSubmit.type = 'button';
elSubmit.value = 'Update';
elSubmit.onclick = ArtistManagerSubmit;
elSubmitDiv.appendChild(elSubmit);
elSubmitDiv.appendChild(document.createTextNode(' '));
var elDelButton = document.createElement('input');
elDelButton.type = 'button';
elDelButton.value = 'Delete';
elDelButton.onclick = ArtistManagerDelete;
elSubmitDiv.appendChild(elDelButton);
elArtistForm.appendChild(elSubmitDiv);
elArtistManager.appendChild(elArtistForm);
ArtistList.parentNode.appendChild(elArtistManager);
2013-06-17 08:01:02 +00:00
$('#artist_list').ghide();
2011-11-20 08:00:18 +00:00
}
}
function SelectArtist(e,obj) {
2013-04-19 08:00:55 +00:00
if (window.event) {
2011-11-20 08:00:18 +00:00
e = window.event;
}
EndBox = Number(obj.id.substr(17));
2013-04-19 08:00:55 +00:00
if (!e.shiftKey || typeof StartBox == 'undefined') {
2011-11-20 08:00:18 +00:00
StartBox = Number(obj.id.substr(17));
}
Dir = (EndBox > StartBox ? 1 : -1);
var checked = obj.checked;
2013-04-30 18:18:07 +00:00
for (var i = StartBox; i != EndBox; i += Dir) {
2011-11-20 08:00:18 +00:00
var key, importance = obj.value.substr(0,1), id = obj.value.substr(2);
2013-04-30 18:18:07 +00:00
$('#artistmanager_box' + i).raw().checked = checked;
2011-11-20 08:00:18 +00:00
}
StartBox = Number(obj.id.substr(17));
}
function ArtistManagerSubmit() {
var Selection = new Array();
var MainSelectionCount = 0;
2013-04-30 18:18:07 +00:00
for (var i = 0, boxes = $('[name="artistmanager_box"]'); boxes.raw(i); i++) {
2013-04-19 08:00:55 +00:00
if (boxes.raw(i).checked) {
2012-02-23 08:00:18 +00:00
Selection.push(boxes.raw(i).value);
2013-04-19 08:00:55 +00:00
if (boxes.raw(i).value.substr(0,1) == '1') {
2011-11-20 08:00:18 +00:00
MainSelectionCount++;
}
}
}
2013-04-19 08:00:55 +00:00
if (Selection.length == 0 || ($('#manager_action').raw().value == 'delete' && !confirm('Are you sure you want to delete '+Selection.length+' artists from this group?'))) {
2011-11-20 08:00:18 +00:00
return;
}
$('#artists_selection').raw().value = Selection.join(',');
2013-04-19 08:00:55 +00:00
if ((($('#artists_importance').raw().value != 1 && $('#artists_importance').raw().value != 4 && $('#artists_importance').raw().value != 6) || $('#manager_action').raw().value == 'delete') && MainSelectionCount == MainArtistCount) {
if (!$('.error_message').raw()) {
2011-11-20 08:00:18 +00:00
error_message('All groups need to have at least one main artist, composer, or DJ.');
}
$('.error_message').raw().scrollIntoView();
return;
}
$('#artistmanager_form').raw().submit();
}
function ArtistManagerDelete() {
$('#manager_action').raw().value = 'delete';
ArtistManagerSubmit();
$('#manager_action').raw().value = 'manage';
}
2012-02-05 08:00:20 +00:00
function Vote(amount, requestid) {
2013-04-19 08:00:55 +00:00
if (typeof amount == 'undefined') {
2012-02-05 08:00:20 +00:00
amount = parseInt($('#amount').raw().value);
}
2013-04-19 08:00:55 +00:00
if (amount == 0) {
2012-02-05 08:00:20 +00:00
amount = 20 * 1024 * 1024;
}
2013-02-22 08:00:24 +00:00
2012-02-05 08:00:20 +00:00
var index;
var votecount;
2013-04-19 08:00:55 +00:00
if (!requestid) {
2012-02-05 08:00:20 +00:00
requestid = $('#requestid').raw().value;
votecount = $('#votecount').raw();
index = false;
} else {
votecount = $('#vote_count_' + requestid).raw();
bounty = $('#bounty_' + requestid).raw();
index = true;
}
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-19 08:00:55 +00:00
if (response == 'bankrupt') {
2012-02-05 08:00:20 +00:00
error_message("You do not have sufficient upload credit to add " + get_size(amount) + " to this request");
return;
} else if (response == 'dupesuccess') {
//No increment
} else if (response == 'success') {
votecount.innerHTML = (parseInt(votecount.innerHTML)) + 1;
}
2013-04-19 08:00:55 +00:00
if ($('#total_bounty').results() > 0) {
2012-02-05 08:00:20 +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");
}
}
);
2012-10-27 08:00:09 +00:00
}
2012-10-28 08:00:19 +00:00
var voteLock = false;
2012-10-27 08:00:09 +00:00
function DownVoteGroup(groupid, authkey) {
2012-10-28 08:00:19 +00:00
if (voteLock) {
return;
}
voteLock = true;
2013-10-05 08:01:00 +00:00
ajax.get('ajax.php?action=votefavorite&do=vote&groupid=' + groupid + '&vote=down' + '&auth=' + authkey, function (response) {
2012-10-27 08:00:09 +00:00
if (response == 'noaction') {
//No increment
} else if (response == 'success') {
2013-10-05 08:01:00 +00:00
$('#downvotes').raw().innerHTML = (parseInt($('#downvotes').raw().innerHTML)) + 1;
2012-10-27 08:00:09 +00:00
$('#totalvotes').raw().innerHTML = (parseInt($('#totalvotes').raw().innerHTML)) + 1;
}
}
);
2013-06-17 08:01:02 +00:00
$('#vote_message').ghide();
$('#unvote_message').gshow();
$('#upvoted').ghide();
$('#downvoted').gshow();
2012-10-28 08:00:19 +00:00
voteLock = false;
2012-10-27 08:00:09 +00:00
}
function UpVoteGroup(groupid, authkey) {
2012-10-28 08:00:19 +00:00
if (voteLock) {
return;
}
voteLock = true;
2013-10-05 08:01:00 +00:00
ajax.get('ajax.php?action=votefavorite&do=vote&groupid=' + groupid + '&vote=up' + '&auth=' + authkey, function (response) {
2012-10-27 08:00:09 +00:00
if (response == 'noaction') {
//No increment
} else if (response == 'success') {
// Increment both the upvote count and the total votes count
2013-04-18 08:00:54 +00:00
$('#upvotes').raw().innerHTML = (parseInt($('#upvotes').raw().innerHTML)) + 1;
2012-10-27 08:00:09 +00:00
$('#totalvotes').raw().innerHTML = (parseInt($('#totalvotes').raw().innerHTML)) + 1;
}
}
);
2013-06-17 08:01:02 +00:00
$('#vote_message').ghide();
$('#unvote_message').gshow();
$('#upvoted').gshow();
$('#downvoted').ghide();
2012-10-28 08:00:19 +00:00
voteLock = false;
2012-10-27 08:00:09 +00:00
}
function UnvoteGroup(groupid, authkey) {
2012-10-28 08:00:19 +00:00
if (voteLock) {
return;
}
voteLock = true;
2013-10-05 08:01:00 +00:00
ajax.get('ajax.php?action=votefavorite&do=unvote&groupid=' + groupid + '&auth=' + authkey, function (response) {
2012-10-27 08:00:09 +00:00
if (response == 'noaction') {
//No increment
} else if (response == 'success-down') {
$('#totalvotes').raw().innerHTML = (parseInt($('#totalvotes').raw().innerHTML)) - 1;
2013-10-05 08:01:00 +00:00
$('#downvotes').raw().innerHTML = (parseInt($('#downvotes').raw().innerHTML)) - 1;
2012-10-27 08:00:09 +00:00
} else if (response == 'success-up') {
$('#totalvotes').raw().innerHTML = (parseInt($('#totalvotes').raw().innerHTML)) - 1;
$('#upvotes').raw().innerHTML = (parseInt($('#upvotes').raw().innerHTML)) - 1;
2013-02-22 08:00:24 +00:00
}
2012-10-27 08:00:09 +00:00
}
);
2013-06-17 08:01:02 +00:00
$('#vote_message').gshow();
$('#unvote_message').ghide();
$('#upvoted').ghide();
$('#downvoted').ghide();
2012-10-28 08:00:19 +00:00
voteLock = false;
2013-04-18 08:00:54 +00:00
}