]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/sidebar.js
added useful wrapper method
[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         if(isXUL()) hideMe( G.ui.sidebar.logoutbox );
44 }
45
46 /* sets up the login ui components */
47 var loginBoxVisible = false;
48
49 function loginDance() {
50         if(doLogin()) {
51                 showCanvas();
52                 G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
53                 unHideMe(G.ui.sidebar.logoutbox);
54                 unHideMe(G.ui.sidebar.logged_in_as);
55                 hideMe(G.ui.sidebar.loginbox);
56                 runEvt("common", "loggedIn");
57         }
58 }
59
60 function initLogin() {
61
62         G.ui.login.button.onclick = loginDance;
63         G.ui.login.username.onkeydown = 
64                 function(evt) {if(userPressedEnter(evt)) loginDance();};
65         G.ui.login.password.onkeydown = 
66                 function(evt) {if(userPressedEnter(evt)) loginDance();};
67
68         if(loginBoxVisible) {
69                 showCanvas();
70         } else {
71                 swapCanvas(G.ui.login.box);
72                 try{G.ui.login.username.focus();}catch(e){}
73         }
74
75         loginBoxVisible = !loginBoxVisible;
76         G.ui.login.cancel.onclick = showCanvas;
77         if(findCurrentPage() == MYOPAC) 
78                 G.ui.login.cancel.onclick = goHome;
79 }
80
81 function setSidebarLinks() {
82         G.ui.sidebar.home_link.setAttribute("href", buildOPACLink({page:HOME}));
83         G.ui.sidebar.advanced_link.setAttribute("href", buildOPACLink({page:ADVANCED}));
84         G.ui.sidebar.myopac_link.setAttribute("href", buildOPACLink({page:MYOPAC}, false, true));
85 }
86
87 function sidebarTreesFree() {
88         removeChildren($(subjectSidebarTree.rootid));
89         removeChildren($(authorSidebarTree.rootid));
90         removeChildren($(seriesSidebarTree.rootid));
91         subjectSidebarTree = null;
92         authorSidebarTree = null;
93         seriesSidebarTree = null;
94 }
95