summaryrefslogtreecommitdiffstats
path: root/static/functions/notifications.js
blob: dbd94c4140b77aba10bc7ead83a760feb5e73314 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function clearItem(torrentId) {
	ajax.get("?action=notify_clear_item&torrentid=" + torrentId + "&auth=" + authkey, function() {
			$("#torrent" + torrentId).remove();
		});
}

function clearSelected(filterId) {
	var checkBoxes, checkedBoxes = [];
	if (filterId) {
		var filterForm = $('#notificationform_' + filterId);
		checkBoxes = $('.notify_box_' + filterId, filterForm);
	} else {
		checkBoxes = $('.notify_box');
	}
	for (var i = checkBoxes.length - 1; i >= 0; i--) {
		if (checkBoxes[i].checked) {
			checkedBoxes.push(checkBoxes[i].value);
		}
	}
	ajax.get("?action=notify_clear_items&torrentids=" + checkedBoxes.join(',') + "&auth=" + authkey, function() {
			for (var i = checkedBoxes.length - 1; i >= 0; i--) {
				$('#torrent' + checkedBoxes[i]).remove();
			}
		});
}

$(document).ready(function () {
	var notifyBoxes = $('.notify_box');
	notifyBoxes.keydown(function(e) {
		var nextBox, index = notifyBoxes.index($(this));
		if (index > 0 && e.which === 75) { // K
			nextBox = notifyBoxes.get(index-1);
		} else if (index < notifyBoxes.size()-1 && e.which === 74) { // J
			nextBox = notifyBoxes.get(index+1);
		} else if (e.which === 88) {
			$(this).prop('checked', !$(this).prop('checked'));
		}
		if (nextBox) {
			nextBox.focus();
			$(window).scrollTop($(nextBox).position()['top']-$(window).height()/4);
		}
	});
});