Skip to content

Commit e28912b

Browse files
committed
Input event modal and create some supporting infra
update form to split date/time as well
1 parent 3a41dc6 commit e28912b

File tree

5 files changed

+139
-9
lines changed

5 files changed

+139
-9
lines changed

goathacks/admin/events.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def list_events():
1616

1717
events = Event.query.all()
1818

19-
return render_template("events/list.html", events=events)
19+
form = forms.EventForm()
20+
21+
return render_template("events/list.html", events=events, form=form)
2022

2123
@bp.route("/events/events.json")
2224
@login_required

goathacks/admin/forms.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from flask_wtf import FlaskForm
2-
from wtforms import StringField, DateTimeField, SubmitField, TextAreaField
2+
from wtforms import StringField, DateField, TimeField, SubmitField, TextAreaField
33
from wtforms.validators import DataRequired
44

55
class EventForm(FlaskForm):
66
name = StringField("Name", validators=[DataRequired()])
77
description = TextAreaField("Description")
88
location = StringField("Location", validators=[DataRequired()])
9-
start_time = DateTimeField("Start Time", validators=[DataRequired()])
10-
end_time = DateTimeField("End Time", validators=[DataRequired()])
9+
start_day = DateField("Start Day", validators=[DataRequired()])
10+
start_time = TimeField("Start Time", validators=[DataRequired()])
11+
end_day = DateField("End Day", validators=[DataRequired()])
12+
end_time = TimeField("End Time", validators=[DataRequired()])
1113
category = StringField("Category")
1214
submit = SubmitField("Submit")

