0
1
Fork 0
hedera-web-mindshore/web/forms/ecomerce/catalog/catalog.js

252 lines
5.0 KiB
JavaScript
Raw Normal View History

Vn.Catalog = new Class
({
Extends: Vn.Module
,open: function ()
{
if (this.basketChecked)
this.parent ();
}
,activate: function ()
{
Vn.BasketChecker.check (this.conn,
this.onBasketCheck.bind (this));
}
,onBasketCheck: function (isOk)
{
if (!isOk)
return;
this.basketChecked = true;
this.open ();
2015-07-07 15:27:47 +00:00
this.popup = new Htk.Popup ();
this.popup.setChildNode (this.$('lots-popup'));
}
2015-02-08 15:38:38 +00:00
2015-07-23 15:58:48 +00:00
,typeRenderer: function (builder, form)
2015-02-08 15:38:38 +00:00
{
2015-07-23 15:58:48 +00:00
var link = builder.$('link');
link.href = this.hash.make ({'type': form.get ('tipo_id')}, true);
2015-02-08 15:38:38 +00:00
}
2015-07-23 15:58:48 +00:00
,realmRenderer: function (builder, form)
2015-02-08 15:38:38 +00:00
{
2015-07-23 15:58:48 +00:00
var link = builder.$('link');
link.href = this.hash.make ({
'form': this.hash.get ('form'),
'realm': form.get ('id')
});
var img = builder.$('image');
img.src = 'image/family/'+ form.get ('id') +'.svg';
img.title = form.get ('reino');
img.alt = img.title;
2015-02-08 15:38:38 +00:00
}
,onTypeChange: function ()
2015-02-08 15:38:38 +00:00
{
if (Vn.isMobile () && this.$('type').value)
2015-02-08 15:38:38 +00:00
this.hideMenu ();
2015-07-23 15:58:48 +00:00
var realms = this.$('realms-model');
if (!realms.ready)
return;
2015-07-07 15:27:47 +00:00
2015-02-08 15:38:38 +00:00
this.refreshTitle ();
var color = null;
2015-03-06 23:33:54 +00:00
if (this.$('type').value)
2015-07-23 15:58:48 +00:00
{
var row = realms.search ('id', this.$('realm').value);
if (row != -1)
color = '#'+ realms.get (row, 'color');
}
2015-02-08 15:38:38 +00:00
2015-03-06 23:33:54 +00:00
this.$('header').style.backgroundColor = color;
2015-02-08 15:38:38 +00:00
2015-08-17 18:02:14 +00:00
var tr = this.$('items-grid').getNode ()
.getElementsByTagName ('thead')[0]
.getElementsByTagName ('tr')[0];
//.querySelector ('thead tr');
2015-02-08 15:38:38 +00:00
tr.style.backgroundColor = color;
}
,refreshTitle: function (title)
{
2015-07-23 15:58:48 +00:00
var types = this.$('types-model');
if (!types.ready)
return;
var title = _('Catalog');
2015-02-08 15:38:38 +00:00
2015-03-06 23:33:54 +00:00
if (this.$('type').value)
2015-02-08 15:38:38 +00:00
{
2015-03-06 23:33:54 +00:00
var row = types.search ('tipo_id', this.$('type').value);
2015-02-08 15:38:38 +00:00
if (row != -1)
title = types.get (row, 'Tipo');
}
2015-03-06 23:33:54 +00:00
else if (this.$('search-entry').value)
2015-02-08 15:38:38 +00:00
title = _('SearchResults');
2015-07-23 15:58:48 +00:00
Vn.Node.setText (this.$('title'), title);
2015-02-08 15:38:38 +00:00
}
,onSearch: function (event)
{
2015-03-06 23:33:54 +00:00
var searchTags = this.$('search-entry').value;
2015-02-08 15:38:38 +00:00
searchTags = searchTags != '' ? searchTags : null;
2015-03-06 23:33:54 +00:00
var batch = this.$('batch');
2015-02-08 15:38:38 +00:00
batch.block ();
2015-03-06 23:33:54 +00:00
this.$('search').value = searchTags;
2015-02-08 15:38:38 +00:00
if (searchTags)
{
2015-03-06 23:33:54 +00:00
this.$('type').value = null;
this.$('realm').value = null;
2015-02-08 15:38:38 +00:00
}
batch.unblock ();
batch.changed ();
}
,onMenuClick: function (event)
{
event.stopPropagation ();
}
,onShowMenuClick: function (event)
2015-02-08 15:38:38 +00:00
{
event.stopPropagation ();
this.gui.showBackground ();
2015-03-07 00:56:24 +00:00
this.$('menu').style.display = 'block';
2015-02-08 15:38:38 +00:00
this.hideMenuCallback = this.hideMenu.bind (this);
document.addEventListener ('click', this.hideMenuCallback);
}
,hideMenu: function ()
{
this.gui.hideBackground ();
2015-03-07 00:56:24 +00:00
this.$('menu').style.display = 'none';
2015-02-08 15:38:38 +00:00
document.removeEventListener ('click', this.hideMenuCallback);
this.hideMenuCallback = null;
}
,onBasketClick: function ()
{
2015-07-10 12:30:08 +00:00
this.hash.set ({'form': 'ecomerce/basket'});
}
2015-07-07 15:27:47 +00:00
,featuresRender: function (renderer, form)
{
renderer.value = form.get ('Medida') +' '+ form.get ('Categoria') +' '+ form.get ('Color');
}
2015-07-23 15:58:48 +00:00
,amountRender: function (renderer, form)
{
var amount = form.get ('amount');
var grouping = form.get ('grouping');
if (amount && grouping)
renderer.value = amount / grouping;
else
renderer.value = null;
}
,amountChanged: function (renderer, row, newValue)
{
2015-03-06 23:33:54 +00:00
var model = this.$('items-model');
model.set (row, 'amount', newValue * model.get (row, 'grouping'));
}
,catRenderer: function (column, form)
{
switch (form.get ('Categoria'))
{
case 'A2':
column.td.className = 'second-category';
break;
case 'B1':
column.td.className = 'third-category';
break;
default:
column.td.className = '';
}
}
2015-07-07 15:27:47 +00:00
,onAddItemClick: function (column, value, row, button)
{
var itemId = this.$('items-model').get (row, 'item_id')
this.$('lots-batch').addValue ('item', itemId);
2015-07-07 15:27:47 +00:00
this.itemId = itemId;
this.onEraseClick ();
this.popup.show (button);
}
,onAddLotClick: function (column, value, row, button)
{
2015-07-07 15:27:47 +00:00
var model = this.$('item-lots');
var grouping = model.get (row, 'grouping');
var warehouse = model.get (row, 'warehouse_id');
2015-07-21 14:16:07 +00:00
var lotAmount = this.items[warehouse];
2015-07-07 15:27:47 +00:00
2015-07-21 14:16:07 +00:00
if (lotAmount === undefined)
lotAmount = 0;
lotAmount += grouping;
if (lotAmount <= model.get (row, 'available'))
2015-07-07 15:27:47 +00:00
{
2015-07-21 14:16:07 +00:00
this.items[warehouse] = lotAmount;
this.$('amount').value += grouping;
2015-07-07 15:27:47 +00:00
}
else
2015-08-17 18:02:14 +00:00
Htk.Toast.showError (_('NoMoreAmountAvailable'));
2015-07-07 15:27:47 +00:00
}
,onEraseClick: function ()
{
this.$('amount').value = 0;
2015-07-21 14:16:07 +00:00
this.items = {};
2015-07-07 15:27:47 +00:00
}
,onConfirmClick: function ()
{
2015-07-21 14:16:07 +00:00
var sql = '';
var batch = new Sql.Batch ();
var query = new Sql.String ({query: 'CALL basket_item_add (#warehouse, #item, #amount);'});
for (var warehouse in this.items)
2015-07-07 15:27:47 +00:00
{
2015-07-21 14:16:07 +00:00
batch.addValue ('warehouse', warehouse);
batch.addValue ('item', this.itemId);
batch.addValue ('amount', this.items[warehouse]);
sql += query.render (batch);
}
2015-07-07 15:27:47 +00:00
2015-07-21 14:16:07 +00:00
if (sql != '')
2015-07-07 15:27:47 +00:00
this.conn.execQuery (sql);
this.popup.hide ();
}
2015-07-21 14:16:07 +00:00
,onStatusChange: function (model)
{
if (this.popup)
this.popup.reset ();
}
});