diff --git a/schoolapps/static/common/helper.js b/schoolapps/static/common/helper.js index 016ff11c793119fbc68e9ee83dcc65791d05cf4a..37de467cbe636e1bf33df74af943cf4d7cbdd10a 100644 --- a/schoolapps/static/common/helper.js +++ b/schoolapps/static/common/helper.js @@ -105,4 +105,10 @@ $(document).ready(function () { // Initialize collapsible [MAT] $('.collapsible').collapsible(); + // Initialize delete button + $(".delete-button").click(function (e) { + if (!confirm("Wirklich löschen?")) { + e.preventDefault(); + } + }) }); \ No newline at end of file diff --git a/schoolapps/timetable/templates/timetable/addhint.html b/schoolapps/timetable/templates/timetable/hintform.html similarity index 93% rename from schoolapps/timetable/templates/timetable/addhint.html rename to schoolapps/timetable/templates/timetable/hintform.html index 15a9231aa2cfbf086262eb1f8cf27e78737ade9e..5251dadd2feffe7b9f241b006a8f2e27cab707a7 100755 --- a/schoolapps/timetable/templates/timetable/addhint.html +++ b/schoolapps/timetable/templates/timetable/hintform.html @@ -5,7 +5,13 @@ {% load widget_tweaks %} <main> - <h4>Neuen Hinweis erstellen</h4> + <h4> + {% if mode == "new" %} + Neuen Hinweis erstellen + {% else %} + Hinweis bearbeiten + {% endif %} + </h4> {% if msg == "success" %} <div class="alert success"> @@ -100,7 +106,8 @@ <button type="submit" class="waves-effect waves-light btn green"> - <i class="material-icons left">add</i> Hinweis erstellen und veröffentlichen + <i class="material-icons left">save</i> Hinweis {% if mode == "new" %} erstellen und + veröffentlichen {% else %} aktualisieren {% endif %} </button> </form> diff --git a/schoolapps/timetable/templates/timetable/hints.html b/schoolapps/timetable/templates/timetable/hints.html index c1a5a7113848463037c46a75509f19a9a8aadde6..b7930785ec40a640151d068bc02a9683e2e355e3 100755 --- a/schoolapps/timetable/templates/timetable/hints.html +++ b/schoolapps/timetable/templates/timetable/hints.html @@ -3,6 +3,15 @@ {% load martortags %} <main> + {% if msg %} + <div class="alert success"> + <p> + <i class="material-icons left">check_circle</i> + Der Hinweis wurde erfolgreich {% if msg == "success_edit" %}gespeichert. {% else %} + gelöscht. {% endif %} + </p> + </div> + {% endif %} <h4>Hinweise</h4> @@ -55,11 +64,13 @@ <div class="collapsible-body row"> {# <div class="col s12 m4">#} <div class="right"> - <a class="btn-flat waves-effect waves-teal green-text"> + <a class="btn-flat waves-effect waves-teal green-text" + href="{% url "timetable_edit_hint" hint.id %}"> <i class="material-icons left">edit</i> <span class="hide-on-small-only">Bearbeiten</span> </a> - <a class="btn-flat waves-effect waves-teal red-text"> + <a class="btn-flat waves-effect waves-teal red-text delete-button" + href="{% url "timetable_delete_hint" hint.id %}"> <i class="material-icons left">delete</i> <span class="hide-on-small-only">Löschen</span> </a> diff --git a/schoolapps/timetable/urls.py b/schoolapps/timetable/urls.py index 2c40960df7979e09c099061f9bd27bc776cee3ea..e5f64712947fe44b92d60f2fc0900657f4638bbe 100755 --- a/schoolapps/timetable/urls.py +++ b/schoolapps/timetable/urls.py @@ -2,6 +2,10 @@ from django.urls import path from . import views urlpatterns = [ + path('hints', views.hints, name="timetable_hints"), + path('hints/add', views.add_hint, name="timetable_add_hint"), + path('hints/<int:id>/edit', views.edit_hint, name="timetable_edit_hint"), + path('hints/<int:id>/delete', views.delete_hint, name="timetable_delete_hint"), path('', views.all, name='timetable_admin_all'), path('my', views.my_plan, name='timetable_my_plan'), path('my/<int:year>/<int:month>/<int:day>/', views.my_plan, name='timetable_my_plan'), @@ -14,6 +18,5 @@ urlpatterns = [ path('substitutions/', views.substitutions, name='timetable_substitutions'), path('substitutions/<int:year>/<int:month>/<int:day>/', views.substitutions, name='timetable_substitutions_date'), path('class.pdf', views.sub_pdf, name="timetable_substitutions_pdf"), - path('hints', views.hints, name="timetable_hints"), - path('hints/add', views.add_hint, name="timetable_add_hint"), + ] diff --git a/schoolapps/timetable/views.py b/schoolapps/timetable/views.py index 7e60c31bc744a967d7cda571427616595c685a61..138079ae2046e658b215ad90c6c91f557c6eac88 100755 --- a/schoolapps/timetable/views.py +++ b/schoolapps/timetable/views.py @@ -4,7 +4,7 @@ import os from PyPDF2 import PdfFileMerger from django.contrib.auth.decorators import login_required, permission_required from django.http import Http404, FileResponse -from django.shortcuts import render, redirect +from django.shortcuts import render, redirect, get_object_or_404 from django.utils import timezone from material import Fieldset, Row @@ -261,8 +261,12 @@ def substitutions(request, year=None, day=None, month=None): @permission_required("timetable.can_view_hint") def hints(request): f = HintFilter(request.GET, queryset=Hint.objects.all()) + msg = None + if request.session.get("msg", False): + msg = request.session["msg"] + request.session["msg"] = None # f.form.layout = Fieldset("Hi", Row("from_date", "to_date", "classes", "teachers")) - return render(request, "timetable/hints.html", {"f": f}) + return render(request, "timetable/hints.html", {"f": f, "msg": msg}) @login_required @@ -280,4 +284,30 @@ def add_hint(request): else: form = HintForm() - return render(request, 'timetable/addhint.html', {'form': form, "martor": True, "msg": msg}) + return render(request, 'timetable/hintform.html', {'form': form, "martor": True, "msg": msg, "mode": "new"}) + + +@login_required +@permission_required("timetable.can_edit_hint") +def edit_hint(request, id): + hint = get_object_or_404(Hint, pk=id) + if request.method == 'POST': + form = HintForm(request.POST, instance=hint) + + if form.is_valid(): + form.save() + request.session["msg"] = "success_edit" + return redirect('timetable_hints') + else: + form = HintForm(instance=hint) + + return render(request, 'timetable/hintform.html', {'form': form, "martor": True, "mode": "edit"}) + + +@login_required +@permission_required("timetable.can_delete_hint") +def delete_hint(request, id): + hint = get_object_or_404(Hint, pk=id) + hint.delete() + request.session["msg"] = "success_delete" + return redirect('timetable_hints')