summaryrefslogtreecommitdiffstats
path: root/static/functions/user_notifications.js
blob: 43a343cbe0cf609a828807148da13e5de5ae71ba (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
$(document).ready(function() {
	var skip = getSkippedPage();
	$('.noty-notification').each(function() {
		var $this = $(this);
		var type = $this.data('noty-type'),
			importance = $this.data('noty-importance'),
			id = $this.data('noty-id'),
			url = $this.data('noty-url');
		if (type != skip) {
			createNoty(type, id, $this.text(), url, importance);
		}
		$this.remove();
	});
});

function getSkippedPage() {
	var skip, url = new gazURL();
	switch(url.path) {
		case "inbox":
			if (url.query.length == 0 || (url.query.length == 1 && url.query.hasOwnProperty('sort'))) {
				skip = "Inbox";
			}
			break;
		case "userhistory":
			if (url.query['action'] == "subscriptions") {
				skip = "Subscriptions";
			}
			if (url.query['action'] == "quote_notifications") {
				skip = "Quotes";
			}
			if (url.query['action'] == "subscribed_collages") {
				skip = "Collages";
			}
			break;
		case "user":
			if (url.query['action'] == "notify") {
				skip = "Torrents";
			}
			break;
		case "blog":
			if (url.query.length == 0) {
				skip = "Blog";
			}
			break;
		case "index":
			if (url.query.length == 0) {
				skip = "News";
			}
			break;
		case "staffpm":
			if (url.query.length == 0) {
				skip = "StaffPM";
			}
			break;
		default:
			break;
	}
	return skip;
}

function createNoty(type, id, message, url, importance) {
	var hideButtons = !url;
	noty({
		text: message,
		type: importance,
		layout: 'bottomRight',
		closeWith: ['click'],
		animation: {
			open: {height: 'toggle'},
			close: {height: 'toggle'},
			easing: 'swing',
			speed: 250
		},
		buttonElement : 'a',
		buttons: [
		{
			addClass: 'brackets noty_button_view' + (hideButtons ? ' hidden' : ''), text: 'View', href: url
		},
		{
			addClass: 'brackets noty_button_clear', text: 'Clear', onClick: function($noty) {
				$noty.close();
				clear(type, id);
			}
		},
		{
			addClass: 'brackets noty_button_close ', text: 'Hide', onClick: function($noty) {
				$noty.close();
			}
		},
		]
	});
}

function clear(type, id) {
	$.ajax({
		type : "POST",
		url: "ajax.php?action=clear_user_notification",
		dataType: "json",
		data : {
			"type" : type,
			"id" : id
		}
	});
}