]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/main/menu.js
pass the session to the test URLs
[Evergreen.git] / Open-ILS / xul / staff_client / server / main / menu.js
1 dump('entering main/menu.js\n');
2
3 if (typeof main == 'undefined') main = {};
4 main.menu = function () {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.window'); this.window = new util.window();
8
9         this.w = window;
10 }
11
12 main.menu.prototype = {
13
14         'init' : function( params ) {
15
16                 var session = params['session'];
17                 var authtime = params['authtime'];
18
19                 var obj = this;
20                 obj.view = {};
21
22                 obj.view.tabbox = obj.w.document.getElementById('main_tabbox');
23                 obj.view.tabs = obj.view.tabbox.firstChild;
24                 obj.view.panels = obj.view.tabbox.lastChild;
25
26                 var cmd_map = {
27                         'cmd_broken' : [
28                                 ['command','keypress'],
29                                 function() { alert('Not Yet Implemented'); }
30                         ],
31
32                         /* File Menu */
33                         'cmd_close_window' : [ 
34                                 ['command','keypress'], 
35                                 function() { obj.w.close(); } 
36                         ],
37                         'cmd_new_window' : [
38                                 ['command','keypress'],
39                                 function() {
40                                         obj.window.open(urls.remote_menu_frame,'test' + 
41                                                 obj.window.appshell_name_increment++ ,'chrome'); 
42                                 }
43                         ],
44                         'cmd_new_tab' : [
45                                 ['command','keypress'],
46                                 function() { obj.new_tab(true); }
47                         ],
48                         'cmd_close_tab' : [
49                                 ['command','keypress'],
50                                 function() { obj.close_tab(); }
51                         ],
52
53                         /* Search Menu */
54                         'cmd_patron_search' : [
55                                 ['command','keypress'],
56                                 function() {
57                                         obj.set_tab(urls.remote_patron_display 
58                                                 + '?session='+obj.w.escape(session),{},{});
59                                 }
60                         ],
61                         'cmd_search_opac' : [
62                                 ['command','keypress'],
63                                 function() {
64                                         var content_params = { 'authtoken' : session, 'authtime' : authtime };
65                                         obj.set_tab(urls.xul_opac_wrapper,{},content_params);
66                                 }
67                         ],
68
69
70                         /* Circulation Menu */
71                         'cmd_circ_checkin' : [
72                                 ['command','keypress'],
73                                 function() { 
74                                         obj.set_tab(urls.remote_checkin + '?session='+obj.w.escape(session),{},{});
75                                 }
76                         ],
77                         'cmd_circ_checkout' : [
78                                 ['command','keypress'],
79                                 function() { 
80                                         obj.set_tab(urls.remote_patron_barcode_entry + '?session='+obj.w.escape(session),{},{});
81                                 }
82                         ],
83                         'cmd_circ_hold_capture' : [
84                                 ['command','keypress'],
85                                 function() { 
86                                         obj.set_tab(urls.remote_hold_capture + '?session='+obj.w.escape(session),{},{});
87                                 }
88                         ],
89
90
91                         /* Admin menu */
92                         'cmd_test_html' : [
93                                 ['command','keypress'],
94                                 function() {
95                                         obj.set_tab(urls.test_html + '?session='+obj.w.escape(session),{},{});
96                                 }
97                         ],
98                         'cmd_test_xul' : [
99                                 ['command','keypress'],
100                                 function() {
101                                         obj.set_tab(urls.test_xul + '?session='+obj.w.escape(session),{},{});
102                                 }
103                         ],
104                         'cmd_console' : [
105                                 ['command','keypress'],
106                                 function() {
107                                         obj.set_tab(urls.remote_debug_console,{},{});
108                                 }
109                         ],
110                         'cmd_shell' : [
111                                 ['command','keypress'],
112                                 function() {
113                                         obj.set_tab(urls.remote_debug_shell,{},{});
114                                 }
115                         ],
116                         'cmd_xuleditor' : [
117                                 ['command','keypress'],
118                                 function() {
119                                         obj.set_tab(urls.remote_debug_xuleditor,{},{});
120                                 }
121                         ],
122                         'cmd_fieldmapper' : [
123                                 ['command','keypress'],
124                                 function() {
125                                         obj.set_tab(urls.remote_debug_fieldmapper,{},{});
126                                 }
127                         ],
128
129                 };
130
131                 for (var i in cmd_map) {
132                         var cmd = this.w.document.getElementById(i);
133                         if (cmd) {
134                                 for (var j in cmd_map[i][0]) {
135                                         cmd.addEventListener(cmd_map[i][0][j],cmd_map[i][1],false);
136                                 }
137                         }
138                         obj.view[i] = cmd;
139                 }
140
141                 obj.new_tab(true);
142         },
143
144         'close_tab' : function () {
145                 var idx = this.view.tabs.selectedIndex;
146                 if (idx == 0) {
147                         try {
148                                 this.view.tabs.advanceSelectedTab(+1);
149                         } catch(E) {
150                                 this.error.sdump('D_TAB','failed tabs.advanceSelectedTab(+1):'+js2JSON(E) + '\n');
151                                 try {
152                                         this.view.tabs.advanceSelectedTab(-1);
153                                 } catch(E) {
154                                         this.error.sdump('D_TAB','failed again tabs.advanceSelectedTab(-1):'+
155                                                 js2JSON(E) + '\n');
156                                 }
157                         }
158                 } else {
159                         try {
160                                 this.view.tabs.advanceSelectedTab(-1);
161                         } catch(E) {
162                                 this.error.sdump('D_TAB','failed tabs.advanceSelectedTab(-1):'+js2JSON(E) + '\n');
163                                 try {
164                                         this.view.tabs.advanceSelectedTab(+1);
165                                 } catch(E) {
166                                         this.error.sdump('D_TAB','failed again tabs.advanceSelectedTab(+1):'+
167                                                 js2JSON(E) + '\n');
168                                 }
169                         }
170
171                 }
172                 
173                 this.error.sdump('D_TAB','\tnew tabbox.selectedIndex = ' + this.view.tabbox.selectedIndex + '\n');
174
175                 this.view.tabs.childNodes[ idx ].hidden = true;
176                 this.error.sdump('D_TAB','tabs.childNodes[ ' + idx + ' ].hidden = true;\n');
177
178                 // Make sure we keep at least one tab open.
179                 var tab_flag = true;
180                 for (var i = 0; i < this.view.tabs.childNodes.length; i++) {
181                         var tab = this.view.tabs.childNodes[i];
182                         if (!tab.hidden)
183                                 tab_flag = false;
184                 }
185                 if (tab_flag) this.new_tab();
186         },
187
188         'find_free_tab' : function() {
189                 var last_not_hidden = -1;
190                 for (var i = 0; i<this.view.tabs.childNodes.length; i++) {
191                         var tab = this.view.tabs.childNodes[i];
192                         if (!tab.hidden)
193                                 last_not_hidden = i;
194                 }
195                 if (last_not_hidden == this.view.tabs.childNodes.length - 1)
196                         last_not_hidden = -1;
197                 // If the one next to last_not_hidden is hidden, we want it.
198                 // Basically, we fill in tabs after existing tabs for as 
199                 // long as possible.
200                 var idx = last_not_hidden + 1;
201                 var candidate = this.view.tabs.childNodes[ idx ];
202                 if (candidate.hidden)
203                         return idx;
204                 // Alright, find the first hidden then
205                 for (var i = 0; i<this.view.tabs.childNodes.length; i++) {
206                         var tab = this.view.tabs.childNodes[i];
207                         if (tab.hidden)
208                                 return i;
209                 }
210                 return -1;
211         },
212
213         'new_tab' : function(focus) {
214                 var tc = this.find_free_tab();
215                 if (tc == -1) { return null; } // 9 tabs max
216                 var tab = this.view.tabs.childNodes[ tc ];
217                 //tab.setAttribute('label','Tab ' + (tc + 1) );
218                 tab.hidden = false;
219                 try {
220                         if (focus) this.view.tabs.selectedIndex = tc;
221                         this.set_tab('data:text/html,<h1>Hello World</h1>',{ 'index' : tc });
222                 } catch(E) {
223                         this.error.sdump('D_ERROR',E);
224                 }
225         },
226
227         'set_tab' : function(url,params,content_params) {
228                 var idx = this.view.tabs.selectedIndex;
229                 if (params && typeof params.index != 'undefined') idx = params.index;
230                 var tab = this.view.tabs.childNodes[ idx ];
231                 var panel = this.view.panels.childNodes[ idx ];
232                 while ( panel.lastChild ) panel.removeChild( panel.lastChild );
233                 var frame = this.w.document.createElement('iframe');
234                 frame.setAttribute('flex','1');
235                 frame.setAttribute('src',url);
236                 panel.appendChild(frame);
237                 if (content_params) {
238                         try {
239                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
240                                 //this.error.sdump('D_MENU', 'frame.contentWindow = ' + frame.contentWindow + '\n');
241                                 frame.contentWindow.IAMXUL = true;
242                                 frame.contentWindow.xulG = content_params;
243                                 //this.error.sdump('D_MENU','content_params ' + js2JSON(content_params) +
244                                 //'\nframe.contentWindow.xulG = ' + js2JSON(frame.contentWindow.xulG) );
245                         } catch(E) {
246                                 this.error.sdump('D_ERROR', 'main.menu: ' + E);
247                         }
248                 }
249                 return frame;
250         }
251
252 }
253
254 dump('exiting main/menu.js\n');