Browse Source

Updated reconciliation period delete button

pull/160/head
Charles Shin 8 years ago
parent
commit
ca6db8cc74
4 changed files with 45 additions and 56 deletions
  1. +21
    -10
      edivorce/apps/core/static/js/controllers.js
  2. +13
    -33
      edivorce/apps/core/static/js/main.js
  3. +10
    -12
      edivorce/apps/core/templates/prequalification/step_03.html
  4. +1
    -1
      edivorce/apps/core/utils/question_step_mapping.py

+ 21
- 10
edivorce/apps/core/static/js/controllers.js View File

@ -98,27 +98,38 @@ var getValue = function(el, question){
}); });
return JSON.stringify(value); 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 // TODO clean up console.log
else if (question == "reconciliation_period"){ 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 () { $('#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 // 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 { else {
console.log(from_date + " : " + to_date);
console.log(sFromDate + " : " + sToDate);
console.log("From date must be smaller than To date") console.log("From date must be smaller than To date")
} }
} }
else { else {
console.log("Invalid: " + from_date + " : " + to_date);
console.log("Invalid: " + sFromDate + " : " + sToDate);
console.log("invalid date format"); console.log("invalid date format");
} }
}); });


+ 13
- 33
edivorce/apps/core/static/js/main.js View File

@ -24,38 +24,18 @@ $(function () {
$('#other_names_fields').append($('#other_names_group').children().clone(true)); $('#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 () { $("#btn_add_reconciliation_periods").on('click', function () {
$('#reconciliation_period_fields').append($('#reconciliation_period_group').children().clone()); $('#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(); date_picker();
}); });
// Delete button will remove field and update user responses // 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 // add date_picker
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(); $(this).parent('div').remove();
// when there is only one field left, clear it instead of delete it // 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 // 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 // Configuration for datepicker


+ 10
- 12
edivorce/apps/core/templates/prequalification/step_03.html View File

@ -77,7 +77,7 @@
</div> </div>
<div class="question-well"> <div class="question-well">
<h3>Did you and {% if name_spouse %} {{ name_spouse }} {% else %} your spouse {% endif %} try and reconcile after you separated <span id="separation_date_span"></span>?</h3>
<h3>Did you and {% if name_spouse %} {{ name_spouse }} {% else %} your spouse {% endif %} try and reconcile after you separated <span id="separation_date_span">{% if separation_date %} on {{ separation_date }}{% endif %}</span>?</h3>
<div class="radio"><label>{% input_field type="radio" name="try_reconcile_after_separated" value="NO" data_target_id="reconciliation_period" data_reveal_target="false" %} <div class="radio"><label>{% input_field type="radio" name="try_reconcile_after_separated" value="NO" data_target_id="reconciliation_period" data_reveal_target="false" %}
No, {% if name_spouse %} {{ name_spouse }} {% else %} my spouse {% endif %} and I have not reconciled (gotten back together)</label> No, {% if name_spouse %} {{ name_spouse }} {% else %} my spouse {% endif %} and I have not reconciled (gotten back together)</label>
</div> </div>
@ -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</label> 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</label>
</div> </div>
<!-- TODO: Dev note: If reconciliation period is greater than 90 days, display Alert message in column F -->
<!-- TODO: Add multiple date adding fields -->
<div id="reconciliation_period" hidden> <div id="reconciliation_period" hidden>
<div id="reconciliation_period_group" hidden> <div id="reconciliation_period_group" hidden>
{% include "partials/reconciliation_period.html" %} {% include "partials/reconciliation_period.html" %}
@ -104,15 +102,6 @@
<input type="button" id="btn_add_reconciliation_periods" value="Add Period"/> <input type="button" id="btn_add_reconciliation_periods" value="Add Period"/>
</div> </div>
<div>
<div class="information-message bg-danger" hidden>
<p>Based on the date(s) you have provided for reconciliation, we have detected that your reconciliation may be for a period of greater than 90 days. Within the one year separation period, you can only live together for 90 days or less. </p>
<p>You can still proceed to complete the application, however, it will be up to the court to decide if you have lived separate and apart for the required period of one year.</p>
<!-- TODO: Talk to a lawyer links to help centre page. -->
<p>You may want to talk to a lawyer regarding your legal rights and options. </p>
</div>
</div>
<div class="collapse-trigger collapsed" data-toggle="collapse" aria-expanded="false" data-target="#collapse_reconcile_not_work" aria-controls="collapse_reconcile_not_work"> <div class="collapse-trigger collapsed" data-toggle="collapse" aria-expanded="false" data-target="#collapse_reconcile_not_work" aria-controls="collapse_reconcile_not_work">
<div> <div>
What happens if my spouse and I tried to get back together for a short time but it did not work out? What happens if my spouse and I tried to get back together for a short time but it did not work out?
@ -128,6 +117,15 @@
</p> </p>
</div> </div>
</div> </div>
<div>
<div class="information-message bg-danger" id="reconciliation_90_days_alert" hidden>
<p>Based on the date(s) you have provided for reconciliation, we have detected that your reconciliation may be for a period of greater than 90 days. Within the one year separation period, you can only live together for 90 days or less. </p>
<p>You can still proceed to complete the application, however, it will be up to the court to decide if you have lived separate and apart for the required period of one year.</p>
<!-- TODO: Talk to a lawyer links to help centre page. -->
<p>You may want to talk to a lawyer regarding your legal rights and options. </p>
</div>
</div>
</div> </div>
{% endblock %} {% endblock %}


+ 1
- 1
edivorce/apps/core/utils/question_step_mapping.py View File

@ -5,7 +5,7 @@
question_step_mapping = {'prequalification': ['married_marriage_like', 'lived_in_bc', 'lived_in_bc_at_least_year', 'separation_date', 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', 'children_of_marriage', 'any_under_19', 'children_financial_support', 'original_marriage_certificate',
'provide_certificate_later', 'provide_certificate_later_reason', 'not_provide_certificate_reason', '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',], 'which_orders': ['want_which_orders',],
'your_information': ['name_you', 'any_other_name_you', 'other_name_you', 'last_name_born_you', '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',], 'last_name_before_married_you', 'birthday_you', 'lived_in_bc_you', 'moved_to_bc_date_you',],


Loading…
Cancel
Save