From ca6db8cc741deaef18836a53d9d1617131fbed20 Mon Sep 17 00:00:00 2001 From: Charles Shin Date: Fri, 3 Mar 2017 15:41:22 -0800 Subject: [PATCH] Updated reconciliation period delete button --- edivorce/apps/core/static/js/controllers.js | 31 +++++++++---- edivorce/apps/core/static/js/main.js | 46 ++++++------------- .../templates/prequalification/step_03.html | 22 ++++----- .../apps/core/utils/question_step_mapping.py | 2 +- 4 files changed, 45 insertions(+), 56 deletions(-) diff --git a/edivorce/apps/core/static/js/controllers.js b/edivorce/apps/core/static/js/controllers.js index e858211b..f62c63e6 100644 --- a/edivorce/apps/core/static/js/controllers.js +++ b/edivorce/apps/core/static/js/controllers.js @@ -98,27 +98,38 @@ var getValue = function(el, question){ }); return JSON.stringify(value); } - // for adding reconciliation_period fields, create list of [from_date, to_date] and - // check if from_date is earlier than to_date + // for adding reconciliation_period fields, create list of [sFromDate, sToDate] and + // check if sFromDate is earlier than sToDate // TODO clean up console.log else if (question == "reconciliation_period"){ - var to_date, from_date; + var sToDate, sFromDate, dToDate, dFromDate; + var hideAlert = true; $('#reconciliation_period_fields').find(".reconciliation-from-date").each(function () { - to_date = $(this).closest('div').find(".reconciliation-to-date").val(); - from_date = $(this).val(); + sToDate = $(this).closest('div').find(".reconciliation-to-date").val(); + sFromDate = $(this).val(); // check if both date is in valid format and all - if (to_date != '' && from_date != '' && validateDate(to_date) && validateDate(from_date)) + if (sToDate != '' && sFromDate != '' && validateDate(sToDate) && validateDate(sFromDate)) { - if (stringToDate(from_date) < stringToDate(to_date)){ - value.push([from_date, to_date]); + dToDate = stringToDate(sToDate); + dFromDate = stringToDate(sFromDate); + if (dFromDate < dToDate){ + value.push([sFromDate, sToDate]); + // show alert message if reconciliation period is greater than 90 days + if (dToDate.setDate(dToDate.getDate() - 90) > dFromDate){ + $('#reconciliation_90_days_alert').show(); + hideAlert = false; + } + if (hideAlert){ + $('#reconciliation_90_days_alert').hide(); + } } else { - console.log(from_date + " : " + to_date); + console.log(sFromDate + " : " + sToDate); console.log("From date must be smaller than To date") } } else { - console.log("Invalid: " + from_date + " : " + to_date); + console.log("Invalid: " + sFromDate + " : " + sToDate); console.log("invalid date format"); } }); diff --git a/edivorce/apps/core/static/js/main.js b/edivorce/apps/core/static/js/main.js index 57fc5727..e003d6a1 100755 --- a/edivorce/apps/core/static/js/main.js +++ b/edivorce/apps/core/static/js/main.js @@ -24,38 +24,18 @@ $(function () { $('#other_names_fields').append($('#other_names_group').children().clone(true)); }); - // TODO delete button is not working if they are added $("#btn_add_reconciliation_periods").on('click', function () { $('#reconciliation_period_fields').append($('#reconciliation_period_group').children().clone()); - $('#reconciliation_period_fields input:text').on('change', ajaxOnChange); - // $('.btn-delete-period').on('click', deleteAddedField); + // add event lister for newly added from_date field, to_date field, delete button, and date picker + $('#reconciliation_period_fields .reconciliation-from-date').last().on('change', ajaxOnChange); + $('#reconciliation_period_fields .reconciliation-to-date').last().on('change', ajaxOnChange); + $('#reconciliation_period_fields .btn-delete-period').last().on('click', {field_name: 'reconciliation_period_fields', button_name: 'btn_add_reconciliation_periods'}, deleteAddedField); date_picker(); }); // Delete button will remove field and update user responses - $(".btn-delete-name").on('click', function () { - $(this).parent('div').remove(); - - // when there is only one field left, clear it instead of delete it - if ($('#other_names_fields').find('input:text').length < 1){ - $("#btn_add_other_names").triggerHandler('click'); - } - // update by trigger change event on one of the text field - $('#other_names_fields').find('input:text').first().triggerHandler('change'); - - }); - - $(".btn-delete-period").on('click', function () { - $(this).parent('div').remove(); - - // when there is only one field left, clear it instead of delete it - if ($('#reconciliation_period_fields').find('input:text').length < 1){ - $("#btn_add_reconciliation_periods").triggerHandler('click'); - } - // update by trigger change event on one of the text field - $('#reconciliation_period_fields').find('input:text').first().triggerHandler('change'); - - }); + $(".btn-delete-name").on('click', {field_name: 'other_names_fields', button_name: 'btn_add_other_names'}, deleteAddedField); + $(".btn-delete-period").on('click', {field_name: 'reconciliation_period_fields', button_name: 'btn_add_reconciliation_periods'}, deleteAddedField); // add date_picker date_picker(); @@ -73,18 +53,18 @@ $(function () { }); }); -// TODO make ajax call way too many times -var deleteAddedField = function(){ - console.log($(this)); +// delete and added field and save the change +var deleteAddedField = function(e){ + var field = $('#' + e.data.field_name); + var button = $('#' + e.data.button_name); $(this).parent('div').remove(); // when there is only one field left, clear it instead of delete it - if ($('#reconciliation_period_fields').find('input:text').length < 1){ - $("#btn_add_reconciliation_periods").triggerHandler('click'); + if (field.find('input:text').length < 1){ + button.triggerHandler('click'); } // update by trigger change event on one of the text field - $('#reconciliation_period_fields').find('input:text').first().triggerHandler('change'); - console.log($('#reconciliation_period_fields').find('input:text').first()); + field.find('input:text').first().triggerHandler('change'); }; // Configuration for datepicker diff --git a/edivorce/apps/core/templates/prequalification/step_03.html b/edivorce/apps/core/templates/prequalification/step_03.html index 1cb7a367..bc84501e 100644 --- a/edivorce/apps/core/templates/prequalification/step_03.html +++ b/edivorce/apps/core/templates/prequalification/step_03.html @@ -77,7 +77,7 @@
-

