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
|
<h2>New event</h2>
<hr>
<div class="alert alert-info mb-4 text-center" role="alert">
<i class="fas fa-exclamation-circle"></i> Events are visible to anyone who knows the link.
</div>
{{#each errors}}
<div class="alert alert-danger" role="alert">{{this.msg}}</div>
{{/each}}
<div class="container mb-4">
<div class="row">
<div class="col-sm-4 p-2">
<button type="button" id="showNewEventFormButton" class="btn btn-secondary w-100"><i class="fas fa-file"></i> Create a new event</button>
</div>
<div class="col-sm-4 p-2">
<button type="button" id="showImportEventFormButton" class="btn btn-secondary w-100"><i class="fas fa-file-import"></i> Import an existing event</button>
</div>
<div class="col-sm-4 p-2">
<button type="button" id="showNewEventGroupFormButton" class="btn btn-secondary w-100"><i class="fas fa-folder-open"></i> Create a new event group </button>
</div>
</div>
</div>
<div id="newEventFormContainer">
<h4 class="mb-2">Create an event</h4>
<form id="newEventForm" enctype="multipart/form-data" x-data="newEventForm()" x-init="init()" @submit.prevent="submitForm">
{{>eventForm}}
<div class="form-group row">
<div class="col-sm-12 pt-3 pb-3 text-center">
<button
id="newEventFormSubmit"
type="submit"
class="btn btn-primary w-50"
x-bind:disabled="submitting"
>Create</button>
</div>
</div>
</form>
</div>
<div id="importEventFormContainer">
{{>importeventform}}
</div>
<div id="newEventGroupFormContainer">
{{>neweventgroupform}}
</div>
<script>
$(document).ready(function(){
if ($('#icsImportControl')[0].files[0] != null){
var file = $('#icsImportControl')[0].files[0].name;
$('#icsImportControl').next('label').html('<i class="far fa-file-alt"></i> ' + file);
}
$("#showNewEventFormButton").click(function(){
$("button").removeClass("active");
$("#showImportEventFormButton #showNewEventGroupFormButton").removeClass("active");
if ($("#newEventFormContainer").is(":visible")){
$("#newEventFormContainer").slideUp("fast");
}
else {
$("#newEventFormContainer").slideDown("fast");
$("#importEventFormContainer").slideUp("fast");
$("#newEventGroupFormContainer").slideUp("fast");
$(this).addClass("active");
}
})
$("#showImportEventFormButton").click(function(){
$("button").removeClass("active");
$("#showNewEventFormButton #showNewEventGroupFormButton").removeClass("active");
if ($("#importEventFormContainer").is(":visible")){
$("#importEventFormContainer").slideUp("fast");
}
else {
$("#importEventFormContainer").slideDown("fast");
$("#newEventFormContainer").slideUp("fast");
$("#newEventGroupFormContainer").slideUp("fast");
$(this).addClass("active");
}
})
$("#showNewEventGroupFormButton").click(function(){
$("button").removeClass("active");
$("#showNewEventFormButton #showImportEventFormButton").removeClass("active");
if ($("#newEventGroupFormContainer").is(":visible")){
$("#newEventGroupFormContainer").slideUp("fast");
}
else {
$("#newEventGroupFormContainer").slideDown("fast");
$("#newEventFormContainer").slideUp("fast");
$("#importEventFormContainer").slideUp("fast");
$(this).addClass("active");
}
})
$('#icsImportControl').change(function(){
var file = $('#icsImportControl')[0].files[0].name;
$(this).next('label').html('<i class="far fa-file-alt"></i> ' + file);
});
})
</script>
<script type="text/javascript" src="/js/generate-timezones.js"></script>
<script>
$(document).ready(function() {
$.uploadPreview({
input_field: "#image-upload",
preview_box: "#image-preview",
label_field: "#image-label",
label_default: "Choose file",
label_selected: "Change file",
no_label: false
});
autosize($('textarea'));
});
function newEventForm() {
return {
data: {
eventName: '',
eventLocation: '',
eventStart: '',
eventEnd: '',
timezone: '',
eventDescription: '',
eventURL: '',
hostName: '',
creatorEmail: '',
eventGroupID: '',
eventGroupEditToken: '',
interactionCheckbox: false,
joinCheckbox: false,
maxAttendeesCheckbox: false,
maxAttendees: '',
},
errors: [],
submitting: false,
init() {
// Set up Select2
this.select2 = $(this.$refs.timezone).select2();
this.select2.on("select2:select", (event) => {
this.data.timezone = event.target.value;
});
this.data.timezone = this.select2.val();
// Reset checkboxes
this.data.eventGroupCheckbox = false;
this.data.interactionCheckbox = false;
this.data.joinCheckbox = false;
this.data.maxAttendeesCheckbox = false;
},
async submitForm() {
this.submitting = true;
this.errors = [];
const formData = new FormData();
for (const key in this.data) {
if (this.data.hasOwnProperty(key)) {
formData.append(key, this.data[key]);
}
}
formData.append("imageUpload", this.$refs.eventImageUpload.files[0]);
try {
const response = await fetch("/event", {
method: "POST",
body: formData,
});
this.submitting = false;
if (!response.ok) {
if (response.status !== 400) {
this.errors = [
{
message: "An unexpected error has occurred. Please try again later.",
}
];
return;
}
const json = await response.json();
this.errors = json.errors;
// Set Bootstrap validation classes using 'field' property
$("input, textarea").removeClass("is-invalid");
this.errors.forEach((error) => {
$(`#${error.field}`).addClass("is-invalid");
});
return;
}
const json = await response.json();
window.location.assign(json.url);
} catch (error) {
console.log(error);
this.errors = [
{
message: "An unexpected error has occurred. Please try again later.",
}
];
this.submitting = false;
}
},
}
}
</script>
|