2015-01-23 13:09:30 +00:00
|
|
|
|
2015-09-28 09:46:24 +00:00
|
|
|
Vn.resource ('forms/ecomerce/catalog/filter-button.xml');
|
|
|
|
Vn.define (function () {
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
Vn.Catalog = new Class
|
|
|
|
({
|
|
|
|
Extends: Vn.Module
|
2015-09-16 16:11:15 +00:00
|
|
|
|
|
|
|
,_menuShown: false
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
,open: function ()
|
|
|
|
{
|
|
|
|
if (this.basketChecked)
|
|
|
|
this.parent ();
|
|
|
|
}
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
,activate: function ()
|
|
|
|
{
|
2015-09-01 14:10:44 +00:00
|
|
|
if (!Vn.Url.getQuery ('guest'))
|
|
|
|
{
|
|
|
|
Vn.BasketChecker.check (this.conn,
|
|
|
|
this.onBasketCheck.bind (this));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var query = 'CALL basket_configure_for_guest ()';
|
|
|
|
this.conn.execQuery (query, this.onBasketForGuest.bind (this));
|
|
|
|
}
|
|
|
|
}
|
2015-09-22 07:20:47 +00:00
|
|
|
|
|
|
|
,close: function ()
|
|
|
|
{
|
|
|
|
if (this.node)
|
|
|
|
{
|
|
|
|
this.gui.$('top-bar').style.backgroundColor = '';
|
|
|
|
Vn.Node.remove (this.$('right-panel'));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.parent ();
|
|
|
|
}
|
2015-09-16 16:11:15 +00:00
|
|
|
|
2015-09-01 14:10:44 +00:00
|
|
|
,onBasketForGuest: function ()
|
|
|
|
{
|
|
|
|
this.onBasketCheck (true);
|
2015-07-28 19:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,onBasketCheck: function (isOk)
|
|
|
|
{
|
|
|
|
if (!isOk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.basketChecked = true;
|
|
|
|
this.open ();
|
2015-09-16 16:11:15 +00:00
|
|
|
|
|
|
|
document.body.appendChild (this.$('right-panel'));
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2015-07-07 15:27:47 +00:00
|
|
|
this.popup = new Htk.Popup ();
|
|
|
|
this.popup.setChildNode (this.$('lots-popup'));
|
2015-09-22 07:20:47 +00:00
|
|
|
|
|
|
|
this.setView ('GRID');
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-02-08 15:38:38 +00:00
|
|
|
|
2015-09-22 07:20:47 +00:00
|
|
|
,onSwitchViewClick: function ()
|
2015-09-16 16:11:15 +00:00
|
|
|
{
|
2015-09-22 07:20:47 +00:00
|
|
|
this.setView (this.view == 'LIST' ? 'GRID' : 'LIST');
|
|
|
|
}
|
|
|
|
|
|
|
|
,setView: function (view)
|
|
|
|
{
|
|
|
|
if (this.viewNode)
|
|
|
|
{
|
|
|
|
Vn.Node.remove (this.viewNode);
|
|
|
|
this.viewHolder.model = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view == 'GRID')
|
|
|
|
{
|
|
|
|
this.view = 'GRID';
|
|
|
|
this.viewNode = this.$('grid-view').getNode ();
|
|
|
|
this.viewHolder = this.$('grid-view');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.view = 'LIST';
|
|
|
|
this.viewNode = this.$('list-view');
|
|
|
|
this.viewHolder = this.$('items-grid');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$('main').appendChild (this.viewNode);
|
|
|
|
this.viewHolder.model = this.$('items-model');
|
2015-09-16 16:11:15 +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
|
|
|
}
|
|
|
|
|
2015-03-27 19:10:49 +00:00
|
|
|
,onTypeChange: function ()
|
2015-02-08 15:38:38 +00:00
|
|
|
{
|
2015-09-16 16:11:15 +00:00
|
|
|
if (this._menuShown && 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-09-11 09:37:16 +00:00
|
|
|
this.gui.$('top-bar').style.backgroundColor = color;
|
2015-09-16 16:11:15 +00:00
|
|
|
}
|
2015-02-08 15:38:38 +00:00
|
|
|
|
|
|
|
,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-09-11 09:37:16 +00:00
|
|
|
Vn.Node.setText (this.$('title-text'), 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-08-27 14:04:34 +00:00
|
|
|
searchTags = searchTags != '' ? searchTags : undefined;
|
2015-02-08 15:38:38 +00:00
|
|
|
|
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-08-27 14:04:34 +00:00
|
|
|
this.$('type').value = undefined;
|
|
|
|
this.$('realm').value = undefined;
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
batch.unblock ();
|
|
|
|
batch.changed ();
|
|
|
|
}
|
|
|
|
|
2015-09-16 16:11:15 +00:00
|
|
|
,onRightPanelClick: function (event)
|
2015-02-08 15:38:38 +00:00
|
|
|
{
|
|
|
|
event.stopPropagation ();
|
|
|
|
}
|
|
|
|
|
2015-03-27 19:10:49 +00:00
|
|
|
,onShowMenuClick: function (event)
|
2015-02-08 15:38:38 +00:00
|
|
|
{
|
2015-09-16 16:11:15 +00:00
|
|
|
this._menuShown = true;
|
2015-02-08 15:38:38 +00:00
|
|
|
event.stopPropagation ();
|
|
|
|
this.gui.showBackground ();
|
2015-09-16 16:11:15 +00:00
|
|
|
Vn.Node.addClass (this.$('right-panel'), 'show');
|
2015-02-08 15:38:38 +00:00
|
|
|
this.hideMenuCallback = this.hideMenu.bind (this);
|
|
|
|
document.addEventListener ('click', this.hideMenuCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
,hideMenu: function ()
|
|
|
|
{
|
2015-09-16 16:11:15 +00:00
|
|
|
if (!this._menuShown)
|
|
|
|
return;
|
|
|
|
|
2015-02-08 15:38:38 +00:00
|
|
|
this.gui.hideBackground ();
|
2015-09-16 16:11:15 +00:00
|
|
|
Vn.Node.removeClass (this.$('right-panel'), 'show');
|
2015-02-08 15:38:38 +00:00
|
|
|
document.removeEventListener ('click', this.hideMenuCallback);
|
|
|
|
this.hideMenuCallback = null;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-03-27 19:10:49 +00:00
|
|
|
,onBasketClick: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-09-01 14:10:44 +00:00
|
|
|
if (!Vn.Url.getQuery ('guest'))
|
|
|
|
this.hash.set ({'form': 'ecomerce/basket'});
|
|
|
|
else
|
|
|
|
Htk.Toast.showError (_('YouMustBeLoggedIn'));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 09:37:16 +00:00
|
|
|
,nameRenderer: function (renderer, form)
|
|
|
|
{
|
|
|
|
renderer.subtitle = form.get ('producer');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-01-23 13:09:30 +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');
|
2015-01-23 13:09:30 +00:00
|
|
|
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-09-11 09:37:16 +00:00
|
|
|
|
|
|
|
,onGridAddItemClick: function (button, form)
|
|
|
|
{
|
2015-09-16 16:11:15 +00:00
|
|
|
this.showAmountPopup (button.getNode (), form.row);
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-07-07 15:27:47 +00:00
|
|
|
,onAddItemClick: function (column, value, row, button)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
|
|
|
this.showAmountPopup (button, row);
|
|
|
|
}
|
|
|
|
|
|
|
|
,showAmountPopup: function (button, row)
|
2015-07-07 15:27:47 +00:00
|
|
|
{
|
2015-09-01 14:10:44 +00:00
|
|
|
if (Vn.Url.getQuery ('guest'))
|
|
|
|
{
|
|
|
|
Htk.Toast.showError (_('YouMustBeLoggedIn'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-07 15:27:47 +00:00
|
|
|
var itemId = this.$('items-model').get (row, 'item_id')
|
2015-08-25 09:16:13 +00:00
|
|
|
this.$('lots-batch').addValue ('item', itemId);
|
2015-07-07 15:27:47 +00:00
|
|
|
|
2015-08-27 14:04:34 +00:00
|
|
|
this.itemRow = row;
|
2015-07-07 15:27:47 +00:00
|
|
|
this.onEraseClick ();
|
2015-09-11 09:37:16 +00:00
|
|
|
this.popup.show (button);
|
2015-07-07 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,onAddLotClick: function (column, value, row, button)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
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
|
|
|
}
|
2015-01-23 13:09:30 +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-08-27 14:04:34 +00:00
|
|
|
var model = this.$('items-model');
|
|
|
|
|
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);'});
|
2015-08-27 14:04:34 +00:00
|
|
|
var amountSum = 0;
|
2015-07-21 14:16:07 +00:00
|
|
|
|
|
|
|
for (var warehouse in this.items)
|
2015-07-07 15:27:47 +00:00
|
|
|
{
|
2015-08-27 14:04:34 +00:00
|
|
|
var amount = this.items[warehouse];
|
|
|
|
amountSum += amount;
|
|
|
|
|
2015-07-21 14:16:07 +00:00
|
|
|
batch.addValue ('warehouse', warehouse);
|
2015-08-27 14:04:34 +00:00
|
|
|
batch.addValue ('item', model.get (this.itemRow, 'item_id'));
|
|
|
|
batch.addValue ('amount', amount);
|
2015-07-21 14:16:07 +00:00
|
|
|
sql += query.render (batch);
|
|
|
|
}
|
2015-07-07 15:27:47 +00:00
|
|
|
|
2015-08-27 14:04:34 +00:00
|
|
|
if (amountSum > 0)
|
|
|
|
{
|
2015-07-07 15:27:47 +00:00
|
|
|
this.conn.execQuery (sql);
|
|
|
|
|
2015-08-27 14:04:34 +00:00
|
|
|
var itemName = model.get (this.itemRow, 'Article');
|
|
|
|
Htk.Toast.showMessage (
|
|
|
|
sprintf (_('Added%dOf%s'), amountSum, itemName));
|
|
|
|
}
|
|
|
|
|
2015-07-07 15:27:47 +00:00
|
|
|
this.popup.hide ();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-07-21 14:16:07 +00:00
|
|
|
|
|
|
|
,onStatusChange: function (model)
|
|
|
|
{
|
|
|
|
if (this.popup)
|
|
|
|
this.popup.reset ();
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
});
|
|
|
|
|
2015-09-28 09:46:24 +00:00
|
|
|
Vn.FilterButton = new Class
|
|
|
|
({
|
|
|
|
Extends: Htk.Widget
|
|
|
|
,Tag: 'vn-filter-button'
|
|
|
|
,Child: 'model'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
model:
|
|
|
|
{
|
|
|
|
type: Db.Model
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._grid.model = x;
|
|
|
|
this._model = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._model;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
text:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
Vn.Node.setText (this._button, x);;
|
|
|
|
this._text = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._text;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
column:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._col.column = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._col.column;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
,initialize: function (props)
|
|
|
|
{
|
|
|
|
this.parent (props);
|
|
|
|
this.builderInit ('forms/ecomerce/catalog/filter-button.xml');
|
|
|
|
|
|
|
|
this._button = this.createElement ('button');
|
|
|
|
this._button.className = 'vn-filter-button thin';
|
|
|
|
this._button.addEventListener ('click', this._onButtonClick.bind (this));
|
|
|
|
|
|
|
|
this._grid = new Htk.Grid ();
|
|
|
|
this._grid.showHeader = false;
|
|
|
|
|
|
|
|
this._col = new Htk.ColumnText ();
|
|
|
|
this._grid.appendColumn (this._col);
|
|
|
|
}
|
|
|
|
|
|
|
|
,_onButtonClick: function ()
|
|
|
|
{
|
|
|
|
if (!this._model)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._model.refresh ();
|
|
|
|
|
|
|
|
var popup = new Htk.Popup ();
|
|
|
|
popup.setChild (this._grid);
|
|
|
|
popup.show (this._button);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Vn.ColumnItem = new Class
|
2015-09-11 09:37:16 +00:00
|
|
|
({
|
|
|
|
Extends: Htk.Column
|
|
|
|
,Tag: 'vn-column-item'
|
|
|
|
|
|
|
|
,render: function (tr)
|
|
|
|
{
|
|
|
|
var td = this.parent (tr);
|
|
|
|
td.style.textAlign = 'left';
|
|
|
|
|
|
|
|
if (this.value)
|
|
|
|
{
|
|
|
|
var node = document.createTextNode (
|
|
|
|
Vn.Value.format (this.value, this._format));
|
|
|
|
td.appendChild (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.subtitle)
|
|
|
|
{
|
|
|
|
td.appendChild (document.createElement ('br'));
|
|
|
|
td.appendChild (document.createTextNode (this.subtitle));
|
|
|
|
}
|
|
|
|
|
|
|
|
return td;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-28 09:46:24 +00:00
|
|
|
});
|