diff --git a/edivorce/apps/core/static/js/ajax.js b/edivorce/apps/core/static/js/ajax.js index 6739d16f..ba49979d 100644 --- a/edivorce/apps/core/static/js/ajax.js +++ b/edivorce/apps/core/static/js/ajax.js @@ -9,7 +9,7 @@ var ajaxOnChange = function () { // Check if date is in valid format DD/MM/YYYY if (el.is(".date-picker")){ - isValid = validateDatePicker(value); + isValid = validateDate(value); } if (el.is("#email_textbox")){ diff --git a/edivorce/apps/core/static/js/controllers.js b/edivorce/apps/core/static/js/controllers.js index 90ca9241..e858211b 100644 --- a/edivorce/apps/core/static/js/controllers.js +++ b/edivorce/apps/core/static/js/controllers.js @@ -89,6 +89,7 @@ var getValue = function(el, question){ // to remove last space and semi-colon return JSON.stringify(value); } + // for adding other_name fields, create list of [aliasType, alias] else if (question == "other_name_you" || question == "other_name_spouse"){ var aliasType; $('#other_names_fields').find("input[type=text]").each(function () { @@ -97,6 +98,32 @@ 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 + // TODO clean up console.log + else if (question == "reconciliation_period"){ + var to_date, from_date; + $('#reconciliation_period_fields').find(".reconciliation-from-date").each(function () { + to_date = $(this).closest('div').find(".reconciliation-to-date").val(); + from_date = $(this).val(); + // check if both date is in valid format and all + if (to_date != '' && from_date != '' && validateDate(to_date) && validateDate(from_date)) + { + if (stringToDate(from_date) < stringToDate(to_date)){ + value.push([from_date, to_date]); + } + else { + console.log(from_date + " : " + to_date); + console.log("From date must be smaller than To date") + } + } + else { + console.log("Invalid: " + from_date + " : " + to_date); + console.log("invalid date format"); + } + }); + return JSON.stringify(value); + } else{ return el.val(); } @@ -104,9 +131,13 @@ var getValue = function(el, question){ // check if value in date field is in DD/MM/YYYY format // and check if it is valid date and it is today or earlier -var validateDatePicker = function(value){ +var validateDate = function(value){ var isValid = false; var regex = '[0-9]{2}[/][0-9]{2}[/][0-9]{4}'; + if (value == ''){ + return true; + } + if (value.match(regex)){ value = value.split('/'); var d = parseInt(value[0], 10); @@ -121,6 +152,15 @@ var validateDatePicker = function(value){ return isValid; }; +// take date string in DD/MM/YYYY format and return date object +var stringToDate = function(value){ + value = value.split('/'); + var d = parseInt(value[0], 10); + var m = parseInt(value[1], 10); + var y = parseInt(value[2], 10); + return new Date(y,m-1,d); +}; + // check if email is in valid format var validateEmail = function(value){ var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; diff --git a/edivorce/apps/core/static/js/main.js b/edivorce/apps/core/static/js/main.js index becc374d..57fc5727 100755 --- a/edivorce/apps/core/static/js/main.js +++ b/edivorce/apps/core/static/js/main.js @@ -24,29 +24,42 @@ $(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); + date_picker(); + }); + // Delete button will remove field and update user responses - $(".btn-delete").on('click', function () { + $(".btn-delete-name").on('click', function () { $(this).parent('div').remove(); - // update by trigger change event on one of the text field - var textField = $('#other_names_fields').find('input:text'); - textField.first().triggerHandler('change'); - // when there is only one field left, clear it instead of delete it - if (textField.length < 1){ + if ($('#other_names_fields').find('input:text').length < 1){ $("#btn_add_other_names").triggerHandler('click'); - $('#other_names_fields').find('input:text').first().triggerHandler('change'); } + // update by trigger change event on one of the text field + $('#other_names_fields').find('input:text').first().triggerHandler('change'); }); - // Configuration for datepicker - $(".date-picker-group").datepicker({ - format: "dd/mm/yyyy", - endDate: "today", - autoclose: true + $(".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'); + }); + // add date_picker + date_picker(); + // On step_03.html, update text when user enters separation date $("#separated_date").on("change", function () { $("#separation_date_span").text(" on " + $(this).val()); @@ -60,6 +73,31 @@ $(function () { }); }); +// TODO make ajax call way too many times +var deleteAddedField = function(){ + console.log($(this)); + $(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'); + console.log($('#reconciliation_period_fields').find('input:text').first()); +}; + +// Configuration for datepicker +var date_picker = function () { + $(".date-picker-group").datepicker({ + format: "dd/mm/yyyy", + startDate: "-100y", + endDate: "0d", + autoclose: true, + todayHighlight: true + }); +}; + // Expand More Information boxes $(".more_information-link a").click(function () { var moreInfo = $(".more_information-column"); diff --git a/edivorce/apps/core/templates/partials/alias_field.html b/edivorce/apps/core/templates/partials/alias_field.html index 966e27f9..01a28dd3 100644 --- a/edivorce/apps/core/templates/partials/alias_field.html +++ b/edivorce/apps/core/templates/partials/alias_field.html @@ -6,8 +6,6 @@ - {% input_field type="text" name=name value=value class="form-block input-wide response-textbox" %} - {% if delete_button == "true" %} - - {% endif %} + {% input_field type="text" name=name value=value multiple="true" class="form-block input-wide response-textbox" %} + \ No newline at end of file diff --git a/edivorce/apps/core/templates/partials/name_with_alias.html b/edivorce/apps/core/templates/partials/name_with_alias.html index 2e421ebc..f6973754 100644 --- a/edivorce/apps/core/templates/partials/name_with_alias.html +++ b/edivorce/apps/core/templates/partials/name_with_alias.html @@ -2,10 +2,10 @@
{{ name }} - {% if other_names %} + {% if other_names and use_other_name == 'YES' %} {% multiple_values_to_list source=other_names as values %} {% for alias_type, value in values %} - {% if value != '' and value != ' ' %} {{alias_type}} {{value}} {% endif %} + {% if value != '' %} {{alias_type}} {{value}} {% endif %} {% endfor %} {% endif %} \ No newline at end of file diff --git a/edivorce/apps/core/templates/partials/reconciliation_period.html b/edivorce/apps/core/templates/partials/reconciliation_period.html new file mode 100644 index 00000000..57f5002f --- /dev/null +++ b/edivorce/apps/core/templates/partials/reconciliation_period.html @@ -0,0 +1,6 @@ +{% load input_field %} +
+

+

+ +
\ No newline at end of file diff --git a/edivorce/apps/core/templates/pdf/form1.html b/edivorce/apps/core/templates/pdf/form1.html index c208767c..b6c2764a 100644 --- a/edivorce/apps/core/templates/pdf/form1.html +++ b/edivorce/apps/core/templates/pdf/form1.html @@ -31,10 +31,10 @@ In the Supreme Court of British Columbia

- Claimant 1:{% include "partials/name_with_alias.html" with name=responses.name_you other_names=responses.other_name_you %} + Claimant 1:{% include "partials/name_with_alias.html" with name=responses.name_you use_other_name=responses.any_other_name_you other_names=responses.other_name_you %}

- Claimant 2:{% include "partials/name_with_alias.html" with name=responses.name_spouse other_names=responses.other_name_spouse %} + Claimant 2:{% include "partials/name_with_alias.html" with name=responses.name_spouse use_other_name=responses.any_other_name_spouse other_names=responses.other_name_spouse %}

  diff --git a/edivorce/apps/core/templates/pdf/form35.html b/edivorce/apps/core/templates/pdf/form35.html index 10dc0e1b..8390ae63 100644 --- a/edivorce/apps/core/templates/pdf/form35.html +++ b/edivorce/apps/core/templates/pdf/form35.html @@ -32,11 +32,11 @@ In the Supreme Court of British Columbia

- Claimant 1: {% if responses.name_you %} {% include "partials/name_with_alias.html" with name=responses.name_you other_names=responses.other_name_you %} + Claimant 1: {% if responses.name_you %} {% include "partials/name_with_alias.html" with name=responses.name_you use_other_name=responses.any_other_name_you other_names=responses.other_name_you %} {% else %}   {% endif %}

- Claimant 2: {% if responses.name_spouse %} {% include "partials/name_with_alias.html" with name=responses.name_spouse other_names=responses.other_name_spouse %} + Claimant 2: {% if responses.name_spouse %} {% include "partials/name_with_alias.html" with name=responses.name_spouse use_other_name=responses.any_other_name_spouse other_names=responses.other_name_spouse %} {% else %}   {% endif %}

diff --git a/edivorce/apps/core/templates/pdf/form36.html b/edivorce/apps/core/templates/pdf/form36.html index e011443c..c4d55ba6 100644 --- a/edivorce/apps/core/templates/pdf/form36.html +++ b/edivorce/apps/core/templates/pdf/form36.html @@ -31,11 +31,11 @@ In the Supreme Court of British Columbia

- Claimant 1: {% if responses.name_you %} {% include "partials/name_with_alias.html" with name=responses.name_you other_names=responses.other_name_you %} + Claimant 1: {% if responses.name_you %} {% include "partials/name_with_alias.html" with name=responses.name_you use_other_name=responses.any_other_name_you other_names=responses.other_name_you %} {% else %}   {% endif %}

- Claimant 2: {% if responses.name_spouse %} {% include "partials/name_with_alias.html" with name=responses.name_spouse other_names=responses.other_name_spouse %} + Claimant 2: {% if responses.name_spouse %} {% include "partials/name_with_alias.html" with name=responses.name_spouse use_other_name=responses.any_other_name_spouse other_names=responses.other_name_spouse %} {% else %}   {% endif %}

diff --git a/edivorce/apps/core/templates/prequalification/step_03.html b/edivorce/apps/core/templates/prequalification/step_03.html index ffb92daa..60569d69 100644 --- a/edivorce/apps/core/templates/prequalification/step_03.html +++ b/edivorce/apps/core/templates/prequalification/step_03.html @@ -76,15 +76,32 @@

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

-