After scanning a barcode, I'm trying to take the barcode value, one other value, and perhaps the date/time and insert them into a table in my Postgres database on the server. I found some XBasic examples in the docs, but the docs indicate that the code will only work for desktop apps. The code for this comes from Bob's PhoneGap sample app and looks like this:
You can see that I will return result.text to the calling program, which in this case is the Click event of a button (or I could maybe do the insert directly from the scanBarCode function, but I'd like that function to only do scanning and not do database operations). So from the Click event of the button, I could call another function that would handle this, but I'm not sure how to do this from JavaScript or if I can somehow use XBasic to do it. Some detailed code examples would be helpful. I'm new to Alpha and I'm only just starting to get my head around how to make things happen. I'm good with the SQL statements, just not how to get them executed in Alpha from Javascript.
Code:
function scanBarCode(){ if ({dialog.object}.appVars.debug) { console.log('scanBarCode function called.'); } // this is a minimal check to verify plugin installation if (typeof (cordova) == 'undefined') { alert('PhoneGap plugin is not installed.'); return 'Test'; } cordova.plugins.barcodeScanner.scan(function(result) { //save to global for use in callback if ISBN not found {dialog.object}.appVars.scannerResult = result; if (result.cancelled) { navigator.notification.alert('Scan cancelled.'); } else { navigator.notification.alert('Barcode value = ' + result.text); return result.text; // var _lookupUrl = 'https://itunes.apple.com/lookup?isbn='+result.text; // {dialog.object}.ajaxCallbackCrossDomain(_lookupUrl,'iTunesCallback'); } }, function(error) { navigator.notification.alert('Scanner failed: '+error); }); }
Comment