mirror of
https://github.com/ae-utbm/sith.git
synced 2025-11-10 14:03:12 +00:00
rework news form
This commit is contained in:
@@ -10,21 +10,6 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if 'preview' in request.POST.keys() %}
|
||||
<section class="news_event">
|
||||
<h4>{{ form.instance.title }}</h4>
|
||||
<p class="date">
|
||||
<span>{{ form.instance.dates.first().start_date|localtime|date(DATETIME_FORMAT) }}
|
||||
{{ form.instance.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</span> -
|
||||
<span>{{ form.instance.dates.first().end_date|localtime|date(DATETIME_FORMAT) }}
|
||||
{{ form.instance.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span>
|
||||
</p>
|
||||
<p><a href="#">{{ form.instance.club or "Club" }}</a></p>
|
||||
<div>{{ form.instance.summary|markdown }}</div>
|
||||
<div>{{ form.instance.content|markdown }}</div>
|
||||
<p>{% trans %}Author: {% endtrans %} {{ user_profile_link(form.instance.author) }}</p>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% if object %}
|
||||
<h2>{% trans %}Edit news{% endtrans %}</h2>
|
||||
{% else %}
|
||||
@@ -33,103 +18,73 @@
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors() }}
|
||||
{{ form.author }}
|
||||
<p>
|
||||
{{ form.type.errors }}
|
||||
<label for="{{ form.type.name }}" class="required">{{ form.type.label }}</label>
|
||||
<ul>
|
||||
<li>{% trans %}Notice: Information, election result - no date{% endtrans %}</li>
|
||||
<li>{% trans %}Event: punctual event, associated with one date{% endtrans %}</li>
|
||||
<li>
|
||||
{% trans trimmed%}
|
||||
Weekly: recurrent event, associated with many dates
|
||||
(specify the first one, and a deadline)
|
||||
{% endtrans %}
|
||||
</li>
|
||||
<li>
|
||||
{% trans trimmed %}
|
||||
Call: long time event, associated with a long date (like election appliance)
|
||||
{% endtrans %}
|
||||
</li>
|
||||
</ul>
|
||||
{{ form.type }}
|
||||
</p>
|
||||
<p class="date">
|
||||
{{ form.start_date.errors }}
|
||||
<label for="{{ form.start_date.name }}">{{ form.start_date.label }}</label>
|
||||
{{ form.start_date }}
|
||||
</p>
|
||||
<p class="date">
|
||||
{{ form.end_date.errors }}
|
||||
<label for="{{ form.end_date.name }}">{{ form.end_date.label }}</label>
|
||||
{{ form.end_date }}
|
||||
</p>
|
||||
<p class="until">
|
||||
{{ form.until.errors }}
|
||||
<label for="{{ form.until.name }}">{{ form.until.label }}</label>
|
||||
{{ form.until }}
|
||||
</p>
|
||||
<p>
|
||||
<fieldset>
|
||||
{{ form.title.errors }}
|
||||
<label for="{{ form.title.name }}" class="required">{{ form.title.label }}</label>
|
||||
{{ form.title.label_tag() }}
|
||||
{{ form.title }}
|
||||
</p>
|
||||
<p>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
{{ form.club.errors }}
|
||||
<label for="{{ form.club.name }}" class="required">{{ form.club.label }}</label>
|
||||
{{ form.club.label_tag() }}
|
||||
<span class="helptext">{{ form.club.help_text }}</span>
|
||||
{{ form.club }}
|
||||
</p>
|
||||
<p>
|
||||
</fieldset>
|
||||
{{ form.date_form.non_field_errors() }}
|
||||
<div
|
||||
class="row gap-2x"
|
||||
x-data="{startDate: '{{ form.date_form.start_date.value() }}'}"
|
||||
>
|
||||
{# startDate is used to dynamically ensure end_date >= start_date,
|
||||
whatever the value of start_date #}
|
||||
<fieldset>
|
||||
{{ form.date_form.start_date.errors }}
|
||||
{{ form.date_form.start_date.label_tag() }}
|
||||
<span class="helptext">{{ form.date_form.start_date.help_text }}</span>
|
||||
{{ form.date_form.start_date|add_attr("x-model=startDate") }}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
{{ form.date_form.end_date.errors }}
|
||||
{{ form.date_form.end_date.label_tag() }}
|
||||
<span class="helptext">{{ form.date_form.end_date.help_text }}</span>
|
||||
{{ form.date_form.end_date|add_attr(":min=startDate") }}
|
||||
</fieldset>
|
||||
</div>
|
||||
{# lower to convert True and False to true and false #}
|
||||
<div x-data="{isWeekly: {{ form.date_form.is_weekly.value()|lower }}}">
|
||||
<fieldset>
|
||||
<div class="row gap">
|
||||
{{ form.date_form.is_weekly|add_attr("x-model=isWeekly") }}
|
||||
<div>
|
||||
{{ form.date_form.is_weekly.label_tag() }}
|
||||
<span class="helptext">{{ form.date_form.is_weekly.help_text }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset x-show="isWeekly" x-transition x-cloak>
|
||||
{{ form.date_form.occurrences.label_tag() }}
|
||||
<span class="helptext">{{ form.date_form.occurrences.help_text }}</span>
|
||||
{{ form.date_form.occurrences }}
|
||||
</fieldset>
|
||||
</div>
|
||||
<fieldset>
|
||||
{{ form.summary.errors }}
|
||||
<label for="{{ form.summary.name }}" class="required">{{ form.summary.label }}</label>
|
||||
{{ form.summary.label_tag() }}
|
||||
<span class="helptext">{{ form.summary.help_text }}</span>
|
||||
{{ form.summary }}
|
||||
</p>
|
||||
<p>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
{{ form.content.errors }}
|
||||
<label for="{{ form.content.name }}">{{ form.content.label }}</label>
|
||||
{{ form.content.label_tag() }}
|
||||
<span class="helptext">{{ form.content.help_text }}</span>
|
||||
{{ form.content }}
|
||||
</p>
|
||||
{% if user.is_com_admin %}
|
||||
<p>
|
||||
{{ form.automoderation.errors }}
|
||||
<label for="{{ form.automoderation.name }}">{{ form.automoderation.label }}</label>
|
||||
{{ form.automoderation }}
|
||||
</p>
|
||||
</fieldset>
|
||||
{% if user.is_root or user.is_com_admin %}
|
||||
<fieldset>
|
||||
{{ form.auto_moderate.errors }}
|
||||
{{ form.auto_moderate }}
|
||||
{{ form.auto_moderate.label_tag() }}
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
<p><input type="submit" name="preview" value="{% trans %}Preview{% endtrans %}"/></p>
|
||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}"/></p>
|
||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}" class="btn btn-blue"/></p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
$(function () {
|
||||
let type = $('input[name=type]');
|
||||
let dates = $('.date');
|
||||
let until = $('.until');
|
||||
|
||||
function update_targets() {
|
||||
const type_checked = $('input[name=type]:checked');
|
||||
if (["CALL", "EVENT"].includes(type_checked.val())) {
|
||||
dates.show();
|
||||
until.hide();
|
||||
} else if (type_checked.val() === "WEEKLY") {
|
||||
dates.show();
|
||||
until.show();
|
||||
} else {
|
||||
dates.hide();
|
||||
until.hide();
|
||||
}
|
||||
}
|
||||
|
||||
update_targets();
|
||||
type.change(update_targets);
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user