Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | var Login = function() { |
| 2 | |||
| 3 | var handleLogin = function() { |
||
| 4 | |||
| 5 | $('.login-form').validate({ |
||
| 6 | errorElement: 'span', //default input error message container |
||
| 7 | errorClass: 'help-block', // default input error message class |
||
| 8 | focusInvalid: false, // do not focus the last invalid input |
||
| 9 | rules: { |
||
| 10 | username: { |
||
| 11 | required: true |
||
| 12 | }, |
||
| 13 | password: { |
||
| 14 | required: true |
||
| 15 | }, |
||
| 16 | remember: { |
||
| 17 | required: false |
||
| 18 | } |
||
| 19 | }, |
||
| 20 | |||
| 21 | messages: { |
||
| 22 | username: { |
||
| 23 | required: "Username is required." |
||
| 24 | }, |
||
| 25 | password: { |
||
| 26 | required: "Password is required." |
||
| 27 | } |
||
| 28 | }, |
||
| 29 | |||
| 30 | invalidHandler: function(event, validator) { //display error alert on form submit |
||
| 31 | $('.alert-danger', $('.login-form')).show(); |
||
| 32 | }, |
||
| 33 | |||
| 34 | highlight: function(element) { // hightlight error inputs |
||
| 35 | $(element) |
||
| 36 | .closest('.form-group').addClass('has-error'); // set error class to the control group |
||
| 37 | }, |
||
| 38 | |||
| 39 | success: function(label) { |
||
| 40 | label.closest('.form-group').removeClass('has-error'); |
||
| 41 | label.remove(); |
||
| 42 | }, |
||
| 43 | |||
| 44 | errorPlacement: function(error, element) { |
||
| 45 | error.insertAfter(element.closest('.input-icon')); |
||
| 46 | }, |
||
| 47 | |||
| 48 | submitHandler: function(form) { |
||
| 49 | form.submit(); // form validation success, call ajax form submit |
||
| 50 | } |
||
| 51 | }); |
||
| 52 | |||
| 53 | $('.login-form input').keypress(function(e) { |
||
| 54 | if (e.which == 13) { |
||
| 55 | if ($('.login-form').validate().form()) { |
||
| 56 | $('.login-form').submit(); //form validation success, call ajax form submit |
||
| 57 | } |
||
| 58 | return false; |
||
| 59 | } |
||
| 60 | }); |
||
| 61 | } |
||
| 62 | |||
| 63 | var handleForgetPassword = function() { |
||
| 64 | $('.forget-form').validate({ |
||
| 65 | errorElement: 'span', //default input error message container |
||
| 66 | errorClass: 'help-block', // default input error message class |
||
| 67 | focusInvalid: false, // do not focus the last invalid input |
||
| 68 | ignore: "", |
||
| 69 | rules: { |
||
| 70 | email: { |
||
| 71 | required: true, |
||
| 72 | email: true |
||
| 73 | } |
||
| 74 | }, |
||
| 75 | |||
| 76 | messages: { |
||
| 77 | email: { |
||
| 78 | required: "Email is required." |
||
| 79 | } |
||
| 80 | }, |
||
| 81 | |||
| 82 | invalidHandler: function(event, validator) { //display error alert on form submit |
||
| 83 | |||
| 84 | }, |
||
| 85 | |||
| 86 | highlight: function(element) { // hightlight error inputs |
||
| 87 | $(element) |
||
| 88 | .closest('.form-group').addClass('has-error'); // set error class to the control group |
||
| 89 | }, |
||
| 90 | |||
| 91 | success: function(label) { |
||
| 92 | label.closest('.form-group').removeClass('has-error'); |
||
| 93 | label.remove(); |
||
| 94 | }, |
||
| 95 | |||
| 96 | errorPlacement: function(error, element) { |
||
| 97 | error.insertAfter(element.closest('.input-icon')); |
||
| 98 | }, |
||
| 99 | |||
| 100 | submitHandler: function(form) { |
||
| 101 | form.submit(); |
||
| 102 | } |
||
| 103 | }); |
||
| 104 | |||
| 105 | $('.forget-form input').keypress(function(e) { |
||
| 106 | if (e.which == 13) { |
||
| 107 | if ($('.forget-form').validate().form()) { |
||
| 108 | $('.forget-form').submit(); |
||
| 109 | } |
||
| 110 | return false; |
||
| 111 | } |
||
| 112 | }); |
||
| 113 | |||
| 114 | jQuery('#forget-password').click(function() { |
||
| 115 | jQuery('.login-form').hide(); |
||
| 116 | jQuery('.forget-form').show(); |
||
| 117 | }); |
||
| 118 | |||
| 119 | jQuery('#back-btn').click(function() { |
||
| 120 | jQuery('.login-form').show(); |
||
| 121 | jQuery('.forget-form').hide(); |
||
| 122 | }); |
||
| 123 | |||
| 124 | } |
||
| 125 | |||
| 126 | var handleRegister = function() { |
||
| 127 | |||
| 128 | function format(state) { |
||
| 129 | if (!state.id) { return state.text; } |
||
| 130 | var $state = $( |
||
| 131 | '<span><img src="../assets/global/img/flags/' + state.element.value.toLowerCase() + '.png" class="img-flag" /> ' + state.text + '</span>' |
||
| 132 | ); |
||
| 133 | |||
| 134 | return $state; |
||
| 135 | } |
||
| 136 | |||
| 137 | if (jQuery().select2 && $('#country_list').size() > 0) { |
||
| 138 | $("#country_list").select2({ |
||
| 139 | placeholder: '<i class="fa fa-map-marker"></i> Select a Country', |
||
| 140 | templateResult: format, |
||
| 141 | templateSelection: format, |
||
| 142 | width: 'auto', |
||
| 143 | escapeMarkup: function(m) { |
||
| 144 | return m; |
||
| 145 | } |
||
| 146 | }); |
||
| 147 | |||
| 148 | |||
| 149 | $('#country_list').change(function() { |
||
| 150 | $('.register-form').validate().element($(this)); //revalidate the chosen dropdown value and show error or success message for the input |
||
| 151 | }); |
||
| 152 | } |
||
| 153 | |||
| 154 | $('.register-form').validate({ |
||
| 155 | errorElement: 'span', //default input error message container |
||
| 156 | errorClass: 'help-block', // default input error message class |
||
| 157 | focusInvalid: false, // do not focus the last invalid input |
||
| 158 | ignore: "", |
||
| 159 | rules: { |
||
| 160 | |||
| 161 | fullname: { |
||
| 162 | required: true |
||
| 163 | }, |
||
| 164 | email: { |
||
| 165 | required: true, |
||
| 166 | email: true |
||
| 167 | }, |
||
| 168 | address: { |
||
| 169 | required: true |
||
| 170 | }, |
||
| 171 | city: { |
||
| 172 | required: true |
||
| 173 | }, |
||
| 174 | country: { |
||
| 175 | required: true |
||
| 176 | }, |
||
| 177 | |||
| 178 | username: { |
||
| 179 | required: true |
||
| 180 | }, |
||
| 181 | password: { |
||
| 182 | required: true |
||
| 183 | }, |
||
| 184 | rpassword: { |
||
| 185 | equalTo: "#register_password" |
||
| 186 | }, |
||
| 187 | |||
| 188 | tnc: { |
||
| 189 | required: true |
||
| 190 | } |
||
| 191 | }, |
||
| 192 | |||
| 193 | messages: { // custom messages for radio buttons and checkboxes |
||
| 194 | tnc: { |
||
| 195 | required: "Please accept TNC first." |
||
| 196 | } |
||
| 197 | }, |
||
| 198 | |||
| 199 | invalidHandler: function(event, validator) { //display error alert on form submit |
||
| 200 | |||
| 201 | }, |
||
| 202 | |||
| 203 | highlight: function(element) { // hightlight error inputs |
||
| 204 | $(element) |
||
| 205 | .closest('.form-group').addClass('has-error'); // set error class to the control group |
||
| 206 | }, |
||
| 207 | |||
| 208 | success: function(label) { |
||
| 209 | label.closest('.form-group').removeClass('has-error'); |
||
| 210 | label.remove(); |
||
| 211 | }, |
||
| 212 | |||
| 213 | errorPlacement: function(error, element) { |
||
| 214 | if (element.attr("name") == "tnc") { // insert checkbox errors after the container |
||
| 215 | error.insertAfter($('#register_tnc_error')); |
||
| 216 | } else if (element.closest('.input-icon').size() === 1) { |
||
| 217 | error.insertAfter(element.closest('.input-icon')); |
||
| 218 | } else { |
||
| 219 | error.insertAfter(element); |
||
| 220 | } |
||
| 221 | }, |
||
| 222 | |||
| 223 | submitHandler: function(form) { |
||
| 224 | form[0].submit(); |
||
| 225 | } |
||
| 226 | }); |
||
| 227 | |||
| 228 | $('.register-form input').keypress(function(e) { |
||
| 229 | if (e.which == 13) { |
||
| 230 | if ($('.register-form').validate().form()) { |
||
| 231 | $('.register-form').submit(); |
||
| 232 | } |
||
| 233 | return false; |
||
| 234 | } |
||
| 235 | }); |
||
| 236 | |||
| 237 | jQuery('#register-btn').click(function() { |
||
| 238 | jQuery('.login-form').hide(); |
||
| 239 | jQuery('.register-form').show(); |
||
| 240 | }); |
||
| 241 | |||
| 242 | jQuery('#register-back-btn').click(function() { |
||
| 243 | jQuery('.login-form').show(); |
||
| 244 | jQuery('.register-form').hide(); |
||
| 245 | }); |
||
| 246 | } |
||
| 247 | |||
| 248 | return { |
||
| 249 | //main function to initiate the module |
||
| 250 | init: function() { |
||
| 251 | |||
| 252 | handleLogin(); |
||
| 253 | handleForgetPassword(); |
||
| 254 | handleRegister(); |
||
| 255 | |||
| 256 | } |
||
| 257 | |||
| 258 | }; |
||
| 259 | |||
| 260 | }(); |
||
| 261 | |||
| 262 | jQuery(document).ready(function() { |
||
| 263 | Login.init(); |
||
| 264 | }); |