Skip to content

Instantly share code, notes, and snippets.

@philipbreau
Forked from rvgarimrj/application.html.erb
Last active March 17, 2016 17:39

Revisions

  1. philipbreau revised this gist Mar 17, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion application.js
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@
    // I need the function below to call a ajax after barcode has been read from bridgeit

    window.novo_cod_barras = function (elemento,valor){

    console.log('entering novo_cod_barras()');
    if (valor === "") return;
    var parent = $(elemento).parents('.nested-fields');
    var cod_barras = $(parent).find('.cod_barras');
    @@ -75,6 +75,7 @@ window.novo_cod_barras = function (elemento,valor){
    window.onAfterCaptureScan = function(event)
    {
    try{
    console.log('entering onAfterCaptureScan()');
    var valor = event.value;
    var elemento = event.target;
    document.getElementById("barcode").value = valor;
  2. philipbreau revised this gist Mar 17, 2016. 1 changed file with 12 additions and 11 deletions.
    23 changes: 12 additions & 11 deletions application.js
    Original file line number Diff line number Diff line change
    @@ -20,8 +20,7 @@

    // I need the function below to call a ajax after barcode has been read from bridgeit

    var novo_cod_barras;
    novo_cod_barras = function (elemento,valor){
    window.novo_cod_barras = function (elemento,valor){

    if (valor === "") return;
    var parent = $(elemento).parents('.nested-fields');
    @@ -75,15 +74,17 @@ novo_cod_barras = function (elemento,valor){

    window.onAfterCaptureScan = function(event)
    {
    var valor = event.value;

    var elemento = event.target;
    document.getElementById("barcode").value = valor;
    // is ok, the value is being displayed here, but when i call the
    // function below, i get the error
    novo_cod_barras(elemento,valor);


    try{
    var valor = event.value;
    var elemento = event.target;
    document.getElementById("barcode").value = valor;
    // is ok, the value is being displayed here, but when i call the
    // function below, i get the error
    novo_cod_barras(elemento,valor);
    }
    catch(e){
    alert(e.message);
    }
    }
    $(document).on('ready page:load', function () {

  3. @rvgarimrj rvgarimrj created this gist Mar 17, 2016.
    89 changes: 89 additions & 0 deletions application.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,89 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title><%= content_for?(:title) ? yield(:title) : "Jolét" %></title>
    <%= Gon::Base.render_data({}) %>

    <%= stylesheet_link_tag "application" %>
    <%= javascript_include_tag "application" %>

    <%= javascript_include_tag "vendor/modernizr" %>
    <script type="text/javascript" src="http://api.bridgeit.mobi/bridgeit/bridgeit.js"></script>

    <%= csrf_meta_tags %>
    </head>

    <body>
    <div class="contain-to-grid sticky">
    <nav class="top-bar" data-topbar role="navigation">
    <ul class="title-area">
    <li class="name">
    <h1><%= link_to "Jolét", root_path %></li></h1>
    </li>
    <!-- Remove the class "menu-icon" to get rid of menu icon. Take out "Menu" to just have icon alone -->
    <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
    </ul>

    <section class="top-bar-section">
    <ul class="left">

    <% if user_signed_in? %>
    <li><%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link'%></li>

    <% else %>
    <li><%= link_to "Login", new_user_session_path, :class => 'navbar-link'%></li>
    <% end %>
    </ul>
    <!-- Right Nav Section -->
    <ul class="right">

    <li class="has-dropdown">
    <a href="#">Cadastros</a>
    <ul class="dropdown">
    <li><%= link_to "Produto", products_path %></li>
    <li><%= link_to "Cliente", customers_path %></li>
    <li><%= link_to "Cor", colors_path %></li>
    <li><%= link_to "Tamanho", sizes_path %></li>

    </ul>
    </li>
    <li class="divider"></li>
    <li class="has-dropdown">
    <a href="#">Pedidos</a>
    <ul class="dropdown">
    <li><%= link_to "Listar", orders_path %></li>
    <li><%= link_to "Novo", new_order_path %></li>
    </ul>

    <li class="divider"></li>
    <li><%= link_to "Relatórios" %></li>
    <li class="has-dropdown">
    <a href="#">Exportar</a>
    <ul class="dropdown">
    <li><%= link_to "Código de Barras", variations_export_path(format: "csv") %></li>
    <li><%= link_to "Base de dados", new_order_path %></li>
    </ul>

    </section>
    </nav>
    </div>
    <div class="row">
    <div class="small-12 columns">


    <p class="alert"><%= alert %></p>
    <!-- <% if user_signed_in? %>
    <%= current_user.email %>
    <% end %> -->
    <% flash.each do |key, value| %>
    <div data-alert class="alert-box radius success"><%= value %></div>
    <% end %>
    <%= yield %>
    </div>
    </div>
    </body>
    </html>
    119 changes: 119 additions & 0 deletions application.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,119 @@
    // This is a manifest file that'll be compiled into application.js, which will include all the files
    // listed below.
    //
    // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
    // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
    //
    // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
    // compiled file.
    //
    // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
    // about supported directives.
    //
    //= require jquery
    //= require jquery_ujs
    //= require variations
    //= require foundation
    //= require cocoon
    //= require turbolinks
    //= require orders

    // I need the function below to call a ajax after barcode has been read from bridgeit

    var novo_cod_barras;
    novo_cod_barras = function (elemento,valor){

    if (valor === "") return;
    var parent = $(elemento).parents('.nested-fields');
    var cod_barras = $(parent).find('.cod_barras');
    var desc_produto = $(parent).find('.desc_produto_ror');
    var cod_cor = $(parent).find('.cod_cor_ror');
    var desc_cor = $(parent).find('.desc_cor_ror');
    var desc_tamanho = $(parent).find('.desc_tamanho_ror');
    var input_preco = $(parent).find('.preco_ror');
    var input_qtd = $(parent).find('.quantidade_ror');
    var input_total = $(parent).find('.total_ror');
    var not_found = $(parent).find('.not_found');
    var barcode_variacao = $(parent).find('.barcode_ror');
    $(cod_barras).val(valor);
    $.ajax({
    type: "GET",
    url: "/consulta_produto",
    dataType: "json",
    data: { barcode: valor},
    complete: function() {},
    success: function(response)
    {
    if ((response.resultado.cod_produto === undefined) || (response.resultado.cod_produto === null))
    {
    not_found.show();
    $(cod_produto).val('');
    $(desc_produto).val('');
    $(cod_cor).val('');
    $(desc_cor).val('');
    $(desc_tamanho).val('');
    $(input_preco).val('');
    $(barcode).focus();

    }
    else
    {
    not_found.hide();
    $(cod_produto).val(response.resultado.cod_produto);
    $(desc_produto).val(response.resultado.desc_produto);
    $(cod_cor).val(response.resultado.cod_cor);
    $(desc_cor).val(response.resultado.desc_cor);
    $(desc_tamanho).val(response.resultado.desc_tamanho);
    $(input_preco).val(response.resultado.preco);
    $(barcode_variacao).val(response.resultado.barcode);
    $(input_qtd).focus();

    }
    }
    });
    }

    window.onAfterCaptureScan = function(event)
    {
    var valor = event.value;

    var elemento = event.target;
    document.getElementById("barcode").value = valor;
    // is ok, the value is being displayed here, but when i call the
    // function below, i get the error
    novo_cod_barras(elemento,valor);


    }
    $(document).on('ready page:load', function () {

    $(".not_found").hide();
    $(".add").hide();
    $(".remove").hide();
    var valor_total = $(".valor_total").text();
    var item_total = $(".item_total").text();

    $('.cod_produto_ror').attr('readonly', true);
    $('.desc_produto_ror').attr('readonly', true);
    $('.desc_cor_ror').attr('readonly', true);
    $('.desc_tamanho_ror').attr('readonly', true);
    $('.preco_ror').attr('readonly', true);
    $('.total_ror').attr('readonly', true);
    $('.read_only').attr('readonly', true);
    $('.cod_produto_ror_dev').attr('readonly', true);
    $('.desc_produto_ror_dev').attr('readonly', true);
    $('.desc_cor_ror_dev').attr('readonly', true);
    $('.desc_tamanho_ror_dev').attr('readonly', true);
    $('.preco_ror_dev').attr('readonly', true);
    $('.total_ror_dev').attr('readonly', true);
    $('.barcode_ror_dev').attr('readonly', true);

    $(function(){ $(document).foundation(); });
    $("form").on("keypress", function (e) {
    if (e.keyCode == 13) {
    return false;
    }
    });
    });

    // $(document).foundation();
    52 changes: 52 additions & 0 deletions detail_fields.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    <div class="nested-fields">
    <div class="row">
    <div class="small-6 medium-2 columns leitor">
    <a id='scanBtn' type="button"
    onclick="bridgeit.scan('scanBtn', 'onAfterCaptureScan');">Scan a Code</a>
    <form action="#" method="post">
    <input id = "barcode" class = "cod_barras" type="text" name="cod_barras" value="" />
    </form>
    </div>
    <div class="small-5 columns end not_found">
    <span class="not_found">Produto não existe ! <%= link_to 'Cadastrar ?', new_product_path, :target => "_blank", class: "button radius tiny" %></span>

    </div>
    </div>
    <div class="row">
    <%= f.input :id, :as => :hidden, input_html: { class: 'id_detail_ror' } %>
    <div class="small-6 columns show-for-small-only">
    <%= f.input :barcode, :as => :hidden, input_html: { class: 'barcode_ror' } %>
    </div>
    <%= f.input :order_id, :as => :hidden, input_html: { class: 'order_id_ror' } %>
    <div class="show-for-medium-up small-1 columns">
    <%= f.input :cod_produto, label: "Produto", input_html: { class: 'cod_produto_ror' } %>
    </div>
    <%= f.input :desc_produto,:as => :hidden, input_html: { class: 'desc_produto_ror' } %>
    <%= f.input :cod_cor,:as => :hidden, input_html: { class: 'cod_cor_ror' } %>
    <div class="small-2 show-for-medium-up columns">
    <%= f.input :desc_cor,label: "Cor", input_html: { class: 'desc_cor_ror' } %>
    </div>
    <div class="small-1 show-for-medium-up columns">
    <%= f.input :desc_tamanho,label: "Tam", input_html: { class: 'desc_tamanho_ror' } %>
    </div>
    <div class="small-2 show-for-medium-up columns">
    <%= f.input :preco,label: "Preço",input_html: { class: 'preco_ror' } %>
    </div>
    <div class="small-4 medium-1 columns">
    <% if !f.object.id.present? %>
    <%= f.input :quantidade,label: "Qtd", input_html: { class: 'quantidade_ror' } %>
    <% else %>
    <%= f.input :quantidade,label: "Qtd", input_html: { class: 'read_only' } %>
    <% end %>
    </div>
    <div class="show-for-medium-up small-2 columns end">
    <%= f.input :total,label: "Total",input_html: { class: 'total_ror' } %>
    </div>
    <div class="small-1 columns end">
    <% if !f.object.id.present? %>
    <%= link_to_remove_association "-", f, :class => "button tiny alert"%>
    <% end %>
    </div>
    <hr/>
    </div>
    </div>