-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_create.js
executable file
·454 lines (369 loc) · 19.1 KB
/
event_create.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/**
* After the navs are setup, this method will load the actual content
* This is a single entry point that displayed one of the contents
* inside of it based on the contentId
*/
function eventsButtonHandler(contentId)
{
if (0 == contentId) {
showUserEvents();
}
else if (1 == contentId) {
showUserEventCreate();
}
else if (2 == contentId) {
showUserMultiEvents();
}
else if (3 == contentId) {
showUserMultiEventCreate();
}
}
/**
* This is called by showUserEvents() to get content of ONE event
* @param ev The event structure with name, datetime, id, and info of the event
* @param expandedView If true, this event will show expanded view (rather than collapsed)
*/
function getEventContent(ev, expandedView)
{
var content = "";
if (expandedView) {
expandedView = "collapse in";
}
else {
expandedView = "collapse";
}
content += '<div class="panel panel-default">\
<div class="panel-heading">\
<h4 class="panel-title">\
<a data-toggle="collapse" data-parent="#accordion" href="#collapse' + ev.event_id + '">' +
'<B>' + urldecode(ev.event_name) + ' (' + urldecode(ev.date_time) + ')</B>' +
'</a>' +
'<div width="100px" align="right">' +
' <button type="button" title="Realtime viewer" class="btn btn-default" onClick="realtimeEventViewer(' + ev.event_id + ')"><span class="glyphicon glyphicon-dashboard"></span> </button>' +
' <button type="button" title="Results" class="btn btn-info" onClick="RegisteredHandler(' + ev.event_id + ')"><span class="glyphicon glyphicon-th-list"></span> </button>' +
' <button type="button" title="Delete the event" class="btn btn-warning" onClick="deleteAdminEvent(' + ev.event_id + ')"><span class="glyphicon glyphicon-trash"></span> Delete</button>' +
'</div>' +
'</h4>\
</div>' +
'<div id="collapse' + ev.event_id + '" class="panel-collapse ' + expandedView + '">\
<div class="panel-body">' +
urldecode(ev.event_info) +
'</div>\
</div>\
</div>';
return content;
}
/**
* This function shows the user events that were created
* @param funcAfterShowCompletes The callback function to invoke after loading finishes
*/
function showUserEvents(funcAfterShowCompletes)
{
sendAjaxRequest("getAdminEvents", "",
function(response) {
var content = "";
if (0 == response.eventsArray.length) {
content += '<div class="jumbotron"><H1>Hello there!</H1>';
content += '<HR><p>I see that you are new here, and you have not created any events yet.</p>';
content += '<HR><p>Begin the experience by creating a new QR-Event!</p>';
content += '<HR></DIV>';
}
else {
content += '<div class="panel panel-primary"><div class="panel-heading">\
<h3><center>Your Events</center></h3>\
</div></div>';
content += '<div class="panel-group" id="accordion">';
for (var i = 0; i < response.eventsArray.length; i++) {
content += getEventContent(response.eventsArray[i], 0==i);
}
content += '</div>';
}
updateMainContent(content);
if (funcAfterShowCompletes) {
funcAfterShowCompletes();
}
});
}
/**
* This shows the form fields to be able to create a new event
*/
function showUserEventCreate()
{
var content = "";
var length = tinymce.editors.length;
for (var i=0; i < length; i++) {
tinyMCE.execCommand('mceRemoveControl',false, tinymce.editors[i].id);
};
/* Event name and time */
content += '<form class="form-horizontal" role="form">';
content += '<div class="form-group">';
content += '<label for="userInputEventName" class="col-sm-2 control-label">Event Name</label>';
content += '<div class="col-sm-5">';
content += '<input type="text" class="form-control" id="userInputEventName" placeholder="Event Name">';
content += '</div><div class="col-sm-3">'
content += '<button type="button" class="btn btn-success btn-lg" href="#" onClick="javascript: verifyCreateNewEvent()"><i class="glyphicon glyphicon-envelope"></i> Create Event</button>';
content += '</div></div>';
content += '<div class="form-group">';
content += '<label for="userInputEventTime" class="col-sm-2 control-label">Event Time</label>';
content += '<div class="col-sm-5">';
content += '<input type="text" class="form-control" id="userInputEventTime" placeholder="Event Time">';
content += '</div></div>';
content += '</form><HR>';
content += '<textarea class="eventTinymce" id="userInputEventInfo"></textarea><HR>';
// imhere
content += '<table class="table table-hover"><TR><TD>';
content += '</TD><TD>';
content += '</TD></TR></table>';
updateMainContent('<div class="well"><BR/>' + content + '</div>');
// After publishing content, convert textarea to datetime picker
$('#userInputEventTime').datetimepicker({ dateFormat: 'yy-mm-dd' });
// After writing HTML content, convert the textarea to TinyMCE based text
tinymce.init({
mode : "specific_textareas",
editor_selector : "eventTinymce",
plugins: [
"advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"table contextmenu directionality emoticons template textcolor paste fullpage textcolor"
],
toolbar1: "bold italic underline strikethrough forecolor removeformat hr| alignleft aligncenter alignright alignjustify | formatselect fontsizeselect",
toolbar2: "cut copy paste | table bullist numlist | outdent indent blockquote | undo redo | link unlink preview fullscreen | spellchecker nonbreaking",
menubar: false,
toolbar_items_size: 'small'
});
var ed = tinymce.get('userInputEventInfo');
if (ed) {
ed.setContent('');
}
}
/**
* This function is called by the user clicking the create new event button.
* We will grab the input values and create the event
*/
function verifyCreateNewEvent()
{
var exitPopupModal = "";
exitPopupModal += '<button type="button" class="btn btn-warning btn-lg" href="#" onClick="javascript: hidePopupModal()">';
exitPopupModal += '<i class="glyphicon glyphicon-edit"></i> Edit</button>';
var eventName = $("#userInputEventName").val();
var eventTime = $("#userInputEventTime").val();
var eventInvitees = $("#userInputEventInvitees").val();
var eventInfo = '<h3>' + eventName + '</h3> (' + eventTime + ')<HR>' +
tinymce.get('userInputEventInfo').getContent();
if (eventName == "") { showPopupModal("Error", "You must input the event name.", exitPopupModal); }
else if (eventTime == "") { showPopupModal("Error", "You must input the event time.", exitPopupModal); }
else if (eventInfo == "") { showPopupModal("Error", "You must input the event information to send out to guests.", exitPopupModal); }
else if (eventInvitees == "") { showPopupModal("Error", "You must input the event attendees.", exitPopupModal); }
else {
var button = "";
button += exitPopupModal;
button += '<button type="button" class="btn btn-success btn-lg" href="#" onClick="javascript: commitCreateNewEvent()">';
button += '<i class="glyphicon glyphicon-envelope"></i> Finalize Event</button>';
showPopupModal("Verify Event Details", eventInfo, button);
}
}
/**
* After a form fields are validated, this will send the event info to the server
* to create the event
*/
function commitCreateNewEvent()
{
var timeout = 10 * 1000;
var eventName = $("#userInputEventName").val();
var eventTime = $("#userInputEventTime").val();
var eventInvitees = $("#userInputEventInvitees").val();
var eventInfo = tinymce.get('userInputEventInfo').getContent();
var filename = $("#attendeesFileName").val();
var postVars = "";
postVars += "name=" +urlencode(eventName);
postVars += "&time="+(eventTime);
postVars += "&list="+urlencode(eventInvitees);
postVars += "&info="+urlencode(eventInfo);
postVars += "&file="+urlencode(filename);
sendAjaxRequest("createAdminEvent", postVars,
function(response) {
// Display events page after creating the event
showUserEvents(function() {
prependMainContent(getDismissibleAlert("All Done", eventName + " has been created!", "success"), timeout);
}
);
});
}
/**
* After a form fields are validated, this will send the event info to the server
* to create the event
*/
function commitCreateNewMultiEvent()
{
var timeout = 10 * 1000;
var eventInfo = tinymce.get('userInputEventInfo').getContent();
var eventName = $("#userInputEventName").val();
var eventInvitees = $("#userInputEventInvitees").val();
var eventselection = [];
var eventIDsCSV = "";
$('#eventCheckbox :checked').each(function() {
eventIDsCSV += $(this).val();
eventIDsCSV += ",";
});
var postVars = "";
postVars += "name=" +urlencode(eventName);
postVars += "&info="+urlencode(eventInfo);
postVars += "&eventids="+urlencode(eventIDsCSV);
sendAjaxRequest("createAdminMultiEvent", postVars,
function(response) {
// Display events page after creating the event
showUserEvents(function() {
prependMainContent(getDismissibleAlert("All Done", eventName + " has been created!", "success"), timeout);
}
);
});
}
/**
* Given an event id, this will delete the event
*/
function deleteAdminEvent(id)
{
var timeout = 10 * 1000;
showPopupModal("Ooops", "Cannot delete for this preview version", "");
return;
sendAjaxRequest("deleteAdminEvent", "eventId="+id,
function(response) {
showUserEvents(function() {
prependMainContent(getDismissibleAlert("All Done", "Event has been deleted!", "warning"), timeout);
}
);
});
}
function verifyEventInvite()
{
var exitPopupModal = "";
exitPopupModal += '<button type="button" class="btn btn-warning btn-lg" href="#" onClick="javascript: hidePopupModal()">';
exitPopupModal += '<i class="glyphicon glyphicon-edit"></i> Edit</button>';
var eventName = $("#userInputEventName").val();
var eventInvitees = $("#userInputEventInvitees").val();
var eventselection = [];
$('#eventCheckbox :checked').each(function() {
eventselection.push($(this).val());
});
var eventInfo = '<h3>' + eventName + '</h3><p> Events' + JSON.stringify(eventselection) + '</p><HR>' +
tinymce.get('userInputEventInfo').getContent();
if (eventName == "") { showPopupModal("Error", "You must input the event name.", exitPopupModal); }
else if (eventInfo == "") { showPopupModal("Error", "You must input the event information to send out to guests.", exitPopupModal); }
else if (eventselection == []) { showPopupModal("Error", "You must select Events.", exitPopupModal); }
else if (eventInvitees == "") { showPopupModal("Error", "You must input the event attendees.", exitPopupModal); }
else {
var button = "";
button += exitPopupModal;
button += '<button type="button" class="btn btn-success btn-lg" href="#" onClick="javascript: commitCreateNewMultiEvent()">';
button += '<i class="glyphicon glyphicon-envelope"></i> Finalize Event</button>';
showPopupModal("Verify Event Details", eventInfo, button);
}
}
function getSelectEventContent(ev)
{
var content = "";
content += "<input type='checkbox' name='eventselection' value='" + ev.event_id + "'>";
content += " ";
content += urldecode(ev.event_name);
content += " - ";
content += urldecode(ev.date_time);
content += "<br>";
return content;
}
/**
* This shows the form fields to be able to create a new multi event
*/
function showUserMultiEventCreate()
{
sendAjaxRequest("getAdminEvents", "",
function(response) {
var content = "";
var length = tinymce.editors.length;
for (var i=0; i < length; i++) {
tinyMCE.execCommand('mceRemoveControl',false, tinymce.editors[i].id);
};
var pagetitle = "";
pagetitle += '<div class="panel panel-primary">';
pagetitle += '<div class="panel-heading">';
pagetitle += '<h3>';
pagetitle += '<center>Event Invite</center>';
pagetitle += '</h3>';
pagetitle += '</div>';
pagetitle += '</div>';
/* Event name */
content += '<form class="form-horizontal" role="form">';
content += '<div class="form-group">';
content += '<label for="userInputEventName" class="col-sm-3 control-label">Group Invite Name</label>';
content += '<div class="col-sm-5">';
content += '<input type="text" class="form-control" id="userInputEventName" placeholder="Q-IN Event Invite">';
content += '</div><div class="col-sm-3">'
content += '</div></div>';
content += '</form><HR>';
content += '<textarea class="eventTinymce" id="userInputEventInfo"></textarea><HR>';
content += '<table class="table table-hover"><TR><TD>';
content += '</TD><TD>';
content += '</TD></TR></table>';
if (0 == response.eventsArray.length) {
content += '<p>Please Create Events to include</p>';
}
else {
content += '<div class="panel-group" id="accordion">';
content += '<div id="eventCheckbox" class="checkbox">';
content += "<label>";
for (var i = 0; i < response.eventsArray.length; i++) {
content += getSelectEventContent(response.eventsArray[i]);
}
content += "</label>";
content += '</div>';
content += '</div>';
}
content += '<button type="button" class="btn btn-success btn-lg" href="#" onClick="javascript: verifyEventInvite()"><i class="glyphicon glyphicon-envelope"></i> Create Event</button>';
updateMainContent( pagetitle + '<div class="well"><BR/>' + content + '</div>');
// After writing HTML content, convert the textarea to TinyMCE based text
tinymce.init({
mode : "specific_textareas",
editor_selector : "eventTinymce",
plugins: [
"advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"table contextmenu directionality emoticons template textcolor paste fullpage textcolor"
],
toolbar1: "bold italic underline strikethrough forecolor removeformat hr| alignleft aligncenter alignright alignjustify | formatselect fontsizeselect",
toolbar2: "cut copy paste | table bullist numlist | outdent indent blockquote | undo redo | link unlink preview fullscreen | spellchecker nonbreaking",
menubar: false,
toolbar_items_size: 'small'
});
var ed = tinymce.get('userInputEventInfo');
if (ed) {
ed.setContent('');
}
});
}
function showUserMultiEvents(funcAfterShowCompletes)
{
sendAjaxRequest("getAdminMultiEvents", "",
function(response) {
var content = "";
if (0 == response.multieventsArray.length) {
content += '<div class="jumbotron"><H1>Hello there!</H1>';
content += '<HR><p>I see that you are new here, and you have not created any Multi-Events yet.</p>';
content += '<HR><p>Begin the experience by creating a new Multi-Event</p>';
content += '<HR></DIV>';
}
else {
content += '<div class="panel panel-primary"><div class="panel-heading">\
<h3><center>Your Multi Events</center></h3>\
</div></div>';
content += '<div class="panel-group" id="accordion">';
for (var i = 0; i < response.multieventsArray.length; i++) {
content += '<p>' + JSON.stringify(response.multieventsArray[i]) + '</p>';
//content += getMultiEventContent(response.multieventsArray[i], 0==i);
}
content += '</div>';
}
updateMainContent(content);
if (funcAfterShowCompletes) {
funcAfterShowCompletes();
}
});
}