forked from csc325/GCal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.php
123 lines (105 loc) · 3.85 KB
/
main.php
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
header('Content-type: application/x-javascript');
include '../global.php';
?>
$(document).ready ( function () {
$('a.attend_event').click ( function () {
attend_event($(this));
});
$('a.attend_event span.cancel').click ( function () {
cancel_attend($(this));
});
$('div.filter h3 span.arrow').toggle ( function () {
$(this).parent().parent().animate({left:'0px'},250);
$(this).html("«");
}, function () {
$(this).parent().parent().animate({left:'-160px'},250);
$(this).html("»");
});
var attend_event = function (this_el) {
if (this_el.hasClass('attending')) return false;
var this_id = this_el.attr('id');
this_id = this_id.split('_');
var event_id = this_id[1];
var user_id = this_id[2];
$.ajax({
type: "POST",
url: "<?php ed(); ?>functions/ajax.php",
data: ({action:'ajax',function:'attend_event',eventID:event_id, userID:user_id}),
success: function (r) {
if (r == 1) {
var sel = $('a#event_'+event_id+'_'+user_id);
sel.addClass('attending').html('Attending <span class="cancel">X</span>');
sel.find('span.cancel').click ( function () { cancel_attend($(this)); });
var count = parseInt(sel.parent().find('span.val.attend_count').text());
sel.parent().find('span.val.attend_count').html(count+1);
update_sidebar();
}
}
});
}
var cancel_attend = function (this_el) {
var this_id = this_el.parent().attr('id');
this_id = this_id.split('_');
var event_id = this_id[1];
var user_id = this_id[2];
$.ajax({
type: "POST",
url: "<?php ed(); ?>functions/ajax.php",
data: ({action:'ajax',function:'cancel_attend',eventID:event_id, userID:user_id}),
success: function (r) {
if (r == 1) {
var sel = $('a#event_'+event_id+'_'+user_id);
sel.removeClass('attending').html('Attend!');
sel.find('span.cancel').remove();
var count = parseInt(sel.parent().find('span.val.attend_count').text());
sel.parent().find('span.val.attend_count').html(count-1);
update_sidebar();
}
}
});
}
var update_sidebar = function () {
$.ajax({
type: "POST",
url: "<?php ed(); ?>sidebar.php",
data: ({action:'update'}),
success: function (r) {
$('div.side').html(r);
}
});
}
$('a.hide_event').click ( function () {
hide_event($(this));
});
var hide_event = function (this_el) {
var this_id = this_el.attr('id');
this_id = this_id.split('_');
var event_id = this_id[1];
var user_id = this_id[2];
$.ajax({
type: "POST",
url: "<?php ed(); ?>functions/ajax.php",
data: ({action:'ajax',function:'hide_event',eventID:event_id,
userID:user_id}),
success: function (r) {
if (r == 1) {
var sel = $('a#hidden_'+event_id+'_'+user_id);
sel.click ( function () {
hide_event($(this)); });
update_events();
}
}
});
}
var update_events = function () {
$.ajax({
type: "POST",
url: window.location.pathname,
data: ({action:'update'}),
success: function (r) {
$('div.event_listing').html(r);
}
});
}
});