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