hedera-web/web/forms/ecomerce/confirm/confirm.js

180 lines
3.4 KiB
JavaScript
Raw Normal View History

2015-07-07 15:27:47 +00:00
Vn.Confirm = new Class
({
Extends: Vn.Form
2015-12-10 13:48:43 +00:00
,open: function ()
{
this.close ();
this.isOpen = true;
Vn.BasketChecker.check (this.conn,
this.onBasketCheck.bind (this));
}
,onBasketCheck: function (isOk)
{
if (isOk)
this.loadUi ();
}
2015-07-07 15:27:47 +00:00
2015-07-17 14:34:42 +00:00
,onOrderReady: function (form)
{
if (form.row < 0)
return;
if (form.get ('method') != 'PICKUP')
{
Vn.Node.show (this.$('address'));
2015-07-17 14:34:42 +00:00
Vn.Node.setText (this.$('method'), _('Agency'));
}
else
{
Vn.Node.hide (this.$('address'));
2015-07-17 14:34:42 +00:00
Vn.Node.setText (this.$('method'), _('Warehouse'));
}
var total = form.get ('tax_base') + form.get ('vat');
if (total === null)
total = 0;
var credit = form.get ('credit');
var debt = form.get ('debt');
var totalDebt = debt + total;
var exceededCredit = totalDebt - credit;
var creditExceededCond = exceededCredit > 0;
if (creditExceededCond)
Htk.Toast.showWarning (
_('You have exceeded your credit.'));
this.$('debt').value = debt;
this.$('total-debt').value = totalDebt;
this.$('total-amount').value = totalDebt;
this.$('credit-excess').value = exceededCredit;
this.$('excess-amount').value = exceededCredit;
this.$('pay-amount').value = 'ALL';
if (credit > 0)
{
this.$('credit-info').style.display = 'table-row';
if (creditExceededCond)
{
this.$('amount-selector').style.display = 'block';
this.$('exceeded-info').style.display = 'table-row';
this.$('pay-amount').value = 'EXCEEDED';
}
}
var methods = [];
if (totalDebt <= 0)
{
methods = ['balance'];
selectedMethod = 'BALANCE';
}
else
{
methods = ['card', 'transfer', 'later'];
if (!creditExceededCond)
{
methods.push ('credit');
selectedMethod = 'CREDIT';
}
else
selectedMethod = 'CARD';
}
for (var i = 0; i < methods.length; i++)
this.$(methods[i] +'-method').style.display = 'block';
this.$('pay-method').value = selectedMethod;
2015-07-17 14:34:42 +00:00
}
,onPayMethodChange: function (payMethod)
2015-07-07 15:27:47 +00:00
{
var id = this.displayedInfo;
if (id)
Vn.Node.removeClass (this.$(id), 'selected');
switch (payMethod.value)
{
case 'BALANCE':
id = 'balance-method';
break;
case 'CREDIT':
id = 'credit-method';
break;
case 'CARD':
id = 'card-method';
break;
case 'TRANSFER':
id = 'transfer-method';
break;
default:
id = null;
}
this.displayedInfo = id;
if (id)
Vn.Node.addClass (this.$(id), 'selected');
2015-07-07 15:27:47 +00:00
}
,disableButtons: function (disable)
{
this.$('modify').disabled = disable;
this.$('confirm').disabled = disable;
}
,onModifyClick: function ()
{
window.history.back();
}
,onConfirmClick: function ()
{
2015-08-17 18:02:14 +00:00
this.disableButtons (true);
2015-07-17 14:34:42 +00:00
this.$('confirm-query').execute ();
2015-07-07 15:27:47 +00:00
}
2015-07-17 14:34:42 +00:00
,onConfirm: function (query, resultSet)
2015-07-07 15:27:47 +00:00
{
this.disableButtons (false);
if (resultSet.fetchResult ())
2015-07-17 14:34:42 +00:00
{
Vn.Cookie.unset ('order');
this.$('success-dialog').show ();
2015-07-17 14:34:42 +00:00
}
2015-07-07 15:27:47 +00:00
}
,onAcceptClick: function ()
{
this.$('success-dialog').hide ();
}
,onPopupClose: function ()
{
if (this.$('pay-method').value === 'CARD')
{
if (this.$('pay-amount').value === 'EXCEEDED')
var payAmount = this.$('excess-amount').value;
else
var payAmount = this.$('total-amount').value;
var tpv = new Vn.Tpv ({conn: this.conn});
tpv.pay (payAmount, this.$('order-form').get ('company_id'));
}
2015-07-07 15:27:47 +00:00
else
this.hash.set ({'form': 'ecomerce/orders'});
}
});