forked from davidfcarr/rsvpmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsvpmaker.js
129 lines (114 loc) · 3.23 KB
/
rsvpmaker.js
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
124
125
126
127
128
129
jQuery(document).ready(function($) {
$('.timezone_on').click( function () {
$('.timezone_hint').each( function () {
var utc = $(this).attr('utc');
var target = $(this).attr('target');
var localdate = new Date(utc);
localstring = localdate.toString();
$('#'+target).html('<div>'+localstring+'<div>');
var data = {
'action': 'rsvpmaker_localstring',
'localstring': localstring
};
jQuery.post(ajaxurl, data, function(response) {
$('#'+target).html('<div>'+response+'</div>');
});
});
});
$('.signed_up_ajax').each( function () {
var post = $(this).attr('post');
var data = {
'action': 'signed_up',
'event_count': post,
};
jQuery.get(window.location.href, data, function(response) {
$('#signed_up_'+post).html(response);
});
});
var guestlist = '';
function format_guestlist(guest) {
if(!guest.first)
return;
guestlist = guestlist.concat('<h3>'+guest.first);
if(guest.last)
guestlist = guestlist.concat(' '+guest.last);
guestlist = guestlist.concat('</h3>\n');
if(guest.note)
guestlist = guestlist.concat('<p>'+guest.note+'</p>');
}
function display_guestlist (post_id) {
var url = rsvpmaker_json_url+'guestlist/'+post_id;
fetch(url)
.then(response => {
return response.json()
})
.then(data => {
if(Array.isArray(data))
{
data.forEach(format_guestlist);
if(guestlist == '')
guestlist = '<div>?</div>';
$('#attendees-'+post_id).html(guestlist);
}
})
.catch(err => {
console.log(err);
$('#attendees-'+post_id).html('Error fetching guestlist from '+url);
});
}
$( ".rsvpmaker_show_attendees" ).click(function( event ) {
var post_id = $(this).attr('post_id');
guestlist = '';
display_guestlist(post_id);//,nonce);
});
});
//end jquery
class RSVPJsonWidget {
constructor(divid, url, limit, morelink = '') {
this.el = document.getElementById(divid);
this.url = url;
this.limit = limit;
this.morelink = morelink;
let eventslist = '';
//this.showEvent = ;
fetch(url)
.then(response => {
return response.json()
})
.then(data => {
var showmorelink = false;
if(Array.isArray(data))
{
if(limit && (data.length >= limit)) {
data = data.slice(0,limit);
showmorelink = true;
}
data.forEach(function (value, index, data) {
if(!value.datetime)
return '';
var d = new Date(value.datetime);
console.log('event '+ index);
console.log(d);
eventslist = eventslist.concat('<li><a href="' + value.guid + '">' + value.post_title + ' - ' + value.date + '</a></li>');
});
}
else
{
this.el.innerHTML = 'None found: '+data.code;
console.log(data);
}
if(eventslist == '')
this.el.innerHTML = 'No event listings found';
else
{
if(showmorelink && (morelink != ''))
eventslist = eventslist.concat('<li><a href="'+morelink+'">More events</a></li>');
this.el.innerHTML = '<ul class="eventslist rsvpmakerjson">'+eventslist+'</ul>';
}
})
.catch(err => {
this.el.innerHTML = 'Error fetching events from '+this.url;
console.log(err);
});
}
}