Shivam Mishra | dfdb92f | 2019-05-30 16:35:15 +0530 | [diff] [blame] | 1 | {% macro hero(title, description, has_access) %} |
Shivam Mishra | 87a7438 | 2019-05-21 12:05:19 +0530 | [diff] [blame] | 2 | <div class='container pb-5'> |
Shivam Mishra | dfdb92f | 2019-05-30 16:35:15 +0530 | [diff] [blame] | 3 | <h1>{{ title }} </h1> |
Shivam Mishra | 87a7438 | 2019-05-21 12:05:19 +0530 | [diff] [blame] | 4 | <p class='lead' style="max-width: 100%;">{{ description }}</p> |
| 5 | <p class="mt-4"> |
Shivam Mishra | ae2871f | 2019-05-29 13:11:34 +0530 | [diff] [blame] | 6 | {% if frappe.session.user == 'Guest' %} |
Shivam Mishra | 5aa8df8 | 2019-05-29 18:38:09 +0530 | [diff] [blame] | 7 | <a id="signup" class="btn btn-primary btn-lg" href="/login#signup">Sign Up</a> |
Shivam Mishra | dfdb92f | 2019-05-30 16:35:15 +0530 | [diff] [blame] | 8 | {% elif not has_access %} |
| 9 | <button id="enroll" class="btn btn-primary btn-lg" onclick="enroll()" disabled>Enroll</button> |
Shivam Mishra | ae2871f | 2019-05-29 13:11:34 +0530 | [diff] [blame] | 10 | {% endif %} |
Shivam Mishra | 87a7438 | 2019-05-21 12:05:19 +0530 | [diff] [blame] | 11 | </p> |
| 12 | </div> |
| 13 | |
| 14 | {% block script %} |
| 15 | <script type="text/javascript"> |
Shivam Mishra | dfdb92f | 2019-05-30 16:35:15 +0530 | [diff] [blame] | 16 | frappe.ready(() => { |
| 17 | btn = document.getElementById('enroll'); |
| 18 | if (btn) btn.disabled = false; |
| 19 | }) |
| 20 | |
Shivam Mishra | 5aa8df8 | 2019-05-29 18:38:09 +0530 | [diff] [blame] | 21 | function enroll() { |
Shivam Mishra | dfdb92f | 2019-05-30 16:35:15 +0530 | [diff] [blame] | 22 | let params = frappe.utils.get_query_params() |
Shivam Mishra | 3336fb5 | 2019-05-30 18:04:36 +0530 | [diff] [blame] | 23 | |
Shivam Mishra | dfdb92f | 2019-05-30 16:35:15 +0530 | [diff] [blame] | 24 | let btn = document.getElementById('enroll'); |
| 25 | btn.disbaled = true; |
| 26 | btn.innerText = 'Enrolling...' |
| 27 | |
| 28 | let opts = { |
| 29 | method: 'erpnext.education.utils.enroll_in_program', |
| 30 | args: { |
| 31 | program_name: params.program |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | frappe.call(opts).then(res => { |
Shivam Mishra | dfdb92f | 2019-05-30 16:35:15 +0530 | [diff] [blame] | 36 | let success_dialog = new frappe.ui.Dialog({ |
| 37 | title: __('Success'), |
| 38 | secondary_action: function() { |
| 39 | window.location.reload() |
| 40 | } |
| 41 | }) |
| 42 | success_dialog.set_message('You have successfully enrolled for the program '); |
| 43 | success_dialog.$message.show() |
| 44 | success_dialog.show(); |
| 45 | btn.disbaled = false; |
| 46 | }) |
Shivam Mishra | 5aa8df8 | 2019-05-29 18:38:09 +0530 | [diff] [blame] | 47 | } |
Shivam Mishra | 87a7438 | 2019-05-21 12:05:19 +0530 | [diff] [blame] | 48 | </script> |
| 49 | {% endblock %} |
| 50 | {% endmacro %} |