diff --git a/app/assets/javascripts/plan_shopping.js.erb b/app/assets/javascripts/plan_shopping.js.erb index b4b4754fb24..032290e1562 100644 --- a/app/assets/javascripts/plan_shopping.js.erb +++ b/app/assets/javascripts/plan_shopping.js.erb @@ -86,6 +86,12 @@ function applyPlanFilterCBs(cbKlass, cbFilterKlass, planValueTag) { function initSorts() { console.log('Plans are loaded'); + + const compareChecks = document.querySelectorAll(".compare_plan_checkbox"); + compareChecks.forEach(check => check.addEventListener('click', event => { + comparePlan(check); + })); + ogPlanSort = $('#all-plans #ivl_plans .plan-row') } } @@ -452,3 +458,76 @@ $(document).on("click", "#dependentList", function(event) { event.preventDefault(); $("#dependentTable").toggleClass('hidden'); }); + +//// app/views/insured/plan_shoppings/_plan_details.html.erb +function resetComparePlan() { + + var compareBtn = document.getElementById('compareBtn') + compareBtn.classList.add('hidden') + checkboxes = document.querySelectorAll('.compare_plan_checkbox') + checkboxes.forEach(function(checkbox) { + checkbox.checked = false; + }) +} + +function comparePlan(element) { + plansToCompareArray = []; + checkboxes = document.querySelectorAll('.compare_plan_checkbox') + count = 0; + checkboxes.forEach(function(checkbox) { + // + if (checkbox.checked) { + count++; + hios = checkbox.dataset.hiosId; + planYear = checkbox.dataset.planYear; + hbxId = checkbox.dataset.hbxId; + enrollmentKind = checkbox.dataset.planEnrollmentKind; + changePlan = checkbox.dataset.planChangePlan; + uri = checkbox + + var compareBtn = document.getElementById('compareBtn') + + if (count > 1) { + compareBtn.classList.remove('hidden') + } else { + compareBtn.classList.add('hidden') + } + + if (count > 3) { + checkbox.checked = false; + if (document.getElementById('planComparisonCountExceeded')) { + $('#planComparisonCountExceeded').modal('show'); + } else { + swal({ + title: "Plan count exceeded", + text: "You may only compare up to 3 plans at a time", + icon: "warning" + }); + } + } + if (count <= 3) { + plansToCompareArray.push(hios) + plansToCompareArray = uniqueValues(plansToCompareArray) + } + } + }) +} + +function compareResults() { + uri = document.getElementById('compareBtn').dataset.uri; + $.ajax({ + type: "GET", + url: uri, + dataType: 'script', + data: { + "standard_component_ids": plansToCompareArray,"hbx_enrollment_id": hbxId, "active_year": planYear, "enrollment_kind": enrollmentKind, + "change_plan": changePlan + } + }); +} + +function uniqueValues(array) { + let map = new Map(); + array.forEach(value => map.set(value, value)); + return [...map.values()]; +}; diff --git a/app/views/insured/plan_shoppings/_plan_details.html.erb b/app/views/insured/plan_shoppings/_plan_details.html.erb index 7be3cdc78ec..88a864e078c 100644 --- a/app/views/insured/plan_shoppings/_plan_details.html.erb +++ b/app/views/insured/plan_shoppings/_plan_details.html.erb @@ -145,14 +145,14 @@ <% else %> <% if (@tax_household || @aptc_grants) && params[:market_kind]=='individual' && params[:coverage_kind] == 'health' %> <% if @csr_available && plan.metal_level != "silver" %> - <%= link_to l10n("select_plan"), "javascript:void(0)", class: 'btn btn-default btn-right', data: {'toggle': 'modal', 'target': "#csrEligibleReminder-#{plan.id}"} %> - <%= link_to(l10n("select_plan"), "javascript:void(0)", {class: 'hidden btn btn-default btn-right plan-select select', data: {url: thankyou_insured_plan_shopping_path(@hbx_enrollment, plan_id: plan.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @coverage_kind, enrollment_kind: @enrollment_kind)}}) %> + <%= link_to l10n("select_plan"), "#", class: 'btn btn-default btn-right', data: {'toggle': 'modal', 'target': "#csrEligibleReminder-#{plan.id}"} %> + <%= link_to(l10n("select_plan"), "#", {class: 'hidden btn btn-default btn-right plan-select select', data: {url: thankyou_insured_plan_shopping_path(@hbx_enrollment, plan_id: plan.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @coverage_kind, enrollment_kind: @enrollment_kind)}}) %> <%= render partial: "shared/csr_eligible_reminder_modal", locals: { plan: plan } %> <% else %> - <%= link_to(l10n("select_plan"), "javascript:void(0)", {class: 'btn btn-default btn-right plan-select select', data: {url: thankyou_insured_plan_shopping_path(@hbx_enrollment, plan_id: plan.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @coverage_kind, enrollment_kind: @enrollment_kind)}}) %> + <%= link_to(l10n("select_plan"), "#", {class: 'btn btn-default btn-right plan-select select', data: {url: thankyou_insured_plan_shopping_path(@hbx_enrollment, plan_id: plan.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @coverage_kind, enrollment_kind: @enrollment_kind)}}) %> <% end %> <% else %> - <%= link_to(l10n("select_plan"), "javascript:void(0)", {class: 'btn btn-default btn-right plan-select select', data: {url: thankyou_insured_plan_shopping_path(@hbx_enrollment, plan_id: plan.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @coverage_kind, enrollment_kind: @enrollment_kind)}}) %> + <%= link_to(l10n("select_plan"), "#", {class: 'btn btn-default btn-right plan-select select', data: {url: thankyou_insured_plan_shopping_path(@hbx_enrollment, plan_id: plan.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @coverage_kind, enrollment_kind: @enrollment_kind)}}) %> <% end %> <% end %> @@ -184,16 +184,6 @@ - - - - - - - - - - <% else %>