Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pages-account-settings-billing.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /**
  2. * Account Settings - Billing & Plans
  3. */
  4. 'use strict';
  5. document.addEventListener('DOMContentLoaded', function (e) {
  6. (function () {
  7. const creditCardMask = document.querySelector('.credit-card-mask'),
  8. expiryDateMask = document.querySelector('.expiry-date-mask'),
  9. CVVMask = document.querySelector('.cvv-code-mask');
  10. // Credit Card
  11. if (creditCardMask) {
  12. creditCardMask.addEventListener('input', event => {
  13. creditCardMask.value = formatCreditCard(event.target.value);
  14. const cleanValue = event.target.value.replace(/\D/g, '');
  15. let cardType = getCreditCardType(cleanValue);
  16. if (cardType && cardType !== 'unknown' && cardType !== 'general') {
  17. document.querySelector('.card-type').innerHTML =
  18. `<img src="${assetsPath}img/icons/payments/${cardType}-cc.png" height="19"/>`;
  19. } else {
  20. document.querySelector('.card-type').innerHTML = '';
  21. }
  22. });
  23. registerCursorTracker({
  24. input: creditCardMask,
  25. delimiter: ' '
  26. });
  27. }
  28. // Expiry Date Mask
  29. if (expiryDateMask) {
  30. expiryDateMask.addEventListener('input', event => {
  31. expiryDateMask.value = formatDate(event.target.value, {
  32. delimiter: '/',
  33. datePattern: ['m', 'y']
  34. });
  35. });
  36. registerCursorTracker({
  37. input: expiryDateMask,
  38. delimiter: '/'
  39. });
  40. }
  41. // CVV Mask
  42. if (CVVMask) {
  43. CVVMask.addEventListener('input', event => {
  44. const cleanValue = event.target.value.replace(/\D/g, '');
  45. CVVMask.value = formatNumeral(cleanValue, {
  46. numeral: true,
  47. numeralPositiveOnly: true
  48. });
  49. });
  50. }
  51. const formAccSettings = document.getElementById('formAccountSettings'),
  52. mobileNumber = document.querySelector('.mobile-number'),
  53. zipCode = document.querySelector('.zip-code'),
  54. creditCardForm = document.getElementById('creditCardForm');
  55. // Form validation
  56. if (formAccSettings) {
  57. const fv = FormValidation.formValidation(formAccSettings, {
  58. fields: {
  59. companyName: {
  60. validators: {
  61. notEmpty: {
  62. message: 'Please enter company name'
  63. }
  64. }
  65. },
  66. billingEmail: {
  67. validators: {
  68. notEmpty: {
  69. message: 'Please enter billing email'
  70. },
  71. emailAddress: {
  72. message: 'Please enter valid email address'
  73. }
  74. }
  75. }
  76. },
  77. plugins: {
  78. trigger: new FormValidation.plugins.Trigger(),
  79. bootstrap5: new FormValidation.plugins.Bootstrap5({
  80. eleValidClass: '',
  81. rowSelector: '.form-control-validation'
  82. }),
  83. submitButton: new FormValidation.plugins.SubmitButton(),
  84. // Submit the form when all fields are valid
  85. // defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
  86. autoFocus: new FormValidation.plugins.AutoFocus()
  87. }
  88. });
  89. }
  90. // Credit card form validation
  91. if (creditCardForm) {
  92. FormValidation.formValidation(creditCardForm, {
  93. fields: {
  94. paymentCard: {
  95. validators: {
  96. notEmpty: {
  97. message: 'Please enter your credit card number'
  98. }
  99. }
  100. }
  101. },
  102. plugins: {
  103. trigger: new FormValidation.plugins.Trigger(),
  104. bootstrap5: new FormValidation.plugins.Bootstrap5({
  105. // Use this for enabling/changing valid/invalid class
  106. // eleInvalidClass: '',
  107. eleValidClass: ''
  108. }),
  109. submitButton: new FormValidation.plugins.SubmitButton(),
  110. // Submit the form when all fields are valid
  111. // defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
  112. autoFocus: new FormValidation.plugins.AutoFocus()
  113. },
  114. init: instance => {
  115. instance.on('plugins.message.placed', function (e) {
  116. //* Move the error message out of the `input-group` element
  117. if (e.element.parentElement.classList.contains('input-group')) {
  118. e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
  119. }
  120. });
  121. }
  122. });
  123. }
  124. // Cancel Subscription alert
  125. const cancelSubscription = document.querySelector('.cancel-subscription');
  126. // Alert With Functional Confirm Button
  127. if (cancelSubscription) {
  128. cancelSubscription.onclick = function () {
  129. Swal.fire({
  130. text: 'Are you sure you would like to cancel your subscription?',
  131. icon: 'warning',
  132. showCancelButton: true,
  133. confirmButtonText: 'Yes',
  134. customClass: {
  135. confirmButton: 'btn btn-primary me-2',
  136. cancelButton: 'btn btn-label-secondary'
  137. },
  138. buttonsStyling: false
  139. }).then(function (result) {
  140. if (result.value) {
  141. Swal.fire({
  142. icon: 'success',
  143. title: 'Unsubscribed!',
  144. text: 'Your subscription cancelled successfully.',
  145. customClass: {
  146. confirmButton: 'btn btn-success'
  147. }
  148. });
  149. } else if (result.dismiss === Swal.DismissReason.cancel) {
  150. Swal.fire({
  151. title: 'Cancelled',
  152. text: 'Unsubscription Cancelled!!',
  153. icon: 'error',
  154. customClass: {
  155. confirmButton: 'btn btn-success'
  156. }
  157. });
  158. }
  159. });
  160. };
  161. }
  162. // Cleave-zen validation
  163. // Phone Mask
  164. if (mobileNumber) {
  165. mobileNumber.addEventListener('input', event => {
  166. const cleanValue = event.target.value.replace(/\D/g, '');
  167. mobileNumber.value = formatGeneral(cleanValue, {
  168. blocks: [3, 3, 4],
  169. delimiters: [' ', ' ']
  170. });
  171. });
  172. registerCursorTracker({
  173. input: mobileNumber,
  174. delimiter: ' '
  175. });
  176. }
  177. // Pincode
  178. if (zipCode) {
  179. zipCode.addEventListener('input', event => {
  180. zipCode.value = formatNumeral(event.target.value, {
  181. delimiter: '',
  182. numeral: true
  183. });
  184. });
  185. }
  186. })();
  187. });
  188. // Select2 (jquery)
  189. $(function () {
  190. var select2 = $('.select2');
  191. // Select2
  192. if (select2.length) {
  193. select2.each(function () {
  194. var $this = $(this);
  195. $this.wrap('<div class="position-relative"></div>');
  196. $this.select2({
  197. dropdownParent: $this.parent()
  198. });
  199. });
  200. }
  201. });