Commit 722ae801 authored by berumuron's avatar berumuron
Browse files

add: Add support for events on several days

parent 6ec3b3e8
......@@ -27,6 +27,7 @@ def create():
if request.method == "POST":
title = request.form["title"].strip()
date = request.form["date"].strip()
date_end = request.form["date_end"].strip()
is_private = request.form["is_private"].strip() == "yes"
project_name = request.form["project"].strip()
description = request.form["description"].strip()
......@@ -43,7 +44,11 @@ def create():
flash("Le titre est requis.")
elif not date:
flash("La date est requise.")
elif not Event.create(title, date, is_private, project_id, description):
elif date_end and date >= date_end:
flash("La date de fin doit être supérieure à la date de début.")
elif not Event.create(
title, date, date_end, is_private, project_id, description
):
flash("L’évènement n’a pas pu être ajouté.")
else:
flash("L’évènement a été ajouté.", "success")
......
......@@ -50,10 +50,11 @@ class User:
class Event:
def __init__(self, id, title, date, is_private, project_id, description):
def __init__(self, id, title, date, date_end, is_private, project_id, description):
self.id = id
self.title = title
self.date = date
self.date_end = date_end
self.is_private = is_private
self.project_id = project_id
self.description = description
......@@ -72,6 +73,7 @@ class Event:
event["id"],
event["title"],
event["date"],
event["date_end"],
event["is_private"],
event["project_id"],
event["description"],
......@@ -92,6 +94,7 @@ class Event:
event["id"],
event["title"],
event["date"],
event["date_end"],
event["is_private"],
event["project_id"],
event["description"],
......@@ -112,6 +115,7 @@ class Event:
event["id"],
event["title"],
event["date"],
event["date_end"],
event["is_private"],
event["project_id"],
event["description"],
......@@ -133,20 +137,22 @@ class Event:
event["id"],
event["title"],
event["date"],
event["date_end"],
event["is_private"],
event["project_id"],
event["description"],
)
@classmethod
def create(cls, title, date, is_private, project_id, description):
def create(cls, title, date, date_end, is_private, project_id, description):
database = db.get_db()
cursor = database.execute(
(
"INSERT INTO events (title, date, is_private, project_id, description) "
"VALUES (?, ?, ?, ?, ?)"
"INSERT INTO events "
"(title, date, date_end, is_private, project_id, description) "
"VALUES (?, ?, ?, ?, ?, ?)"
),
(title, date, is_private, project_id, description),
(title, date, date_end, is_private, project_id, description),
)
database.commit()
......
......@@ -12,6 +12,7 @@ CREATE TABLE events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
date DATE NOT NULL,
date_end DATE,
is_private BOOLEAN NOT NULL DEFAULT true,
description TEXT NOT NULL,
project_id INTEGER,
......
......@@ -89,6 +89,17 @@ form {
margin-bottom: 5rem;
}
form .form-row {
display: flex;
}
form .form-row .form-group {
flex: 1;
}
form .form-row .form-group + .form-group {
margin-left: 1rem;
}
form .form-group {
margin-bottom: 1rem;
}
......@@ -107,7 +118,8 @@ form label {
margin-bottom: .25rem;
padding-left: .5rem;
}
form .form-group.form-group-radios label {
form .form-group.form-group-radios label,
form .form-group.form-group-checkbox label {
display: inline-block;
margin-right: 1rem;
padding-left: 0;
......@@ -329,7 +341,7 @@ button.button-ghost {
.events .event .event-date {
display: inline-block;
width: 5rem;
min-width: 5rem;
padding-left: .5rem;
padding-right: .5rem;
......@@ -491,3 +503,8 @@ button.button-ghost {
.folder.folder-folded .folder-toggle::after {
content: "▹";
}
/* Utilities */
.hidden {
visibility: hidden;
}
......@@ -12,9 +12,21 @@
<input type="text" name="title" id="title" required autofocus />
</div>
<div class="form-group">
<label for="date">Date</label>
<input type="date" name="date" id="date" required value="{{ today_date }}" />
<div class="form-row">
<div class="form-group">
<label for="date">Date</label>
<input type="date" name="date" id="date" required value="{{ today_date }}" />
</div>
<div class="form-group hidden">
<label for="date-end">Date de fin</label>
<input type="date" name="date_end" id="date-end" />
</div>
</div>
<div class="form-group form-group-checkbox">
<input type="checkbox" id="is-duration" />
<label for="is-duration">Évènement sur plusieurs jours&nbsp;?</label>
</div>
<div class="form-group form-group-radios">
......@@ -51,5 +63,40 @@
</a>
</div>
</form>
</div
</div>
<script>
(function() {
var isDurationInput = document.getElementById('is-duration');
var dateInput = document.getElementById('date');
var dateEndInput = document.getElementById('date-end');
// Consider the case where user check the input, reload the page
// and the browser keep in cache the check.
if (isDurationInput.checked) {
const dayStart = dateInput.valueAsDate;
if (dayStart) {
var nextDay = new Date(dayStart);
nextDay.setDate(nextDay.getDate() + 1);
dateEndInput.valueAsDate = nextDay;
}
dateEndInput.parentElement.classList.remove('hidden');
}
isDurationInput.addEventListener('click', function (e) {
if (isDurationInput.checked) {
const dayStart = dateInput.valueAsDate;
if (dayStart) {
var nextDay = new Date(dayStart);
nextDay.setDate(nextDay.getDate() + 1);
dateEndInput.valueAsDate = nextDay;
}
dateEndInput.parentElement.classList.remove('hidden');
} else {
dateEndInput.parentElement.classList.add('hidden');
dateEndInput.value = '';
}
});
}());
</script>
{% endblock %}
......@@ -41,7 +41,19 @@
{% for event in group_by_month.list|sort(attribute='date', reverse=True) %}
<li class="event {{ 'event-private' if event.is_private }} {{ 'folder folder-folded' if event.description }}">
<span class="event-date">
{{ event.date.strftime('%d %b') }}
{% if event.date_end %}
{% if event.date.month == event.date_end.month %}
{{ event.date.strftime('%d') }}
{{ event.date_end.strftime('%d %b') }}
{% else %}
{{ event.date.strftime('%d %b') }}
{{ event.date_end.strftime('%d %b') }}
{% endif %}
{% else %}
{{ event.date.strftime('%d %b') }}
{% endif %}
</span>
{% if event.description %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment