]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/sidebar.js
added next / previous links on details page. started support for copy and volume...
[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                 $("sidebar_title_group_results").setAttribute("href", prevMResults());
27         }
28
29         if( page == RDETAIL ) {
30                 unHideMe($("sidebar_results_wrapper"));
31                 $("sidebar_title_group_results").setAttribute("href", prevMResults());
32                 unHideMe(G.ui.sidebar[MRESULT]);
33                 $("sidebar_title_results").setAttribute("href", prevRResults());
34                 unHideMe(G.ui.sidebar[RRESULT]);
35         }
36
37         unHideMe(G.ui.sidebar[page]);
38         addCSSClass(G.ui.sidebar[page], "sidebar_item_active");
39
40         /* if we're logged in, show it and replace the Login link with the Logout link */
41         if(grabUser()) {
42                 G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
43                 unHideMe(G.ui.sidebar.logoutbox);
44                 unHideMe(G.ui.sidebar.logged_in_as);
45                 hideMe(G.ui.sidebar.loginbox);
46         }
47
48         if(G.ui.sidebar.login) G.ui.sidebar.login.onclick = initLogin;
49         if(G.ui.sidebar.logout) G.ui.sidebar.logout.onclick = doLogout; 
50
51         if(isXUL()) hideMe( G.ui.sidebar.logoutbox );
52 }
53
54 /* sets up the login ui components */
55 var loginBoxVisible = false;
56
57 function loginDance() {
58
59         if(doLogin(true)) {
60
61                 if(!strongPassword( G.ui.login.password.value ) ) {
62
63                         cookieManager.write(COOKIE_SES, "");
64                         hideMe($('login_table'));
65                         unHideMe($('change_pw_table'));
66                         $('change_pw_current').focus();
67                         $('change_pw_button').onclick = changePassword;
68                         setEnterFunc($('change_pw_2'), changePassword);
69
70                 } else {
71                         loggedInOK();
72                 }
73         }
74 }
75
76 function loggedInOK() {
77         showCanvas();
78         G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
79         unHideMe(G.ui.sidebar.logoutbox);
80         unHideMe(G.ui.sidebar.logged_in_as);
81         hideMe(G.ui.sidebar.loginbox);
82         runEvt( 'common', 'loggedIn');
83         runEvt( "common", "locationChanged", G.user.home_ou(), findOrgDepth(G.user.home_ou()) );
84 }
85
86
87 function changePassword() {
88
89         var pc = $('change_pw_current').value;
90         var p1 = $('change_pw_1').value;
91         var p2 = $('change_pw_2').value;
92
93         if( p1 != p2 ) {
94                 alert($('pw_no_match').innerHTML);
95                 return;
96         }
97
98         if(!strongPassword(p2, true) ) return;
99
100         var req = new Request(UPDATE_PASSWORD, G.user.session, p2, pc );
101         req.send(true);
102         if(req.result()) {
103                 alert($('pw_update_successful').innerHTML);
104                 loggedInOK();
105         }
106 }
107
108 function strongPassword(pass, alrt) {
109         var good = false;
110
111         do {
112
113                 if(pass.length < 7) break;
114                 if(!pass.match(/.*\d+.*/)) break;
115                 if(!pass.match(/.*[A-Za-z]+.*/)) break;
116                 good = true;
117
118         } while(0);
119
120         if(!good && alrt) alert($('pw_not_strong').innerHTML);
121         return good;
122 }
123
124 function initLogin() {
125
126         G.ui.login.button.onclick = loginDance;
127         G.ui.login.username.onkeydown = 
128                 function(evt) {if(userPressedEnter(evt)) loginDance();};
129         G.ui.login.password.onkeydown = 
130                 function(evt) {if(userPressedEnter(evt)) loginDance();};
131
132         if(loginBoxVisible) {
133                 showCanvas();
134         } else {
135                 swapCanvas(G.ui.login.box);
136                 try{G.ui.login.username.focus();}catch(e){}
137         }
138
139         loginBoxVisible = !loginBoxVisible;
140         G.ui.login.cancel.onclick = showCanvas;
141         if(findCurrentPage() == MYOPAC) 
142                 G.ui.login.cancel.onclick = goHome;
143 }
144
145 function setSidebarLinks() {
146         G.ui.sidebar.home_link.setAttribute("href", buildOPACLink({page:HOME}));
147         G.ui.sidebar.advanced_link.setAttribute("href", buildOPACLink({page:ADVANCED}));
148         G.ui.sidebar.myopac_link.setAttribute("href", buildOPACLink({page:MYOPAC}, false, true));
149 }
150
151 function sidebarTreesFree() {
152         removeChildren($(subjectSidebarTree.rootid));
153         removeChildren($(authorSidebarTree.rootid));
154         removeChildren($(seriesSidebarTree.rootid));
155         subjectSidebarTree = null;
156         authorSidebarTree = null;
157         seriesSidebarTree = null;
158 }
159