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