Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

pages-account-settings-account.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * Account Settings - Account
  3. */
  4. 'use strict';
  5. document.addEventListener('DOMContentLoaded', function (e) {
  6. (function () {
  7. const formAccSettings = document.querySelector('#formAccountSettings'),
  8. deactivateAcc = document.querySelector('#formAccountDeactivation'),
  9. deactivateButton = deactivateAcc.querySelector('.deactivate-account');
  10. // Form validation for Add new record
  11. if (formAccSettings) {
  12. const fv = FormValidation.formValidation(formAccSettings, {
  13. fields: {
  14. firstName: {
  15. validators: {
  16. notEmpty: {
  17. message: 'Please enter first name'
  18. }
  19. }
  20. },
  21. lastName: {
  22. validators: {
  23. notEmpty: {
  24. message: 'Please enter last name'
  25. }
  26. }
  27. }
  28. },
  29. plugins: {
  30. trigger: new FormValidation.plugins.Trigger(),
  31. bootstrap5: new FormValidation.plugins.Bootstrap5({
  32. eleValidClass: '',
  33. rowSelector: '.form-control-validation'
  34. }),
  35. submitButton: new FormValidation.plugins.SubmitButton(),
  36. // Submit the form when all fields are valid
  37. // defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
  38. autoFocus: new FormValidation.plugins.AutoFocus()
  39. },
  40. init: instance => {
  41. instance.on('plugins.message.placed', function (e) {
  42. if (e.element.parentElement.classList.contains('input-group')) {
  43. e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
  44. }
  45. });
  46. }
  47. });
  48. }
  49. if (deactivateAcc) {
  50. const fv = FormValidation.formValidation(deactivateAcc, {
  51. fields: {
  52. accountActivation: {
  53. validators: {
  54. notEmpty: {
  55. message: 'Please confirm you want to delete account'
  56. }
  57. }
  58. }
  59. },
  60. plugins: {
  61. trigger: new FormValidation.plugins.Trigger(),
  62. bootstrap5: new FormValidation.plugins.Bootstrap5({
  63. eleValidClass: ''
  64. }),
  65. submitButton: new FormValidation.plugins.SubmitButton(),
  66. fieldStatus: new FormValidation.plugins.FieldStatus({
  67. onStatusChanged: function (areFieldsValid) {
  68. areFieldsValid
  69. ? // Enable the submit button
  70. // so user has a chance to submit the form again
  71. deactivateButton.removeAttribute('disabled')
  72. : // Disable the submit button
  73. deactivateButton.setAttribute('disabled', 'disabled');
  74. }
  75. }),
  76. // Submit the form when all fields are valid
  77. // defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
  78. autoFocus: new FormValidation.plugins.AutoFocus()
  79. },
  80. init: instance => {
  81. instance.on('plugins.message.placed', function (e) {
  82. if (e.element.parentElement.classList.contains('input-group')) {
  83. e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
  84. }
  85. });
  86. }
  87. });
  88. }
  89. // Deactivate account alert
  90. const accountActivation = document.querySelector('#accountActivation');
  91. // Alert With Functional Confirm Button
  92. if (deactivateButton) {
  93. deactivateButton.onclick = function () {
  94. if (accountActivation.checked == true) {
  95. Swal.fire({
  96. text: 'Are you sure you would like to deactivate your account?',
  97. icon: 'warning',
  98. showCancelButton: true,
  99. confirmButtonText: 'Yes',
  100. customClass: {
  101. confirmButton: 'btn btn-primary me-2',
  102. cancelButton: 'btn btn-label-secondary'
  103. },
  104. buttonsStyling: false
  105. }).then(function (result) {
  106. if (result.value) {
  107. Swal.fire({
  108. icon: 'success',
  109. title: 'Deleted!',
  110. text: 'Your file has been deleted.',
  111. customClass: {
  112. confirmButton: 'btn btn-success'
  113. }
  114. });
  115. } else if (result.dismiss === Swal.DismissReason.cancel) {
  116. Swal.fire({
  117. title: 'Cancelled',
  118. text: 'Deactivation Cancelled!!',
  119. icon: 'error',
  120. customClass: {
  121. confirmButton: 'btn btn-success'
  122. }
  123. });
  124. }
  125. });
  126. }
  127. };
  128. }
  129. // CleaveJ-zen validation
  130. const phoneNumber = document.querySelector('#phoneNumber'),
  131. zipCode = document.querySelector('#zipCode');
  132. // Phone Mask
  133. if (phoneNumber) {
  134. phoneNumber.addEventListener('input', event => {
  135. const cleanValue = event.target.value.replace(/\D/g, '');
  136. phoneNumber.value = formatGeneral(cleanValue, {
  137. blocks: [3, 3, 4],
  138. delimiters: [' ', ' ']
  139. });
  140. });
  141. registerCursorTracker({
  142. input: phoneNumber,
  143. delimiter: ' '
  144. });
  145. }
  146. // Pincode
  147. if (zipCode) {
  148. zipCode.addEventListener('input', event => {
  149. zipCode.value = formatNumeral(event.target.value, {
  150. delimiter: '',
  151. numeral: true
  152. });
  153. });
  154. }
  155. // Update/reset user image of account page
  156. let accountUserImage = document.getElementById('uploadedAvatar');
  157. const fileInput = document.querySelector('.account-file-input'),
  158. resetFileInput = document.querySelector('.account-image-reset');
  159. if (accountUserImage) {
  160. const resetImage = accountUserImage.src;
  161. fileInput.onchange = () => {
  162. if (fileInput.files[0]) {
  163. accountUserImage.src = window.URL.createObjectURL(fileInput.files[0]);
  164. }
  165. };
  166. resetFileInput.onclick = () => {
  167. fileInput.value = '';
  168. accountUserImage.src = resetImage;
  169. };
  170. }
  171. })();
  172. });
  173. // Select2 (jquery)
  174. $(function () {
  175. var select2 = $('.select2');
  176. // For all Select2
  177. if (select2.length) {
  178. select2.each(function () {
  179. var $this = $(this);
  180. $this.wrap('<div class="position-relative"></div>');
  181. $this.select2({
  182. dropdownParent: $this.parent()
  183. });
  184. });
  185. }
  186. });