2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
Vn.Catalog = new Class
|
|
|
|
({
|
2015-11-17 10:34:33 +00:00
|
|
|
Extends: Vn.Form
|
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 ()
|
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
this.close ();
|
|
|
|
this.isOpen = true;
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
if (!Vn.Cookie.check ('hedera_guest'))
|
2015-09-01 14:10:44 +00:00
|
|
|
{
|
|
|
|
Vn.BasketChecker.check (this.conn,
|
|
|
|
this.onBasketCheck.bind (this));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var query = 'CALL basket_configure_for_guest ()';
|
2015-12-10 13:48:43 +00:00
|
|
|
this.conn.execQuery (query, this.loadUi.bind (this));
|
2015-09-01 14:10:44 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
|
|
|
,onBasketCheck: function (isOk)
|
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
if (isOk)
|
|
|
|
this.loadUi ();
|
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,activate: function ()
|
|
|
|
{
|
2015-09-16 16:11:15 +00:00
|
|
|
document.body.appendChild (this.$('right-panel'));
|
2015-09-28 15:21:37 +00:00
|
|
|
|
2015-12-10 23:24:14 +00:00
|
|
|
this.$('items-model').setInfo ('a', 'Articles', 'vn2008', ['item_id']);
|
2015-12-10 13:48:43 +00:00
|
|
|
|
|
|
|
if (Vn.Cookie.check ('hedera_view'))
|
|
|
|
this.setView (Vn.Cookie.getInt ('hedera_view'));
|
|
|
|
else
|
|
|
|
this.setView (Vn.Catalog.View.GRID);
|
|
|
|
}
|
2015-09-01 14:10:44 +00:00
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,deactivate: function ()
|
2015-09-01 14:10:44 +00:00
|
|
|
{
|
2015-12-10 23:24:14 +00:00
|
|
|
this.hideMenu ();
|
2015-12-10 13:48:43 +00:00
|
|
|
this.gui.$('top-bar').style.backgroundColor = '';
|
|
|
|
Vn.Node.remove (this.$('right-panel'));
|
2015-07-28 19:14:26 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 07:20:47 +00:00
|
|
|
,setView: function (view)
|
2015-07-28 19:14:26 +00:00
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
if (view === Vn.Catalog.View.GRID)
|
2015-09-22 07:20:47 +00:00
|
|
|
{
|
2016-01-07 12:58:29 +00:00
|
|
|
this.$('view-button').setProperties ({
|
|
|
|
image: 'image/dark/view-list.svg',
|
|
|
|
tip: _('List view')
|
|
|
|
});
|
2015-12-10 13:48:43 +00:00
|
|
|
this.view = Vn.Catalog.View.GRID;
|
2016-01-08 21:00:02 +00:00
|
|
|
var className = 'grid-view';
|
2015-09-22 07:20:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-07 12:58:29 +00:00
|
|
|
this.$('view-button').setProperties ({
|
|
|
|
image: 'image/dark/view-grid.svg',
|
|
|
|
tip: _('Grid view')
|
|
|
|
});
|
2015-12-10 13:48:43 +00:00
|
|
|
this.view = Vn.Catalog.View.LIST;
|
2016-01-08 21:00:02 +00:00
|
|
|
var className = 'list-view';
|
2015-09-22 07:20:47 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 13:10:51 +00:00
|
|
|
var node = this.$('grid-view').getNode ();
|
2016-01-08 21:00:02 +00:00
|
|
|
node.className = className;
|
|
|
|
Vn.Cookie.set ('hedera_view', this.view);
|
2015-12-10 13:48:43 +00:00
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2016-01-10 13:10:51 +00:00
|
|
|
,onSwitchViewClick: function ()
|
|
|
|
{
|
|
|
|
this.setView (this.view === Vn.Catalog.View.LIST ?
|
|
|
|
Vn.Catalog.View.GRID : Vn.Catalog.View.LIST);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-02-08 15:38:38 +00:00
|
|
|
|
2015-10-08 08:15:14 +00:00
|
|
|
,onBasketReady: function (form)
|
|
|
|
{
|
|
|
|
if (form.get ('method') != 'PICKUP')
|
|
|
|
Vn.Node.setText (this.$('method'), _('Agency'));
|
|
|
|
else
|
|
|
|
Vn.Node.setText (this.$('method'), _('Warehouse'));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2016-01-07 12:58:29 +00:00
|
|
|
,onItemsChange: function (model, status)
|
|
|
|
{
|
|
|
|
if (status !== Db.Model.Status.CLEAN)
|
|
|
|
this.$('order').style.display = 'block';
|
|
|
|
else
|
|
|
|
this.$('order').style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
,onOrderChange: function (e)
|
|
|
|
{
|
|
|
|
var value = e.target.value;
|
|
|
|
var sortField = value.substr (2);
|
|
|
|
var sortWay = value.charAt (0) === 'A' ?
|
|
|
|
Db.Model.SortWay.ASC : Db.Model.SortWay.DESC;
|
|
|
|
|
|
|
|
if (sortField)
|
|
|
|
this.$('items-model').sortByName (sortField, sortWay);
|
2016-01-10 13:10:51 +00:00
|
|
|
|
|
|
|
this.hideMenu ();
|
|
|
|
}
|
|
|
|
|
|
|
|
,onFilterChange: function (param, newValue)
|
|
|
|
{
|
|
|
|
if (newValue)
|
|
|
|
this.hideMenu ();
|
2016-01-07 12:58:29 +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');
|
2016-01-07 12:58:29 +00:00
|
|
|
img.src = 'image/family_dark/'+ form.get ('id') +'.svg';
|
|
|
|
img.title = form.get ('name');
|
2015-07-23 15:58:48 +00:00
|
|
|
img.alt = img.title;
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
2016-01-07 12:58:29 +00:00
|
|
|
|
|
|
|
,onRealmChange: function (param, newValue)
|
2015-02-08 15:38:38 +00:00
|
|
|
{
|
2016-01-07 12:58:29 +00:00
|
|
|
if (newValue)
|
|
|
|
{
|
|
|
|
this.$('filters').style.display = 'block';
|
|
|
|
this.$('realm-msg').style.display = 'none';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.$('filters').style.display = 'none';
|
|
|
|
this.$('realm-msg').style.display = 'block';
|
|
|
|
}
|
|
|
|
|
|
|
|
this.refreshTitleColor ();
|
|
|
|
this.refreshFilter (newValue, undefined);
|
|
|
|
}
|
2015-07-23 15:58:48 +00:00
|
|
|
|
2016-01-07 12:58:29 +00:00
|
|
|
,onTypeChange: function (param, newValue)
|
2015-02-08 15:38:38 +00:00
|
|
|
{
|
2016-01-10 13:10:51 +00:00
|
|
|
this.onFilterChange (param, newValue);
|
2015-12-10 13:48:43 +00:00
|
|
|
this.refreshTitle ();
|
2016-01-07 12:58:29 +00:00
|
|
|
this.refreshFilter (undefined, newValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
,refreshFilter: function (realm, type)
|
|
|
|
{
|
|
|
|
var batch = this.$('filter-batch');
|
|
|
|
batch.block ();
|
|
|
|
this.$('realm-value').value = realm;
|
|
|
|
this.$('type-value').value = type;
|
|
|
|
this.$('search').value = undefined;
|
|
|
|
this.$('color').value = undefined;
|
|
|
|
this.$('origin').value = undefined;
|
|
|
|
this.$('category').value = undefined;
|
|
|
|
this.$('producer').value = undefined;
|
|
|
|
batch.unblock ();
|
|
|
|
batch.changed ();
|
2015-12-10 13:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,refreshTitleColor: function ()
|
|
|
|
{
|
2015-07-23 15:58:48 +00:00
|
|
|
var realms = this.$('realms-model');
|
2015-12-10 13:48:43 +00:00
|
|
|
|
2015-07-23 15:58:48 +00:00
|
|
|
if (!realms.ready)
|
|
|
|
return;
|
2015-02-08 15:38:38 +00:00
|
|
|
|
|
|
|
var color = null;
|
2015-12-10 13:48:43 +00:00
|
|
|
var realm = this.$('realm').value;
|
2015-02-08 15:38:38 +00:00
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
if (realm)
|
2015-07-23 15:58:48 +00:00
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
var row = realms.search ('id', realm);
|
2015-07-23 15:58:48 +00:00
|
|
|
|
|
|
|
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-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,refreshTitle: function ()
|
2015-02-08 15:38:38 +00:00
|
|
|
{
|
2015-07-23 15:58:48 +00:00
|
|
|
var types = this.$('types-model');
|
|
|
|
|
|
|
|
if (!types.ready)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var title = _('Catalog');
|
2015-12-10 13:48:43 +00:00
|
|
|
var type = this.$('type').value;
|
2015-02-08 15:38:38 +00:00
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
if (type)
|
2015-02-08 15:38:38 +00:00
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
var row = types.search ('tipo_id', type);
|
2015-02-08 15:38:38 +00:00
|
|
|
|
|
|
|
if (row != -1)
|
2015-12-10 13:48:43 +00:00
|
|
|
title = types.get (row, 'name');
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 09:37:16 +00:00
|
|
|
Vn.Node.setText (this.$('title-text'), title);
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
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-12-15 15:22:46 +00:00
|
|
|
|
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-12-10 13:48:43 +00:00
|
|
|
if (!Vn.Cookie.check ('hedera_guest'))
|
2015-09-01 14:10:44 +00:00
|
|
|
this.hash.set ({'form': 'ecomerce/basket'});
|
|
|
|
else
|
|
|
|
Htk.Toast.showError (_('YouMustBeLoggedIn'));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2016-04-26 10:36:59 +00:00
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,onConfigureClick: function ()
|
2015-09-30 06:45:42 +00:00
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
if (!Vn.Cookie.check ('hedera_guest'))
|
2015-09-30 06:45:42 +00:00
|
|
|
this.hash.set ({'form': 'ecomerce/checkout'});
|
|
|
|
else
|
|
|
|
Htk.Toast.showError (_('YouMustBeLoggedIn'));
|
|
|
|
}
|
|
|
|
|
2015-09-22 07:25:50 +00:00
|
|
|
,nameRenderer: function (renderer, form)
|
|
|
|
{
|
2015-09-11 09:37:16 +00:00
|
|
|
renderer.subtitle = form.get ('producer');
|
2015-07-07 15:27:47 +00:00
|
|
|
}
|
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
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
,onInfoClick: function (button, form)
|
|
|
|
{
|
2016-01-07 12:58:29 +00:00
|
|
|
var descNode = this.$('description');
|
2015-11-19 13:57:23 +00:00
|
|
|
Vn.Node.removeChilds (descNode);
|
|
|
|
|
2016-01-07 12:58:29 +00:00
|
|
|
var desc = form.get ('description');
|
2015-11-19 13:57:23 +00:00
|
|
|
|
|
|
|
if (!desc)
|
|
|
|
desc = _('No info available');
|
|
|
|
|
|
|
|
descNode.appendChild (document.createTextNode (desc));
|
|
|
|
|
2016-01-07 12:58:29 +00:00
|
|
|
this.$('desc-popup').show (button.getNode ());
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
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-12-10 13:48:43 +00:00
|
|
|
if (Vn.Cookie.check ('hedera_guest'))
|
2015-09-01 14:10:44 +00:00
|
|
|
{
|
|
|
|
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 ();
|
2016-01-07 12:58:29 +00:00
|
|
|
this.$('lots-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-10-14 15:02:06 +00:00
|
|
|
var available = model.get (row, 'available');
|
2015-07-21 14:16:07 +00:00
|
|
|
|
|
|
|
var lotAmount = this.items[warehouse];
|
2015-10-14 15:02:06 +00:00
|
|
|
|
2015-07-21 14:16:07 +00:00
|
|
|
if (lotAmount === undefined)
|
|
|
|
lotAmount = 0;
|
|
|
|
|
2015-10-14 15:02:06 +00:00
|
|
|
if (lotAmount < available)
|
2015-07-07 15:27:47 +00:00
|
|
|
{
|
2015-10-14 15:02:06 +00:00
|
|
|
var newAmount = lotAmount + grouping;
|
|
|
|
|
|
|
|
if (newAmount > available)
|
|
|
|
newAmount = available;
|
|
|
|
|
|
|
|
this.items[warehouse] = newAmount;
|
|
|
|
this.$('amount').value += newAmount - lotAmount;
|
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));
|
|
|
|
}
|
|
|
|
|
2016-01-07 12:58:29 +00:00
|
|
|
this.$('lots-popup').hide ();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-07-21 14:16:07 +00:00
|
|
|
|
|
|
|
,onStatusChange: function (model)
|
|
|
|
{
|
2016-01-07 12:58:29 +00:00
|
|
|
this.$('lots-popup').reset ();
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
2015-11-19 13:57:23 +00:00
|
|
|
|
|
|
|
,gridRenderer: function (res, form)
|
|
|
|
{
|
|
|
|
if (!form.get ('description'))
|
|
|
|
{
|
|
|
|
var button = res.$('info-button').getNode ();
|
|
|
|
button.style.display = 'none';
|
|
|
|
}
|
2015-07-21 14:16:07 +00:00
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
});
|
|
|
|
|
2016-01-07 12:58:29 +00:00
|
|
|
Vn.Catalog.extend
|
|
|
|
({
|
|
|
|
View: {
|
|
|
|
LIST: 0,
|
|
|
|
GRID: 1
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-14 11:51:43 +00:00
|
|
|
Vn.Filter = new Class
|
2015-09-28 09:46:24 +00:00
|
|
|
({
|
2015-11-09 17:11:51 +00:00
|
|
|
Extends: Htk.Field
|
2015-10-14 11:51:43 +00:00
|
|
|
,Tag: 'vn-filter'
|
2015-09-28 09:46:24 +00:00
|
|
|
,Child: 'model'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
model:
|
|
|
|
{
|
|
|
|
type: Db.Model
|
|
|
|
,set: function (x)
|
|
|
|
{
|
2015-11-17 10:34:33 +00:00
|
|
|
x.batch = this._batch;
|
2015-09-28 09:46:24 +00:00
|
|
|
this._model = x;
|
2015-11-19 13:57:23 +00:00
|
|
|
this._select.model = x;
|
2015-09-28 09:46:24 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._model;
|
|
|
|
}
|
|
|
|
},
|
2015-10-14 11:51:43 +00:00
|
|
|
placeholder:
|
2015-09-28 09:46:24 +00:00
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
2015-10-14 11:51:43 +00:00
|
|
|
this._select.placeholder = x;
|
|
|
|
this._placeholder = x;
|
2015-09-28 09:46:24 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
2015-10-14 11:51:43 +00:00
|
|
|
return this._placeholder;
|
2015-09-28 09:46:24 +00:00
|
|
|
}
|
|
|
|
},
|
2015-11-17 10:34:33 +00:00
|
|
|
filter:
|
|
|
|
{
|
|
|
|
type: Sql.Filter
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._filter = x;
|
|
|
|
this._batch.addObject ('filter', x);
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._filter;
|
|
|
|
}
|
|
|
|
},
|
2015-09-28 09:46:24 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
,_valueColumnIndex: 0
|
|
|
|
,_showColumnIndex: 1
|
2015-10-14 11:51:43 +00:00
|
|
|
|
2015-09-28 09:46:24 +00:00
|
|
|
,initialize: function (props)
|
|
|
|
{
|
2015-10-14 11:51:43 +00:00
|
|
|
this.createElement ('div');
|
|
|
|
this.node.className = 'vn-filter';
|
2015-09-28 09:46:24 +00:00
|
|
|
|
2015-10-14 11:51:43 +00:00
|
|
|
this._select = new Htk.Select ();
|
2016-01-07 12:58:29 +00:00
|
|
|
this._select.on ('mousedown', this._onMouseDown, this);
|
2015-11-09 17:11:51 +00:00
|
|
|
this._select.on ('changed', this._onChange, this);
|
2015-11-19 13:57:23 +00:00
|
|
|
this._select.on ('ready', this._onReady, this);
|
2015-10-14 11:51:43 +00:00
|
|
|
this.node.appendChild (this._select.getNode ());
|
2015-09-28 09:46:24 +00:00
|
|
|
|
2015-10-14 11:51:43 +00:00
|
|
|
this._ul = document.createElement ('ul');
|
|
|
|
this.node.appendChild (this._ul);
|
2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
this._batch = new Sql.Batch ();
|
2015-11-09 08:14:33 +00:00
|
|
|
this.parent (props);
|
2015-09-28 09:46:24 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 12:58:29 +00:00
|
|
|
,_onMouseDown: function (e)
|
2015-09-28 09:46:24 +00:00
|
|
|
{
|
2015-10-14 11:51:43 +00:00
|
|
|
if (this._model && this._model.status === Db.Model.Status.CLEAN)
|
2015-11-17 10:34:33 +00:00
|
|
|
this._model.refresh ();
|
2015-10-14 11:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,_onCloseClick: function (li)
|
|
|
|
{
|
2015-11-19 13:57:23 +00:00
|
|
|
this._removeSelectionNode ();
|
2015-11-17 10:34:33 +00:00
|
|
|
this._changeValue (undefined);
|
2015-10-14 11:51:43 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
,_removeSelectionNode: function ()
|
|
|
|
{
|
|
|
|
if (this._lastLi)
|
|
|
|
{
|
|
|
|
Vn.Node.remove (this._lastLi);
|
|
|
|
this._lastLi = null;
|
|
|
|
this._label = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 11:51:43 +00:00
|
|
|
,_onChange: function ()
|
2015-11-19 13:57:23 +00:00
|
|
|
{
|
2015-10-14 11:51:43 +00:00
|
|
|
if (this._select.value === null
|
|
|
|
|| this._select.value === undefined)
|
2015-09-28 09:46:24 +00:00
|
|
|
return;
|
2015-11-19 13:57:23 +00:00
|
|
|
|
|
|
|
this._realSetValue (this._select.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
,_onReady: function ()
|
|
|
|
{
|
|
|
|
if (this._emptyLabel)
|
|
|
|
this._refreshLabel ();
|
|
|
|
}
|
|
|
|
|
|
|
|
,_changeValue: function (newValue)
|
|
|
|
{
|
|
|
|
this._batch.block ();
|
|
|
|
this.value = newValue;
|
|
|
|
this._batch.unblock ();
|
|
|
|
}
|
|
|
|
|
|
|
|
,_onTimeout: function ()
|
|
|
|
{
|
|
|
|
this._select.value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
,putValue: function (value)
|
|
|
|
{
|
2016-01-07 12:58:29 +00:00
|
|
|
this._onMouseDown ();
|
2015-11-19 13:57:23 +00:00
|
|
|
this._realSetValue (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
,_realSetValue: function (value)
|
|
|
|
{
|
|
|
|
this._removeSelectionNode ();
|
2015-11-17 10:34:33 +00:00
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
if (value === null || value === undefined)
|
|
|
|
return;
|
2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
var li = this._lastLi = document.createElement ('li');
|
2015-10-14 11:51:43 +00:00
|
|
|
this._ul.appendChild (li);
|
|
|
|
|
|
|
|
var button = document.createElement ('button');
|
|
|
|
button.addEventListener ('click',
|
|
|
|
this._onCloseClick.bind (this, li));
|
|
|
|
li.appendChild (button);
|
|
|
|
|
|
|
|
var img = document.createElement ('img');
|
|
|
|
img.src = 'image/close.svg';
|
2015-11-19 13:57:23 +00:00
|
|
|
button.appendChild (img);
|
|
|
|
|
|
|
|
var text = this._label = document.createTextNode ('');
|
2015-10-14 11:51:43 +00:00
|
|
|
li.appendChild (text);
|
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
setTimeout (this._onTimeout.bind (this));
|
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
this._changeValue (value);
|
|
|
|
this._refreshLabel ();
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
,_refreshLabel: function ()
|
2015-11-17 10:34:33 +00:00
|
|
|
{
|
2015-11-19 13:57:23 +00:00
|
|
|
if (!this._label)
|
|
|
|
return;
|
2015-10-14 11:51:43 +00:00
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
var row = -1;
|
|
|
|
|
|
|
|
if (this._model.ready)
|
|
|
|
row = this._model.searchByIndex (this._valueColumnIndex, this._value);
|
|
|
|
|
|
|
|
if (row != -1)
|
|
|
|
{
|
|
|
|
var label = this._model.getByIndex (row, this._showColumnIndex);
|
|
|
|
this._label.nodeValue = label;
|
|
|
|
this._emptyLabel = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._emptyLabel = true;
|
|
|
|
this._label.nodeValue = _('Loading...');
|
|
|
|
}
|
2015-09-28 09:46:24 +00:00
|
|
|
}
|
2015-12-10 13:48:43 +00:00
|
|
|
})
|
|
|
|
|
2015-09-22 07:25:50 +00:00
|
|
|
Vn.ColumnItem = new Class
|
|
|
|
({
|
|
|
|
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-12-10 13:48:43 +00:00
|
|
|
})
|
2015-09-22 07:25:50 +00:00
|
|
|
|