]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/sidebar.js
f11aaee952cd16d739dee97a4cc1967dfcb4b332
[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 initSideBar() {
10         var page = findCurrentPage();
11
12         if( page == MRESULT ) 
13                 unHideMe($("sidebar_results_wrapper"));
14
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 }));
19         }
20
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]);
27         }
28
29         unHideMe(G.ui.sidebar[page]);
30         addCSSClass(G.ui.sidebar[page], "sidebar_item_active");
31
32         /* if we're logged in, show it and replace the Login link with the Logout link */
33         if(grabUser()) {
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);
38         }
39
40         if(G.ui.sidebar.login) G.ui.sidebar.login.onclick = initLogin;
41         if(G.ui.sidebar.logout) G.ui.sidebar.logout.onclick = doLogout; 
42 }
43
44 /* sets up the login ui components */
45 var loginBoxVisible = false;
46
47 function loginDance() {
48         if(doLogin()) {
49                 showCanvas();
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                 runEvt("common", "loggedIn");
55         }
56 }
57
58 function initLogin() {
59
60         G.ui.login.button.onclick = loginDance;
61         G.ui.login.username.onkeydown = 
62                 function(evt) {if(userPressedEnter(evt)) loginDance();};
63         G.ui.login.password.onkeydown = 
64                 function(evt) {if(userPressedEnter(evt)) loginDance();};
65
66         if(loginBoxVisible) {
67                 showCanvas();
68         } else {
69                 swapCanvas(G.ui.login.box);
70                 try{G.ui.login.username.focus();}catch(e){}
71         }
72
73         loginBoxVisible = !loginBoxVisible;
74         G.ui.login.cancel.onclick = showCanvas;
75         if(findCurrentPage() == MYOPAC) 
76                 G.ui.login.cancel.onclick = goHome;
77 }
78
79 function setSidebarLinks() {
80         G.ui.sidebar.home_link.setAttribute("href", buildOPACLink({page:HOME}));
81         G.ui.sidebar.advanced_link.setAttribute("href", buildOPACLink({page:ADVANCED}));
82         G.ui.sidebar.myopac_link.setAttribute("href", buildOPACLink({page:MYOPAC}, false, true));
83 }
84
85 function sidebarTreesFree() {
86         removeChildren($(subjectSidebarTree.rootid));
87         removeChildren($(authorSidebarTree.rootid));
88         removeChildren($(seriesSidebarTree.rootid));
89         subjectSidebarTree = null;
90         authorSidebarTree = null;
91         seriesSidebarTree = null;
92 }
93