Activating bcmagic model & initial data.
[htsworkflow.git] / htsworkflow / frontend / static / js / htsw.js
index 2d12e87b93965d0c38581cbc56c149385f54e49e..4be8a5dc69f6dc21ecb4ced9f74771781c0d2ad1 100644 (file)
@@ -22,6 +22,17 @@ var goto_url = function(www_url)
 }
 
 $(document).ready(function(){
+    //----------------------------------------
+    // Django Library Page CSS Fix
+    var fix_library_css = function() {
+      var tofix = Ext.fly('library-index-div');
+      if (tofix != null)
+      {
+       tofix.select('*').addClass('djangocss');
+      }
+    }
+    fix_library_css();
+    
     
     //----------------------------------------
     // Dynamically Generate Panels from HTML!
@@ -59,6 +70,7 @@ $(document).ready(function(){
     var menuPanel = new Ext.Panel({
         id: 'menu_panel',
         region: 'west',
+       hidden: true,
         collapsible: true,
        split: true,
        collapseMode: 'mini',
@@ -78,14 +90,26 @@ $(document).ready(function(){
        items: create_dynamic_panels().concat([panel_bcmagic])
     });
     
+    
+    
+    //-------------------------------
+    // East Region Setup
+    //-------------------------------
     var get_east_panel_content = function(){
       // East panel contentEl id is supplied in html div id of east_region_config.
       var east_id = Ext.fly('east_region_config').dom.textContent;
       
+      // Length of zero is a valid response... also happens to return null in next
+      //   if statement if not handled before hand.
+      if (east_id.length == 0){
+       return east_id;
+      }
+      
       // If no element exists with the supplied content id, report and error.
       if (Ext.fly(east_id) == null){
        return 'east_region_config_error';
       }
+      
       return east_id;
     }
     
@@ -138,21 +162,27 @@ $(document).ready(function(){
                 },{
                     id: 'main_toolbar',
                     xtype: 'toolbar',
+                   height: 30,
                     //height: 100,
                     /*items: [{
                         text: "Demo Button",
                         handler: function() { quick_msg('Messages can be fun!'); }
                     }],*/
                     margins: '2 0 0 0'
-            }],
-            height: 60 
+               },{
+                   id: 'app_toolbar',
+                   xtype: 'toolbar',
+                   height: 30
+                   //margins: '2 0 0 0'
+               }],
+           height: 90
        },menuPanel,{
             //title: 'Body',
             region: 'center',
             xtype: 'panel',
            //autoScroll: true,
             layout: 'fit',
-            margins: '2 2 2 2',
+            margins: '2 0 2 0',
             items: [{
                 //title: 'Inner Panel',
                 contentEl: 'body_content',
@@ -167,48 +197,47 @@ $(document).ready(function(){
     //-------------------------------
     var main_tb = Ext.getCmp('main_toolbar');
     
-    var add_buttons_from_html_left = function(main_tb){
-        var left_tbar_data = Ext.fly('left_tbar_data');
-        var div_array = left_tbar_data.query('div');
-        var div_id = null;
-        // Loop through each div since it defines a button and link or a spacer and add it to the right side of the toolbar
-        Ext.each(div_array, function(divobj) {
-            div_id = divobj.id;
-            if (div_id == 'spacer'){
-                main_tb.add('-');
-            } else {
-                main_tb.add({
-                    text: div_id,
-                    handler: function() { goto_url(divobj.getAttribute('href')); }
-                });
-            }
-        });
-        //return right_tbar_data;
-    }
-    
-    var add_buttons_from_html_right = function(main_tb){
-        var right_tbar_data = Ext.fly('right_tbar_data');
-        var div_array = right_tbar_data.query('div');
+    var add_buttons_from_html = function(tb, bar_id){
+        var tbar_data = Ext.fly(bar_id);
+        var div_array = tbar_data.query('div');
         var div_id = null;
         // Loop through each div since it defines a button and link or a spacer and add it to the right side of the toolbar
         Ext.each(div_array, function(divobj) {
             div_id = divobj.id;
             if (div_id == 'spacer'){
-                main_tb.add('-');
+                tb.add('-');
             } else {
-                main_tb.add({
+                tb.add({
                     text: div_id,
                     handler: function() { goto_url(divobj.getAttribute('href')); }
                 });
             }
         });
-        //return right_tbar_data;
     }
     
-    add_buttons_from_html_left(main_tb);
+    // Fill in left side of main toolbar
+    add_buttons_from_html(main_tb, 'left_tbar_data');
     
     // Shifts the remaining toolbar options to the right side.
     main_tb.add({ xtype: 'tbfill' });
+    
+    //----------------------------------------
+    // ExtJS Barcode Magic Implementation
+    var bcmagic_ext_keyhandler = function(sObj, e){
+      //Process upon enter key as input.
+      if (e.getKey() == e.ENTER)
+       bcmagic_process();
+    }
+    
+    var bcmagic_input = new Ext.form.TextField({
+      id: 'bcmagic_input_field',
+      emptyText: 'barcode magic'
+    });
+    bcmagic_input.on('specialkey', bcmagic_ext_keyhandler);
+    
+    main_tb.add(bcmagic_input);
+    //--------------------------------------
+    
     var user_info = Ext.fly('login_info');
     var logout_url = user_info.getAttribute('logouturl');
     var login_url = user_info.getAttribute('loginurl');
@@ -219,7 +248,7 @@ $(document).ready(function(){
                         text: 'User: ' + user_info.getAttribute('user')
                     });
         main_tb.add('-');
-        add_buttons_from_html_right(main_tb);
+        add_buttons_from_html(main_tb, 'right_tbar_data');
         main_tb.add('-');
        main_tb.add({
                         text: 'Logout',
@@ -235,4 +264,15 @@ $(document).ready(function(){
     
     main_tb.doLayout();
     
+    //-------------------------------
+    // App Toolbar Setup
+    //-------------------------------
+    var app_tb = Ext.getCmp('app_toolbar');
+    add_buttons_from_html(app_tb, 'app_toolbar_west');
+    app_tb.add({ xtype: 'tbfill' });
+    add_buttons_from_html(app_tb, 'app_toolbar_east');
+    app_tb.doLayout();
+    
+    // Focus on barcode magic, because it's awesome and needs attention! ;-)
+    bcmagic_input.focus();
 });
\ No newline at end of file