]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/main/app_shell.js
this close_tab seems to be more robust
[working/Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / main / app_shell.js
1 sdump('D_TRACE','Loading app_shell.js\n');
2
3 var tab_count = [ false, false, false, false, false, false, false, false, false, false ];
4
5 function app_shell_init(params) {
6         dump("TESTING: app_shell.js: " + mw.G['main_test_variable'] + '\n');
7         replace_tab(params.d,'main_tabbox','Tab','chrome://evergreen/content/main/about.xul');
8         mw.G.sound.beep();
9 }
10
11 function close_tab( d, tabbox ) {
12         sdump('D_TAB','calling close_tab( ' + d + ',' + tabbox + ');\n');
13         if (typeof(tabbox)!='object')
14                 tabbox = d.getElementById(tabbox);
15         if (typeof(tabbox)!='object')
16                 throw('Could not find tabbox. d = ' + d + ' tabbox = ' + tabbox + '\n');
17         try {
18                 var idx = tabbox.selectedIndex;
19                 var tabs = tabbox.firstChild; 
20                 var panels = tabbox.lastChild;
21
22                 if (idx == 0)
23                         tabs.advanceSelectedTab(+1);
24                 else
25                         tabs.advanceSelectedTab(-1);
26
27                 if (tabs.childNodes.length > 1 ) {
28                         tabs.removeItemAt( idx );
29                         panels.removeChild( panels.childNodes[ idx ] );
30                 } else {
31                         replace_tab(d,tabbox,'Tab','chrome://evergreen/content/main/about.xul');
32                 }
33
34         } catch(E) {
35                 dump(E+'\n');
36                 throw(E);
37         }
38         sdump('D_TAB',' : tabs.childNodes.length = ' + tabs.childNodes.length + '  panels.childNodes.length = ' + panels.childNodes.length + '\n');
39 }
40
41 function delete_tab_contents( tab, panel ) {
42         sdump('D_TAB','calling delete_tab_contents( ' + tab + ',' + panel + ');\n');
43         try {
44                 while (tab.lastChild) { tab.removeChild(tab.lastChild); }
45                 while (panel.lastChild) { panel.removeChild(panel.lastChild); }
46         } catch(E) {
47                 dump(js2JSON(E)+'\n');
48         }
49 }
50
51 function first_free_tab_count() {
52         for (var i = 0; i<10; i++) {
53                 if (! tab_count[i]) {
54                         tab_count[i] = true;
55                         return i;
56                 }
57         }
58         return -1;
59 }
60
61 function new_tab( d, tabbox ) {
62         sdump('D_TAB','calling new_tab( ' + d + ',' + tabbox + ');\n');
63         if (typeof(tabbox)!='object')
64                 tabbox = d.getElementById(tabbox);
65         if (typeof(tabbox)!='object')
66                 throw('Could not find tabbox. d = ' + d + ' tabbox = ' + tabbox + '\n');
67         var tabs = tabbox.firstChild;
68         var panels = tabbox.lastChild;
69         var tc = first_free_tab_count();
70         if (tc == -1) { return; } // let's only have up to 10 tabs
71         var panel = d.createElement('tabpanel');
72                 var pl = d.createElement('label');
73                 pl.setAttribute('value','Panel ' + tc);
74                 panel.setAttribute('flex','1');
75                 //panel.setAttribute('style','overflow: auto; min-width: 500px; min-height: 500px;');
76                 panel.setAttribute('id','panel'+tc);
77                 panel.appendChild(pl);
78         panels.appendChild(panel);
79
80         var tab = d.createElement('tab');
81                 tab.setAttribute('label','Tab ' + tc );
82                 tab.setAttribute('count',tc);
83                 tab.setAttribute('accesskey',tc);
84                 tab.setAttribute('linkedpanel','panel'+tc);
85         tabs.appendChild(tab);
86         try {
87                 tabbox.selectedIndex = tc;
88                 tabs.selectedIndex = tc;
89                 //tabbox.selectedIndex = tabs.childNodes.length - 1;
90                 //tabs.selectedIndex = tabs.childNodes.length - 1;
91                 replace_tab(d,tabbox,'Tab','chrome://evergreen/content/main/about.xul');
92         } catch(E) {
93                 dump(js2JSON(E)+'\n');
94         }
95         sdump('D_TAB',' : tabs.childNodes.length = ' + tabs.childNodes.length + '  panels.childNodes.length = ' + panels.childNodes.length + '\n');
96 }
97
98 function replace_tab( d, tabbox, label, chrome, params ) {
99         sdump('D_TAB','calling replace_tab( ' + d + ',' + tabbox + ');\n');
100         if (typeof(tabbox)!='object')
101                 tabbox = d.getElementById(tabbox);
102         if (typeof(tabbox)!='object')
103                 throw('Could not find tabbox. d = ' + d + ' tabbox = ' + tabbox + '\n');
104         var tabs = tabbox.firstChild;
105         var panels = tabbox.lastChild;
106         if (tabs.childNodes.length == 0) { new_tab(d,tabbox); }
107         try {
108                 var tab = tabs.selectedItem;
109                 var panel = tabbox.selectedPanel;
110                 delete_tab_contents(tab,panel);
111
112                 tab.setAttribute('label',label + ' ' + tab.getAttribute('count') );
113
114                 var frame = d.createElement('iframe');
115                 frame.setAttribute('flex','1');
116                 //frame.setAttribute('style','overflow: scroll; min-height: 500px; min-width: 500px;');
117                 frame.setAttribute('src',chrome);
118                 panel.appendChild(frame);
119                 //frame.contentWindow.parentWindow = parentWindow;
120                 //frame.contentWindow.tabWindow = this;
121                 //dump('replace_tab.tabWindow = ' + this + '\n');
122                 frame.contentWindow.mw = mw;
123                 //frame.contentWindow.am_i_a_top_level_tab = true;
124                 if (params) {
125                         frame.contentWindow.params = params;
126                 }
127                 return frame.contentWindow;
128         } catch(E) {
129                 dump(js2JSON(E)+'\n');
130         }
131         sdump('D_TAB',' : tabs.childNodes.length = ' + tabs.childNodes.length + '  panels.childNodes.length = ' + panels.childNodes.length + '\n');
132
133 }