From 9dbd47968851b54fdf0f9aa98f2e07201d1b52e4 Mon Sep 17 00:00:00 2001 From: Benard Ebinu Date: Wed, 3 Jan 2018 11:27:33 -0800 Subject: [PATCH] DIV-627: Logic in place to show fact sheet B and fact sheet C based off of children living with arrangement --- edivorce/apps/core/static/js/main.js | 61 +++- .../question/06_children_your_children.html | 316 ++++++++++++++++++ 2 files changed, 375 insertions(+), 2 deletions(-) diff --git a/edivorce/apps/core/static/js/main.js b/edivorce/apps/core/static/js/main.js index 85f7b232..ea5dd9b9 100755 --- a/edivorce/apps/core/static/js/main.js +++ b/edivorce/apps/core/static/js/main.js @@ -276,6 +276,7 @@ $(function () { // with the contents of the row. newElement.on('click', populateChildInputFields); $('.children-list').hide(); + $('.fact-sheets').hide(); }, customDeleteAction: function(settings, element) { $('[type=radio]').prop('checked', false); @@ -305,6 +306,7 @@ $(function () { var populateChildInputFields = function() { $('.children-questions').show(); $('.children-list').hide(); + $('.fact-sheets').hide(); $('[type=radio]').prop('checked', false); @@ -328,6 +330,57 @@ $(function () { }); }; + var populateChildrenFactSheets = function() { + var childrenData = []; + + // The hidden row is the first now so make sure to skip it. + $('#claimant_children').find('tbody:first').find('tr:gt(0)').each(function() { + var childData = {}; + $(this).find('.child-field').each(function() { + childData[$(this).attr('data-target-form-field')] = $(this).text(); + }); + + childrenData.push(childData); + }); + + var childWithBoth = false; + var childWithYou = 0; + var childWithSpouse = 0; + var childWithOther = 0; + childrenData.forEach(function(child) { + if (child.child_live_with === 'Lives with both') { + childWithBoth |= true; + } + if (childrenData.length > 1 ) { + if (child.child_live_with === 'Lives with you' ) { + childWithYou += 1; + } + if (child.child_live_with === 'Lives with spouse') { + childWithSpouse +=1 ; + } + if (child.child_live_with === 'Other') { + childWithOther +=1 ; + } + } + }); + + // show fact sheet b + if (childWithBoth) { + $('#fact_sheet_b').show(); + } else { + $('#fact_sheet_b').hide(); + } + + // show fact sheet c + if (childWithYou === 1 && (childWithSpouse > 0 || childWithOther > 0 || childWithBoth)) { + $('#fact_sheet_c').show(); + } else if (childWithSpouse === 1 && (childWithYou > 0 || childWithOther > 0 || childWithBoth)) { + $('#fact_sheet_c').show(); + } else { + $('#fact_sheet_c').hide(); + } + }; + $('.child-item-row').on('click', populateChildInputFields); $('#btn_save_child').on('click', function(e) { e.preventDefault(); @@ -341,11 +394,15 @@ $(function () { $(this).find('.child-field').each(function() { childData[$(this).attr('data-target-form-field')] = $(this).text(); }); - childrenData.push(childData); }); var jsonChildrenData = JSON.stringify(childrenData); ajaxCall($(this).prop('name'), jsonChildrenData); + populateChildrenFactSheets(); + }); + + $('#claimant_children').each(function(){ + populateChildrenFactSheets(); }); $("#btn_add_reconciliation_periods").on('click', function () { @@ -701,7 +758,7 @@ var sumFieldOnChange = function() { var sumFields = function(addend_selector, sum_selector) { var total = 0.0; $(addend_selector).each(function () { - if ($(this).val() !== undefined && $(this).val().length != 0) { + if ($(this).val() !== undefined && $(this).val().length !== 0) { total += parseFloat($(this).val()); } }); diff --git a/edivorce/apps/core/templates/question/06_children_your_children.html b/edivorce/apps/core/templates/question/06_children_your_children.html index fc662572..3f20705b 100644 --- a/edivorce/apps/core/templates/question/06_children_your_children.html +++ b/edivorce/apps/core/templates/question/06_children_your_children.html @@ -254,6 +254,322 @@ + + + + + +