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