Fixed dynamic east panel code
[htsworkflow.git] / htsworkflow / frontend / static / js / htsw.js
1 Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
2
3 Ext.override(Ext.Panel,{
4   getState: function() {
5     return { collapsed: this.collapsed };
6     }
7 });
8
9 var quick_msg = function(msg)
10 {
11     Ext.MessageBox.show({
12         title: 'Info',
13         msg: msg,
14         buttons: Ext.MessageBox.OK,
15         icon: Ext.MessageBox.INFO
16     });
17 }
18
19 var goto_url = function(www_url)
20 {
21     window.location = www_url; 
22 }
23
24 $(document).ready(function(){
25     //----------------------------------------
26     // Django Library Page CSS Fix
27     var fix_library_css = function() {
28       var tofix = Ext.fly('library-index-div');
29       if (tofix != null)
30       {
31         tofix.select('*').addClass('djangocss');
32       }
33     }
34     fix_library_css();
35     
36     
37     //----------------------------------------
38     // Dynamically Generate Panels from HTML!
39     var create_dynamic_panels = function(){
40         var wp_items = Ext.fly('west_panel_items');
41         var ul_items = wp_items.query('ul');
42         
43         var dynamic_panels = new Array();
44         Ext.each(ul_items, function(ul) {
45             var panel_obj = new Ext.Panel({
46                 frame: true,
47                 title: ul.id,
48                 //collapsible: true,
49                 //titleCollapse: true,
50                 //collapsed: true,
51                 //stateful: true,
52                 //stateId: 'freezer_panel_state',
53                 margins: '0 0 0 0',
54                 //width: 200,
55                 contentEl: ul
56                 //stateEvents: ['collapse', 'expand']
57             });
58             dynamic_panels.push(panel_obj);
59         });
60         return dynamic_panels;
61     }
62     
63     var panel_bcmagic = new Ext.Panel({
64         //title: 'BC Magic',
65         unstyled: true,
66         contentEl: 'bcmagic_div',
67         height: 180
68     });
69     
70     var menuPanel = new Ext.Panel({
71         id: 'menu_panel',
72         region: 'west',
73         hidden: true,
74         collapsible: true,
75         split: true,
76         collapseMode: 'mini',
77         margins: '4 0 0 0',
78         //cmargins: '2 2 0 2',
79         width: 200,
80         minWidth: 150,
81         border: false,
82         //baseCls: 'x-plain',
83         unstyled: true,
84         layout: 'vbox',
85         layoutConfig: {
86             align: 'stretch',
87             pack: 'start'
88         },
89         // Add dynamically generated panels from html and include barcode magic
90        items: create_dynamic_panels().concat([panel_bcmagic])
91     });
92     
93     
94     
95     //-------------------------------
96     // East Region Setup
97     //-------------------------------
98     var get_east_panel_content = function(){
99       // East panel contentEl id is supplied in html div id of east_region_config.
100       var east_id = Ext.fly('east_region_config').dom.textContent;
101       
102       if (east_id.length == 0){
103         return east_id;
104       }
105       
106       // If no element exists with the supplied content id, report and error.
107       if (Ext.fly(east_id) == null){
108         return 'east_region_config_error';
109       }
110       return east_id;
111     }
112     
113     var east_panel_content_id = get_east_panel_content();
114     if (east_panel_content_id.length > 0){
115       var eastPanel = new Ext.Panel({
116           region: 'east',
117           layout: 'auto',
118           //margins: '0 2 0 2',
119           width: 180,
120           collapsible: true,
121           split: true,
122           collapseMode: 'mini',
123           autoScroll: true,
124           contentEl: east_panel_content_id
125       });
126     } else {
127       var eastPanel = new Ext.Panel({
128           region: 'east',
129           layout: 'auto',
130           //margins: '0 2 0 2',
131           width: 180,
132           collapsible: true,
133           split: true,
134           hidden: true,
135           collapseMode: 'mini',
136           autoScroll: true
137           //contentEl: ''
138       });
139     }
140     
141
142     //-------------------------------
143     // Main Viewport Setup
144     //-------------------------------
145     var mainBorderPanel = new Ext.Viewport({
146        layout: 'border',
147        items: [{
148             region: 'north',
149             layout: 'vBox',
150             layoutConfig: {
151                 align: 'stretch',
152                 pack: 'start'
153             },
154             items: [{
155                     xtype: 'box',
156                     applyTo: 'header',
157                     id: 'header-panel',
158                     height: 30
159                 },{
160                     id: 'main_toolbar',
161                     xtype: 'toolbar',
162                     height: 30,
163                     //height: 100,
164                     /*items: [{
165                         text: "Demo Button",
166                         handler: function() { quick_msg('Messages can be fun!'); }
167                     }],*/
168                     margins: '2 0 0 0'
169                 },{
170                     id: 'app_toolbar',
171                     xtype: 'toolbar',
172                     height: 30
173                     //margins: '2 0 0 0'
174                 }],
175             height: 90
176        },menuPanel,{
177             //title: 'Body',
178             region: 'center',
179             xtype: 'panel',
180             //autoScroll: true,
181             layout: 'fit',
182             margins: '2 2 2 0',
183             items: [{
184                 //title: 'Inner Panel',
185                 contentEl: 'body_content',
186                 border: true,
187                 autoScroll: true
188             }]
189             },eastPanel]
190     });
191     
192     //-------------------------------
193     // Menu Bar Setup
194     //-------------------------------
195     var main_tb = Ext.getCmp('main_toolbar');
196     
197     var add_buttons_from_html = function(tb, bar_id){
198         var tbar_data = Ext.fly(bar_id);
199         var div_array = tbar_data.query('div');
200         var div_id = null;
201         // Loop through each div since it defines a button and link or a spacer and add it to the right side of the toolbar
202         Ext.each(div_array, function(divobj) {
203             div_id = divobj.id;
204             if (div_id == 'spacer'){
205                 tb.add('-');
206             } else {
207                 tb.add({
208                     text: div_id,
209                     handler: function() { goto_url(divobj.getAttribute('href')); }
210                 });
211             }
212         });
213     }
214     
215     // Fill in left side of main toolbar
216     add_buttons_from_html(main_tb, 'left_tbar_data');
217     
218     // Shifts the remaining toolbar options to the right side.
219     main_tb.add({ xtype: 'tbfill' });
220     var user_info = Ext.fly('login_info');
221     var logout_url = user_info.getAttribute('logouturl');
222     var login_url = user_info.getAttribute('loginurl');
223     
224     if (user_info.getAttribute('authenticated') == 'true') {
225         main_tb.add({
226                         xtype: 'tbtext',
227                         text: 'User: ' + user_info.getAttribute('user')
228                     });
229         main_tb.add('-');
230         add_buttons_from_html(main_tb, 'right_tbar_data');
231         main_tb.add('-');
232         main_tb.add({
233                         text: 'Logout',
234                         handler: function() { goto_url(logout_url); }
235                     });
236         
237     } else {
238         main_tb.add({
239                         text: 'Login',
240                         handler: function() { goto_url(login_url) }
241                     });
242     }
243     
244     main_tb.doLayout();
245     
246     //-------------------------------
247     // App Toolbar Setup
248     //-------------------------------
249     var app_tb = Ext.getCmp('app_toolbar');
250     add_buttons_from_html(app_tb, 'app_toolbar_west');
251     app_tb.add({ xtype: 'tbfill' });
252     add_buttons_from_html(app_tb, 'app_toolbar_east');
253     app_tb.doLayout();
254     
255     
256 });