]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/GlobalInit.js
fixin and makin purdy
[Evergreen.git] / Open-ILS / src / javascript / opac / GlobalInit.js
1 /* */
2
3 var globalPage                                          = null; /* the current top level page object */
4 var globalUser                                          = null; /* the user session */
5 var globalOrgTreeWidget                 = null;
6 var globalLocation                              = null;
7 var globalOrgTreeWidgetBox              = null;
8 var globalSelectedLocation              = null;
9 var globalSearchDepth                   = null;
10 var globalMenuManager                   = null;
11 var globalCopyStatus                            = null;
12 var locationStack                                       = new Array();
13
14 var lastSearchString                            = null;
15 var lastSearchType                              = null;
16
17 /* this is true if we directed to the record detail page
18         becuase of only having one hit on the record result
19         page.  this allows us to back up from the detail
20         page to the mr_result page */
21 var recordResultRedirect = false;
22
23 var loaded = false;
24
25
26 function addLocation(type, title) {
27         try { 
28                 if(globalAppFrame) {
29                         var obj = new Object();
30                         obj.location = globalAppFrame.location.href;
31                         obj.title = title;
32                         locationStack[type] = obj;
33                 }
34         } catch(E){}
35
36 }
37
38 function _test() {
39         debug("At: " + (new RegExp(".+").exec(
40                         arguments.callee.toString()))[0].replace("{", "") );
41 }
42
43
44 function globalInit() {
45
46
47         _test();
48         debug(" --- XUL IS " + isXUL() );
49
50
51         if( isXUL() && globalAppFrame )
52                 globalAppFrame.document.body.style.background = "#FFF";
53
54         getDocument().body.onunload = cleanIEMemory;
55
56
57         var page_name = globalPageTarget;
58
59         if(!page_name) 
60                 throw new EXArg("globalInit requires globalPageTarget to be set");
61
62         debug("globalInit init-ing page: " + page_name );
63
64         switch( page_name ) {
65
66                 case "start":
67                         globalPage = new OPACStartPage();
68                         addLocation("start", "Home");
69                         locationStack["advanced_search"] = null;
70                         break;
71
72                 case  "advanced_search":
73                         globalPage = new AdvancedSearchPage();
74                         addLocation("advanced_search", "Advanced Search");
75                         locationStack["start"] = null;
76                         break;
77
78                 case  "mr_result":
79                         //globalPage = new MRResultPage();
80                         globalPage = MRResultPage.instance();
81                         addLocation("mr_result", "Title Group Results");
82                         break;
83
84                 case  "record_result":
85                         //globalPage = new RecordResultPage();
86                         globalPage = RecordResultPage.instance();
87                         addLocation("record_result", "Title Results");
88                         break;
89
90                 case  "login":
91                         globalPage = new LoginPage();
92                         break;
93
94                 case  "logout":
95                         globalPage = new LogoutPage();
96                         break;
97
98                 case  "my_opac":
99                         globalPage = new MyOPACPage();
100                         break;
101
102                 case "record_detail":
103                         globalPage = new RecordDetailPage();
104                         addLocation("record_detail", "Title Details");
105                         break;
106
107                 case  "about":
108                         globalPage = new AboutPage();
109                         break;
110
111                 }
112
113         if( ! globalPage ) 
114                 throw new EXArg(
115                         "globalInit requires a valid page target: " + page_name );
116
117         if(!loaded) { loaded = true; GlobalInitLoad(); }
118
119         globalMenuManager = new ContextMenuManager();
120
121         /* hide all context menus on body click */
122         getDocument().body.onclick = function() {
123                         globalMenuManager.hideAll(); 
124         }
125
126         globalPage.init();
127
128         if(paramObj.__location != null) {
129                 globalSelectedLocation = findOrgUnit(paramObj.__location);
130                 if(globalSelectedLocation == null) 
131                         debug("Invalid location in url : " + paramObj.__location);
132                 else
133                         debug("Setting selected location to " + globalSelectedLocation.name() );
134         } 
135
136
137         if(paramObj.__depth != null) {
138                 debug("Passed in depth from search params: " + paramObj.__depth);
139                 globalSearchDepth = parseInt(paramObj.__depth);
140                 debug("Setting selected depth to " + globalSearchDepth );
141         }
142
143         globalPage.setLocDisplay();
144         globalPage.locationTree = globalOrgTreeWidget;
145         globalPage.setPageTrail();
146
147         if(globalSearchBarChunk)
148                 globalSearchBarChunk.reset();
149         
150         if( globalSearchBarFormChunk != null)
151                 globalSearchBarFormChunk.resetPage();
152
153
154
155 }
156
157
158 /* we only do this on loading of the outer frame (i.e. only once) */
159 function GlobalInitLoad() {
160
161         debug("Global Init is doing its primary load");
162         globalOrgTreeWidget = new LocationTree(globalOrgTree);
163         globalUser = UserSession.instance();
164
165         var ses = null;
166         var org = null;
167
168         if(isXUL()) {
169                 ses = G['auth_ses'][0]; /* G is shoved in by XUL */
170                 org = G['user_ou']; /* the desired location of the user */
171         }
172
173         if(globalUser.verifySession(ses)) {
174                 globalUser.grabOrgUnit(org);
175
176         } else  {
177                 globalUser = null;
178                 globalLocation = globalOrgTree;
179                 if(globalSearchDepth == null)
180                         globalSearchDepth = findOrgDepth(globalOrgTree.ou_type());
181         }
182
183         grabCopyStatus();
184
185 }
186
187 function grabCopyStatus() {
188         if(globalCopyStatus) return;
189
190         debug("Grabbing copy statuses");
191         var req = new RemoteRequest(
192                 "open-ils.search",
193                 "open-ils.search.config.copy_status.retrieve.all" );
194
195         if(paramObj.__sub_frame) {
196                 /* we have to grab the copy statuses synchronously */
197                 req.send(true);
198                 globalCopyStatus = r.getResultObject();
199
200         } else {
201
202                 req.setCompleteCallback(function(r) { 
203                         debug("Got globalCopyStatus");
204                         globalCopyStatus = r.getResultObject(); });
205         
206                 req.send();
207         }
208
209
210 }
211
212
213