Skip to content

Commit

Permalink
Progress in the frontend logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbdavide committed Oct 12, 2017
1 parent b804bc3 commit 58fb095
Showing 1 changed file with 94 additions and 23 deletions.
117 changes: 94 additions & 23 deletions sales/static/js/app.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,111 @@
$(document).ready(function() {

var $amount_field = $('#amount');
console.log($('#remove_product'))
elements = {
'name': $('#name'),
'price': $('#price'),
'amount': $('#amount'),
'bar_code': $('#bar_code'),
'comission': $('#comission'),
'descripcion': $('#descripcion'),
'tipo_ingreso': $('#tipo_ingreso'),
'pay_with_card': $('#pay_with_card'),
'amount_holder': $('#amount_holder'),
'cedula_cliente': $('#cedula_cliente'),
'cedula_vendedor': $('#cedula_vendedor')
}

$('#add_product').on('click', function() {
buttons = {
'add_product': $('#add_product'),
'search_product': $('#search_product'),
'remove_product': $('#remove_product'),
}

var value = to_int($amount_field)
$amount_field.val(value + 1)
forms = {
'register': $('#register'),
'get_product': $('#get_product')
}

//TODO: No exceder la cantidad máxima de producto
initialize(elements)

})
elements['tipo_ingreso'].change(function() {
$tipo = elements['tipo_ingreso']

$('#remove_product').on('click', function() {
console.log('guasap')
var value = to_int($amount_field) - 1
$amount_field.val(value < 0 ? 0 : value)
if($tipo.val() === 'Producto')
saleProduct(elements, buttons)

})
else
saleService(elements, buttons)

$('#get_product').on('submit', function(e) {
console.log('buenala')
e.preventDefault()
})
})

buttons['add_product'].on('click', function() {

var value = to_int(elements['amount'])
elements['amount'].val(value + 1)

//TODO: No exceder la cantidad máxima de producto

})

buttons['remove_product'].on('click', function() {

var value = to_int(elements['amount']) - 1
elements['amount'].val(value < 0 ? 0 : value)

})

forms['get_product'].on('submit', function(e) {
console.log('Sending product...')
$.get('http://59dede2bb11b290012f17b52.mockapi.io/kenosis/product',
function(data) {
$('#price').val(data[0].price)
$('#name').val(data[0].name)
}
)
e.preventDefault()
})

forms['register'].on('submit', function(e) {
console.log('ja')
e.preventDefault()
})

$('#register').on('submit', function(e) {
console.log('ja')
e.preventDefault()
})

})

function to_int($element) {
var value = $element.val()
value = value == '' ? 0 : parseInt(value)
return value
var value = $element.val()
value = value == '' ? 0 : parseInt(value)
return value
}

function saleProduct(elements, buttons) {
elements['price'].attr('readonly', true)
elements['name'].attr('readonly', true)
elements['bar_code'].attr('disabled', false)
buttons['search_product'].attr('disabled', false)
}

function saleService(elements, buttons) {
elements['price'].attr('readonly', false)
elements['name'].attr('readonly', false)
elements['bar_code'].attr('disabled', true)
buttons['search_product'].attr('disabled', true)
}

function initialize(elements) {

elements['name'].val('')
elements['price'].val('')
elements['amount'].val('')
elements['bar_code'].val('')
elements['comission'].val('')
elements['descripcion'].val('')
elements['tipo_ingreso'].val('Producto')
elements['amount_holder'].val('')
elements['cedula_cliente'].val('')
elements['cedula_vendedor'].val('')

elements['pay_with_card'].prop('checked', false)

}

0 comments on commit 58fb095

Please sign in to comment.