diff --git a/smash/web/migrations/0132_study_default_visit_duration_in_months.py b/smash/web/migrations/0132_study_default_visit_duration_in_months.py new file mode 100644 index 0000000000000000000000000000000000000000..522e672e1041241ab5c52140cebbbc53b8be7bbc --- /dev/null +++ b/smash/web/migrations/0132_study_default_visit_duration_in_months.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2018-11-13 10:05 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0131_study_default_voucher_expiration_in_months'), + ] + + operations = [ + migrations.AddField( + model_name='study', + name='default_visit_duration_in_months', + field=models.IntegerField(default=3, validators=[django.core.validators.MinValueValidator(1)], verbose_name=b'Default duration of the visits in months'), + ), + ] diff --git a/smash/web/models/study.py b/smash/web/models/study.py index e89ac16fc1f491a335b770d6e953b127227771bd..5b9d0a740ca08cdfc620377d23ed6975b6474074 100644 --- a/smash/web/models/study.py +++ b/smash/web/models/study.py @@ -44,6 +44,12 @@ class Study(models.Model): validators=[MinValueValidator(1)] ) + default_visit_duration_in_months = models.IntegerField( + verbose_name='Default duration of the visits in months', + default=3, + validators=[MinValueValidator(1)] + ) + def check_nd_number(self, nd_number): regex = re.compile(self.nd_number_study_subject_regex) return regex.match(nd_number) is not None diff --git a/smash/web/static/js/visit.js b/smash/web/static/js/visit.js index a2636ed219748484b648296a736608d14732589c..1e5aa2208b0177fad7bd72613cf637f7681c6f3e 100644 --- a/smash/web/static/js/visit.js +++ b/smash/web/static/js/visit.js @@ -1,10 +1,12 @@ -function visit_dates_behaviour(startDateInput, endDateInput) { +function visit_dates_behaviour(startDateInput, endDateInput, default_visit_duration) { $(startDateInput).change(function () { var object = $(this); try { var date = new Date(object.val()); - date.setMonth(date.getMonth() + 3); - $(endDateInput).val(date.toISOString().substring(0, 10)); + date.setMonth(date.getMonth() + default_visit_duration); + if($(endDateInput).val() == ""){ + $(endDateInput).val(date.toISOString().substring(0, 10)); + } } catch (err) { //there was a problematic date to process } diff --git a/smash/web/templates/visits/add.html b/smash/web/templates/visits/add.html index 749641be57b7d9c1e4160a5d7457fff0cbfa5fed..4c93ee497b56c5d68886deb070115662d1fa3e05 100644 --- a/smash/web/templates/visits/add.html +++ b/smash/web/templates/visits/add.html @@ -70,7 +70,8 @@ <script src="{% static 'js/visit.js' %}"></script> <script> - visit_dates_behaviour($("[name='datetime_begin']"),$("[name='datetime_end']")); + var default_visit_duration_in_months = parseInt("{{default_visit_duration}}"); + visit_dates_behaviour($("[name='datetime_begin']"), $("[name='datetime_end']"), default_visit_duration_in_months); </script> {% include "includes/datepicker.js.html" %} diff --git a/smash/web/templates/visits/details.html b/smash/web/templates/visits/details.html index 62069efad065578c2615da6a13a554e261b11629..08a133afefd9e41d417bc31aef7147177f77c19a 100644 --- a/smash/web/templates/visits/details.html +++ b/smash/web/templates/visits/details.html @@ -221,7 +221,8 @@ <script src="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.min.js' %}"></script> <script src="{% static 'js/visit.js' %}"></script> <script> - visit_dates_behaviour($("[name='datetime_begin']"), $("[name='datetime_end']")); + var default_visit_duration_in_months = parseInt("{{default_visit_duration}}"); + visit_dates_behaviour($("[name='datetime_begin']"), $("[name='datetime_end']"), default_visit_duration_in_months); </script> {% include "includes/datepicker.js.html" %} diff --git a/smash/web/views/visit.py b/smash/web/views/visit.py index 96dde765288b7b54fd87468952d6a742e2fd133a..585e40c379150c39aba1b1eb01b8f3ad5eaa6ffa 100644 --- a/smash/web/views/visit.py +++ b/smash/web/views/visit.py @@ -74,6 +74,7 @@ def visit_details(request, id): languages.extend(study_subject.subject.languages.all()) return wrap_response(request, 'visits/details.html', { + 'default_visit_duration' : study_subject.study.default_visit_duration_in_months, 'visit_form': visit_form, 'study_subject_form': study_subject_form, 'subject_form': subject_form,