goathacks/templates/events/list.html

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h2>Events</h2>
1919
<th>Category</th>
2020
<th>Checked in</th>
2121
<th>QR Code</th>
22-
<th><a href="{{url_for('admin.new_event')}}">New</a></th>
22+
<th><a href="#editModal" data-bs-toggle="modal" data-id="0">New</a></th>
2323
</tr>
2424
</thead>
2525
<tbody>
@@ -34,11 +34,137 @@ <h2>Events</h2>
3434
<td>{{ event.get_checkins()|length }}</td>
3535
<td><a href='{{ url_for("admin.qrcode_event", id=event.id)
3636
}}'>QR Code</a></td>
37-
<td><a href="{{url_for('admin.edit_event', id=event.id)}}">Edit</a></td>
37+
<td><a href="#editModal" data-bs-toggle="modal" data-id="{{ e.id}}" >Edit</a></td>
3838
</tr>
3939
{% endfor %}
4040
</tbody>
4141
</table>
4242
</div>
4343
</div>
44+
45+
<div class="modal" id="editModal" tabindex="-1" aria-labelledby="editModalLabel"
46+
aria-hidden="true">
47+
<div class="modal-dialog">
48+
<div class="modal-content">
49+
<div class="modal-header">
50+
<h1 class="modal-title fs-5" id="editModalLabel">Event</h1>
51+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
52+
</div>
53+
<form class="form" id="edit-form" action="/admin/events/0" role="form" method="post">
54+
<div class="modal-body">
55+
{{ form.csrf_token }}
56+
<div class="form-floating mb-3 required">
57+
{{ form.name(class="form-control") }}
58+
{{ form.name.label() }}
59+
</div>
60+
<div class="form-floating mb-3">
61+
{{ form.description(class="form-control") }}
62+
{{ form.description.label() }}
63+
</div>
64+
<div class="form-floating mb-3 required">
65+
{{ form.location(class="form-control") }}
66+
{{ form.location.label() }}
67+
</div>
68+
<div class="row">
69+
<div class="col">
70+
<div class="form-floating mb-3 required">
71+
{{ form.start_day(class="form-control") }}
72+
{{ form.start_day.label() }}
73+
</div>
74+
</div>
75+
<div class="col">
76+
<div class="form-floating mb-3 required">
77+
{{ form.start_time(class="form-control") }}
78+
{{ form.start_time.label() }}
79+
</div>
80+
</div>
81+
</div>
82+
<div class="row">
83+
<div class="col">
84+
<div class="form-floating mb-3 required">
85+
{{ form.end_day(class="form-control") }}
86+
{{ form.end_day.label() }}
87+
</div>
88+
</div>
89+
<div class="col">
90+
<div class="form-floating mb-3 required">
91+
{{ form.end_time(class="form-control") }}
92+
{{ form.end_time.label() }}
93+
</div>
94+
</div>
95+
</div>
96+
</div>
97+
<div class="modal-footer">
98+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
99+
<button type="submit" class="btn btn-primary" id="edit-save">Save changes</button>
100+
</div>
101+
</form>
102+
</div>
103+
</div>
104+
</div>
105+
106+
<script src="{{ url_for('static', filename='js/jquery-3.6.3.min.js') }}" charset="utf-8"></script>
107+
108+
<script charset="utf-8">
109+
const editButton = document.getElementById("edit-save")
110+
111+
$('#editModal').on('show.bs.modal', function(event) {
112+
var modal = $(this)
113+
modal.find('#name').val('')
114+
modal.find('#location').val('')
115+
modal.find('#description').val('')
116+
modal.find('#start_day').val('')
117+
modal.find('#start_time').val('')
118+
modal.find('#end_day').val('')
119+
modal.find('#end_time').val('')
120+
121+
var button = $(event.relatedTarget)
122+
var name,description,loc,start_time,start_day,end_time,end_day
123+
id = button.data('id')
124+
125+
saveButton = document.getElementById("edit-save")
126+
saveButton.dataset.id = id
127+
128+
editForm = document.getElementById("edit-form")
129+
editForm.action = "/admin/event/" + id
130+
131+
if (id) {
132+
$.get(`/admin/event/${id}`, (data) => {
133+
134+
if (data.status == "error") {
135+
// This is a new event, do nothing!
136+
} else {
137+
name = data.name,
138+
description = data.description,
139+
loc = data.location
140+
141+
start = new Date(data.start_time)
142+
143+
var day = ("0" + start.getDate()).slice(-2);
144+
var month = ("0" + (start.getMonth() + 1)).slice(-2);
145+
146+
start_day = start.getFullYear()+"-"+(month)+"-"+(day);
147+
start_time = `${start.getHours()}:${padTwoDigits(start.getMinutes())}`
148+
end = new Date(data.end_time)
149+
150+
var day = ("0" + end.getDate()).slice(-2);
151+
var month = ("0" + (end.getMonth() + 1)).slice(-2);
152+
153+
end_day = end.getFullYear()+"-"+(month)+"-"+(day);
154+
end_time = `${end.getHours()}:${padTwoDigits(end.getMinutes())}`
155+
}
156+
157+
modal.find('#name').val(name)
158+
modal.find('#location').val(loc)
159+
modal.find('#description').val(description)
160+
modal.find('#start_day').val(start_day)
161+
modal.find('#start_time').val(start_time)
162+
modal.find('#end_day').val(end_day)
163+
modal.find('#end_time').val(end_time)
164+
165+
166+
});
167+
}
168+
})
169+
</script>
44170
{% endblock %}

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Flask-Login==0.6.2
99
Flask-Migrate==4.0.0
1010
Flask-SQLAlchemy==3.0.2
1111
Flask-WTF==1.0.1
12-
greenlet==2.0.1
12+
greenlet
1313
itsdangerous==2.1.2
1414
Jinja2==3.1.2
1515
Mako==1.2.4
@@ -19,7 +19,7 @@ psycopg2==2.9.5
1919
pynvim==0.4.3
2020
python-dotenv==0.21.0
2121
SQLAlchemy==1.4.44
22-
uWSGI==2.0.21
22+
uWSGI
2323
Werkzeug==2.2.2
2424
WTForms==3.0.1
2525
ulid

0 commit comments

Comments
 (0)