Trigub_Ilia

Пример прототипа в js Битрикс

Nov 20th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.     $(function(){
  3.         if(!Firstbit)
  4.             Firstbit = {};
  5.  
  6.         if(!Firstbit.Project)
  7.             Firstbit.Project = {};
  8.  
  9.         Firstbit.Project.ChangePassword = function(){
  10.             this.form = $('#<?= $arResult["FORM_ID"] ?>');
  11.             this.wrap = 'div[data-cid="' + this.fieldName + '"]';
  12.         };
  13.  
  14.         Firstbit.Project.ChangePassword.prototype.init = function(){
  15.             this.events();
  16.         };
  17.  
  18.         Firstbit.Project.ChangePassword.prototype.events = function(){
  19.             var self = this;
  20.  
  21.             var errors = false,
  22.                 message = 0;
  23.             $(document).on('submit', self.form, function() {
  24.                 if (!$('#modal-window [name=USER_PASSWORD]').val()) {
  25.                     $('#modal-window [name=USER_PASSWORD]').addClass('_error').focus(function() {$(this).removeClass('_error');});
  26.                     errors = true;
  27.                 }
  28.                 if (!$('#modal-window [name=USER_PASSWORD_NEW]').val()) {
  29.                     $('#modal-window [name=USER_PASSWORD_NEW]').addClass('_error').focus(function() {$(this).removeClass('_error');});
  30.                     errors = true;
  31.                 }
  32.                 if (!$('#modal-window [name=USER_PASSWORD_NEW_CONFIRM]').val()) {
  33.                     $('#modal-window [name=USER_PASSWORD_NEW_CONFIRM]').addClass('_error').focus(function() {$(this).removeClass('_error');});
  34.                     errors = true;
  35.                 }
  36.                 if ($('#modal-window [name=USER_PASSWORD_NEW_CONFIRM]').val() != $('#modal-window [name=USER_PASSWORD_NEW]').val()) {
  37.                     $('#modal-window [name=USER_PASSWORD_NEW]').addClass('_error').focus(function() {$(this).removeClass('_error');});
  38.                     $('#modal-window [name=USER_PASSWORD_NEW_CONFIRM]').addClass('_error').focus(function() {$(this).removeClass('_error');});
  39.                     errors = true;
  40.                 }
  41.                 if (!errors) {
  42.                     $.post(self.form.attr('action'), self.form.serialize(), function (res) {
  43.                         var response = res.data;
  44.                         console.log(response);
  45.                         if (response && response.STATUS) {
  46.                             if (response.MESSAGES !== false ) {
  47.                                 message = response.MESSAGES.length;
  48.                             }
  49.                             if (response.STATUS == 'OK') {
  50.                                 window.location = window.location;
  51.                             }
  52.                             else {
  53.                                 if (response.STATUS == 'ERROR' && message > 0) {
  54.                                     $('#modal-window .form__errors-wrapper').empty().append('<div class="form__errors-container"></div>');
  55.                                     while (message--) {
  56.                                         $('#modal-window .form__errors-container').append('<span>' + response.MESSAGES[message] + '</span>');
  57.                                         notificationOpen('message', {'message': response.MESSAGES[message]}, 10000);
  58.                                     }
  59.                                 }
  60.                             }
  61.                         }
  62.                     }, 'json');
  63.                 }
  64.                 errors = false;
  65.                 return false;
  66.             });
  67.         };
  68.  
  69.         var calculator = new Firstbit.Project.ChangePassword();
  70.         calculator.init();
  71.     });
  72. </script>
Add Comment
Please, Sign In to add comment