135 lines
4.3 KiB
HTML
Executable File
135 lines
4.3 KiB
HTML
Executable File
<div id="products">
|
|
<div id="product_menu"></div>
|
|
<div id="product_list">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
|
|
oPedidor.pageInit = function(asHash, bFirstPage)
|
|
{
|
|
//Export button
|
|
$('#product_menu')
|
|
.addButton('excel', 'Descargar en Excel', oPedidor.getActionLink('dl_products'), '')
|
|
.addButton('search', 'Buscar por un producto', function(){switchToMode('search');}, '')
|
|
.addButton('add', 'Añadir un producto', function(){switchToMode('insert');}, '');
|
|
|
|
function switchToMode(sMode)
|
|
{
|
|
var $SwitchBtn = $('.jsgrid-mode-button');
|
|
if($SwitchBtn.hasClass('jsgrid-'+sMode+'-mode-button')) $SwitchBtn.click();
|
|
$('.jsgrid-'+sMode+'-row').find('td').eq(1).find('input').focus();
|
|
}
|
|
|
|
getInfo('products', function(asData){
|
|
|
|
//Adding null values
|
|
asData.mat_types.unshift({'id':0, 'text':'Todos'});
|
|
|
|
//Building controller
|
|
var oController = {
|
|
|
|
modifyProduct: function(sActionType, oProduct, sSuccessMsg)
|
|
{
|
|
var d = $.Deferred();
|
|
getInfo('product',
|
|
function(asItem){d.resolve(asItem); oPedidor.onFeedback('success', asItem.Producto+' '+sSuccessMsg)},
|
|
{t:sActionType, item:oProduct},
|
|
function(sMsg){oPedidor.onFeedback('error', sMsg);d.resolve({});});
|
|
|
|
return d.promise();
|
|
},
|
|
|
|
loadData: function(filter) { //search
|
|
return $.grep(this.products, function(product) {
|
|
|
|
var bValidProducto = (!filter.Producto || removeDiacritics(product.Producto).toLowerCase().indexOf(removeDiacritics(filter.Producto).toLowerCase()) > -1);
|
|
var bValidCat = (!filter.Categoria || product.Categoria == filter.Categoria);
|
|
var bValidZeta = (!filter['Codigo Zeta'] || product['Codigo Zeta'].indexOf(filter['Codigo Zeta']) > -1);
|
|
var bValidPrice = (!filter.Precio || product.Precio >= filter.Precio);
|
|
|
|
return bValidProducto && bValidCat && bValidZeta && bValidPrice;
|
|
});
|
|
},
|
|
|
|
insertItem: function(oProduct) {
|
|
//Add to search
|
|
this.products.push(oProduct);
|
|
|
|
return this.modifyProduct(self.consts.rest.insert, oProduct, 'añadido');
|
|
},
|
|
|
|
updateItem: function(oProduct) {
|
|
console.log(oProduct);
|
|
return this.modifyProduct(self.consts.rest.update, oProduct, 'modificado');
|
|
},
|
|
|
|
deleteItem: function(oProduct) {
|
|
//remove from search
|
|
var productIndex = $.inArray(oProduct, this.products);
|
|
this.products.splice(productIndex, 1);
|
|
|
|
return this.modifyProduct(self.consts.rest.remove, oProduct, 'borrado');
|
|
}
|
|
};
|
|
window.oController = oController;
|
|
oController.products = asData.products;
|
|
oController.mat_types = asData.mat_types;
|
|
|
|
$("#product_list").jsGrid({
|
|
width: "100%",
|
|
height: "calc(100% - 3em)",
|
|
filtering: true,
|
|
selecting:true,
|
|
inserting:true,
|
|
editing: true,
|
|
sorting: true,
|
|
paging: false,
|
|
autoload: true,
|
|
controller: oController,
|
|
noDataContent: 'No hay resultados (lo siento)',
|
|
confirmDeleting:true,
|
|
deleteConfirm: function(oItem){return '¿Está seguro que quiere borrar permanentemente el producto "'+oItem.Producto+'"?';},
|
|
fields: [
|
|
{name: 'Categoria', type: 'select', width:80, items: oController.mat_types, valueField:'id', textField:'text'},
|
|
{name: 'Codigo Zeta', type: 'text', width: 50},
|
|
{name: 'Producto', type:'text', width:200},
|
|
{name: 'Precio', type:'money', width:50},
|
|
{
|
|
type: 'control',
|
|
editButton: true,
|
|
deleteButton:true,
|
|
inserting:true,
|
|
modeSwitchButton:true,
|
|
searchModeButtonTooltip: "Cambiar a Buscar",
|
|
insertModeButtonTooltip: "Cambiar a añadir",
|
|
editButtonTooltip: "Editar",
|
|
deleteButtonTooltip: "Borrar",
|
|
searchButtonTooltip: "Buscar",
|
|
clearFilterButtonTooltip: "Borrar filtros",
|
|
insertButtonTooltip: "Insertar",
|
|
updateButtonTooltip: "Actualisar",
|
|
cancelEditButtonTooltip: "Cancelar"
|
|
}
|
|
],
|
|
onItemInserting: function(args) {
|
|
args.cancel = true;
|
|
if(args.item.Categoria == '0') oPedidor.onFeedback('warning', 'Eligir una categoria');
|
|
else if(args.item.Producto == '') oPedidor.onFeedback('warning', 'No hay ningun descricion por este producto');
|
|
else if(args.item.Precio <= 0) oPedidor.onFeedback('warning', 'Un producto gratis, uhm?');
|
|
else args.cancel = false;
|
|
},
|
|
onRefreshed:function(){
|
|
// $('.jsgrid-search-button').buildClone();
|
|
}
|
|
});
|
|
}, {}, function(msg){feedback('error', msg);});
|
|
};
|
|
|
|
|
|
$.prototype.buildClone = function() {
|
|
var $This = $(this);
|
|
|
|
|
|
return $This;
|
|
};
|
|
</script> |