Updated left side of toolbar to be generated from html
[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     window.location = www_url; 
22 }
23
24 $(document).ready(function(){
25     
26     //----------------------------------------
27     // Dynamically Generate Panels from HTML!
28     var create_dynamic_panels = function(){
29         var wp_items = Ext.fly('west_panel_items');
30         var ul_items = wp_items.query('ul');
31         
32         var dynamic_panels = new Array();
33         Ext.each(ul_items, function(ul) {
34             var panel_obj = new Ext.Panel({
35                 frame: true,
36                 title: ul.id,
37                 //collapsible: true,
38                 //titleCollapse: true,
39                 //collapsed: true,
40                 //stateful: true,
41                 //stateId: 'freezer_panel_state',
42                 contentEl: ul
43                 //stateEvents: ['collapse', 'expand']
44             });
45             dynamic_panels.push(panel_obj);
46         });
47         return dynamic_panels;
48     }
49     
50     var panel_bcmagic = new Ext.Panel({
51         //title: 'BC Magic',
52         unstyled: true,
53         contentEl: 'bcmagic_div',
54         height: 180
55     });
56     
57     var menuPanel = new Ext.Panel({
58         id: 'menu_panel',
59         region: 'west',
60         collapsible: true,
61         margins: '2 0 0 0',
62         cmargins: '2 2 0 2',
63         //collapseMode: 'mini',
64         width: 200,
65         minWidth: 150,
66         border: false,
67         //baseCls: 'x-plain',
68         unstyled: true,
69         layout: 'vbox',
70         layoutConfig: {
71             align: 'stretch',
72             pack: 'start'
73         },
74         // Add dynamically generated panels from html and include barcode magic
75        items: create_dynamic_panels().concat([panel_bcmagic])
76     });
77     
78     //-------------------------------
79     // Main Viewport Setup
80     //-------------------------------
81     var mainBorderPanel = new Ext.Viewport({
82        layout: 'border',
83        items: [{
84             region: 'north',
85             layout: 'vBox',
86             layoutConfig: {
87                 align: 'stretch',
88                 pack: 'start'
89             },
90             items: [{
91                     xtype: 'box',
92                     applyTo: 'header',
93                     id: 'header-panel',
94                     height: 30
95                 },{
96                     id: 'main_toolbar',
97                     xtype: 'toolbar',
98                     //height: 100,
99                     /*items: [{
100                         text: "Demo Button",
101                         handler: function() { quick_msg('Messages can be fun!'); }
102                     }],*/
103                     margins: '2 0 0 0'
104             }],
105             height: 60 
106        },menuPanel,{
107             title: 'Body',
108             region: 'center',
109             xtype: 'container',
110             layout: 'fit',
111             margins: '2 2 2 2',
112             items: {
113                 //title: 'Inner Panel',
114                 contentEl: 'body_content',
115                 border: true
116             }
117        }]
118     });
119     
120     //-------------------------------
121     // Menu Bar Setup
122     //-------------------------------
123     var main_tb = Ext.getCmp('main_toolbar');
124     
125     var add_buttons_from_html_left = function(main_tb){
126         var left_tbar_data = Ext.fly('left_tbar_data');
127         var div_array = left_tbar_data.query('div');
128         var div_id = null;
129         // Loop through each div since it defines a button and link or a spacer and add it to the right side of the toolbar
130         Ext.each(div_array, function(divobj) {
131             div_id = divobj.id;
132             if (div_id == 'spacer'){
133                 main_tb.add('-');
134             } else {
135                 main_tb.add({
136                     text: div_id,
137                     handler: function() { goto_url(divobj.getAttribute('href')); }
138                 });
139             }
140         });
141         //return right_tbar_data;
142     }
143     
144     var add_buttons_from_html_right = function(main_tb){
145         var right_tbar_data = Ext.fly('right_tbar_data');
146         var div_array = right_tbar_data.query('div');
147         var div_id = null;
148         // Loop through each div since it defines a button and link or a spacer and add it to the right side of the toolbar
149         Ext.each(div_array, function(divobj) {
150             div_id = divobj.id;
151             if (div_id == 'spacer'){
152                 main_tb.add('-');
153             } else {
154                 main_tb.add({
155                     text: div_id,
156                     handler: function() { goto_url(divobj.getAttribute('href')); }
157                 });
158             }
159         });
160         //return right_tbar_data;
161     }
162     
163     add_buttons_from_html_left(main_tb);
164     
165     // Shifts the remaining toolbar options to the right side.
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_right(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 });