1 /* set up the colors in the sidebar
2 Disables/Enables certain components based on various state data */
4 attachEvt("common", "init", initSideBar);
5 attachEvt("common", "init", setSidebarLinks);
7 attachEvt("common", "unload", sidebarTreesFree );
9 function initSideBar() {
10 var page = findCurrentPage();
13 unHideMe($("sidebar_results_wrapper"));
15 if( page == RRESULT ) {
16 unHideMe($("sidebar_results_wrapper"));
17 unHideMe(G.ui.sidebar[MRESULT]);
18 $("sidebar_title_group_results").setAttribute("href", buildOPACLink({ page: MRESULT }));
21 if( page == RDETAIL ) {
22 unHideMe($("sidebar_results_wrapper"));
23 $("sidebar_title_group_results").setAttribute("href", buildOPACLink({ page: MRESULT }));
24 unHideMe(G.ui.sidebar[MRESULT]);
25 $("sidebar_title_results").setAttribute("href", buildOPACLink({ page : RRESULT }));
26 unHideMe(G.ui.sidebar[RRESULT]);
29 unHideMe(G.ui.sidebar[page]);
30 addCSSClass(G.ui.sidebar[page], "sidebar_item_active");
32 /* if we're logged in, show it and replace the Login link with the Logout link */
34 G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
35 unHideMe(G.ui.sidebar.logoutbox);
36 unHideMe(G.ui.sidebar.logged_in_as);
37 hideMe(G.ui.sidebar.loginbox);
40 if(G.ui.sidebar.login) G.ui.sidebar.login.onclick = initLogin;
41 if(G.ui.sidebar.logout) G.ui.sidebar.logout.onclick = doLogout;
43 if(isXUL()) hideMe( G.ui.sidebar.logoutbox );
46 /* sets up the login ui components */
47 var loginBoxVisible = false;
49 function loginDance() {
53 if(!strongPassword( G.ui.login.password.value ) ) {
55 cookieManager.write(COOKIE_SES, "");
56 hideMe($('login_table'));
57 unHideMe($('change_pw_table'));
58 $('change_pw_current').focus();
59 $('change_pw_button').onclick = changePassword;
60 setEnterFunc($('change_pw_2'), changePassword);
68 function loggedInOK() {
70 G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
71 unHideMe(G.ui.sidebar.logoutbox);
72 unHideMe(G.ui.sidebar.logged_in_as);
73 hideMe(G.ui.sidebar.loginbox);
74 runEvt( 'common', 'loggedIn');
75 runEvt( "common", "locationChanged", G.user.home_ou(), findOrgDepth(G.user.home_ou()) );
79 function changePassword() {
81 var pc = $('change_pw_current').value;
82 var p1 = $('change_pw_1').value;
83 var p2 = $('change_pw_2').value;
86 alert($('pw_no_match').innerHTML);
90 if(!strongPassword(p2, true) ) return;
92 var req = new Request(UPDATE_PASSWORD, G.user.session, p2, pc );
95 alert($('pw_update_successful').innerHTML);
100 function strongPassword(pass, alrt) {
105 if(pass.length < 7) break;
106 if(!pass.match(/.*\d+.*/)) break;
107 if(!pass.match(/.*[A-Za-z]+.*/)) break;
112 if(!good && alrt) alert($('pw_not_strong').innerHTML);
116 function initLogin() {
118 G.ui.login.button.onclick = loginDance;
119 G.ui.login.username.onkeydown =
120 function(evt) {if(userPressedEnter(evt)) loginDance();};
121 G.ui.login.password.onkeydown =
122 function(evt) {if(userPressedEnter(evt)) loginDance();};
124 if(loginBoxVisible) {
127 swapCanvas(G.ui.login.box);
128 try{G.ui.login.username.focus();}catch(e){}
131 loginBoxVisible = !loginBoxVisible;
132 G.ui.login.cancel.onclick = showCanvas;
133 if(findCurrentPage() == MYOPAC)
134 G.ui.login.cancel.onclick = goHome;
137 function setSidebarLinks() {
138 G.ui.sidebar.home_link.setAttribute("href", buildOPACLink({page:HOME}));
139 G.ui.sidebar.advanced_link.setAttribute("href", buildOPACLink({page:ADVANCED}));
140 G.ui.sidebar.myopac_link.setAttribute("href", buildOPACLink({page:MYOPAC}, false, true));
143 function sidebarTreesFree() {
144 removeChildren($(subjectSidebarTree.rootid));
145 removeChildren($(authorSidebarTree.rootid));
146 removeChildren($(seriesSidebarTree.rootid));
147 subjectSidebarTree = null;
148 authorSidebarTree = null;
149 seriesSidebarTree = null;