]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/opac/Page.js
more webby goodness
[working/Evergreen.git] / Open-ILS / src / javascript / opac / Page.js
1 /* Top level page object.  All pages descend from this class */
2
3 function Page() {}
4
5 Page.prototype.init = function() {
6         debug("Falling back to Page.init()");
7 }
8
9 /* override me */
10 Page.prototype.instance = function() {
11         throw new EXAbstract(
12                         "instance() must be overridden by all Page subclasses");
13 }
14
15
16 /* XXX move me to the status bar */
17 Page.prototype.updateSelectedLocation = function(org) {
18         var node;
19         if( typeof org == 'object' ) node = org;
20         else node = getOrgById(org);
21         globalSelectedLocation = node;
22         globalSearchDepth = findOrgType(node.ou_type()).depth();
23         this.setLocDisplay();
24 }
25
26 Page.prototype.updateCurrentLocation = function(org) {
27         if( typeof org == 'object' ) node = org;
28         else node = getOrgById(orgid);
29         globalLocation = node;
30         this.setLocDisplay();
31 }
32         
33
34 /* tells the user where he is searching */
35 Page.prototype.setLocDisplay = function(name) {
36
37         debug("Setting loc display on the status bar");
38         this.searchingCell = getById("now_searching_cell");
39
40         if( this.searchingCell == null ) return;
41         var name;
42         
43         var orgunit;
44         if( globalSelectedLocation )
45                 orgunit = globalSelectedLocation;
46         else { orgunit = globalLocation; }
47
48         this.searchingCell.innerHTML = 
49                 "Now Searching <span class='breadcrumb_label'>" + orgunit.name() + "</span>";
50
51         this.resetRange();
52         return;
53
54
55
56
57         var arr = orgNodeTrail(orgunit);
58
59         this.searchingCell.innerHTML = "";
60         var names = new Array()
61         for( var i in arr) 
62                 names.push(arr[i].name());
63
64         this.searchingCell.innerHTML = 
65                 "<span class='breadcrumb_label'>" + 
66                 names.join("</span> / <span class='breadcrumb_label'>") + 
67                 "</span>";
68
69         this.resetRange();
70
71 }
72
73 Page.prototype.resetRange = function() {
74
75         this.searchRange                        = getById("search_range_select");
76
77         while( this.searchRange.options.length ) {
78                 this.searchRange.options[0] = null;
79         }
80
81         var orgunit = globalSelectedLocation;
82         if(!orgunit)
83                 orgunit = globalLocation;
84
85         debug("Reseting search range with search location " + orgunit);
86         debug("Resetting search range with search depth " + globalSearchDepth );
87
88         var selectedOption = null;
89
90         if(this.searchRange) {
91
92                 for( var index in globalOrgTypes ) {
93                         var otype = globalOrgTypes[index];
94
95                         if( otype.depth() > findOrgType(orgunit.ou_type()).depth() )
96                                 continue;
97
98                         var select =  new Option(otype.opac_label(), otype.depth());
99                         this.searchRange.options[this.searchRange.options.length] = select;
100
101                         if( otype.depth() == globalSearchDepth ) {
102                                 selectedOption = index;
103                         }
104                 }
105         }
106
107         this.searchRange.selectedIndex = selectedOption;
108         var opt = this.searchRange.options[selectedOption];
109         if(opt) opt.selected = true;
110
111         if(this.searchRange.options.length == 1 ) 
112                 hideMe(this.searchRange.parentNode);
113         else  {
114                 this.searchRange.parentNode.style.visibility = "visible";
115                 this.searchRange.parentNode.style.display = "inline";
116         }
117
118         if( instanceOf(this, AbstractRecordResultPage) ) {
119
120                 /* submit the search when the search range is selected */
121                 var obj = this;
122
123                 debug("Setting onclick for selector");
124
125                 var obj = this;
126                 this.searchRange.onchange = function() {
127         
128                         var location = globalSelectedLocation;
129                         if(location == null) location = globalLocation.id();
130                         else location = location.id();
131                         globalSearchDepth = obj.searchRange.options[obj.searchRange.selectedIndex].value;       
132         
133                         url_redirect( [ 
134                                         "target",                                       "mr_result",
135                                         "mr_search_type",                       lastSearchType,
136                                         "mr_search_query",              lastSearchString,
137                                         "mr_search_location",   location,
138                                         "mr_search_depth",              globalSearchDepth,      
139                                         "format",                                       paramObj.__format, 
140                                         "page",                                         0
141                                         ] );
142                 }
143         }
144 }
145
146
147
148
149
150 Page.prototype.setPageTrail = function() {
151         debug("Falling back to Page.setPageTrail");
152 }
153
154
155 Page.prototype.buildTrailLink = function(type, active) {
156
157         var obj = locationStack[type];
158         if(obj == null) return;
159
160         var div = createAppElement("div");
161
162         if(active) {
163                 add_css_class(div,"page_trail_word");
164                 var a = createAppElement("a");
165                 a.setAttribute("href", obj.location);
166                 a.appendChild(createAppTextNode(obj.title));
167                 a.title = obj.title;
168                 div.appendChild(a);
169
170         } else {
171                 add_css_class(div,"page_trail_word_inactive");
172                 div.appendChild(createAppTextNode(obj.title));
173         }
174
175         return div;
176 }
177
178 Page.prototype.buildDivider = function() {
179         var div = createAppElement("div");
180         div.className = "page_trail_divider";
181         var text =  createAppTextNode(" / ");
182         div.appendChild(text);
183         return div;
184 }
185
186 /* if 'full' add target=_top to break out of the page */
187 Page.prototype.buildNavBox = function(full) {
188         Page.navBox = new Box();
189         Page.navBox.init("Navigation", false, false);
190         var table = elem("table");
191         add_css_class(table, "main_nav_table");
192
193         var arr = [];
194
195         /* location tree */
196         var loc = null;
197         try {
198                 if(globalOrgTree)
199                         loc = elem("a", 
200                                 {id:"location_nav_link", href:"javascript:void(0);"}, 
201                                 null, "Change Search Location");
202
203                 loc.onclick = function(evt) {
204                         globalPage.locationTree.toggle(getById("location_nav_link"));
205                 }
206                 arr.push(loc);
207         } catch(E){}
208
209         if(globalPort == "443") globalPort = "80";
210         var prefix = "http://" + globalRootURL + ":" + globalPort + globalRootPath;
211
212         arr.push(elem("a", {href: prefix + '?target=advanced_search'}, null, "Advanced Search"));
213
214
215         if(!isXUL()) {
216                 var mylink = elem("a", {href: "?target=my_opac"}, null, "My OPAC");
217                 arr.push(mylink);
218         }
219
220         /* if user is not logged in, popup the login dialog when they
221                 select the myopac link */
222         if(!UserSession.instance().verifySession()) {
223                 mylink.setAttribute("href","javascript:void(0);");
224                 var func = function(){url_redirect(["target","my_opac"])};
225                 var diag = new LoginDialog(func);
226                 mylink.onclick = function(){diag.display(mylink);}
227         }
228
229
230         if(loc) arr.push(this.buildDeepLink());
231
232         if(UserSession.instance().verifySession() && !isXUL() ) {
233                 var a = elem("a", {href:"http://" + globalRootURL + ":" 
234                                 + globalPort + "/" + globalRootPath}, null, "Logout");
235                 a.onclick = doLogout;
236                 arr.push(a);
237         } 
238
239
240         for( var i in arr ) {
241                 var row = table.insertRow(table.rows.length);
242                 add_css_class(row, "main_nav_row");
243                 var cell = row.insertCell(row.cells.length);
244                 add_css_class(cell, "main_nav_cell");
245                 cell.appendChild(arr[i]);
246                 if(full) 
247                         arr[i].setAttribute("target", "_top");
248         }
249
250         /* append to the page */
251         Page.navBox.addItem(table);
252         Page.navBox.finalize();
253
254         var location = getById("main_page_nav_box");
255         if(location) {
256                 removeChildren(location);
257                 location.appendChild(Page.navBox.getNode());
258         }
259         
260
261         return Page.navBox.getNode();
262 }
263
264 Page.prototype.buildDeepLink = function() {
265         try {
266                 if(!globalAppFrame)
267                         return elem("div");
268         } catch(E) { return elem("div"); }
269
270         var org = globalSelectedLocation;
271         if(org == null)
272                 org = globalLocation;
273         if(org) org = org.id();
274
275         var depth = globalSearchDepth;
276
277         if(globalPort == "443") globalPort = "80";
278         var prefix = "http://" + globalRootURL + ":" + globalPort + globalRootPath;
279
280         var string =globalAppFrame.location.href;
281         if(!string.match(/sub_frame/))
282                 string += "&sub_frame=1"
283
284         if(org) {
285                 if(!string.match(/location/))
286                 string += "&location=" + org;
287         }
288
289         if(depth) {
290                 if(!string.match(/depth/))
291                 string += "&depth=" + depth;
292         }
293
294         debug("Redirecting deep link to " + string );
295
296         var a = elem("a",
297                 { href: prefix + string }, null, "Link to this page"
298         );
299
300         a.setAttribute("target", "_blank");
301         return a;
302 }
303
304
305 Page.prototype.destroy = function() { 
306         for( var x in this ){
307                 this[x] = null;
308         }
309 }
310
311
312
313
314
315
316
317