PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/backend/Rapido/assets/js/login.js

https://gitlab.com/kaouech/theme
JavaScript | 197 lines | 183 code | 7 blank | 7 comment | 14 complexity | 5cd9dae2a6ee0e965c5a237a23426123 MD5 | raw file
  1. var Login = function() {
  2. "use strict";
  3. var runBoxToShow = function() {
  4. var el = $('.box-login');
  5. if (getParameterByName('box').length) {
  6. switch(getParameterByName('box')) {
  7. case "register" :
  8. el = $('.box-register');
  9. break;
  10. case "forgot" :
  11. el = $('.box-forgot');
  12. break;
  13. default :
  14. el = $('.box-login');
  15. break;
  16. }
  17. }
  18. el.show().addClass("animated flipInX").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
  19. $(this).removeClass("animated flipInX");
  20. });
  21. };
  22. var runLoginButtons = function() {
  23. $('.forgot').on('click', function() {
  24. $('.box-login').removeClass("animated flipInX").addClass("animated bounceOutRight").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
  25. $(this).hide().removeClass("animated bounceOutRight");
  26. });
  27. $('.box-forgot').show().addClass("animated bounceInLeft").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
  28. $(this).show().removeClass("animated bounceInLeft");
  29. });
  30. });
  31. $('.register').on('click', function() {
  32. $('.box-login').removeClass("animated flipInX").addClass("animated bounceOutRight").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
  33. $(this).hide().removeClass("animated bounceOutRight");
  34. });
  35. $('.box-register').show().addClass("animated bounceInLeft").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
  36. $(this).show().removeClass("animated bounceInLeft");
  37. });
  38. });
  39. $('.go-back').click(function() {
  40. var boxToShow;
  41. if ($('.box-register').is(":visible")) {
  42. boxToShow = $('.box-register');
  43. } else {
  44. boxToShow = $('.box-forgot');
  45. }
  46. boxToShow.addClass("animated bounceOutLeft").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
  47. boxToShow.hide().removeClass("animated bounceOutLeft");
  48. });
  49. $('.box-login').show().addClass("animated bounceInRight").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
  50. $(this).show().removeClass("animated bounceInRight");
  51. });
  52. });
  53. };
  54. //function to return the querystring parameter with a given name.
  55. var getParameterByName = function(name) {
  56. name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  57. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);
  58. return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  59. };
  60. var runSetDefaultValidation = function() {
  61. $.validator.setDefaults({
  62. errorElement : "span", // contain the error msg in a small tag
  63. errorClass : 'help-block',
  64. errorPlacement : function(error, element) {// render error placement for each input type
  65. if (element.attr("type") == "radio" || element.attr("type") == "checkbox") {// for chosen elements, need to insert the error after the chosen container
  66. error.insertAfter($(element).closest('.form-group').children('div').children().last());
  67. } else if (element.attr("name") == "card_expiry_mm" || element.attr("name") == "card_expiry_yyyy") {
  68. error.appendTo($(element).closest('.form-group').children('div'));
  69. } else {
  70. error.insertAfter(element);
  71. // for other inputs, just perform default behavior
  72. }
  73. },
  74. ignore : ':hidden',
  75. success : function(label, element) {
  76. label.addClass('help-block valid');
  77. // mark the current input as valid and display OK icon
  78. $(element).closest('.form-group').removeClass('has-error');
  79. },
  80. highlight : function(element) {
  81. $(element).closest('.help-block').removeClass('valid');
  82. // display OK icon
  83. $(element).closest('.form-group').addClass('has-error');
  84. // add the Bootstrap error class to the control group
  85. },
  86. unhighlight : function(element) {// revert the change done by hightlight
  87. $(element).closest('.form-group').removeClass('has-error');
  88. // set error class to the control group
  89. }
  90. });
  91. };
  92. var runLoginValidator = function() {
  93. var form = $('.form-login');
  94. var errorHandler = $('.errorHandler', form);
  95. form.validate({
  96. rules : {
  97. username : {
  98. minlength : 2,
  99. required : true
  100. },
  101. password : {
  102. minlength : 6,
  103. required : true
  104. }
  105. },
  106. submitHandler : function(form) {
  107. errorHandler.hide();
  108. form.submit();
  109. },
  110. invalidHandler : function(event, validator) {//display error alert on form submit
  111. errorHandler.show();
  112. }
  113. });
  114. };
  115. var runForgotValidator = function() {
  116. var form2 = $('.form-forgot');
  117. var errorHandler2 = $('.errorHandler', form2);
  118. form2.validate({
  119. rules : {
  120. email : {
  121. required : true
  122. }
  123. },
  124. submitHandler : function(form) {
  125. errorHandler2.hide();
  126. form2.submit();
  127. },
  128. invalidHandler : function(event, validator) {//display error alert on form submit
  129. errorHandler2.show();
  130. }
  131. });
  132. };
  133. var runRegisterValidator = function() {
  134. var form3 = $('.form-register');
  135. var errorHandler3 = $('.errorHandler', form3);
  136. form3.validate({
  137. rules : {
  138. full_name : {
  139. minlength : 2,
  140. required : true
  141. },
  142. address : {
  143. minlength : 2,
  144. required : true
  145. },
  146. city : {
  147. minlength : 2,
  148. required : true
  149. },
  150. gender : {
  151. required : true
  152. },
  153. email : {
  154. required : true
  155. },
  156. password : {
  157. minlength : 6,
  158. required : true
  159. },
  160. password_again : {
  161. required : true,
  162. minlength : 5,
  163. equalTo : "#password"
  164. },
  165. agree : {
  166. minlength : 1,
  167. required : true
  168. }
  169. },
  170. submitHandler : function(form) {
  171. errorHandler3.hide();
  172. form3.submit();
  173. },
  174. invalidHandler : function(event, validator) {//display error alert on form submit
  175. errorHandler3.show();
  176. }
  177. });
  178. };
  179. return {
  180. //main function to initiate template pages
  181. init : function() {
  182. runBoxToShow();
  183. runLoginButtons();
  184. runSetDefaultValidation();
  185. runLoginValidator();
  186. runForgotValidator();
  187. runRegisterValidator();
  188. }
  189. };
  190. }();