Last active
December 2, 2017 16:54
-
-
Save destinius/53a221f825537b48447e45ca41c205f7 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
/** | |
* Ajax action to api rest | |
*/ | |
function producto(){ | |
var p = Ladda.create( document.querySelector( '#producto' ) ); | |
p.start(); | |
$.ajax({ | |
type : "POST", | |
url : "api/producto/crear", | |
data : $('#producto_form').serialize(), | |
success : function(json) { | |
if(json.success == 1) { | |
success_toastr('Realizado!', json.message); | |
setTimeout(function(){ | |
location.reload(); | |
},1000); | |
} else { | |
error_toastr('Ups!', json.message); | |
} | |
}, | |
error : function(xhr, status) { | |
error_toastr('Error', 'Ha ocurrido un problema'); | |
}, | |
complete: function() { | |
p.stop(); | |
} | |
}); | |
} | |
/** | |
* Events | |
* | |
* @param {*} e | |
*/ | |
$('#producto').click(function(e) { | |
e.defaultPrevented; | |
producto(); | |
}); | |
$('form#producto_form input').keypress(function(e) { | |
e.defaultPrevented; | |
if(e.which == 13) { | |
producto(); | |
} | |
}); |
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
{% extends 'overall/layout' %} | |
{% block appBody %} | |
<div class="content-wrapper"> | |
{% set view_name = 'Crear un lugar' %} | |
{% include 'overall/breadcrumbs' %} | |
<section class="content"> | |
<div class="box"> | |
<div class="box-header with-border"> | |
<h3 class="box-title">Creación</h3> | |
</div> | |
<div class="box-body"> | |
<form role="form" id="producto_form"> | |
<div class="row"> | |
<div class="form-group col-xs-12 col-sm-12 col-md-6"> | |
<label>Codigo <span class="required">*</span></label> | |
<input type="text" name="codigo" id="id_codigo" class="form-control" placeholder="Codigo del producto" /> | |
</div> | |
<div class="form-group col-xs-12 col-sm-12 col-md-6"> | |
<label>Nombre <span class="required">*</span></label> | |
<input type="text" name="nombre" id="id_nombre" class="form-control" placeholder="nombre del producto" /> | |
</div> | |
<div class="form-group col-xs-12 col-sm-12 col-md-6"> | |
<label>descripcion <span class="required">*</span></label> | |
<input type="text" name="descripcion" id="id_descripcion" class="form-control" placeholder="descripcion del producto" /> | |
</div> | |
<div class="form-group col-xs-12 col-sm-12 col-md-6"> | |
<label>stock_teorico <span class="required">*</span></label> | |
<input type="int" name="stock_teorico" id="id_stock_teorico" class="form-control" placeholder="stock_teorico del producto" /> | |
</div> | |
<div class="form-group col-xs-12 col-sm-12 col-md-6"> | |
<label>stock_fisico <span class="required">*</span></label> | |
<input type="int" name="stock_fisico" id="id_stock_fisico" class="form-control" placeholder="stock_fisico del producto" /> | |
</div> | |
<div class="form-group col-xs-12 col-sm-12 col-md-6"> | |
<label>fecha_fisico <span class="required">*</span></label> | |
<input type="int" name="fecha_fisico" id="id_fecha_fisico" class="form-control" placeholder="fecha_fisico del producto" /> | |
</div> | |
<div class="form-group col-xs-12 col-sm-12 col-md-6"> | |
<label>es_uniforme <span class="required">*</span></label> | |
<input type="int" name="es_uniforme" id="id_es_uniforme" class="form-control" placeholder="es_uniforme del producto" /> | |
</div> | |
<div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12"> | |
<button type="button" class="btn btn-primary btn-flat" id="producto"><i class="fa fa-save"></i> Guardar Información</button> | |
</div> | |
</div> | |
</form> | |
</div> | |
</div> | |
</section> | |
</div> | |
{% endblock %} | |
{% block appFooter %} | |
<script src="views/app/js/producto/crear.js"></script> | |
{% endblock %} |
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
<?php | |
/* | |
* This file is part of the Ocrend Framewok 2 package. | |
* | |
* (c) Ocrend Software <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
use app\models as Model; | |
/* | |
$app->post('/', function() use($app) { | |
return $app->json(array()); | |
}); | |
*/ | |
/** | |
* Acción vía ajax de Producto en api/producto | |
* | |
* @return json | |
*/ | |
$app->post('/producto/crear', function() use($app) { | |
$p = new Model\Producto; | |
return $app->json($p->crear()); | |
}); |
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
<?php | |
/* | |
* This file is part of the Ocrend Framewok 2 package. | |
* | |
* (c) Ocrend Software <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace app\models; | |
use app\models as Model; | |
use Ocrend\Kernel\Models\Models; | |
use Ocrend\Kernel\Models\IModels; | |
use Ocrend\Kernel\Models\ModelsException; | |
use Ocrend\Kernel\Models\Traits\DBModel; | |
use Ocrend\Kernel\Router\IRouter; | |
/** | |
* Modelo Producto | |
* | |
* @author UCAB <[email protected]> | |
*/ | |
class Producto extends Models implements IModels { | |
/** | |
* Característica para establecer conexión con base de datos. | |
*/ | |
use DBModel; | |
/** | |
* Devuelve un arreglo para la api | |
* | |
* @return array | |
*/ | |
final public function foo() : array { | |
try { | |
global $http; | |
return array('success' => 1, 'message' => 'Funcionando'); | |
} catch(ModelsException $e) { | |
return array('success' => 0, 'message' => $e->getMessage()); | |
} | |
} | |
/** | |
* Obtiene elementos de Producto en | |
* | |
* @param string $select: Elementos de a seleccionar | |
* | |
* @return false|array: false si no hay datos. | |
* array con los datos. | |
*/ | |
final public function get(string $select = '*') { | |
return $this->db->select($select,''); | |
} | |
/** | |
* __construct() | |
*/ | |
public function __construct(IRouter $router = null) { | |
parent::__construct($router); | |
$this->startDBConexion(); | |
} | |
/** | |
* __destruct() | |
*/ | |
public function __destruct() { | |
parent::__destruct(); | |
$this->endDBConexion(); | |
} | |
private $codigo; | |
private $nombre; | |
private $descripcion; | |
private $stock_teorico; | |
private $stock_fisico; | |
private $fecha_fisico; | |
private $es_uniforme; | |
private function errors() { | |
global $http; | |
# Obtener datos del formulario | |
$this->codigo = $http->request->get('codigo'); | |
$this->nombre = $http->request->get('nombre'); | |
$this->descripcion = $http->request->get('descripcion'); | |
$this->stock_teorico = $http->request->get('stock_teorico'); | |
$this->stock_fisico = $http->request->get('stock_fisico'); | |
$this->fecha_fisico = $http->request->get('fecha_fisico'); | |
$this->fecha_fisico = $http->request->get('es_uniforme'); | |
# El segundo parámetro es lo que quieres que tenga, si no se envió desde el formulario | |
# Verificar que el nombre y el tipo estén llenos | |
if($this->functions->e($this->codigo,$this->nombre,$this->descripcion,$this->stock_teorico,$this->stock_fisico,$this->fecha_fisico,$this->es_uniforme)) | |
{ | |
throw new ModelsException('Los datos con * son necesarios.'); | |
} | |
} | |
public function crear() : array { | |
try { | |
# Verificar errores | |
# $this->errors(); | |
# Crear la localidad | |
$this->db->query("INSERT INTO material_3 (codigo,nombre,descripcion,stock_teorico,stock_fisico,fecha_fisico,es_uniforme) | |
VALUES( | |
'$this->codigo', | |
'$this->nombre', | |
'$this->descripcion', | |
'$this->stock_teorico', | |
'$this->stock_fisico', | |
'$this->fecha_fisico', | |
'$this->es_uniforme' | |
);"); | |
return array('success' => 1, 'message' => 'Creada con éxito'); | |
} catch(ModelsException $e) { | |
return array('success' => 0, 'message' => $e->getMessage()); | |
} | |
} | |
public function leer(bool $multi = true) { | |
if($multi) { | |
return $this->db->query_select("SELECT codigo, nombre, descripcion, stock_teorico, stock_fisico, fecha_fisico, es_uniforme | |
FROM material_3 AS l3 "); | |
} | |
return $this->db->query_select("SELECT * FROM material_3 WHERE id_material='$this->id' LIMIT 1"); | |
} | |
/** | |
* Borra una localidad si no existen localidades relacionadas a ella. | |
* | |
* @return void | |
*/ | |
} |
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
<?php | |
/* | |
* This file is part of the Ocrend Framewok 2 package. | |
* | |
* (c) Ocrend Software <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace app\controllers; | |
use app\models as Model; | |
use Ocrend\Kernel\Router\IRouter; | |
use Ocrend\Kernel\Controllers\Controllers; | |
use Ocrend\Kernel\Controllers\IControllers; | |
/** | |
* Controlador producto/ | |
* | |
* @author UCAB <[email protected]> | |
*/ | |
class productoController extends Controllers implements IControllers { | |
public function __construct(IRouter $router) { | |
parent::__construct($router); | |
global $config; | |
$p = new Model\Producto($router); | |
$producto = $p->leer(); | |
switch ($this->method) { | |
case 'crear': | |
echo $this->template->render('producto/crear',array( | |
'producto' => $producto | |
)); | |
break; | |
case 'editar': | |
if($this->isset_id and false !== ($item = $p->leer(false))) { | |
echo $this->template->render('producto/editar', array( | |
'data' => $item[0], | |
'producto' => $producto | |
)); | |
} else { | |
$this->functions->redir($config['site']['url'] . 'producto/&success=false'); | |
} | |
break; | |
case 'eliminar': | |
$p->borrar(); | |
break; | |
default: | |
echo $this->template->render('producto/producto',array( | |
'producto' => $producto | |
)); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment