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