]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/main/menu.js
toward checkin
[working/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
84
85                         /* Admin menu */
86                         'cmd_test_html' : [
87                                 ['command','keypress'],
88                                 function() {
89                                         obj.set_tab(urls.test_html,{},{});
90                                 }
91                         ],
92                         'cmd_test_xul' : [
93                                 ['command','keypress'],
94                                 function() {
95                                         obj.set_tab(urls.test_xul,{},{});
96                                 }
97                         ],
98                         'cmd_console' : [
99                                 ['command','keypress'],
100                                 function() {
101                                         obj.set_tab(urls.remote_debug_console,{},{});
102                                 }
103                         ],
104                         'cmd_shell' : [
105                                 ['command','keypress'],
106                                 function() {
107                                         obj.set_tab(urls.remote_debug_shell,{},{});
108                                 }
109                         ],
110                         'cmd_xuleditor' : [
111                                 ['command','keypress'],
112                                 function() {
113                                         obj.set_tab(urls.remote_debug_xuleditor,{},{});
114                                 }
115                         ],
116                         'cmd_fieldmapper' : [
117                                 ['command','keypress'],
118                                 function() {
119                                         obj.set_tab(urls.remote_debug_fieldmapper,{},{});
120                                 }
121                         ],
122
123                 };
124
125                 for (var i in cmd_map) {
126                         var cmd = this.w.document.getElementById(i);
127                         if (cmd) {
128                                 for (var j in cmd_map[i][0]) {
129                                         cmd.addEventListener(cmd_map[i][0][j],cmd_map[i][1],false);
130                                 }
131                         }
132                         obj.view[i] = cmd;
133                 }
134
135                 obj.new_tab(true);
136         },
137
138         'close_tab' : function () {
139                 var idx = this.view.tabs.selectedIndex;
140                 if (idx == 0) {
141                         try {
142                                 this.view.tabs.advanceSelectedTab(+1);
143                         } catch(E) {
144                                 this.error.sdump('D_TAB','failed tabs.advanceSelectedTab(+1):'+js2JSON(E) + '\n');
145                                 try {
146                                         this.view.tabs.advanceSelectedTab(-1);
147                                 } catch(E) {
148                                         this.error.sdump('D_TAB','failed again tabs.advanceSelectedTab(-1):'+
149                                                 js2JSON(E) + '\n');
150                                 }
151                         }
152                 } else {
153                         try {
154                                 this.view.tabs.advanceSelectedTab(-1);
155                         } catch(E) {
156                                 this.error.sdump('D_TAB','failed tabs.advanceSelectedTab(-1):'+js2JSON(E) + '\n');
157                                 try {
158                                         this.view.tabs.advanceSelectedTab(+1);
159                                 } catch(E) {
160                                         this.error.sdump('D_TAB','failed again tabs.advanceSelectedTab(+1):'+
161                                                 js2JSON(E) + '\n');
162                                 }
163                         }
164
165                 }
166                 
167                 this.error.sdump('D_TAB','\tnew tabbox.selectedIndex = ' + this.view.tabbox.selectedIndex + '\n');
168
169                 this.view.tabs.childNodes[ idx ].hidden = true;
170                 this.error.sdump('D_TAB','tabs.childNodes[ ' + idx + ' ].hidden = true;\n');
171
172                 // Make sure we keep at least one tab open.
173                 var tab_flag = true;
174                 for (var i = 0; i < this.view.tabs.childNodes.length; i++) {
175                         var tab = this.view.tabs.childNodes[i];
176                         if (!tab.hidden)
177                                 tab_flag = false;
178                 }
179                 if (tab_flag) this.new_tab();
180         },
181
182         'find_free_tab' : function() {
183                 var last_not_hidden = -1;
184                 for (var i = 0; i<this.view.tabs.childNodes.length; i++) {
185                         var tab = this.view.tabs.childNodes[i];
186                         if (!tab.hidden)
187                                 last_not_hidden = i;
188                 }
189                 if (last_not_hidden == this.view.tabs.childNodes.length - 1)
190                         last_not_hidden = -1;
191                 // If the one next to last_not_hidden is hidden, we want it.
192                 // Basically, we fill in tabs after existing tabs for as 
193                 // long as possible.
194                 var idx = last_not_hidden + 1;
195                 var candidate = this.view.tabs.childNodes[ idx ];
196                 if (candidate.hidden)
197                         return idx;
198                 // Alright, find the first hidden then
199                 for (var i = 0; i<this.view.tabs.childNodes.length; i++) {
200                         var tab = this.view.tabs.childNodes[i];
201                         if (tab.hidden)
202                                 return i;
203                 }
204                 return -1;
205         },
206
207         'new_tab' : function(focus) {
208                 var tc = this.find_free_tab();
209                 if (tc == -1) { return null; } // 9 tabs max
210                 var tab = this.view.tabs.childNodes[ tc ];
211                 //tab.setAttribute('label','Tab ' + (tc + 1) );
212                 tab.hidden = false;
213                 try {
214                         if (focus) this.view.tabs.selectedIndex = tc;
215                         this.set_tab('data:text/html,<h1>Hello World</h1>',{ 'index' : tc });
216                 } catch(E) {
217                         this.error.sdump('D_ERROR',E);
218                 }
219         },
220
221         'set_tab' : function(url,params,content_params) {
222                 var idx = this.view.tabs.selectedIndex;
223                 if (params && typeof params.index != 'undefined') idx = params.index;
224                 var tab = this.view.tabs.childNodes[ idx ];
225                 var panel = this.view.panels.childNodes[ idx ];
226                 while ( panel.lastChild ) panel.removeChild( panel.lastChild );
227                 var frame = this.w.document.createElement('iframe');
228                 frame.setAttribute('flex','1');
229                 frame.setAttribute('src',url);
230                 panel.appendChild(frame);
231                 if (content_params) {
232                         try {
233                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
234                                 //this.error.sdump('D_MENU', 'frame.contentWindow = ' + frame.contentWindow + '\n');
235                                 frame.contentWindow.IAMXUL = true;
236                                 frame.contentWindow.xulG = content_params;
237                                 //this.error.sdump('D_MENU','content_params ' + js2JSON(content_params) +
238                                 //'\nframe.contentWindow.xulG = ' + js2JSON(frame.contentWindow.xulG) );
239                         } catch(E) {
240                                 this.error.sdump('D_ERROR', 'main.menu: ' + E);
241                         }
242                 }
243                 return frame;
244         }
245
246 }
247
248 dump('exiting main/menu.js\n');