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