Major UI Changes:
[htsworkflow.git] / www / 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         //quick_msg(www_url);
22         window.location = www_url; 
23     }
24
25 $(document).ready(function(){
26     
27     var panel_freezers = new Ext.Panel({
28         frame: true,
29         title: 'Freezers',
30         //collapsible: true,
31         titleCollapse: true,
32         //collapsed: true,
33         stateful: true,
34         stateId: 'freezer_panel_state',
35         contentEl: 'freezer_menu',
36         stateEvents: ['collapse', 'expand']
37     });
38     
39     var panel_containers = new Ext.Panel({
40         frame: true,
41         title: 'Containers',
42         //collapsible: true,
43         titleCollapse: true,
44         //collapsed: true,
45         stateful: true,
46         stateId: 'container_panel_state',
47         contentEl: 'container_menu',
48         stateEvents: ['collapse', 'expand']
49     });
50     
51     var panel_samples = new Ext.Panel({
52         frame: true,
53         title: 'Samples',
54         //collapsible: true,
55         titleCollapse: true,
56         //collapsed: true,
57         stateful: true,
58         stateId: 'sample_panel_state',
59         contentEl: 'sample_menu',
60         stateEvents: ['collapse', 'expand']
61     });
62     
63     /*var panel_settings = new Ext.Panel({
64         frame: true,
65         title: 'Settings',
66         //collapsible: true,
67         titleCollapse: true,
68         //collapsed: true,
69         stateful: true,
70         stateId: 'settings_panel_state',
71         contentEl: 'settings_menu',
72         stateEvents: ['collapse', 'expand']
73     });*/
74     
75     var panel_bcmagic = new Ext.Panel({
76         //title: 'BC Magic',
77         unstyled: true,
78         contentEl: 'bcmagic_div',
79         height: 180
80     });
81     
82     var menuPanel = new Ext.Panel({
83         id: 'menu_panel',
84         region: 'west',
85         collapsible: true,
86         margins: '2 0 0 0',
87         cmargins: '2 2 0 2',
88         //collapseMode: 'mini',
89         width: 200,
90         minWidth: 150,
91         border: false,
92         //baseCls: 'x-plain',
93         unstyled: true,
94         layout: 'vbox',
95         layoutConfig: {
96             align: 'stretch',
97             pack: 'start'
98         },
99        items: [panel_freezers, panel_containers, panel_samples, /*panel_settings,*/ panel_bcmagic]
100     });
101     
102     
103     var mainBorderPanel = new Ext.Viewport({
104        layout: 'border',
105        items: [{
106             region: 'north',
107             layout: 'vBox',
108             layoutConfig: {
109                 align: 'stretch',
110                 pack: 'start'
111             },
112             items: [{
113                     xtype: 'box',
114                     applyTo: 'header',
115                     id: 'header-panel',
116                     height: 30
117                 },{
118                     id: 'main_toolbar',
119                     xtype: 'toolbar',
120                     //height: 100,
121                     items: [{
122                         text: "Demo Button",
123                         handler: function() { quick_msg('Messages can be fun!'); }
124                     }],
125                     margins: '2 0 0 0'
126             }],
127             height: 60 
128        },menuPanel,{
129             title: 'Body',
130             region: 'center',
131             xtype: 'container',
132             layout: 'fit',
133             margins: '2 2 2 2',
134             items: {
135                 //title: 'Inner Panel',
136                 contentEl: 'body_content',
137                 border: true
138             }
139        }]
140     });
141     
142     //-------------------------------
143     // Menu Bar Setup
144     //-------------------------------
145     var main_tb = Ext.getCmp('main_toolbar');
146     
147     var add_buttons_from_html = function(main_tb){
148         var right_tbar_data = Ext.fly('right_tbar_data');
149         var div_array = right_tbar_data.query('div');
150         var div_id = null;
151         // Loop through each div since it defines a button and link or a spacer and add it to the right side of the toolbar
152         Ext.each(div_array, function(divobj) {
153             div_id = divobj.id;
154             if (div_id == 'spacer'){
155                 main_tb.add('-');
156             } else {
157                 main_tb.add({
158                     text: div_id,
159                     handler: function() { goto_url(divobj.getAttribute('href')); }
160                 });
161             }
162         });
163         //return right_tbar_data;
164     }
165     
166     main_tb.add({ xtype: 'tbfill' });
167     var user_info = Ext.fly('login_info');
168     var logout_url = user_info.getAttribute('logouturl');
169     var login_url = user_info.getAttribute('loginurl');
170     
171     if (user_info.getAttribute('authenticated') == 'true') {
172         main_tb.add({
173                         xtype: 'tbtext',
174                         text: 'User: ' + user_info.getAttribute('user')
175                     });
176         main_tb.add('-');
177         add_buttons_from_html(main_tb);
178         main_tb.add('-');
179         main_tb.add({
180                         text: 'Logout',
181                         handler: function() { goto_url(logout_url); }
182                     });
183         
184     } else {
185         main_tb.add({
186                         text: 'Login',
187                         handler: function() { goto_url(login_url) }
188                     });
189     }
190     
191     main_tb.doLayout();
192     
193 });