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