-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added form to create an expense, with a basic functionality
- Loading branch information
Showing
2 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
$(document).ready(function() { | ||
|
||
elements = { | ||
'price': $('#price'), | ||
'descripcion': $('#descripcion'), | ||
'cedula_vendedor': $('#cedula_vendedor') | ||
} | ||
|
||
forms = { | ||
'register': $('#register'), | ||
} | ||
|
||
initialize(elements) | ||
|
||
forms['register'].on('submit', function(e) { | ||
|
||
var price = to_int(elements['price']), | ||
description = trimText(elements['descripcion']), | ||
owner_document = trimText(elements['cedula_vendedor']) | ||
|
||
if(!price || price <= 0) { | ||
|
||
alert('Ingresa un precio válido') | ||
elements['price'].val('') | ||
elements['price'].focus() | ||
|
||
} else { | ||
$.post('/gasto/', { | ||
value : price, | ||
description:description, | ||
owner_document: owner_document | ||
}, function(data) { | ||
|
||
if(data.ok) { | ||
alert('La salida se registro correctamente.') | ||
initialize(elements) | ||
|
||
} else { | ||
alert(data.msg) | ||
} | ||
|
||
}) | ||
|
||
} | ||
|
||
e.preventDefault() | ||
}) | ||
|
||
|
||
}) | ||
|
||
function to_int($element) { | ||
var value = $element.val() | ||
value = value == '' ? 0 : parseInt(value) | ||
return value | ||
} | ||
|
||
function trimText($element) { | ||
return $.trim($element.val()) | ||
} | ||
|
||
function initialize(elements) { | ||
|
||
elements['price'].val('') | ||
elements['descripcion'].val('') | ||
elements['cedula_vendedor'].val('') | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,63 @@ | ||
create_expense.html | ||
<!DOCTYPE html> | ||
<html lang="es"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>Ingresar registro</title> | ||
<link rel="stylesheet" type="text/css" href="/static/css/styles.css"> | ||
<link rel="stylesheet" type="text/css" href="/static/css/icons.css"> | ||
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css"> | ||
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap-grid.min.css"> | ||
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap-reboot.min.css"> | ||
</head> | ||
<body> | ||
|
||
<!-- Content --> | ||
<div class="container"> | ||
|
||
<h1>Salida</h1> | ||
|
||
<form id="register"> | ||
|
||
<div class="form-group"> | ||
<label for="bar-code">Descripción: </label> | ||
<input type="text" class="form-control" id="descripcion" placeholder="Descripción" required> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col"> | ||
<div class="form-group"> | ||
<label for="bar-code">Cédula: </label> | ||
<div class="input-group"> | ||
<span class="input-group-addon">C.C.</span> | ||
<input type="text" class="form-control" id="cedula_vendedor" placeholder="Cédula del trabajador" required> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col"> | ||
<div class="form-group"> | ||
<label for="product-price">Precio: </label> | ||
<div class="input-group"> | ||
<span class="input-group-addon">$</span> | ||
<input type="text" id="price" class="form-control input-right" aria-label="Precio" placeholder="0" required> | ||
<span class="input-group-addon">.00</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class=text-right> | ||
<button type="submit" class="btn btn-primary pull-right">Enviar</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
<!-- Dependencies --> | ||
<script src="/static/js/jquery-3.2.1.min.js"></script> | ||
<script src="/static/js/popper.min.js"></script> | ||
<script src="/static/js/boostrap.min.js"></script> | ||
<script src="/static/js/gasto.js"></script> | ||
</body> | ||
</html> |