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