2015-01-23 13:09:30 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
Hedera.Catalog = new Class({
|
2016-09-26 09:28:47 +00:00
|
|
|
Extends: Hedera.Form
|
2015-09-16 16:11:15 +00:00
|
|
|
|
|
|
|
,_menuShown: false
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,open: function() {
|
|
|
|
this.close();
|
2015-12-10 13:48:43 +00:00
|
|
|
this.isOpen = true;
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
if (!localStorage.getItem('hederaGuest')) {
|
|
|
|
Hedera.BasketChecker.check(this.conn,
|
|
|
|
this.onBasketCheck.bind(this));
|
|
|
|
} else {
|
|
|
|
var query = 'CALL mybasket_configureForGuest';
|
|
|
|
this.conn.execQuery(query, this.loadUi.bind(this));
|
2015-09-01 14:10:44 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onBasketCheck: function(isOk) {
|
2015-12-10 13:48:43 +00:00
|
|
|
if (isOk)
|
2019-05-21 14:16:27 +00:00
|
|
|
this.loadUi();
|
2015-12-10 13:48:43 +00:00
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,activate: function() {
|
2022-05-28 01:18:06 +00:00
|
|
|
document.body.appendChild(this.$.rightPanel);
|
2015-09-28 15:21:37 +00:00
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.itemsModel.setInfo('i', 'item', 'vn', ['id']);
|
2015-12-10 13:48:43 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
if (localStorage.getItem('hederaView'))
|
|
|
|
this.setView(parseInt(localStorage.getItem('hederaView')));
|
2015-12-10 13:48:43 +00:00
|
|
|
else
|
2019-05-21 14:16:27 +00:00
|
|
|
this.setView(Hedera.Catalog.View.GRID);
|
2015-12-10 13:48:43 +00:00
|
|
|
}
|
2015-09-01 14:10:44 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,deactivate: function() {
|
|
|
|
this.hideMenu();
|
2022-05-28 01:18:06 +00:00
|
|
|
this.gui.$.topBar.style.backgroundColor = '';
|
|
|
|
Vn.Node.remove(this.$.rightPanel);
|
2015-07-28 19:14:26 +00:00
|
|
|
}
|
2016-04-26 10:54:12 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,setView: function(view) {
|
|
|
|
if (view === Hedera.Catalog.View.GRID) {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.viewButton.setProperties({
|
2022-05-25 18:04:16 +00:00
|
|
|
icon: 'view_list',
|
2016-01-07 12:58:29 +00:00
|
|
|
tip: _('List view')
|
|
|
|
});
|
2016-09-26 09:28:47 +00:00
|
|
|
this.view = Hedera.Catalog.View.GRID;
|
2016-01-08 21:00:02 +00:00
|
|
|
var className = 'grid-view';
|
2019-05-21 14:16:27 +00:00
|
|
|
} else {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.viewButton.setProperties({
|
2022-05-25 18:04:16 +00:00
|
|
|
icon: 'grid_on',
|
2016-01-07 12:58:29 +00:00
|
|
|
tip: _('Grid view')
|
|
|
|
});
|
2016-09-26 09:28:47 +00:00
|
|
|
this.view = Hedera.Catalog.View.LIST;
|
2016-01-08 21:00:02 +00:00
|
|
|
var className = 'list-view';
|
2015-09-22 07:20:47 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
var node = this.$.gridView.node;
|
2016-01-08 21:00:02 +00:00
|
|
|
node.className = className;
|
2019-05-21 14:16:27 +00:00
|
|
|
localStorage.setItem('hederaView', this.view);
|
2015-12-10 13:48:43 +00:00
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onSwitchViewClick: function() {
|
|
|
|
this.setView(this.view === Hedera.Catalog.View.LIST ?
|
2016-09-26 09:28:47 +00:00
|
|
|
Hedera.Catalog.View.GRID : Hedera.Catalog.View.LIST);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-02-08 15:38:38 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onBasketReady: function(form) {
|
2022-05-28 15:49:46 +00:00
|
|
|
if (form.$.method != 'PICKUP')
|
2022-05-28 01:18:06 +00:00
|
|
|
Vn.Node.setText(this.$.method, _('Agency'));
|
2015-10-08 08:15:14 +00:00
|
|
|
else
|
2022-05-28 01:18:06 +00:00
|
|
|
Vn.Node.setText(this.$.method, _('Warehouse'));
|
2015-10-08 08:15:14 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onItemsChange: function(model, status) {
|
2016-01-07 12:58:29 +00:00
|
|
|
if (status !== Db.Model.Status.CLEAN)
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.order.style.display = 'block';
|
2016-01-07 12:58:29 +00:00
|
|
|
else
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.order.style.display = 'none';
|
2016-01-07 12:58:29 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onOrderChange: function(e) {
|
2016-01-07 12:58:29 +00:00
|
|
|
var value = e.target.value;
|
2019-05-21 14:16:27 +00:00
|
|
|
var sortField = value.substr(2);
|
|
|
|
var sortWay = value.charAt(0) === 'A' ?
|
2016-01-07 12:58:29 +00:00
|
|
|
Db.Model.SortWay.ASC : Db.Model.SortWay.DESC;
|
|
|
|
|
|
|
|
if (sortField)
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.itemsModel.sortByName(sortField, sortWay);
|
2016-01-10 13:10:51 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
this.hideMenu();
|
2016-01-10 13:10:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onFilterChange: function(param, newValue) {
|
2016-01-10 13:10:51 +00:00
|
|
|
if (newValue)
|
2019-05-21 14:16:27 +00:00
|
|
|
this.hideMenu();
|
2016-01-07 12:58:29 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,realmRenderer: function(builder, form) {
|
2022-05-28 01:18:06 +00:00
|
|
|
var link = builder.$.link;
|
2019-05-21 14:16:27 +00:00
|
|
|
link.href = this.hash.make({
|
2022-05-28 15:49:46 +00:00
|
|
|
form: this.hash.$.form,
|
|
|
|
realm: form.$.id
|
2015-07-23 15:58:48 +00:00
|
|
|
});
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
2016-01-07 12:58:29 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onRealmChange: function(param, newValue) {
|
|
|
|
if (newValue) {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.filters.style.display = 'block';
|
|
|
|
this.$.realmMsg.style.display = 'none';
|
2019-05-21 14:16:27 +00:00
|
|
|
} else {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.filters.style.display = 'none';
|
|
|
|
this.$.realmMsg.style.display = 'block';
|
2016-01-07 12:58:29 +00:00
|
|
|
}
|
2022-05-05 13:54:53 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
this.refreshFilter(newValue, undefined);
|
2016-01-07 12:58:29 +00:00
|
|
|
}
|
2015-07-23 15:58:48 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onTypeChange: function(param, newValue) {
|
|
|
|
this.onFilterChange(param, newValue);
|
|
|
|
this.refreshTitle();
|
|
|
|
this.refreshFilter(undefined, newValue);
|
2016-01-07 12:58:29 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,refreshFilter: function(realm, type) {
|
2022-05-28 01:18:06 +00:00
|
|
|
var batch = this.$.filterBatch;
|
2019-05-21 14:16:27 +00:00
|
|
|
batch.block();
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.realmValue.value = realm;
|
|
|
|
this.$.typeValue.value = type;
|
|
|
|
this.$.search.value = undefined;
|
|
|
|
this.$.color.value = undefined;
|
|
|
|
this.$.origin.value = undefined;
|
|
|
|
this.$.category.value = undefined;
|
|
|
|
this.$.producer.value = undefined;
|
2019-05-21 14:16:27 +00:00
|
|
|
batch.unblock();
|
|
|
|
batch.changed();
|
2015-12-10 13:48:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,refreshTitle: function() {
|
2022-05-28 01:18:06 +00:00
|
|
|
var types = this.$.typesModel;
|
2015-07-23 15:58:48 +00:00
|
|
|
|
|
|
|
if (!types.ready)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var title = _('Catalog');
|
2022-05-28 01:18:06 +00:00
|
|
|
var type = this.$.type.value;
|
2015-02-08 15:38:38 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
if (type) {
|
|
|
|
var row = types.search('id', type);
|
2015-02-08 15:38:38 +00:00
|
|
|
|
|
|
|
if (row != -1)
|
2019-05-21 14:16:27 +00:00
|
|
|
title = types.get(row, 'name');
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
Vn.Node.setText(this.$.titleText, title);
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onRightPanelClick: function(event) {
|
|
|
|
event.stopPropagation();
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onShowMenuClick: function(event) {
|
2015-09-16 16:11:15 +00:00
|
|
|
this._menuShown = true;
|
2019-05-21 14:16:27 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
this.gui.showBackground();
|
2022-05-28 01:18:06 +00:00
|
|
|
Vn.Node.addClass(this.$.rightPanel, 'show');
|
2019-05-21 14:16:27 +00:00
|
|
|
this.hideMenuCallback = this.hideMenu.bind(this);
|
|
|
|
document.addEventListener('click', this.hideMenuCallback);
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,hideMenu: function() {
|
2015-09-16 16:11:15 +00:00
|
|
|
if (!this._menuShown)
|
|
|
|
return;
|
2015-12-15 15:22:46 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
this.gui.hideBackground();
|
2022-05-28 01:18:06 +00:00
|
|
|
Vn.Node.removeClass(this.$.rightPanel, 'show');
|
2019-05-21 14:16:27 +00:00
|
|
|
document.removeEventListener('click', this.hideMenuCallback);
|
2015-02-08 15:38:38 +00:00
|
|
|
this.hideMenuCallback = null;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,isGuest: function() {
|
|
|
|
if (localStorage.getItem('hederaGuest')) {
|
|
|
|
Htk.Toast.showError(_('YouMustBeLoggedIn'));
|
2016-05-04 14:36:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-09-30 06:45:42 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onBasketClick: function() {
|
|
|
|
if (this.isGuest())
|
2016-05-04 14:36:51 +00:00
|
|
|
return;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-28 00:37:24 +00:00
|
|
|
this.hash.set({form: 'ecomerce/basket'});
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2016-05-04 14:36:51 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onConfigureClick: function() {
|
|
|
|
if (this.isGuest())
|
2016-05-04 14:36:51 +00:00
|
|
|
return;
|
2015-11-19 13:57:23 +00:00
|
|
|
|
2022-05-28 00:37:24 +00:00
|
|
|
this.hash.set({form: 'ecomerce/checkout'});
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 00:37:24 +00:00
|
|
|
,onAddItemClick: function(event, form) {
|
2022-04-13 11:31:52 +00:00
|
|
|
if (event.defaultPrevented) return;
|
|
|
|
event.preventDefault();
|
|
|
|
if (this.isGuest()) return;
|
2015-09-01 14:10:44 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
this.onEraseClick();
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.card.row = form.row;
|
2022-05-28 15:49:46 +00:00
|
|
|
this.$.cardItem.value = form.$.id;
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.cardPopup.show(event.currentTarget);
|
2015-07-07 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onAddLotClick: function(column, value, row) {
|
2022-05-28 01:18:06 +00:00
|
|
|
var model = this.$.itemLots;
|
2019-05-21 14:16:27 +00:00
|
|
|
var grouping = model.get(row, 'grouping');
|
|
|
|
var warehouse = model.get(row, 'warehouseFk');
|
|
|
|
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;
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
if (lotAmount < available) {
|
2015-10-14 15:02:06 +00:00
|
|
|
var newAmount = lotAmount + grouping;
|
|
|
|
|
|
|
|
if (newAmount > available)
|
|
|
|
newAmount = available;
|
|
|
|
|
|
|
|
this.items[warehouse] = newAmount;
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.amount.value += newAmount - lotAmount;
|
2019-05-21 14:16:27 +00:00
|
|
|
} else
|
|
|
|
Htk.Toast.showError(_('NoMoreAmountAvailable'));
|
2015-07-07 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onConfirmClick: function() {
|
2015-07-21 14:16:07 +00:00
|
|
|
var sql = '';
|
2019-05-21 14:16:27 +00:00
|
|
|
var batch = new Sql.Batch();
|
|
|
|
var query = new Sql.String({query: 'CALL myBasket_addItem(#warehouse, #item, #amount);'});
|
2015-08-27 14:04:34 +00:00
|
|
|
var amountSum = 0;
|
2015-07-21 14:16:07 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
for (var warehouse in this.items) {
|
2015-08-27 14:04:34 +00:00
|
|
|
var amount = this.items[warehouse];
|
|
|
|
amountSum += amount;
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
batch.addValue('warehouse', warehouse);
|
2022-05-28 01:18:06 +00:00
|
|
|
batch.addValue('item', this.$.cardItem.value);
|
2019-05-21 14:16:27 +00:00
|
|
|
batch.addValue('amount', amount);
|
|
|
|
sql += query.render(batch);
|
2015-07-21 14:16:07 +00:00
|
|
|
}
|
2015-07-07 15:27:47 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
if (amountSum > 0) {
|
|
|
|
this.conn.execQuery(sql);
|
2015-07-07 15:27:47 +00:00
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
var itemName = this.$.card.get('item');
|
2019-05-21 14:16:27 +00:00
|
|
|
Htk.Toast.showMessage(
|
|
|
|
sprintf(_('Added%dOf%s'), amountSum, itemName));
|
2015-08-27 14:04:34 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.cardPopup.hide();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-07-21 14:16:07 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onEraseClick: function() {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.amount.value = 0;
|
2016-05-04 14:36:51 +00:00
|
|
|
this.items = {};
|
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onPopupClose: function() {
|
|
|
|
this.onEraseClick();
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.card.row = -1;
|
|
|
|
this.$.cardItem.value = undefined;
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
2015-11-19 13:57:23 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,onCardLoad: function() {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.cardPopup.reset();
|
2015-07-21 14:16:07 +00:00
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
});
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
Hedera.Catalog.extend({
|
2016-01-07 12:58:29 +00:00
|
|
|
View: {
|
|
|
|
LIST: 0,
|
|
|
|
GRID: 1
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
Vn.Filter = new Class({
|
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'
|
2022-05-26 08:00:19 +00:00
|
|
|
,Properties: {
|
|
|
|
model: {
|
2015-09-28 09:46:24 +00:00
|
|
|
type: Db.Model
|
2019-05-21 14:16:27 +00:00
|
|
|
,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
|
|
|
}
|
2019-05-21 14:16:27 +00:00
|
|
|
,get: function() {
|
2015-09-28 09:46:24 +00:00
|
|
|
return this._model;
|
|
|
|
}
|
|
|
|
},
|
2022-05-26 08:00:19 +00:00
|
|
|
placeholder: {
|
2015-09-28 09:46:24 +00:00
|
|
|
type: String
|
2019-05-21 14:16:27 +00:00
|
|
|
,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
|
|
|
}
|
2019-05-21 14:16:27 +00:00
|
|
|
,get: function() {
|
2015-10-14 11:51:43 +00:00
|
|
|
return this._placeholder;
|
2015-09-28 09:46:24 +00:00
|
|
|
}
|
|
|
|
},
|
2022-05-26 08:00:19 +00:00
|
|
|
filter: {
|
2015-11-17 10:34:33 +00:00
|
|
|
type: Sql.Filter
|
2019-05-21 14:16:27 +00:00
|
|
|
,set: function(x) {
|
2015-11-17 10:34:33 +00:00
|
|
|
this._filter = x;
|
2019-05-21 14:16:27 +00:00
|
|
|
this._batch.addObject('filter', x);
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
2019-05-21 14:16:27 +00:00
|
|
|
,get: function() {
|
2015-11-17 10:34:33 +00:00
|
|
|
return this._filter;
|
|
|
|
}
|
2022-05-26 08:00:19 +00:00
|
|
|
}
|
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
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,initialize: function(props) {
|
|
|
|
var node = this.createRoot('div');
|
2016-10-16 14:16:08 +00:00
|
|
|
node.className = 'vn-filter';
|
2015-09-28 09:46:24 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
this._select = new Htk.Select();
|
|
|
|
this._select.on('mousedown', this._onMouseDown, this);
|
|
|
|
this._select.on('changed', this._onChange, this);
|
|
|
|
this._select.on('ready', this._onReady, this);
|
|
|
|
this.node.appendChild(this._select.node);
|
2015-09-28 09:46:24 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
this._ul = this.createElement('ul');
|
|
|
|
this.node.appendChild(this._ul);
|
2015-11-17 10:34:33 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
this._batch = new Sql.Batch();
|
|
|
|
this.parent(props);
|
2015-09-28 09:46:24 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,_onMouseDown: function() {
|
2015-10-14 11:51:43 +00:00
|
|
|
if (this._model && this._model.status === Db.Model.Status.CLEAN)
|
2019-05-21 14:16:27 +00:00
|
|
|
this._model.refresh();
|
2015-10-14 11:51:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,_onCloseClick: function() {
|
|
|
|
this._removeSelectionNode();
|
|
|
|
this._changeValue(undefined);
|
2015-10-14 11:51:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,_removeSelectionNode: function() {
|
|
|
|
if (this._lastLi) {
|
|
|
|
Vn.Node.remove(this._lastLi);
|
2015-11-19 13:57:23 +00:00
|
|
|
this._lastLi = null;
|
|
|
|
this._label = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,_onChange: function() {
|
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
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
this._realSetValue(this._select.value);
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,_onReady: function() {
|
2015-11-19 13:57:23 +00:00
|
|
|
if (this._emptyLabel)
|
2019-05-21 14:16:27 +00:00
|
|
|
this._refreshLabel();
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,_changeValue: function(newValue) {
|
|
|
|
this._batch.block();
|
2015-11-19 13:57:23 +00:00
|
|
|
this.value = newValue;
|
2019-05-21 14:16:27 +00:00
|
|
|
this._batch.unblock();
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,_onTimeout: function() {
|
2015-11-19 13:57:23 +00:00
|
|
|
this._select.value = null;
|
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,putValue: function(value) {
|
|
|
|
this._onMouseDown();
|
|
|
|
this._realSetValue(value);
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,_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
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
var li = this._lastLi = this.createElement('li');
|
|
|
|
this._ul.appendChild(li);
|
2015-10-14 11:51:43 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
var button = this.createElement('button');
|
|
|
|
button.addEventListener('click',
|
|
|
|
this._onCloseClick.bind(this, li));
|
|
|
|
li.appendChild(button);
|
2015-10-14 11:51:43 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
var icon = new Htk.Icon({
|
2022-05-21 21:31:56 +00:00
|
|
|
name: 'close',
|
2016-09-26 09:28:47 +00:00
|
|
|
alt: _('Close')
|
|
|
|
});
|
2019-05-21 14:16:27 +00:00
|
|
|
button.appendChild(icon.node);
|
2016-10-04 15:27:49 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
var text = this._label = this.createTextNode('');
|
|
|
|
li.appendChild(text);
|
2015-10-14 11:51:43 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
setTimeout(this._onTimeout.bind(this));
|
2015-11-09 17:11:51 +00:00
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
this._changeValue(value);
|
|
|
|
this._refreshLabel();
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:16:27 +00:00
|
|
|
,_refreshLabel: function() {
|
2015-11-19 13:57:23 +00:00
|
|
|
if (!this._label)
|
|
|
|
return;
|
2015-10-14 11:51:43 +00:00
|
|
|
|
2022-05-26 08:00:19 +00:00
|
|
|
let row = -1;
|
|
|
|
const model = this._model;
|
2022-05-28 15:49:46 +00:00
|
|
|
let showValue = '';
|
|
|
|
this._emptyLabel = true;
|
2015-11-19 13:57:23 +00:00
|
|
|
|
2022-05-26 08:00:19 +00:00
|
|
|
if (model) {
|
2022-05-28 15:49:46 +00:00
|
|
|
if (model.ready) {
|
2022-05-26 08:00:19 +00:00
|
|
|
row = model.searchByIndex(this._valueColumnIndex, this._value);
|
2015-11-19 13:57:23 +00:00
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
if (row != -1) {
|
|
|
|
var label = model.getByIndex(row, this._showColumnIndex);
|
|
|
|
showValue = label;
|
|
|
|
this._emptyLabel = false;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
showValue = _('Loading...');
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
2022-05-28 15:49:46 +00:00
|
|
|
|
|
|
|
this._label.nodeValue = showValue;
|
2015-09-28 09:46:24 +00:00
|
|
|
}
|
2016-05-04 14:36:51 +00:00
|
|
|
});
|
2015-09-22 07:25:50 +00:00
|
|
|
|