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