]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/sidebar.js
Initial external authentication support via proxy
[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 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             dojo.require('dojo.cookie');
72                         dojo.cookie(COOKIE_SES, "");
73                         hideMe($('login_table'));
74                         unHideMe($('change_pw_table'));
75                         $('change_pw_current').focus();
76                         $('change_pw_button').onclick = changePassword;
77                         setEnterFunc($('change_pw_2'), changePassword);
78
79                 } else {
80                         loggedInOK();
81                 }
82         }
83 }
84
85 function loggedInOK() {
86         if (!location.href.match(/&show_login=1/)) {
87                 showCanvas();
88                 G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
89                 unHideMe(G.ui.sidebar.logoutbox);
90                 unHideMe(G.ui.sidebar.logged_in_as);
91                 hideMe(G.ui.sidebar.loginbox);
92         }
93         runEvt( 'common', 'loggedIn');
94         
95         var org = G.user.prefs[PREF_DEF_LOCATION];
96         if(!org) org = G.user.home_ou();
97
98         var depth = G.user.prefs[PREF_DEF_DEPTH];
99         if(! ( depth && depth <= findOrgDepth(org)) ) 
100                 depth = findOrgDepth(org);
101
102         runEvt( "common", "locationChanged", org, depth);
103         if (location.href.match(/&show_login=1/)) {
104                 // this redirect should only happen if the runEvt above didn't already
105                 // trigger one
106                 goTo(location.href.replace(/&show_login=1/, ''));
107         }
108 }
109
110
111 function changePassword() {
112
113         var pc = $('change_pw_current').value;
114         var p1 = $('change_pw_1').value;
115         var p2 = $('change_pw_2').value;
116
117         if( p1 != p2 ) {
118                 alert($('pw_no_match').innerHTML);
119                 return;
120         }
121
122         if(!strongPassword(p2, true) ) return;
123
124         var req = new Request(UPDATE_PASSWORD, G.user.session, p2, pc );
125         req.send(true);
126         if(req.result()) {
127                 alert($('pw_update_successful').innerHTML);
128                 loggedInOK();
129         }
130 }
131
132 var pwRegexSetting;
133 function strongPassword(pass, alrt) {
134
135     /* first, let's see if there is a configured regex */
136     if(!pwRegexSetting) {
137         var regex = fetchOrgSettingDefault(G.user.home_ou(), 'global.password_regex');
138         if(regex) {
139             if(pass.match(new RegExp(regex))) {
140                 return true;
141             } else {
142                 if(alrt)
143                        alert($('pw_not_strong').innerHTML);
144                 return false;
145             }
146         }
147     }
148
149     /* no regex configured, use the default */
150
151         var good = false;
152
153         do {
154
155                 if(pass.length < 7) break;
156                 if(!pass.match(/.*\d+.*/)) break;
157                 if(!pass.match(/.*[A-Za-z]+.*/)) break;
158                 good = true;
159
160         } while(0);
161
162         if(!good && alrt) alert($('pw_not_strong').innerHTML);
163         return good;
164 }
165
166 function initLogin() {
167     var src = location.href;
168     if(forceLoginSSL && src.match(/^http:/)) {
169         src = src.replace(/^http:/, 'https:');
170         if(!src.match(/&show_login=1/)) {
171             src += '&show_login=1';
172         }
173         goTo(src);
174         return false;
175     }
176
177     swapCanvas(G.ui.login.box);
178     try{G.ui.login.username.focus();} catch(e) {}
179
180     G.ui.login.cancel.onclick = function(evt) { 
181         G.ui.login.form.setAttribute('action',
182             'javascript:showCanvas();runEvt("common", "loginCanceled");'); 
183     };
184
185     if(findCurrentPage() == MYOPAC) {
186         G.ui.login.cancel.onclick = function(evt) { 
187             G.ui.login.form.setAttribute('action','javascript:goHome();'); };
188     }
189 }
190
191 function setSidebarLinks() {
192         G.ui.sidebar.home_link.setAttribute("href", buildOPACLink({page:HOME}));
193         G.ui.sidebar.advanced_link.setAttribute("href", buildOPACLink({page:ADVANCED}));
194         G.ui.sidebar.myopac_link.setAttribute("href", buildOPACLink({page:MYOPAC}, false, true));
195 }
196
197 function sidebarTreesFree() {
198 /*
199         removeChildren($(subjectSidebarTree.rootid));
200         removeChildren($(authorSidebarTree.rootid));
201         removeChildren($(seriesSidebarTree.rootid));
202         subjectSidebarTree = null;
203         authorSidebarTree = null;
204         seriesSidebarTree = null;
205 */
206 }
207
208
209
210
211 /* --------------------------------------------------------------------------------- */
212 /* Code to support GALILEO links for PINES.  Fails gracefully
213 /* --------------------------------------------------------------------------------- */
214 attachEvt('common', 'init', buildEGGalLink);
215 function buildEGGalLink() {
216
217         /* we're in a lib, nothing to do here */
218         if( getOrigLocation() ) return;
219         if(!$('eg_gal_link')) return;
220
221         //var link = 'http://demo.galib.uga.edu/express?pinesid=';
222         var link = 'http://www.galileo.usg.edu/express?pinesid=';
223         if(grabUser()) {
224                 $('eg_gal_link').setAttribute('href', link + G.user.session);
225                 return;
226         }
227
228         $('eg_gal_link').setAttribute('href', 'javascript:void(0);');
229         $('eg_gal_link').setAttribute('target', '');
230         $('eg_gal_link').onclick = function() {
231                 /* we're not logged in.  go ahead and login */
232                 detachAllEvt('common','locationChanged');
233                 detachAllEvt('common','loggedIn');
234                 attachEvt('common','loggedIn', function() { goTo(link + G.user.session); })
235                 initLogin();
236         };
237 }
238 /* --------------------------------------------------------------------------------- */
239
240