]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/opac/GlobalInit.js
opac pile of js updates, slowing adding tweeks
[working/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 locationStack                                       = new Array();
12
13 var lastSearchString                            = null;
14 var lastSearchType                              = null;
15
16
17 var loaded = false;
18
19
20 function isXUL() {
21         try {
22                 if(IAMXUL)
23                         return true;
24         } catch(E) {
25                 return false;
26         }
27 }
28
29 function addLocation(type, title) {
30         try { 
31                 if(globalAppFrame) {
32                         var obj = new Object();
33                         obj.location = globalAppFrame.location.href;
34                         obj.title = title;
35                         locationStack[type] = obj;
36                 }
37         } catch(E){}
38
39 }
40
41
42 function globalInit() {
43
44         debug(" --- XUL IS " + isXUL() );
45
46
47         if( isXUL() && globalAppFrame )
48                 globalAppFrame.document.body.style.background = "#FFF";
49
50         var page_name = globalPageTarget;
51
52         if(!page_name) 
53                 throw new EXArg("globalInit requires globalPageTarget to be set");
54
55         debug("globalInit init-ing page: " + page_name );
56
57         switch( page_name ) {
58
59                 case "start":
60                         globalPage = new OPACStartPage();
61                         addLocation("start", "Home");
62                         locationStack["advanced_search"] = null;
63                         break;
64
65                 case  "advanced_search":
66                         globalPage = new AdvancedSearchPage();
67                         addLocation("advanced_search", "Advanced Search");
68                         locationStack["start"] = null;
69                         break;
70
71                 case  "mr_result":
72                         globalPage = new MRResultPage();
73                         addLocation("mr_result", "Title Group Results");
74                         break;
75
76                 case  "record_result":
77                         globalPage = new RecordResultPage();
78                         addLocation("record_result", "Title Results");
79                         break;
80
81                 case  "login":
82                         globalPage = new LoginPage();
83                         break;
84
85                 case  "logout":
86                         globalPage = new LogoutPage();
87                         break;
88
89                 case  "my_opac":
90                         globalPage = new MyOPACPage();
91                         break;
92
93                 case "record_detail":
94                         globalPage = new RecordDetailPage();
95                         addLocation("record_detail", "Title Details");
96                         break;
97
98                 case  "about":
99                         globalPage = new AboutPage();
100                         break;
101
102                 }
103
104         if( ! globalPage ) 
105                 throw new EXArg(
106                         "globalInit requires a valid page target: " + page_name );
107
108         if(!loaded) { loaded = true; GlobalInitLoad(); }
109
110         globalMenuManager = new ContextMenuManager();
111
112         /* hide all context menus on body click */
113         getDocument().body.onclick = function() {
114                         globalMenuManager.hideAll(); 
115         }
116
117         globalPage.init();
118         globalPage.setLocDisplay();
119         globalPage.locationTree = globalOrgTreeWidget;
120         globalPage.setPageTrail();
121
122         if(globalSearchBarChunk)
123                 globalSearchBarChunk.reset();
124         
125         if( globalSearchBarFormChunk != null)
126                 globalSearchBarFormChunk.resetPage();
127
128 }
129
130
131 /* we only do this on loading of the outer frame (i.e. only once) */
132 function GlobalInitLoad() {
133
134         debug("Global Init is doing its primary load");
135         globalOrgTreeWidget = new LocationTree(globalOrgTree);
136         globalUser = UserSession.instance();
137
138         var ses = null;
139         var org = null;
140
141         if(isXUL()) {
142                 ses = G['auth_ses'][0]; /* G is shoved in by XUL */
143                 org = G['user_ou']; /* the desired location of the user */
144         }
145
146         if(globalUser.verifySession(ses)) {
147                 globalUser.grabOrgUnit(org);
148
149         } else  {
150                 globalUser = null;
151                 globalLocation = globalOrgTree;
152                 globalSearchDepth = findOrgDepth(globalOrgTree.ou_type());
153         }
154
155 }
156
157