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