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
|
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editModalLabel">Edit '{{eventData.name}}'</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="editEventForm" enctype="multipart/form-data" x-data="editEventForm()" x-init="init()"
@submit.prevent="submitForm">
{{> eventForm }}
<div class="form-group">
<div class="card border-danger mb-3">
<div class="card-header text-danger">Delete this event</div>
<div class="card-body text-danger">
<button type="button" id="deleteEvent" class="btn btn-danger" data-toggle="modal"
data-target="#deleteModal" data-event-id="{{eventData.id}}"><i class="fas fa-trash"></i>
Delete</button>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</form>
</div>
</div>
</div>
</div>
<script>
$('#deleteImage').click(function () {
$.post('/deleteimage/{{eventData.id}}/{{eventData.editToken}}', function (response) {
if (response === "Success") {
location.reload();
} else {
alert(response);
}
});
})
</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'));
$("#image-preview").css("background-image", "url('/events/{{eventData.image}}')");
$("#image-preview").css("background-size", "cover");
$("#image-preview").css("background-position", "center center");
$("#timezone").val('{{eventData.timezone}}').trigger('change');
});
function editEventForm() {
return {
data: {
eventName: `{{{eventData.name}}}`,
eventLocation: `{{{ eventData.location }}}`,
eventStart: `{{{ parsedStartForDateInput }}}`,
eventEnd: `{{{ parsedEndForDateInput }}}`,
timezone: `{{{ eventData.timezone }}}`,
eventDescription: `{{{ eventData.description }}}`,
eventURL: `{{{ eventData.url }}}`,
hostName: `{{{ eventData.hostName }}}`,
creatorEmail: `{{{ eventData.creatorEmail }}}`,
eventGroupID: `{{{ eventData.eventGroupID }}}`,
eventGroupEditToken: `{{{ eventData.eventGroupEditToken }}}`,
interactionCheckbox: {{{ eventData.usersCanComment }}},
joinCheckbox: {{{ eventData.usersCanAttend }}},
maxAttendeesCheckbox: {{#if eventData.maxAttendees}}true{{else}}false{{/if}},
maxAttendees: `{{{ eventData.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();
/* Set up checkboxes */
this.data.eventGroupCheckbox = {{#if eventData.eventGroupID}}true{{else}}false{{/if}};
this.data.interactionCheckbox = {{eventData.usersCanComment}};
this.data.joinCheckbox = {{eventData.usersCanAttend}};
this.data.maxAttendeesCheckbox = {{#if eventData.maxAttendees}}true{{else}}false{{/if}};
},
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]);
formData.append("editToken", '{{eventData.editToken}}');
try {
const response = await fetch("/event/{{eventData.id}}", {
method: "PUT",
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;
}
window.location.reload();
} catch (error) {
console.log(error);
this.errors = [
{
message: "An unexpected error has occurred. Please try again later.",
}
];
this.submitting = false;
}
},
}
}
</script>
|