]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/sidebar.js
fixed place hold bug where loggin in does not bring up hold box
[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', 'loggedIn');
75         runEvt( "common", "locationChanged", G.user.home_ou(), findOrgDepth(G.user.home_ou()) );
76 }
77
78
79 function changePassword() {
80
81         var pc = $('change_pw_current').value;
82         var p1 = $('change_pw_1').value;
83         var p2 = $('change_pw_2').value;
84
85         if( p1 != p2 ) {
86                 alert($('pw_no_match').innerHTML);
87                 return;
88         }
89
90         if(!strongPassword(p2, true) ) return;
91
92         var req = new Request(UPDATE_PASSWORD, G.user.session, p2, pc );
93         req.send(true);
94         if(req.result()) {
95                 alert($('pw_update_successful').innerHTML);
96                 loggedInOK();
97         }
98 }
99
100 function strongPassword(pass, alrt) {
101         var good = false;
102
103         do {
104
105                 if(pass.length < 7) break;
106                 if(!pass.match(/.*\d+.*/)) break;
107                 if(!pass.match(/.*[A-Za-z]+.*/)) break;
108                 good = true;
109
110         } while(0);
111
112         if(!good && alrt) alert($('pw_not_strong').innerHTML);
113         return good;
114 }
115
116 function initLogin() {
117
118         G.ui.login.button.onclick = loginDance;
119         G.ui.login.username.onkeydown = 
120                 function(evt) {if(userPressedEnter(evt)) loginDance();};
121         G.ui.login.password.onkeydown = 
122                 function(evt) {if(userPressedEnter(evt)) loginDance();};
123
124         if(loginBoxVisible) {
125                 showCanvas();
126         } else {
127                 swapCanvas(G.ui.login.box);
128                 try{G.ui.login.username.focus();}catch(e){}
129         }
130
131         loginBoxVisible = !loginBoxVisible;
132         G.ui.login.cancel.onclick = showCanvas;
133         if(findCurrentPage() == MYOPAC) 
134                 G.ui.login.cancel.onclick = goHome;
135 }
136
137 function setSidebarLinks() {
138         G.ui.sidebar.home_link.setAttribute("href", buildOPACLink({page:HOME}));
139         G.ui.sidebar.advanced_link.setAttribute("href", buildOPACLink({page:ADVANCED}));
140         G.ui.sidebar.myopac_link.setAttribute("href", buildOPACLink({page:MYOPAC}, false, true));
141 }
142
143 function sidebarTreesFree() {
144         removeChildren($(subjectSidebarTree.rootid));
145         removeChildren($(authorSidebarTree.rootid));
146         removeChildren($(seriesSidebarTree.rootid));
147         subjectSidebarTree = null;
148         authorSidebarTree = null;
149         seriesSidebarTree = null;
150 }
151