MDL-69166 enrol_fee: use template for payment btn & properly format cost
[moodle.git] / enrol / fee / templates / payment_region.mustache
1 {{!
2     This file is part of Moodle - http://moodle.org/
4     Moodle is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
9     Moodle is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
14     You should have received a copy of the GNU General Public License
15     along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16 }}
17 {{!
18     @template enrol_fee/payment_region
20     This template will render information about course fee along with a button for payment.
22     Classes required for JS:
23     * none
25     Data attributes required for JS:
26     * data-amount
27     * data-currency
28     * data-component
29     * data-componentid
30     * data-description
32     Context variables required for this template:
33     * cost - Human readable cost string including amount and currency
34     * amount - amount of the cost
35     * currency - currency of the cost
36     * instanceid - Id of the enrolment instance
37     * description - The description for this purchase
39     Example context (json):
40     {
41         "cost": "$108.50",
42         "amount": 108.50,
43         "currency": "AUD",
44         "instanceid": 11,
45         "description": "Enrolment in course Introduction to algorithms",
46         "isguestuser": false
47     }
49 }}
50 <div class="enrol_fee_payment_region text-center">
51     {{#isguestuser}}
52         <div class="mdl-align">
53             <p>{{# str }} paymentrequired {{/ str}}</p>
54             <p><b>{{cost}}</b></p>
55             <p><a href="{{config.wwwroot}}/login/">{{# str }} loginsite {{/ str }}</a></p>
56         </div>
57     {{/isguestuser}}
58     {{^isguestuser}}
59         <p>{{# str }} paymentrequired {{/ str}}</p>
60         <p><b>{{cost}}</b></p>
61         <button
62             class="btn btn-secondary"
63             type="button"
64             id="gateways-modal-trigger-{{ uniqid }}"
65             data-amount="{{amount}}"
66             data-currency="{{currency}}"
67             data-component="enrol_fee"
68             data-componentid="{{instanceid}}"
69             data-description={{# quote }}{{description}}{{/ quote }}
70         >
71             {{# str }} sendpaymentbutton, enrol_fee {{/ str }}
72         </button>
73     {{/isguestuser}}
74 </div>
75 {{#js}}
76     require(['core_payment/gateways_modal'], function(modal) {
77         modal.registerEventListeners(document.querySelector('#gateways-modal-trigger-{{ uniqid }}'));
78     });
79 {{/js}}