rhomobile / rhoelements-issues

Issues area for RhoElements
0 stars 0 forks source link

Barcode scanning with JS api from erb views #14

Closed pfmaggi closed 11 years ago

pfmaggi commented 11 years ago

using beta47, with the barcode extension in the build.yml.

If I use the following HTML page, and it works:

<html>
<head>
<script src="/public/api/rhoapi-modules.js"></script>
<script>
// Take Barcode callback, here we've the barcode and status params
// - barcode
// - status
function fnTBCallback(params) {
  if (params["status"]=="ok") {
    alert('Barcode scanning complete. Scanned barcode: '+params["barcode"]);
    document.getElementById("scanData").value = params["barcode"];
  } else {
    alert('Barcode scanning aborted');
  }
  Rho.Barcode.stop();
}

// Take Barcode and start the scanning (single shot, no HW button)
function fnTakeBarcode() {
  Rho.Barcode.take({}, fnTBCallback);
  Rho.Barcode.start();
}

// Enable Barcode callback, here we've the full params:
// - data
// - source
// - type
// - time
// - lenght
// - direction
function fnEBCallback(params) {
  document.getElementById("scanData").value = params["data"];
}

// Enable Barcode, HW button will start the scanning
function fnEnableBarcode() {
  Rho.Barcode.enable({}, fnEBCallback);
}

</script>
</head>
<body>
<h1>RhoElements v4.0 Barcode API</h1>

<form action="#">
<input type="text" id="scanData" value="100">
<input type="button" value="Take Barcode" onclick="fnTakeBarcode();">
<input type="button" value="Enable Barcode" onclick="fnEnableBarcode();">
<input type="button" value="Quit App" onclick="Rho.Application.quit();">
</form>
</body>
</html>

If I try to use in the following erb files, nothing happens and I don't see any particular message in the log. This is the erb file (in layout.erb I'm NOT loading the rhoapi-modules.js):

<div data-role="page">

  <div data-role="header" data-position="fixpos">
  <h1>Transferring data...</h1>
  <a href="<%= Rho::RhoConfig.start_path %>" class="ui-btn-left" data-icon="home" data-direction="reverse" <%= "data-ajax='false'" if is_bb6 %>>
    Home
  </a>
  </div>

  <div data-role="content">
    <h2>Items Page</h2>
  </div>

</div>
genywind commented 11 years ago

you should include in layout.erb to use JS API from erb-file

include it before JQM!

pfmaggi commented 11 years ago

Done, and it works. Thanks. so at this moment I've in my layout.erb:

        <script src="/public/api/rhoapi-modules.js" type="text/javascript"s></script>
        <script src="/public/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>

        <link rel="stylesheet" href="/public/jqmobile/jquery.mobile-1.3.1.min.css">
        <link rel="stylesheet" href="/public/css/jqmobile-patch.css">
        <script type="text/javascript" charset="utf-8" src="/public/jqmobile/jquery.mobile-1.3.1.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="/public/js/jqmobile-patch.js"></script>

~Pietro