Did you and {% if name_spouse %} {{ name_spouse }} {% else %} your spouse {% endif %} try and reconcile after you separated ?

+

Did you and {% if name_spouse %} {{ name_spouse }} {% else %} your spouse {% endif %} try and reconcile after you separated {% if separation_date %} on {{ separation_date }}{% endif %}?

@@ -85,8 +85,6 @@ Yes, {% if name_spouse %} {{ name_spouse }} {% else %} my spouse {% endif %} and I lived together again during the following period(s) in an unsuccessful attempt to reconcile
- - {% endblock %} diff --git a/edivorce/apps/core/utils/question_step_mapping.py b/edivorce/apps/core/utils/question_step_mapping.py index 09508ffa..eab3a4a5 100644 --- a/edivorce/apps/core/utils/question_step_mapping.py +++ b/edivorce/apps/core/utils/question_step_mapping.py @@ -5,7 +5,7 @@ question_step_mapping = {'prequalification': ['married_marriage_like', 'lived_in_bc', 'lived_in_bc_at_least_year', 'separation_date', 'children_of_marriage', 'any_under_19', 'children_financial_support', 'original_marriage_certificate', 'provide_certificate_later', 'provide_certificate_later_reason', 'not_provide_certificate_reason', - 'divorce_reason', 'marriage_certificate_in_english', 'try_reconcile_after_separated'], + 'divorce_reason', 'marriage_certificate_in_english', 'try_reconcile_after_separated', 'reconciliation_period',], 'which_orders': ['want_which_orders',], 'your_information': ['name_you', 'any_other_name_you', 'other_name_you', 'last_name_born_you', 'last_name_before_married_you', 'birthday_you', 'lived_in_bc_you', 'moved_to_bc_date_you',],