diff --git a/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_list.html b/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_list.html index 9bd5e75..c6ee250 100644 --- a/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_list.html +++ b/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_list.html @@ -14,6 +14,7 @@ {% trans "Updated" %} {% trans "Status" %} {% trans "Report" %} + {% trans "Actions" %} {% for schedule in object_list %} @@ -23,6 +24,7 @@ {{ schedule.updated_at|date:"SHORT_DATETIME_FORMAT" }} {{ schedule.get_status_display }} None + Clone {% empty %} diff --git a/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_new.html b/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_new.html index 9b9d62e..1b5c7d6 100644 --- a/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_new.html +++ b/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_new.html @@ -2,8 +2,8 @@ {% load i18n %} {% load static %} -{% block title %}{% trans "New schedule" %}{% endblock %} -{% block pagetitle %}{% trans "New schedule" %}{% endblock %} +{% block title %}{% if form.json.value %}{% trans "Clone schedule" %}{% else %}{% trans "New schedule" %}{% endif %}{% endblock %} +{% block pagetitle %}{% if form.json.value %}{% trans "Clone schedule" %}{% else %}{% trans "New schedule" %}{% endif %}{% endblock %} {% block content %}
{% csrf_token %} @@ -464,7 +464,7 @@ var clone = jQuery('div.poliekliniek_specialisatie:first').clone() clone.find('input').val(''); clone.find('option:disabled').removeAttr('disabled'); - clone.find('small').show(); + clone.find('small.text-muted').show(); clone.insertAfter('div.poliekliniek_specialisatie:last'); updateSpecialisaties(); loadRemoveSpecialisatie(); @@ -476,6 +476,7 @@ jQuery(this).parentsUntil('.poliekliniek_specialisatie').parent().remove(); updateSpecialisaties(); updateSpecialisatieValues(); + calculateBehandelingen(); }); } @@ -502,7 +503,7 @@ }); jQuery('div.werktijden select').off('change').on('change',function(event){ - check_working_hours(this); + check_working_hours(jQuery(this).parentsUntil('.werktijden').parent()); }); } @@ -536,11 +537,7 @@ clone.insertAfter('tr.behandeling:last'); - jQuery('tr.behandeling input.behandeling_calc').off('change keyup').on('change keyup',function(){ - calculateBehandelingen(); - }); - - jQuery('tr.behandeling select').off('change').on('change',function(){ + jQuery('tr.behandeling :input').off('change keyup').on('change keyup',function(){ calculateBehandelingen(); }); @@ -554,6 +551,7 @@ jQuery(this).parentsUntil('.behandeling').parent().remove(); updateBehandelingen(); + calculateBehandelingen(); }); } @@ -811,8 +809,11 @@ } function check_working_hours(html, showerror) { - html = jQuery(html).parentsUntil('.werktijden').parent(); - html = jQuery(html[0]); + if (Array.isArray(html)) { + html = html[0]; + } + + html = jQuery(html); let day_start = html.find('select[name^="werkdag_start_afdeling_"]'); let day_end = html.find('select[name^="werkdag_end_afdeling_"]'); @@ -917,6 +918,35 @@ } } + function load_clone_data() { + if (jQuery('input#id_json').val() != '') { + let form = jQuery('form#new_schedule_form'); + + let json_data = JSON.parse(form.find('input#id_json').val()); + + jQuery.each(json_data,function(key,value){ + let input = form.find(':input[name="' + key + '"]'); + + if (input.length == 0) { + // check for second or more specilism or treatment + if (key.indexOf('behandeling') >= 0) { + addBehandeling(); + } else { + addSpecialisatie(); + } + + input = form.find(':input[name="' + key + '"]'); + } + input.val(value); + updateSpecialisatieValues(); + }); + + validate_working_hours(); + calculateBehandelingen(); + validate_behandeling_hours(); + } + } + jQuery(function() { jQuery('a.add_specialisatie').on('click',function(event){ event.preventDefault(); @@ -939,7 +969,7 @@ }); jQuery('div.werktijden select').off('change').on('change',function(event){ - check_working_hours(this); + check_working_hours(jQuery(this).parentsUntil('.werktijden').parent()); calculateBehandelingen(); }); @@ -949,7 +979,7 @@ }); }); - jQuery('input.behandeling_calc').off('change keyup').on('change keyup',function(event){ + jQuery('tr.behandeling :input').off('change keyup').on('change keyup',function(event){ calculateBehandelingen(); }); @@ -966,10 +996,11 @@ return true; } else { alert('Er zijn wat problemen met het formulier. Controleer de invoer velden'); - } return false; }); + + load_clone_data(); }); {% endblock %} diff --git a/polyclinic_scheduling/apps/schedule/urls.py b/polyclinic_scheduling/apps/schedule/urls.py index f554c66..6e7970a 100644 --- a/polyclinic_scheduling/apps/schedule/urls.py +++ b/polyclinic_scheduling/apps/schedule/urls.py @@ -5,5 +5,8 @@ from . import views app_name = 'schedule' urlpatterns = [ path('', views.ScheduleListView.as_view(), name='list'), - path('new', views.new_or_update_study, name='new'), + path('new', views.new_or_update_schedule, name='new'), + #path('', views.ScheduleDetailView.as_view(), name='detail'), + path('/clone', views.new_or_update_schedule, name='clone'), + ] \ No newline at end of file diff --git a/polyclinic_scheduling/apps/schedule/views.py b/polyclinic_scheduling/apps/schedule/views.py index 31dabf5..17f96eb 100644 --- a/polyclinic_scheduling/apps/schedule/views.py +++ b/polyclinic_scheduling/apps/schedule/views.py @@ -3,6 +3,7 @@ from django.shortcuts import render, redirect from django.views.generic.list import ListView from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.decorators import login_required +from django.forms.models import model_to_dict from .models import Schedule from .forms import ScheduleForm @@ -19,9 +20,16 @@ class ScheduleListView(LoginRequiredMixin,ListView): return Schedule.objects.filter(employee=self.request.user.employee).order_by('-created_at') @login_required -def new_or_update_study(request, schedule = None): +def new_or_update_schedule(request, schedule_id = None): template_name = 'schedule/schedule_new.html' + schedule = None + if schedule_id is not None: + try: + schedule = Schedule.objects.get(pk=schedule_id) + except Schedule.DoesNotExist: + pass + if request.method == 'POST': schedule_form = ScheduleForm(request.POST) @@ -43,7 +51,12 @@ def new_or_update_study(request, schedule = None): return redirect('schedule:list') else: - schedule_form = ScheduleForm() + if schedule is not None: + print(dir(schedule.planning_source)) + schedule = json.dumps(schedule.planning_source) + + print(schedule) + schedule_form = ScheduleForm(initial={'json' : schedule}) return render(request, template_name, { 'form' : schedule_form,