]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/sidebar.js
3280b50c0007bcb9a857b005a17f3da5e8ca5c73
[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 prevRResults() {
10         return buildOPACLink({ page : RRESULT });
11 }
12
13 function prevMResults() {
14         return buildOPACLink({ page : MRESULT });
15 }
16
17 function initSideBar() {
18         var page = findCurrentPage();
19
20         if( page == MRESULT ) 
21                 unHideMe($("sidebar_results_wrapper"));
22
23         if( page == RRESULT ) {
24                 unHideMe($("sidebar_results_wrapper"));
25                 unHideMe(G.ui.sidebar[MRESULT]);
26                 $("sidebar_title_group_results").setAttribute("href", prevMResults());
27         }
28
29         if( page == RDETAIL ) {
30                 unHideMe($("sidebar_results_wrapper"));
31                 $("sidebar_title_group_results").setAttribute("href", prevMResults());
32                 unHideMe(G.ui.sidebar[MRESULT]);
33                 $("sidebar_title_results").setAttribute("href", prevRResults());
34                 unHideMe(G.ui.sidebar[RRESULT]);
35         }
36
37         unHideMe(G.ui.sidebar[page]);
38         addCSSClass(G.ui.sidebar[page], "sidebar_item_active");
39
40         /* if we're logged in, show it and replace the Login link with the Logout link */
41         if(grabUser()) {
42                 G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
43                 unHideMe(G.ui.sidebar.logoutbox);
44                 unHideMe(G.ui.sidebar.logged_in_as);
45                 hideMe(G.ui.sidebar.loginbox);
46         }
47
48         if(G.ui.sidebar.login) G.ui.sidebar.login.onclick = initLogin;
49         if(G.ui.sidebar.logout) G.ui.sidebar.logout.onclick = doLogout; 
50
51         if(isXUL()) hideMe( G.ui.sidebar.logoutbox );
52 }
53
54 /* sets up the login ui components */
55 var loginBoxVisible = false;
56
57 function loginDance() {
58
59         if(doLogin(true)) {
60
61                 if(!strongPassword( G.ui.login.password.value ) ) {
62
63                         cookieManager.write(COOKIE_SES, "");
64                         hideMe($('login_table'));
65                         unHideMe($('change_pw_table'));
66                         $('change_pw_current').focus();
67                         $('change_pw_button').onclick = changePassword;
68                         setEnterFunc($('change_pw_2'), changePassword);
69
70                 } else {
71                         loggedInOK();
72                 }
73         }
74 }
75
76 function loggedInOK() {
77         showCanvas();
78         G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
79         unHideMe(G.ui.sidebar.logoutbox);
80         unHideMe(G.ui.sidebar.logged_in_as);
81         hideMe(G.ui.sidebar.loginbox);
82         runEvt( 'common', 'loggedIn');
83         
84         var org = G.user.prefs[PREF_DEF_LOCATION];
85         if(!org) org = G.user.home_ou();
86
87         var depth = G.user.prefs[PREF_DEF_DEPTH];
88         if(! ( depth && depth <= findOrgDepth(org)) ) 
89                 depth = findOrgDepth(org);
90
91         runEvt( "common", "locationChanged", org, depth);
92 }
93
94
95 function changePassword() {
96
97         var pc = $('change_pw_current').value;
98         var p1 = $('change_pw_1').value;
99         var p2 = $('change_pw_2').value;
100
101         if( p1 != p2 ) {
102                 alert($('pw_no_match').innerHTML);
103                 return;
104         }
105
106         if(!strongPassword(p2, true) ) return;
107
108         var req = new Request(UPDATE_PASSWORD, G.user.session, p2, pc );
109         req.send(true);
110         if(req.result()) {
111                 alert($('pw_update_successful').innerHTML);
112                 loggedInOK();
113         }
114 }
115
116 function strongPassword(pass, alrt) {
117         var good = false;
118
119         do {
120
121                 if(pass.length < 7) break;
122                 if(!pass.match(/.*\d+.*/)) break;
123                 if(!pass.match(/.*[A-Za-z]+.*/)) break;
124                 good = true;
125
126         } while(0);
127
128         if(!good && alrt) alert($('pw_not_strong').innerHTML);
129         return good;
130 }
131
132 function initLogin() {
133
134         G.ui.login.button.onclick = loginDance;
135         G.ui.login.username.onkeydown = 
136                 function(evt) {if(userPressedEnter(evt)) loginDance();};
137         G.ui.login.password.onkeydown = 
138                 function(evt) {if(userPressedEnter(evt)) loginDance();};
139
140         if(loginBoxVisible) {
141                 showCanvas();
142         } else {
143                 swapCanvas(G.ui.login.box);
144                 try{G.ui.login.username.focus();}catch(e){}
145         }
146
147         loginBoxVisible = !loginBoxVisible;
148         G.ui.login.cancel.onclick = showCanvas;
149         if(findCurrentPage() == MYOPAC) 
150                 G.ui.login.cancel.onclick = goHome;
151 }
152
153 function setSidebarLinks() {
154         G.ui.sidebar.home_link.setAttribute("href", buildOPACLink({page:HOME}));
155         G.ui.sidebar.advanced_link.setAttribute("href", buildOPACLink({page:ADVANCED}));
156         G.ui.sidebar.myopac_link.setAttribute("href", buildOPACLink({page:MYOPAC}, false, true));
157 }
158
159 function sidebarTreesFree() {
160         removeChildren($(subjectSidebarTree.rootid));
161         removeChildren($(authorSidebarTree.rootid));
162         removeChildren($(seriesSidebarTree.rootid));
163         subjectSidebarTree = null;
164         authorSidebarTree = null;
165         seriesSidebarTree = null;
166 }
167
168
169
170
171 /* --------------------------------------------------------------------------------- */
172 /* Code to support GALILEO links for PINES.  Fails gracefully
173 /* --------------------------------------------------------------------------------- */
174 attachEvt('common', 'init', buildEGGalLink);
175 function buildEGGalLink() {
176
177         /* we're in a lib, nothing to do here */
178         if( getOrigLocation() ) return;
179         if(!$('eg_gal_link')) return;
180
181         var link = 'http://demo.galib.uga.edu/express?pinesid=';
182         if(grabUser()) {
183                 $('eg_gal_link').setAttribute('href', link + G.user.session);
184                 return;
185         }
186
187         $('eg_gal_link').setAttribute('href', 'javascript:void(0);');
188         $('eg_gal_link').setAttribute('target', '');
189         $('eg_gal_link').onclick = function() {
190                 /* we're not logged in.  go ahead and login */
191                 detachAllEvt('common','locationChanged');
192                 detachAllEvt('common','loggedIn');
193                 attachEvt('common','loggedIn', function() { goTo(link + G.user.session); })
194                 initLogin();
195         };
196 }
197 /* --------------------------------------------------------------------------------- */
198
199