]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/lib/js/opac/search_bar.js
lots of simple web enhancements, org tree loaded and working
[working/Evergreen.git] / Open-ILS / src / javascript / lib / js / opac / search_bar.js
1
2 var searchBarExpanded = false;
3 var searchBarTable;
4 var searchBarTagLink;
5 var searchBarExtraRow;
6 var searchBarMainRow;
7
8 var typeSelector;
9 var depthSelector;
10 var formSelector;
11 var orgTreeVisible = false;
12
13 /* if set by the org selector, this will be the location used the
14         next time the search is submitted */
15 var newSearchLocation; 
16
17 function searchBarInit() {
18
19         G.ui.searchbar.text.focus();
20         G.ui.searchbar.text.onkeydown = 
21                 function(evt) {if(userPressedEnter(evt)) searchBarSubmit();};
22         G.ui.searchbar.submit.onclick = searchBarSubmit;
23
24         searchBarTable          = G.ui.searchbar.table;
25         searchBarTagLink        = G.ui.searchbar.tag;
26         searchBarExtraRow = G.ui.searchbar.extra_row;
27         searchBarMainRow        = G.ui.searchbar.main_row;
28
29         typeSelector = G.ui.searchbar.type_selector;
30         depthSelector = G.ui.searchbar.depth_selector;
31         formSelector = G.ui.searchbar.form_selector;
32
33         searchBarTagLink.onclick = function(){searchBarToggle();}
34
35         /* set up the selector objects, etc */
36         var t = getTerm();
37         if(t == null) t = "";
38         G.ui.searchbar.text.value = t;
39         setSelector(typeSelector,       getStype());
40         setSelector(depthSelector, getDepth());
41         setSelector(formSelector,       getForm());
42
43         //typeSelector.onchange = function(){searchBarSelectorChanged("type");};
44         //depthSelector.onchange        = function(){searchBarSelectorChanged("depth");};
45         //formSelector.onchange = function(){searchBarSelectorChanged("form");};
46
47         if(getSearchBarExtras()) searchBarToggle();
48
49         G.ui.searchbar.location_tag.onclick = function() {
50                 if(orgTreeVisible) showCanvas();        
51                  else swapCanvas(G.ui.common.org_tree);
52                 orgTreeVisible = !orgTreeVisible;
53         }
54 }
55
56 /*
57 function searchBarSelectorChanged(type) {
58
59         var args = {};
60         switch( type ) {
61
62                 case "type": 
63                         args[PARAM_STYPE] = typeSelector.options[typeSelector.selectedIndex].value
64                         break;
65
66                 case "depth": 
67                         args[PARAM_DEPTH] = parseInt(depthSelector.options[depthSelector.selectedIndex].value);
68                         break;
69
70                 case "form": 
71                         args[PARAM_FORM] = formSelector.options[formSelector.selectedIndex].value;
72                         break;
73         }
74
75         args[PARAM_OFFSET] = 0;
76
77         if(findCurrentPage() == MRESULT || findCurrentPage() == RRESULT )
78                 goTo(buildOPACLink(args));
79 }
80 */
81
82 function searchBarSubmit() {
83         var text = G.ui.searchbar.text.value;
84         if(!text || text == "") return;
85         var type_s = G.ui.searchbar.type_selector;
86
87         var args = {};
88         args.page = MRESULT;
89         args[PARAM_OFFSET] = 0;
90         args[PARAM_TERM] = text;
91         args[PARAM_STYPE] = type_s.options[type_s.selectedIndex].value;
92         args[PARAM_LOCATION] = newSearchLocation;
93
94         args[PARAM_DEPTH] = parseInt(depthSelector.options[depthSelector.selectedIndex].value);
95         args[PARAM_FORM] = formSelector.options[formSelector.selectedIndex].value;
96         goTo(buildOPACLink(args));
97 }
98
99
100 function searchBarToggle() {
101
102         if(searchBarExpanded) {
103
104                 hideMe(searchBarExtraRow);
105                 searchBarExpanded = false;
106                 hideMe(G.ui.searchbar.tag_on);
107                 unHideMe(G.ui.searchbar.tag_off);
108                 //SEARCHBAR_EXTRAS = 0; set cookie...
109
110         } else {
111
112                 removeCSSClass(searchBarExtraRow,config.css.hide_me);
113                 searchBarExpanded = true;
114                 hideMe(G.ui.searchbar.tag_off);
115                 unHideMe(G.ui.searchbar.tag_on);
116                 //SEARCHBAR_EXTRAS = 1; set cookie...
117         }
118 }
119
120