Last active
March 21, 2016 18:18
-
-
Save rvgarimrj/a51bc89f389ad2e5b9ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
window.teste = function (event) { | |
// var target = event.currentTarget; | |
var target = $(event.currentTarget); | |
alert(JSON.stringify(target, null, 4)); | |
console.log(parent); | |
var parent1 = $(target).parents('.nested-fields'); | |
alert(JSON.stringify(parent1, null, 4)); | |
console.log ("parent = " +parent1); | |
var cod_barras = $(parent1).find('.cod_barras'); | |
alert(cod_barras.selector); | |
console.log(cod_barras); | |
var valor = "160P10"; | |
$(cod_barras).val(valor); | |
} | |
window.onAfterCaptureScan = function(event) | |
{ | |
try{ | |
// alert('entering onAfterCaptureScan()'); | |
var target = $(event.currentTarget); | |
alert(JSON.stringify(target, null, 4)); | |
// var parent = $(target.parentElement);//parent of "target" | |
// alert('parent = ' + parent); | |
var parent1 = $(target).parents('.nested-fields'); | |
alert(JSON.stringify(parent1, null, 4)); | |
var valor = event.value; | |
var cod_barras = $(parent1).find('.cod_barras'); | |
$(cod_barras).val(valor); // I could not make the cod_barras input value change, nor the other elements inside ajax function | |
// $(cod_barras).attr('value', valor); // I tried this but no success also | |
alert($(cod_barras).val() + valor); // Here I get undefined + the correct value | |
if (valor === "") return; | |
var cod_barras = $(parent1).find('.cod_barras'); | |
var desc_produto = $(parent1).find('.desc_produto_ror'); | |
var cod_cor = $(parent1).find('.cod_cor_ror'); | |
var desc_cor = $(parent1).find('.desc_cor_ror'); | |
var desc_tamanho = $(parent1).find('.desc_tamanho_ror'); | |
var input_preco = $(parent1).find('.preco_ror'); | |
var input_qtd = $(parent1).find('.quantidade_ror'); | |
var input_total = $(parent1).find('.total_ror'); | |
var not_found = $(parent1).find('.not_found'); | |
var barcode_variacao = $(parent1).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)) | |
{ | |
alert("nao achei"); | |
not_found.show(); | |
$(cod_produto).val(''); | |
$(desc_produto).val(''); | |
$(cod_cor).val(''); | |
$(desc_cor).val(''); | |
$(desc_tamanho).val(''); | |
$(input_preco).val(''); | |
$(barcode).focus(); | |
} | |
else | |
{ | |
alert("achei"); | |
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(); | |
} | |
} | |
}); | |
} | |
catch(e){ | |
alert(e.message); | |
} | |
} | |
$(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; | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if @tipo == "devolucao" %> | |
<div class="nested-fields"> | |
<div class="row listCod" data-cod="<%= f.object.barcode %>"> | |
<div class="small-6 columns show-for-small-only"> | |
<%= f.input :barcode, label: "Cod Barras", input_html: { class: 'barcode_ror_dev' } %> | |
</div> | |
<%= f.input :order_id, :as => :hidden, input_html: { class: 'order_id_ror_dev' } %> | |
<div class="show-for-medium-up small-2 columns"> | |
<%= f.input :cod_produto, label: "Produto", input_html: { class: 'cod_produto_ror_dev' } %> | |
</div> | |
<%= f.input :desc_produto,:as => :hidden, input_html: { class: 'desc_produto_ror_dev' } %> | |
<%= f.input :cod_cor,:as => :hidden, input_html: { class: 'cod_cor_ror_dev' } %> | |
<div class="small-2 show-for-medium-up columns"> | |
<%= f.input :desc_cor,label: "Cor", input_html: { class: 'desc_cor_ror_dev' } %> | |
</div> | |
<div class="small-2 show-for-medium-up columns"> | |
<%= f.input :desc_tamanho,label: "Tam", input_html: { class: 'desc_tamanho_ror_dev' } %> | |
</div> | |
<div class="small-2 show-for-medium-up columns"> | |
<%= f.input :preco,label: "Preço",input_html: { class: 'preco_ror_dev' } %> | |
</div> | |
<div class="small-6 medium-2 columns"> | |
<%= f.input :quantidade_dev,label: "Qtd Dev", input_html: { class: 'quantidade_ror_dev' } %> | |
</div> | |
<div class="show-for-medium-up medium-2 columns end"> | |
<%= f.input :total_dev,label: "Total Dev",input_html: { class: 'total_ror_dev' } %> | |
</div> | |
<div class="small-1 columns end"> | |
<%= link_to_remove_association "-", f, :class => "button tiny alert remove"%> | |
</div> | |
</div> | |
</div> | |
<% else %> | |
<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> | |
<a id='teste' type="button" | |
onclick="teste(event);">teste</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> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment