]> dev.renevier.net Git - syj.git/blob - public/js/account.js
version 0.1
[syj.git] / public / js / account.js
1 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
2     and is published under the AGPL license. */
3
4 document.observe("dom:loaded", function() {
5     var currentmail = $("account_email").value, form = $("accountform");
6
7     form.focus();
8
9     form.observe('submit', function(evt) {
10         var control, errorElements;
11
12         $$('.error').invoke('remove');
13
14         errorElements = $$('#account_email, #account_password').findAll(
15             function(elt) {
16                 return (!elt.check(function() {
17                     return !this.value.strip().empty();
18                 }, SyjStrings.notEmptyField));
19             });
20
21
22         if (!errorElements.length) {
23             control = $("account_password");
24             if (!control.check(function() {
25                 return this.value.length >= 6;
26             }, SyjStrings.passwordLenghtWarn)) {
27                 errorElements.push(control);
28             }
29         }
30
31         if (!errorElements.length) {
32             control = $("account_password");
33             if (control.check(function() {
34                 return this.value === $("account_password_confirm").value;
35             }, SyjStrings.passwordNoMatchWarn)) {
36                 errorElements.push(control);
37             }
38         }
39
40         if (!errorElements.length) {
41             control = $("account_email");
42             if (!control.check(function() {
43                 return this.value !== currentmail || $("account_password").value !== $("account_password_current").value;
44             }, SyjStrings.nochangeWarn)) {
45                 errorElements.push(control);
46             }
47         }
48
49         /*
50          * if there are errors, cancel submission
51          */
52         if (errorElements.length) {
53             errorElements[0].focus();
54             errorElements[0].select();
55             evt.stop();
56         }
57     });
58 });