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