diff --git a/smash/web/static/js/daily_planning.js b/smash/web/static/js/daily_planning.js index 7462569b09b2a11d233cdee274ceb75b15a7dc7b..5d201b60c19d1577eb76a3982c38aa1692c5b74e 100644 --- a/smash/web/static/js/daily_planning.js +++ b/smash/web/static/js/daily_planning.js @@ -217,6 +217,8 @@ $(document).ready(function () { console.log(data); saveButton.css('border-color', 'red'); + showErrorInfo("There was an unexpected problem with saving data. " + + "Please contact administrators."); setTimeout(function () { saveButton.delay(200).css('border-color', currentBorder); }, 200); diff --git a/smash/web/static/js/smash.js b/smash/web/static/js/smash.js index 6c08a8568fcd1d6dca6230ac9beaf935e092a403..3bfb678925183ceaf0ac7f5f88e61d4700ca48ce 100644 --- a/smash/web/static/js/smash.js +++ b/smash/web/static/js/smash.js @@ -24,6 +24,7 @@ $(document).ready(function () { return true; } }) + }); $.ajaxSetup({ @@ -49,4 +50,24 @@ $.ajaxSetup({ xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); } } -}); \ No newline at end of file +}); + +function showErrorInfo(content) { + var errorDialogDiv = document.createElement("div"); + document.body.appendChild(errorDialogDiv); + errorDialogDiv.innerHTML = '<div class="modal-dialog" role="document">' + + '<div class="modal-content">' + + '<div class="modal-header">ERROR' + + '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' + + '<span aria-hidden="true">×</span></button>' + + '</div>' + + '<div name="error-content" class="modal-body">' + content + '</div>' + + '<div class="modal-footer">' + + '<button type="button" class="btn btn-outline pull-right" data-dismiss="modal">Close</button>' + + '</div>' + + '</div>' + + '</div>'; + $(errorDialogDiv).attr("role", "dialog"); + $(errorDialogDiv).addClass("modal modal-danger fade"); + $(errorDialogDiv).modal("show"); +} \ No newline at end of file diff --git a/smash/web/tests/test_view_appointments.py b/smash/web/tests/test_view_appointments.py index bf721ebe836316136b26bb85ed47ae8f030c091f..7bb1f5118ed39775fc3ba461600f3b51ab9533d3 100644 --- a/smash/web/tests/test_view_appointments.py +++ b/smash/web/tests/test_view_appointments.py @@ -1,4 +1,5 @@ import datetime +import logging from django.urls import reverse @@ -9,6 +10,8 @@ from web.models import Appointment, Subject from web.views.notifications import get_today_midnight_date from . import LoggedInTestCase +logger = logging.getLogger(__name__) + class AppointmentsViewTests(LoggedInTestCase): def setUp(self): @@ -71,6 +74,22 @@ class AppointmentsViewTests(LoggedInTestCase): self.assertEqual(response.status_code, 200) + def test_save_as_finished_appointments_edit_without_visit(self): + appointment = create_appointment(None, get_today_midnight_date()) + appointment.visit = None + appointment.save() + + form_appointment = AppointmentEditForm(user=self.user, instance=appointment, prefix="appointment") + form_data = {} + for key, value in form_appointment.initial.items(): + if value is not None: + form_data['appointment-{}'.format(key)] = format_form_field(value) + form_data['appointment-status'.format(key)] = Appointment.APPOINTMENT_STATUS_FINISHED + self.client.post(reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data) + + appointment_result = Appointment.objects.filter(id=appointment.id)[0] + self.assertEqual(Appointment.APPOINTMENT_STATUS_FINISHED, appointment_result.status) + def test_save_appointments_edit(self): subject = create_subject() visit = create_visit(subject) diff --git a/smash/web/views/appointment.py b/smash/web/views/appointment.py index 5f0e6d7d5265997afa2be09493ed84d3fc88a5ee..c0462a996675c62a820e99de9db2e80e5c57e303 100644 --- a/smash/web/views/appointment.py +++ b/smash/web/views/appointment.py @@ -80,7 +80,7 @@ def appointment_edit(request, id): subject_form.save() the_appointment = get_object_or_404(Appointment, id=id) - if the_appointment.status == Appointment.APPOINTMENT_STATUS_FINISHED: + if the_appointment.status == Appointment.APPOINTMENT_STATUS_FINISHED and the_appointment.visit is not None: subject = Subject.objects.get(id=the_appointment.visit.subject.id) subject.information_sent = True if the_appointment.flying_team is not None and subject.flying_team is None: