MDL-69166 core_payment: show cost on the modal
authorShamim Rezaie <shamim@moodle.com>
Tue, 30 Jun 2020 07:14:38 +0000 (17:14 +1000)
committerShamim Rezaie <shamim@moodle.com>
Tue, 27 Oct 2020 03:37:29 +0000 (14:37 +1100)
payment/amd/build/gateways_modal.min.js
payment/amd/build/gateways_modal.min.js.map
payment/amd/build/modal_gateways.min.js
payment/amd/build/modal_gateways.min.js.map
payment/amd/build/selectors.min.js
payment/amd/build/selectors.min.js.map
payment/amd/src/gateways_modal.js
payment/amd/src/selectors.js
payment/templates/fee_breakdown.mustache [new file with mode: 0644]
payment/templates/gateways_modal.mustache

index a2d21ee..aa2086b 100644 (file)
Binary files a/payment/amd/build/gateways_modal.min.js and b/payment/amd/build/gateways_modal.min.js differ
index 57e85ac..0a2256d 100644 (file)
Binary files a/payment/amd/build/gateways_modal.min.js.map and b/payment/amd/build/gateways_modal.min.js.map differ
index 54d199f..4f32883 100644 (file)
Binary files a/payment/amd/build/modal_gateways.min.js and b/payment/amd/build/modal_gateways.min.js differ
index 7be1ed0..6a1a424 100644 (file)
Binary files a/payment/amd/build/modal_gateways.min.js.map and b/payment/amd/build/modal_gateways.min.js.map differ
index 480f147..ac36b96 100644 (file)
Binary files a/payment/amd/build/selectors.min.js and b/payment/amd/build/selectors.min.js differ
index fc5d505..e6532f2 100644 (file)
Binary files a/payment/amd/build/selectors.min.js.map and b/payment/amd/build/selectors.min.js.map differ
index 01cf70b..e1488d0 100644 (file)
@@ -128,9 +128,28 @@ const show = async(rootNode, {
     };
 
     const {html, js} = await Templates.renderForPromise('core_payment/gateways', context);
-    Templates.replaceNodeContents(modal.getRoot().find(Selectors.regions.gatewaysContainer), html, js);
+    const root = modal.getRoot()[0];
+    Templates.replaceNodeContents(root.querySelector(Selectors.regions.gatewaysContainer), html, js);
+    updateCostRegion(root, parseFloat(rootNode.dataset.amount), rootNode.dataset.currency);
 };
 
+/**
+ * Shows the cost of the item the user is purchasing in the cost region.
+ *
+ * @param {HTMLElement} root An HTMLElement that contains the cost region
+ * @param {number} amount The amount part of cost
+ * @param {string} currency The currency part of cost in the 3-letter ISO-4217 format
+ * @returns {Promise<void>}
+ */
+const updateCostRegion = async(root, amount, currency) => {
+    const locale = await updateCostRegion.locale; // This only takes a bit the first time.
+    const localisedCost = amount.toLocaleString(locale, {style: "currency", currency: currency});
+
+    const {html, js} = await Templates.renderForPromise('core_payment/fee_breakdown', {fee: localisedCost});
+    Templates.replaceNodeContents(root.querySelector(Selectors.regions.costContainer), html, js);
+};
+updateCostRegion.locale = getString("localecldr", "langconfig");
+
 /**
  * Process payment using the selected gateway.
  *
index 5bfc1af..1a571e8 100644 (file)
@@ -25,6 +25,7 @@
 export default {
     regions: {
         gatewaysContainer: '[data-region="gateways-container"]',
+        costContainer: '[data-region="fee-breakdown-container"]',
     },
     values: {
         gateway: '[data-region="gateways-container"] input[type="radio"]:checked',
diff --git a/payment/templates/fee_breakdown.mustache b/payment/templates/fee_breakdown.mustache
new file mode 100644 (file)
index 0000000..2e74fd0
--- /dev/null
@@ -0,0 +1,38 @@
+{{!
+    This file is part of Moodle - http://moodle.org/
+
+    Moodle is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Moodle is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+}}
+{{!
+    @template core_payment/fee_breakdown_placeholder
+
+    Classes required for JS:
+    * none
+
+    Data attributes required for JS:
+    * none
+
+    Context variables required for this template:
+    * none
+
+    Example context (json):
+    {}
+
+}}
+<div class="core_payment_fee_breakdown">
+    {{# str }} labelvalue, core, {
+        "label": {{# quote }}{{# str }} cost {{/ str }}{{/ quote }},
+        "value": "{{fee}}"
+        } {{/ str }}
+</div>
index bda71e1..8c1139c 100644 (file)
     {}
 
 }}
-<div class="core_payment_gateways_modal" data-region="gateways-container">
-    {{> core_payment/gateways_placeholder }}
+<div class="core_payment_gateways_modal">
+    <div data-region="gateways-container">
+        {{> core_payment/gateways_placeholder }}
+    </div>
+    <div data-region="fee-breakdown-container">
+        <div class="bg-pulse-grey" style="height: 22px; width: 90px"></div>
+    </div>
 </div>
\ No newline at end of file