Created
April 29, 2019 20:14
-
-
Save donrorro/6988c6139c6efc6ef79f8d5493bd004d to your computer and use it in GitHub Desktop.
modelo-js-articulo.js
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
var tabla; | |
//Función que se ejecuta al inicio | |
function init(){ | |
mostrarform(false); | |
listar(); | |
$("#formulario").on("submit",function(e) | |
{ | |
guardaryeditar(e); | |
}) | |
//Cargamos los items al select categoria | |
$.post("../ajax/articulo.php?op=selectCategoria", function(r){ | |
$("#idcategoria").html(r); | |
$('#idcategoria').selectpicker('refresh'); | |
}); | |
$("#imagenmuestra").hide(); | |
$('#mAlmacen').addClass("treeview active"); | |
$('#lArticulos').addClass("active"); | |
} | |
//Función limpiar | |
function limpiar() | |
{ | |
$("#codigo").val(""); | |
$("#nombre").val(""); | |
$("#descripcion").val(""); | |
$("#stock").val(""); | |
$("#imagenmuestra").attr("src",""); | |
$("#imagenactual").val(""); | |
$("#print").hide(); | |
$("#idarticulo").val(""); | |
} | |
//Función mostrar formulario | |
function mostrarform(flag) | |
{ | |
limpiar(); | |
if (flag) | |
{ | |
$("#listadoregistros").hide(); | |
$("#formularioregistros").show(); | |
$("#btnGuardar").prop("disabled",false); | |
$("#btnagregar").hide(); | |
} | |
else | |
{ | |
$("#listadoregistros").show(); | |
$("#formularioregistros").hide(); | |
$("#btnagregar").show(); | |
} | |
} | |
//Función cancelarform | |
function cancelarform() | |
{ | |
limpiar(); | |
mostrarform(false); | |
} | |
//Función Listar | |
function listar() | |
{ | |
tabla=$('#tbllistado').dataTable( | |
{ | |
"lengthMenu": [ 5, 10, 25, 75, 100],//mostramos el menú de registros a revisar | |
"aProcessing": true,//Activamos el procesamiento del datatables | |
"aServerSide": true,//Paginación y filtrado realizados por el servidor | |
dom: '<Bl<f>rtip>',//Definimos los elementos del control de tabla | |
buttons: [ | |
'copyHtml5', | |
'excelHtml5', | |
'csvHtml5', | |
'pdf' | |
], | |
"ajax": | |
{ | |
url: '../ajax/articulo.php?op=listar', | |
type : "get", | |
dataType : "json", | |
error: function(e){ | |
console.log(e.responseText); | |
} | |
}, | |
"language": { | |
"lengthMenu": "Mostrar : _MENU_ registros", | |
"buttons": { | |
"copyTitle": "Tabla Copiada", | |
"copySuccess": { | |
_: '%d líneas copiadas', | |
1: '1 línea copiada' | |
} | |
} | |
}, | |
"bDestroy": true, | |
"iDisplayLength": 5,//Paginación | |
"order": [[ 0, "desc" ]]//Ordenar (columna,orden) | |
}).DataTable(); | |
} | |
//Función para guardar o editar | |
function guardaryeditar(e) | |
{ | |
e.preventDefault(); //No se activará la acción predeterminada del evento | |
$("#btnGuardar").prop("disabled",true); | |
var formData = new FormData($("#formulario")[0]); | |
$.ajax({ | |
url: "../ajax/articulo.php?op=guardaryeditar", | |
type: "POST", | |
data: formData, | |
contentType: false, | |
processData: false, | |
success: function(datos) | |
{ | |
bootbox.alert(datos); | |
mostrarform(false); | |
tabla.ajax.reload(); | |
} | |
}); | |
limpiar(); | |
} | |
function mostrar(idarticulo){ | |
$.post("../ajax/articulo.php?op=mostrar",{idarticulo : idarticulo}, function(data, status) | |
{ | |
data = JSON.parse(data); | |
mostrarform(true); | |
$("#idcategoria").val(data.idcategoria); | |
$('#idcategoria').selectpicker('refresh'); | |
$("#codigo").val(data.codigo); | |
$("#nombre").val(data.nombre); | |
$("#stock").val(data.stock); | |
$("#descripcion").val(data.descripcion); | |
$("#imagenmuestra").show(); | |
$("#imagenmuestra").attr("src","../files/articulos/"+data.imagen); | |
$("#imagenactual").val(data.imagen); | |
$("#idarticulo").val(data.idarticulo); | |
//generarbarcode(); | |
}) | |
} | |
//Función para desactivar registros | |
function desactivar(idarticulo) | |
{ | |
bootbox.confirm("¿Está Seguro de desactivar el artículo?", function(result){ | |
if(result) | |
{ | |
$.post("../ajax/articulo.php?op=desactivar", {idarticulo : idarticulo}, function(e){ | |
bootbox.alert(e); | |
tabla.ajax.reload(); | |
}); | |
} | |
}) | |
} | |
//Función para activar registros | |
function activar(idarticulo) | |
{ | |
bootbox.confirm("¿Está Seguro de activar el Artículo?", function(result){ | |
if(result) | |
{ | |
$.post("../ajax/articulo.php?op=activar", {idarticulo : idarticulo}, function(e){ | |
bootbox.alert(e); | |
tabla.ajax.reload(); | |
}); | |
} | |
}) | |
} | |
//función para generar el código de barras | |
function generarbarcode() | |
{ | |
codigo=$("#codigo").val(); | |
JsBarcode("#barcode", codigo); | |
$("#print").show(); | |
} | |
//Función para imprimir el Código de barras | |
function imprimir() | |
{ | |
$("#print").printArea(); | |
} | |
init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment