]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/Page.js
Let the onslaught continue...
[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         var arr = orgNodeTrail(orgunit);
49
50         this.searchingCell.innerHTML = "";
51         var names = new Array()
52         for( var i in arr) 
53                 names.push(arr[i].name());
54
55         this.searchingCell.innerHTML = 
56                 "<span class='breadcrumb_label'>" + 
57                 names.join("</span> / <span class='breadcrumb_label'>") + 
58                 "</span>";
59
60         this.resetRange();
61
62 }
63
64 Page.prototype.resetRange = function() {
65
66         this.searchRange                        = getById("search_range_select");
67
68         while( this.searchRange.options.length ) {
69                 this.searchRange.options[0] = null;
70         }
71
72         var orgunit = globalSelectedLocation;
73         if(!orgunit)
74                 orgunit = globalLocation;
75
76         debug("Reseting search range with search location " + orgunit);
77         debug("Resetting search range with search depth " + globalSearchDepth );
78
79         var selectedOption = null;
80
81         if(this.searchRange) {
82
83                 for( var index in globalOrgTypes ) {
84                         var otype = globalOrgTypes[index];
85
86                         if( otype.depth() > findOrgType(orgunit.ou_type()).depth() )
87                                 continue;
88
89                         var select =  new Option(otype.name(), otype.depth());
90
91                         this.searchRange.options[this.searchRange.options.length] = select;
92
93                         if( otype.depth() == globalSearchDepth ) {
94                                 selectedOption = index;
95                         }
96                 }
97         }
98
99         this.searchRange.selectedIndex = selectedOption;
100         this.searchRange.options[selectedOption].selected = true;
101
102         if(this.searchRange.options.length == 1 ) 
103                 hideMe(this.searchRange.parentNode);
104         else  {
105                 this.searchRange.parentNode.style.visibility = "visible";
106                 this.searchRange.parentNode.style.display = "inline";
107         }
108
109         if( instanceOf(this, AbstractRecordResultPage) ) {
110
111                 /* submit the search when the search range is selected */
112                 var obj = this;
113
114                 debug("Setting onclick for selector");
115                 this.searchRange.onchange = function() {
116         
117                         var location = globalSelectedLocation;
118                         if(location == null) location = globalLocation.id();
119                         else location = location.id();
120                         globalSearchDepth = obj.searchRange.options[obj.searchRange.selectedIndex].value;       
121         
122                         url_redirect( [ 
123                                         "target",                                       "mr_result",
124                                         "mr_search_type",                       obj.stype,
125                                         "mr_search_query",              obj.string,
126                                         "mr_search_location",   location,
127                                         "mr_search_depth",              globalSearchDepth,      
128                                         "page",                                         0
129                                         ] );
130                 }
131         }
132 }
133
134