]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/sidebar.js
added code to enforce password strength
[working/Evergreen.git] / Open-ILS / web / opac / skin / default / js / sidebar.js
1 /* set up the colors in the sidebar 
2         Disables/Enables certain components based on various state data */
3
4 attachEvt("common", "init", initSideBar);
5 attachEvt("common", "init", setSidebarLinks);
6
7 attachEvt("common", "unload", sidebarTreesFree );
8
9 function initSideBar() {
10         var page = findCurrentPage();
11
12         if( page == MRESULT ) 
13                 unHideMe($("sidebar_results_wrapper"));
14
15         if( page == RRESULT ) {
16                 unHideMe($("sidebar_results_wrapper"));
17                 unHideMe(G.ui.sidebar[MRESULT]);
18                 $("sidebar_title_group_results").setAttribute("href", buildOPACLink({ page: MRESULT }));
19         }
20
21         if( page == RDETAIL ) {
22                 unHideMe($("sidebar_results_wrapper"));
23                 $("sidebar_title_group_results").setAttribute("href", buildOPACLink({ page: MRESULT }));
24                 unHideMe(G.ui.sidebar[MRESULT]);
25                 $("sidebar_title_results").setAttribute("href", buildOPACLink({ page : RRESULT }));
26                 unHideMe(G.ui.sidebar[RRESULT]);
27         }
28
29         unHideMe(G.ui.sidebar[page]);
30         addCSSClass(G.ui.sidebar[page], "sidebar_item_active");
31
32         /* if we're logged in, show it and replace the Login link with the Logout link */
33         if(grabUser()) {
34                 G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
35                 unHideMe(G.ui.sidebar.logoutbox);
36                 unHideMe(G.ui.sidebar.logged_in_as);
37                 hideMe(G.ui.sidebar.loginbox);
38         }
39
40         if(G.ui.sidebar.login) G.ui.sidebar.login.onclick = initLogin;
41         if(G.ui.sidebar.logout) G.ui.sidebar.logout.onclick = doLogout; 
42
43         if(isXUL()) hideMe( G.ui.sidebar.logoutbox );
44 }
45
46 /* sets up the login ui components */
47 var loginBoxVisible = false;
48
49 function loginDance() {
50
51         if(doLogin(true)) {
52
53                 if(!strongPassword( G.ui.login.password.value ) ) {
54
55                         cookieManager.write(COOKIE_SES, "");
56                         hideMe($('login_table'));
57                         unHideMe($('change_pw_table'));
58                         $('change_pw_current').focus();
59                         $('change_pw_button').onclick = changePassword;
60                         setEnterFunc($('change_pw_2'), changePassword);
61
62                 } else {
63                         loggedInOK();
64                 }
65         }
66 }
67
68 function loggedInOK() {
69         showCanvas();
70         G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
71         unHideMe(G.ui.sidebar.logoutbox);
72         unHideMe(G.ui.sidebar.logged_in_as);
73         hideMe(G.ui.sidebar.loginbox);
74         runEvt( "common", "locationChanged", G.user.home_ou(), findOrgDepth(G.user.home_ou()) );
75 }
76
77
78 function changePassword() {
79
80         var pc = $('change_pw_current').value;
81         var p1 = $('change_pw_1').value;
82         var p2 = $('change_pw_2').value;
83
84         if( p1 != p2 ) {
85                 alert($('pw_no_match').innerHTML);
86                 return;
87         }
88
89         if(!strongPassword(p2, true) ) return;
90
91         var req = new Request(UPDATE_PASSWORD, G.user.session, p2, pc );
92         req.send(true);
93         if(req.result()) {
94                 alert($('pw_update_successful').innerHTML);
95                 loggedInOK();
96         }
97 }
98
99 function strongPassword(pass, alrt) {
100         var good = false;
101
102         do {
103
104                 if(pass.length < 7) break;
105                 if(!pass.match(/.*\d+.*/)) break;
106                 if(!pass.match(/.*[A-Za-z]+.*/)) break;
107                 good = true;
108
109         } while(0);
110
111         if(!good && alrt) alert($('pw_not_strong').innerHTML);
112         return good;
113 }
114
115 function initLogin() {
116
117         G.ui.login.button.onclick = loginDance;
118         G.ui.login.username.onkeydown = 
119                 function(evt) {if(userPressedEnter(evt)) loginDance();};
120         G.ui.login.password.onkeydown = 
121                 function(evt) {if(userPressedEnter(evt)) loginDance();};
122
123         if(loginBoxVisible) {
124                 showCanvas();
125         } else {
126                 swapCanvas(G.ui.login.box);
127                 try{G.ui.login.username.focus();}catch(e){}
128         }
129
130         loginBoxVisible = !loginBoxVisible;
131         G.ui.login.cancel.onclick = showCanvas;
132         if(findCurrentPage() == MYOPAC) 
133                 G.ui.login.cancel.onclick = goHome;
134 }
135
136 function setSidebarLinks() {
137         G.ui.sidebar.home_link.setAttribute("href", buildOPACLink({page:HOME}));
138         G.ui.sidebar.advanced_link.setAttribute("href", buildOPACLink({page:ADVANCED}));
139         G.ui.sidebar.myopac_link.setAttribute("href", buildOPACLink({page:MYOPAC}, false, true));
140 }
141
142 function sidebarTreesFree() {
143         removeChildren($(subjectSidebarTree.rootid));
144         removeChildren($(authorSidebarTree.rootid));
145         removeChildren($(seriesSidebarTree.rootid));
146         subjectSidebarTree = null;
147         authorSidebarTree = null;
148         seriesSidebarTree = null;
149 }
150