]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/sidebar.js
3011a953f47c4af8f8f2cfbe49db1ac39091fc2e
[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(getId("sidebar_results_wrapper"));
14
15         if( page == RRESULT ) {
16                 unHideMe(getId("sidebar_results_wrapper"));
17                 unHideMe(G.ui.sidebar[MRESULT]);
18                 getId("sidebar_title_group_results").setAttribute("href", buildOPACLink({ page: MRESULT }));
19         }
20
21         if( page == RDETAIL ) {
22                 unHideMe(getId("sidebar_results_wrapper"));
23                 getId("sidebar_title_group_results").setAttribute("href", buildOPACLink({ page: MRESULT }));
24                 unHideMe(G.ui.sidebar[MRESULT]);
25                 getId("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 }
76
77 function setSidebarLinks() {
78         G.ui.sidebar.home_link.setAttribute("href", buildOPACLink({page:HOME}));
79         G.ui.sidebar.advanced_link.setAttribute("href", buildOPACLink({page:ADVANCED}));
80         G.ui.sidebar.myopac_link.setAttribute("href", buildOPACLink({page:MYOPAC}, false, true));
81 }
82
83 function sidebarTreesFree() {
84         removeChildren($(subjectSidebarTree.rootid));
85         removeChildren($(authorSidebarTree.rootid));
86         removeChildren($(seriesSidebarTree.rootid));
87         subjectSidebarTree = null;
88         authorSidebarTree = null;
89         seriesSidebarTree = null;
90 }
91