From f39e8c5fc056d9a1fe59ed45fe68bd4eee7149de Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Mon, 13 Mar 2023 14:12:22 +0200 Subject: [PATCH 1/6] check whether the page has state set --- dist/js/accordion.min.js | 2 +- src/js/accordion/state.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dist/js/accordion.min.js b/dist/js/accordion.min.js index 829959695..88efdccda 100644 --- a/dist/js/accordion.min.js +++ b/dist/js/accordion.min.js @@ -1 +1 @@ -!function(){"use strict";var t={8529:function(t,e,i){i.d(e,{Z:function(){return s}});class s{static accordionItemElement="helfi-accordion-item";static toggleElement="accordion-item__button--toggle";static closeElement="accordion-item__button--close";static ariaExpandedElements=["accordion-item__button--toggle","accordion-item__button--close"];static contentElement="accordion-item__content";constructor(t,e){this.element=t,this.id=t.querySelector(".helfi-accordion__header").id,this.localState=e,this.isOpen=this.localState.loadItemState(this.id),this.setHidden(),this.addEventListeners(),setTimeout((()=>{this.handleLinkAnchor(),this.setAriaOpen()}),100)}open=()=>{this.isOpen=!0,this.setAriaOpen(),this.setHidden(),this.localState.saveItemState(this.id,this.isOpen)};close=()=>{this.isOpen=!1,this.setAriaOpen(),this.changeFocus(),this.setHidden(),this.localState.saveItemState(this.id,this.isOpen)};toggle=t=>{s.isClick(t.which)&&(this.isOpen?this.close():this.open())};handleLinkAnchor=()=>{const{hash:t}=window.location;t&&this.element.querySelector(t)&&(this.open(),this.element.scrollIntoView())};setAriaOpen=()=>{s.ariaExpandedElements.forEach((t=>{this.element.getElementsByClassName(t)[0].setAttribute("aria-expanded",this.isOpen)}))};setHidden=()=>{const t=this.element.getElementsByClassName(s.contentElement)[0];this.isOpen?t.classList.remove("is-hidden"):t.classList.add("is-hidden")};changeFocus=()=>{this.element.querySelector(`.${s.toggleElement}`).focus()};addEventListeners=()=>{this.element.getElementsByClassName(s.toggleElement)[0].addEventListener("mouseup",this.toggle),this.element.getElementsByClassName(s.toggleElement)[0].addEventListener("keypress",this.toggle),this.element.getElementsByClassName(s.closeElement)[0].addEventListener("mouseup",this.close),this.element.getElementsByClassName(s.closeElement)[0].addEventListener("keypress",this.close)};static isClick(t){return 1===t||13===t||32===t}getId=()=>this.id}},4670:function(t,e,i){i.d(e,{Z:function(){return o}});var s=i(8529);class o{static accordionWrapper="component--accordion";constructor(t,e){this.accordion=t,this.localState=e,this.accordionItems=[],this.getAccordionLocalState(),this.initializeAccordion()}initializeAccordion=()=>{Array.from(this.accordion.getElementsByClassName(s.Z.accordionItemElement)).forEach((t=>{const e=new s.Z(t,this.localState);this.accordionItems.push(e)}))};getAccordionLocalState=()=>{this.state=localStorage.getItem(o.localStateKey)};getAccordionItemById=t=>this.accordionItems.find((e=>e.getId()===t))}},1077:function(t,e,i){i.d(e,{Z:function(){return s}});class s{constructor(){this.site=window.drupalSettings.path.pathPrefix.match("/(.*?)/").shift().replaceAll("/",""),this.page=window.drupalSettings.path.currentPath;const t=JSON.parse(localStorage.getItem(this.getStorageKey()));null===t?(this.siteAccordionStates={},this.siteAccordionStates[this.page]={},this.pageAccordionStates={}):(this.siteAccordionStates=t,this.pageAccordionStates=void 0===this.siteAccordionStates[this.page]?{}:this.siteAccordionStates[this.page])}getStorageKey=()=>`${this.site}-accordion`;saveItemState=(t,e)=>{this.siteAccordionStates[this.page][t]=e,localStorage.setItem(this.getStorageKey(),JSON.stringify(this.siteAccordionStates))};loadItemState=t=>!!this.siteAccordionStates&&(void 0!==this.pageAccordionStates[t]&&this.pageAccordionStates[t])}}},e={};function i(s){var o=e[s];if(void 0!==o)return o.exports;var n=e[s]={exports:{}};return t[s](n,n.exports,i),n.exports}i.d=function(t,e){for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},function(){var t=i(4670),e=i(1077),s=i(8529);window.addEventListener("hashchange",(t=>{const{hash:e}=window.location;let i=!1;if(window.helfiAccordions.forEach((t=>{const s=t.getAccordionItemById(e.replace("#",""));s&&(i=!0,s.handleLinkAnchor())})),!i){const t=document.querySelector(`${e}`).closest(`.${s.Z.accordionItemElement}`);t&&window.helfiAccordions.forEach((e=>{const i=t.querySelector(".helfi-accordion__header").id,s=e.getAccordionItemById(i);s&&s.handleLinkAnchor()}))}})),window.helfiAccordions=[];const o=new e.Z;setTimeout((()=>{document.querySelectorAll(`.${t.Z.accordionWrapper}`).forEach((e=>{const i=new t.Z(e,o);window.helfiAccordions.push(i)}))}),50)}()}(); \ No newline at end of file +!function(){"use strict";var t={8529:function(t,e,i){i.d(e,{Z:function(){return s}});class s{static accordionItemElement="helfi-accordion-item";static toggleElement="accordion-item__button--toggle";static closeElement="accordion-item__button--close";static ariaExpandedElements=["accordion-item__button--toggle","accordion-item__button--close"];static contentElement="accordion-item__content";constructor(t,e){this.element=t,this.id=t.querySelector(".helfi-accordion__header").id,this.localState=e,this.isOpen=this.localState.loadItemState(this.id),this.setHidden(),this.addEventListeners(),setTimeout((()=>{this.handleLinkAnchor(),this.setAriaOpen()}),100)}open=()=>{this.isOpen=!0,this.setAriaOpen(),this.setHidden(),this.localState.saveItemState(this.id,this.isOpen)};close=()=>{this.isOpen=!1,this.setAriaOpen(),this.changeFocus(),this.setHidden(),this.localState.saveItemState(this.id,this.isOpen)};toggle=t=>{s.isClick(t.which)&&(this.isOpen?this.close():this.open())};handleLinkAnchor=()=>{const{hash:t}=window.location;t&&this.element.querySelector(t)&&(this.open(),this.element.scrollIntoView())};setAriaOpen=()=>{s.ariaExpandedElements.forEach((t=>{this.element.getElementsByClassName(t)[0].setAttribute("aria-expanded",this.isOpen)}))};setHidden=()=>{const t=this.element.getElementsByClassName(s.contentElement)[0];this.isOpen?t.classList.remove("is-hidden"):t.classList.add("is-hidden")};changeFocus=()=>{this.element.querySelector(`.${s.toggleElement}`).focus()};addEventListeners=()=>{this.element.getElementsByClassName(s.toggleElement)[0].addEventListener("mouseup",this.toggle),this.element.getElementsByClassName(s.toggleElement)[0].addEventListener("keypress",this.toggle),this.element.getElementsByClassName(s.closeElement)[0].addEventListener("mouseup",this.close),this.element.getElementsByClassName(s.closeElement)[0].addEventListener("keypress",this.close)};static isClick(t){return 1===t||13===t||32===t}getId=()=>this.id}},4670:function(t,e,i){i.d(e,{Z:function(){return o}});var s=i(8529);class o{static accordionWrapper="component--accordion";constructor(t,e){this.accordion=t,this.localState=e,this.accordionItems=[],this.getAccordionLocalState(),this.initializeAccordion()}initializeAccordion=()=>{Array.from(this.accordion.getElementsByClassName(s.Z.accordionItemElement)).forEach((t=>{const e=new s.Z(t,this.localState);this.accordionItems.push(e)}))};getAccordionLocalState=()=>{this.state=localStorage.getItem(o.localStateKey)};getAccordionItemById=t=>this.accordionItems.find((e=>e.getId()===t))}},1077:function(t,e,i){i.d(e,{Z:function(){return s}});class s{constructor(){this.site=window.drupalSettings.path.pathPrefix.match("/(.*?)/").shift().replaceAll("/",""),this.page=window.drupalSettings.path.currentPath;const t=JSON.parse(localStorage.getItem(this.getStorageKey()));null===t?(this.siteAccordionStates={},this.siteAccordionStates[this.page]={},this.pageAccordionStates={}):(this.siteAccordionStates=t,this.siteAccordionStates[this.page]=void 0===this.siteAccordionStates[this.page]?{}:this.siteAccordionStates[this.page],this.pageAccordionStates=this.siteAccordionStates[this.page])}getStorageKey=()=>`${this.site}-accordion`;saveItemState=(t,e)=>{this.siteAccordionStates[this.page][t]=e,localStorage.setItem(this.getStorageKey(),JSON.stringify(this.siteAccordionStates))};loadItemState=t=>!!this.siteAccordionStates&&(void 0!==this.pageAccordionStates[t]&&this.pageAccordionStates[t])}}},e={};function i(s){var o=e[s];if(void 0!==o)return o.exports;var n=e[s]={exports:{}};return t[s](n,n.exports,i),n.exports}i.d=function(t,e){for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},function(){var t=i(4670),e=i(1077),s=i(8529);window.addEventListener("hashchange",(t=>{const{hash:e}=window.location;let i=!1;if(window.helfiAccordions.forEach((t=>{const s=t.getAccordionItemById(e.replace("#",""));s&&(i=!0,s.handleLinkAnchor())})),!i){const t=document.querySelector(`${e}`).closest(`.${s.Z.accordionItemElement}`);t&&window.helfiAccordions.forEach((e=>{const i=t.querySelector(".helfi-accordion__header").id,s=e.getAccordionItemById(i);s&&s.handleLinkAnchor()}))}})),window.helfiAccordions=[];const o=new e.Z;setTimeout((()=>{document.querySelectorAll(`.${t.Z.accordionWrapper}`).forEach((e=>{const i=new t.Z(e,o);window.helfiAccordions.push(i)}))}),50)}()}(); \ No newline at end of file diff --git a/src/js/accordion/state.js b/src/js/accordion/state.js index 36fff6435..af60d5541 100644 --- a/src/js/accordion/state.js +++ b/src/js/accordion/state.js @@ -11,7 +11,8 @@ export default class State { this.pageAccordionStates = {}; } else { this.siteAccordionStates = siteAccordions; - this.pageAccordionStates = this.siteAccordionStates[this.page] === undefined ? {} : this.siteAccordionStates[this.page]; + this.siteAccordionStates[this.page] = this.siteAccordionStates[this.page] === undefined ? {} : this.siteAccordionStates[this.page]; + this.pageAccordionStates = this.siteAccordionStates[this.page]; } } From 2f44332cbc953f70ed9d9159dd481ecd1071113a Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Wed, 15 Mar 2023 12:46:17 +0200 Subject: [PATCH 2/6] add type button to accordion buttons --- templates/component/accordion.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/component/accordion.twig b/templates/component/accordion.twig index 7afd38e1e..023f3693a 100644 --- a/templates/component/accordion.twig +++ b/templates/component/accordion.twig @@ -15,7 +15,7 @@
<{{ heading_level|default('h2') }} class="accordion-item__header helfi-accordion__header" data-accordion-id="{{heading[0]['#context']['value']|clean_class}}"> - From 493b1dac459d4be6773e7a063e30ad50f8c57150 Mon Sep 17 00:00:00 2001 From: rpnykanen Date: Wed, 15 Mar 2023 14:08:51 +0200 Subject: [PATCH 3/6] remove already removed aria-attributes which were added in merge --- templates/component/accordion.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/component/accordion.twig b/templates/component/accordion.twig index 496595e3b..bcc24fdea 100644 --- a/templates/component/accordion.twig +++ b/templates/component/accordion.twig @@ -13,7 +13,7 @@
<{{ heading_level|default('h2') }} class="accordion-item__header helfi-accordion__header" data-accordion-id="{{heading[0]['#context']['value']|clean_class}}"> - From a3da7c8161d0028350b5be4f1ea838e544aacb2c Mon Sep 17 00:00:00 2001 From: Mikko Tapionlinna Date: Mon, 27 Mar 2023 13:18:42 +0300 Subject: [PATCH 4/6] UHF-7484: Add initial version of service housing service voucher calculator --- src/js/calculator/example-calc.html | 73 ++++++- .../service_housing_service_voucher/_form.js | 34 ++++ .../_translations.js | 86 ++++++++ .../service_housing_service_voucher.js | 187 ++++++++++++++++++ .../paragraph--calculator.html.twig | 2 +- 5 files changed, 378 insertions(+), 4 deletions(-) create mode 100644 src/js/calculator/service_housing_service_voucher/_form.js create mode 100644 src/js/calculator/service_housing_service_voucher/_translations.js create mode 100644 src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js diff --git a/src/js/calculator/example-calc.html b/src/js/calculator/example-calc.html index aba8bfc3c..ed6b93702 100644 --- a/src/js/calculator/example-calc.html +++ b/src/js/calculator/example-calc.html @@ -348,7 +348,40 @@ } } `; - drupalSettings.service_housing_service_voucher = `{}`; + drupalSettings.service_housing_service_voucher = ` +{ + "voucher_from_net_income": { + "0": 3300, + "900.01": 3200, + "1000.01": 3100, + "1100.01": 3000, + "1200.01": 2900, + "1300.01": 2800, + "1400.01": 2700, + "1500.01": 2600, + "1600.01": 2500, + "1700.01": 2400, + "1800.01": 2300, + "1900.01": 2200, + "2000.01": 2100, + "2100.01": 2000, + "2200.01": 1900, + "2300.01": 1800, + "2400.01": 1700, + "2500.01": 1600, + "2600.01": 1500, + "2700.01": 1400, + "2800.01": 1300, + "2900.01": 1200, + "3000.01": 1100, + "3100.01": 1000, + "3200.01": 900, + "3300.01": 800, + "3400.01": 700, + "3500.01": 600 + } +} +`; drupalSettings.family_with_kids_home_service_client_payment = `{}`; drupalSettings.daycare_payment = ` { @@ -508,10 +541,10 @@

House cleaning service voucher

- + + + + +
+
+

Täytä tiedot palvelusetelin arvon arvioimiseksi

+
+ +
+ + +
+
+
diff --git a/src/js/calculator/service_housing_service_voucher/_form.js b/src/js/calculator/service_housing_service_voucher/_form.js new file mode 100644 index 000000000..903339717 --- /dev/null +++ b/src/js/calculator/service_housing_service_voucher/_form.js @@ -0,0 +1,34 @@ +function getFormData(id, t) { + return { + form_id: id, + has_required_fields: true, + items: [ + { + input_float: { + id: 'net_income_per_month', + label: t('net_income_per_month'), + unit: t('unit_euro'), + min: 0, + size: 8, + required: true, + strip: '[€eE ]', + helper_text: t('net_income_per_month_explanation'), + }, + }, + { + input_float: { + id: 'service_provider_price', + label: t('service_provider_price'), + unit: t('unit_euro'), + min: 0, + size: 8, + required: true, + strip: '[€eE ]', + helper_text: t('service_provider_price_explanation'), + }, + }, + ] + }; +} + +export default { getFormData }; diff --git a/src/js/calculator/service_housing_service_voucher/_translations.js b/src/js/calculator/service_housing_service_voucher/_translations.js new file mode 100644 index 000000000..2535d74ff --- /dev/null +++ b/src/js/calculator/service_housing_service_voucher/_translations.js @@ -0,0 +1,86 @@ +/* eslint-disable no-template-curly-in-string */ + +const translations = { + net_income_per_month: { + fi: 'Nettotulot kuukaudessa', + sv: null, + en: null, + }, + net_income_per_month_explanation: { + fi: 'Nettotulot tarkoittavat tuloja verojen vähentämisen jälkeen. Tuloihin lasketaan eläkkeet, elatusavut, elinkorot, elatustuki sekä muut jatkuvat henkilökohtaiset tulot ja pääomasta tai omaisuudesta(kuten korko-, osinko- ja vuokratulot). Eläkkeen saajan hoitotukea, asumistukea, rintamalisää tai sotavammalain mukaista elinkorkoa ei huomioida.', + sv: null, + en: null, + }, + service_provider_price: { + fi: 'Palveluntuottajan kuukausihinta', + sv: null, + en: null, + }, + service_provider_price_explanation: { + fi: 'Valitsemasi palveluntuottajan perimä palveluasumisen kuukausihinta.', + sv: null, + en: null, + }, + receipt_estimate_of_payment: { + fi: 'Arvio palveluasumisen palvelusetelistä', + sv: null, + en: null, + }, + receipt_estimated_payment_prefix: { + fi: 'Omavastuuosuus eli sinulle maksettavaksi jäävä asiakasmaksu on', + sv: null, + en: null, + }, + receipt_estimated_payment_suffix: { + fi: 'euroa kuukaudessa.', + sv: null, + en: null, + }, + receipt_estimated_payment_explanation: { + fi: 'Tämä arvio on suuntaa antava. Tarkka arvo lasketaan kotihoidon tekemän päätöksen mukaan.', + sv: null, + en: null, + }, + receipt_estimate_is_based_on: { + fi: 'Palveluasumisen hinta palvelusetelillä ostettuna muodostuu seuraavasti:', + sv: null, + en: null, + }, + receipt_subtotal_full_price: { + fi: 'Palveluasumisen kokonaiskustannus', + sv: null, + en: null, + }, + receipt_subtotal_city_price: { + fi: 'Kaupunki maksaa palvelusetelillä yksityiselle tuottajalle ', + sv: null, + en: null, + }, + receipt_subtotal_self_price: { + fi: 'Sinulle maksettavaksi jäävä osuus eli omavastuu', + sv: null, + en: null, + }, + receipt_subtotal_euros_per_month: { + fi: '${value} €/kk', + sv: null, + en: null, + }, + receipt_subtotal_euros_per_month_screenreader: { + fi: '${value} euroa kuukaudessa', + sv: null, + en: null, + }, + receipt_additional_details: { + fi: 'Lisähuomiot:', + sv: null, + en: null, + }, + receipt_aria_live: { + fi: 'Omavastuuosuus eli sinulle maksettavaksi jäävä asiakasmaksu on ${payment} euroa kuukaudessa, lue lisätietoja lomakkeen alta.', + sv: null, + en: null, + }, +}; + +export default translations; diff --git a/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js b/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js new file mode 100644 index 000000000..84c37b472 --- /dev/null +++ b/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js @@ -0,0 +1,187 @@ +import form from './_form'; +import translations from './_translations'; + +class ServiceHousingServiceVoucher { + constructor(id, settings) { + this.id = id; + const parsedSettings = JSON.parse(settings); + + // Expecting settings to follow this JSON format: + /* + const parsedSettings = { + voucher_from_net_income: { + '0': 3300, + '900.01': 3200, + '1000.01': 3100, + '1100.01': 3000, + '1200.01': 2900, + '1300.01': 2800, + '1400.01': 2700, + '1500.01': 2600, + '1600.01': 2500, + '1700.01': 2400, + '1800.01': 2300, + '1900.01': 2200, + '2000.01': 2100, + '2100.01': 2000, + '2200.01': 1900, + '2300.01': 1800, + '2400.01': 1700, + '2500.01': 1600, + '2600.01': 1500, + '2700.01': 1400, + '2800.01': 1300, + '2900.01': 1200, + '3000.01': 1100, + '3100.01': 1000, + '3200.01': 900, + '3300.01': 800, + '3400.01': 700, + '3500.01': 600, + }, + }; + // */ + // Form content + const getFormData = () => form.getFormData(this.id, this.t); + + const update = () => { + }; + + const validate = () => { + const errorMessages = []; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Validate basics from form + errorMessages.push(...this.calculator.validateBasics('net_income_per_month')); + errorMessages.push(...this.calculator.validateBasics('service_provider_price')); + + // Check if any missing input errors were found + if (errorMessages.length) { + return { + error: { + title: this.t('missing_input'), + message: errorMessages + }, + }; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Get fielf values for calculating. + const netIncomePerMonth = Number(this.calculator.getFieldValue('net_income_per_month')); + // const netIncomePerMonthRaw = this.calculator.getFieldValue('gross_income_per_month'); + const serviceProviderPrice = Number(this.calculator.getFieldValue('service_provider_price')); + + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Calculate results + + console.log('p', parsedSettings); + + const voucherValue = this.calculator.getMinimumRange(netIncomePerMonth, parsedSettings.voucher_from_net_income); + const selfPayment = Math.max(0, serviceProviderPrice - voucherValue); + + console.log( + '\n netIncomePerMonth', netIncomePerMonth, + '\n serviceProviderPrice', serviceProviderPrice, + '\n', + '\n voucherValue', voucherValue, + '\n selfPayment', selfPayment, + ); + + const subtotals = []; + + subtotals.push( + { + title: this.t('receipt_subtotal_full_price'), + has_details: false, + details: [], + sum: this.t('receipt_subtotal_euros_per_month', { value: this.calculator.formatFinnishEuroCents(serviceProviderPrice) }), + sum_screenreader: this.t('receipt_subtotal_euros_per_month_screenreader', { value: this.calculator.formatEuroCents(serviceProviderPrice) }), + }, + { + title: this.t('receipt_subtotal_city_price'), + has_details: false, + details: [], + sum: this.t('receipt_subtotal_euros_per_month', { value: this.calculator.formatFinnishEuroCents(voucherValue) }), + sum_screenreader: this.t('receipt_subtotal_euros_per_month_screenreader', { value: this.calculator.formatEuroCents(voucherValue) }), + }, + { + title: this.t('receipt_subtotal_self_price'), + has_details: false, + details: [], + sum: this.t('receipt_subtotal_euros_per_month', { value: this.calculator.formatFinnishEuroCents(selfPayment) }), + sum_screenreader: this.t('receipt_subtotal_euros_per_month_screenreader', { value: this.calculator.formatEuroCents(selfPayment) }), + }, + ); + + const additionalDetails = null; + + const receiptData = { + id: this.id, + title: this.t('receipt_estimate_of_payment'), + total_prefix: this.t('receipt_estimated_payment_prefix'), + total_value: this.calculator.formatFinnishEuroCents(selfPayment), + total_suffix: this.t('receipt_estimated_payment_suffix'), + total_explanation: this.t('receipt_estimated_payment_explanation'), + hr: true, + breakdown: { + title: this.t('receipt_estimate_is_based_on'), + subtotals, + additional_details: additionalDetails, + }, + }; + + const receipt = this.calculator.getPartialRender( + '{{>receipt}}', + receiptData, + ); + + return { + receipt, + ariaLive: this.t('receipt_aria_live', { payment: selfPayment }), + }; + }; + + const eventHandlers = { + submit: (event) => { + this.calculator.clearResult(); + event.preventDefault(); + const result = validate(); + this.calculator.renderResult(result); + }, + keydown: () => { + update(); + // this.calculator.clearResult(); + }, + change: () => { + update(); + // this.calculator.clearResult(); + // validate(); + }, + reset: () => { + window.setTimeout(update, 1); + this.calculator.clearResult(); + this.calculator.showAriaLiveText(this.t('reset_aria_live')); + }, + }; + + // Prepare calculator for translations + this.calculator = window.HelfiCalculator({ name: 'home_care_client_payment', translations }); + + // Create shortcut for translations + this.t = (key, value) => this.calculator.translate(key, value); + + // Parse settings to js + this.settings = this.calculator.parseSettings(settings); + + // Initialize calculator + this.calculator.init({ + id, + formData: getFormData(), + eventHandlers, + }); + } +} + +window.helfi_calculator = window.helfi_calculator || {}; +window.helfi_calculator.service_housing_service_voucher = (id, settings) => new ServiceHousingServiceVoucher(id, settings); diff --git a/templates/paragraphs/paragraph--calculator.html.twig b/templates/paragraphs/paragraph--calculator.html.twig index 75cbcbf9f..d05d6c450 100644 --- a/templates/paragraphs/paragraph--calculator.html.twig +++ b/templates/paragraphs/paragraph--calculator.html.twig @@ -28,9 +28,9 @@ 'home_care_service_voucher', 'home_care_client_payment', 'daycare_payment', + 'service_housing_service_voucher', ] %} {# - 'service_housing_service_voucher', 'family_with_kids_home_service_client_payment', 'oral_health_care_procedure', #} From deed1cf6ed5ee2c32dbcf6bfc37fd28ef7ffd301 Mon Sep 17 00:00:00 2001 From: Mikko Tapionlinna Date: Tue, 28 Mar 2023 08:28:43 +0300 Subject: [PATCH 5/6] UHF-7484: Fix review problems --- .../service_housing_service_voucher.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js b/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js index 84c37b472..1862263e2 100644 --- a/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js +++ b/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js @@ -66,7 +66,7 @@ class ServiceHousingServiceVoucher { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Get fielf values for calculating. + // Get field values for calculating. const netIncomePerMonth = Number(this.calculator.getFieldValue('net_income_per_month')); // const netIncomePerMonthRaw = this.calculator.getFieldValue('gross_income_per_month'); const serviceProviderPrice = Number(this.calculator.getFieldValue('service_provider_price')); @@ -75,18 +75,16 @@ class ServiceHousingServiceVoucher { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Calculate results - console.log('p', parsedSettings); - const voucherValue = this.calculator.getMinimumRange(netIncomePerMonth, parsedSettings.voucher_from_net_income); const selfPayment = Math.max(0, serviceProviderPrice - voucherValue); - console.log( - '\n netIncomePerMonth', netIncomePerMonth, - '\n serviceProviderPrice', serviceProviderPrice, - '\n', - '\n voucherValue', voucherValue, - '\n selfPayment', selfPayment, - ); + // console.log( + // '\n netIncomePerMonth', netIncomePerMonth, + // '\n serviceProviderPrice', serviceProviderPrice, + // '\n', + // '\n voucherValue', voucherValue, + // '\n selfPayment', selfPayment, + // ); const subtotals = []; From 2864705267ad0a5faab7d57e99e95c23cfaa878f Mon Sep 17 00:00:00 2001 From: Mikko Tapionlinna Date: Tue, 28 Mar 2023 08:49:29 +0300 Subject: [PATCH 6/6] UHF-7484: Add dist --- dist/js/service_housing_service_voucher.min.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 dist/js/service_housing_service_voucher.min.js diff --git a/dist/js/service_housing_service_voucher.min.js b/dist/js/service_housing_service_voucher.min.js new file mode 100644 index 000000000..273d3cc19 --- /dev/null +++ b/dist/js/service_housing_service_voucher.min.js @@ -0,0 +1 @@ +!function(){"use strict";var e={getFormData:function(e,t){return{form_id:e,has_required_fields:!0,items:[{input_float:{id:"net_income_per_month",label:t("net_income_per_month"),unit:t("unit_euro"),min:0,size:8,required:!0,strip:"[€eE ]",helper_text:t("net_income_per_month_explanation")}},{input_float:{id:"service_provider_price",label:t("service_provider_price"),unit:t("unit_euro"),min:0,size:8,required:!0,strip:"[€eE ]",helper_text:t("service_provider_price_explanation")}}]}}};var t={net_income_per_month:{fi:"Nettotulot kuukaudessa",sv:null,en:null},net_income_per_month_explanation:{fi:"Nettotulot tarkoittavat tuloja verojen vähentämisen jälkeen. Tuloihin lasketaan eläkkeet, elatusavut, elinkorot, elatustuki sekä muut jatkuvat henkilökohtaiset tulot ja pääomasta tai omaisuudesta(kuten korko-, osinko- ja vuokratulot). Eläkkeen saajan hoitotukea, asumistukea, rintamalisää tai sotavammalain mukaista elinkorkoa ei huomioida.",sv:null,en:null},service_provider_price:{fi:"Palveluntuottajan kuukausihinta",sv:null,en:null},service_provider_price_explanation:{fi:"Valitsemasi palveluntuottajan perimä palveluasumisen kuukausihinta.",sv:null,en:null},receipt_estimate_of_payment:{fi:"Arvio palveluasumisen palvelusetelistä",sv:null,en:null},receipt_estimated_payment_prefix:{fi:"Omavastuuosuus eli sinulle maksettavaksi jäävä asiakasmaksu on",sv:null,en:null},receipt_estimated_payment_suffix:{fi:"euroa kuukaudessa.",sv:null,en:null},receipt_estimated_payment_explanation:{fi:"Tämä arvio on suuntaa antava. Tarkka arvo lasketaan kotihoidon tekemän päätöksen mukaan.",sv:null,en:null},receipt_estimate_is_based_on:{fi:"Palveluasumisen hinta palvelusetelillä ostettuna muodostuu seuraavasti:",sv:null,en:null},receipt_subtotal_full_price:{fi:"Palveluasumisen kokonaiskustannus",sv:null,en:null},receipt_subtotal_city_price:{fi:"Kaupunki maksaa palvelusetelillä yksityiselle tuottajalle ",sv:null,en:null},receipt_subtotal_self_price:{fi:"Sinulle maksettavaksi jäävä osuus eli omavastuu",sv:null,en:null},receipt_subtotal_euros_per_month:{fi:"${value} €/kk",sv:null,en:null},receipt_subtotal_euros_per_month_screenreader:{fi:"${value} euroa kuukaudessa",sv:null,en:null},receipt_additional_details:{fi:"Lisähuomiot:",sv:null,en:null},receipt_aria_live:{fi:"Omavastuuosuus eli sinulle maksettavaksi jäävä asiakasmaksu on ${payment} euroa kuukaudessa, lue lisätietoja lomakkeen alta.",sv:null,en:null}};class a{constructor(a,i){this.id=a;const s=JSON.parse(i),l=()=>{},u=()=>{const e=[];if(e.push(...this.calculator.validateBasics("net_income_per_month")),e.push(...this.calculator.validateBasics("service_provider_price")),e.length)return{error:{title:this.t("missing_input"),message:e}};const t=Number(this.calculator.getFieldValue("net_income_per_month")),a=Number(this.calculator.getFieldValue("service_provider_price")),i=this.calculator.getMinimumRange(t,s.voucher_from_net_income),l=Math.max(0,a-i),u=[];u.push({title:this.t("receipt_subtotal_full_price"),has_details:!1,details:[],sum:this.t("receipt_subtotal_euros_per_month",{value:this.calculator.formatFinnishEuroCents(a)}),sum_screenreader:this.t("receipt_subtotal_euros_per_month_screenreader",{value:this.calculator.formatEuroCents(a)})},{title:this.t("receipt_subtotal_city_price"),has_details:!1,details:[],sum:this.t("receipt_subtotal_euros_per_month",{value:this.calculator.formatFinnishEuroCents(i)}),sum_screenreader:this.t("receipt_subtotal_euros_per_month_screenreader",{value:this.calculator.formatEuroCents(i)})},{title:this.t("receipt_subtotal_self_price"),has_details:!1,details:[],sum:this.t("receipt_subtotal_euros_per_month",{value:this.calculator.formatFinnishEuroCents(l)}),sum_screenreader:this.t("receipt_subtotal_euros_per_month_screenreader",{value:this.calculator.formatEuroCents(l)})});const n={id:this.id,title:this.t("receipt_estimate_of_payment"),total_prefix:this.t("receipt_estimated_payment_prefix"),total_value:this.calculator.formatFinnishEuroCents(l),total_suffix:this.t("receipt_estimated_payment_suffix"),total_explanation:this.t("receipt_estimated_payment_explanation"),hr:!0,breakdown:{title:this.t("receipt_estimate_is_based_on"),subtotals:u,additional_details:null}};return{receipt:this.calculator.getPartialRender("{{>receipt}}",n),ariaLive:this.t("receipt_aria_live",{payment:l})}},n={submit:e=>{this.calculator.clearResult(),e.preventDefault();const t=u();this.calculator.renderResult(t)},keydown:()=>{},change:()=>{},reset:()=>{window.setTimeout(l,1),this.calculator.clearResult(),this.calculator.showAriaLiveText(this.t("reset_aria_live"))}};this.calculator=window.HelfiCalculator({name:"home_care_client_payment",translations:t}),this.t=(e,t)=>this.calculator.translate(e,t),this.settings=this.calculator.parseSettings(i),this.calculator.init({id:a,formData:(()=>e.getFormData(this.id,this.t))(),eventHandlers:n})}}window.helfi_calculator=window.helfi_calculator||{},window.helfi_calculator.service_housing_service_voucher=(e,t)=>new a(e,t)}(); \ No newline at end of file