Adding barcode magic commands:
[htsworkflow.git] / www / js / magicbc.js
index 512fc7456c6841ea084f55ee478b117f7a4f2aaf..b7cdae1b28298b07b1d928632cdf717a79d613b0 100644 (file)
@@ -33,6 +33,10 @@ var bcmagic_process_callback = function(data, textStatus) {
                     bcmagic_status('Error', 'No redirect URL provided by server');
                 }
             }
+            else if (data['mode'] == 'autofill')
+            {
+                bcmagic_autofill(data['field'], data['value'])
+            }
             else {
                 bcmagic_message('Message recieved!');
                 bcmagic_status(data['mode'], data['status']);    
@@ -59,9 +63,12 @@ var bcmagic_process = function(){
     var text = magic.attr('value');
     magic.attr('value', '');
     
+    var bcm_mode = $("#id_bcm_mode");
+    var mode = bcm_mode.attr('value');
+    
     // Show what we have captured
     bcmagic_message('Sent command to server');
-    $.post('/bcmagic/magic/', {'text': text}, bcmagic_process_callback, 'json');
+    $.post('/bcmagic/magic/', {'text': text, 'bcm_mode': mode}, bcmagic_process_callback, 'json');
 }
 
 var bcmagic_keyhandler = function(e) {
@@ -100,6 +107,32 @@ var bcmagic_redirect = function(url)
     window.location = url;
 }
 
+var bcmagic_autofill = function(field, val)
+{
+    var txtbox = $('#'+field);
+    txtbox.attr('value', val);
+    
+    var input_fields = $('form input').not(':hidden').not('[type=submit]');
+    
+    // Count the number of text fields which have been filled in.
+    var count = 0;
+    input_fields.each( function(){
+                   if(this.value.length > 0){
+                        count = count + 1;
+                   }
+                });
+    
+    // If the number of text fields filled in is equal to the number of input_fields in the form, submit the form!
+    if (count == input_fields.length)
+    {
+        bcmagic_status('Form Full', 'Form is now full and ready to process');
+    }
+    else
+    {
+        bcmagic_status('Form Fill Count', 'Count(' + count +') - Total(' + input_fields.length + ')');
+    }
+}
+
 //---------------------------------------
 // Main Ready Function
 //---------------------------------------