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

201 lines
4.0 KiB
JavaScript
Raw Normal View History

2015-02-01 03:21:54 +00:00
2016-09-26 09:28:47 +00:00
Hedera.Checkout = new Class
2015-02-01 03:21:54 +00:00
({
2016-09-26 09:28:47 +00:00
Extends: Hedera.Form
2015-02-01 03:21:54 +00:00
2017-04-19 06:16:37 +00:00
,initialize: function (props)
{
this.today = new Date ();
this.today.setHours (0, 0, 0, 0);
this.parent (props);
}
2015-07-10 12:30:08 +00:00
,activate: function ()
{
this.autoStepLocked = true;
}
2015-07-15 13:39:07 +00:00
,onValuesReady: function ()
2015-07-10 12:30:08 +00:00
{
2017-10-20 17:09:06 +00:00
var orderForm = this.$.orderForm;
var defaultsForm = this.$.defaults;
2015-07-10 12:30:08 +00:00
2015-07-15 13:39:07 +00:00
if (!(orderForm.ready && defaultsForm.ready))
return;
var date;
2015-07-15 13:39:07 +00:00
if (orderForm.numRows > 0)
{
var i = orderForm;
date = i.get ('date_send');
2015-07-15 13:39:07 +00:00
}
else
var i = defaultsForm;
if (!date || date.getTime () < (new Date ()).getTime ())
{
date = new Date ();
2015-07-15 13:39:07 +00:00
if (i.get('delivery_method') != 'PICKUP')
2017-04-05 14:06:07 +00:00
date.setDate (date.getDate () + 1);
date.setHours (0, 0, 0, 0);
2015-07-10 12:30:08 +00:00
}
2015-07-15 13:39:07 +00:00
2017-10-20 17:09:06 +00:00
this.$.lot.assign ({
2017-04-07 11:00:33 +00:00
date: date,
method: i.get ('delivery_method'),
agency: i.get ('agency_id'),
address: i.get ('address_id')
});
2015-07-15 13:39:07 +00:00
this.autoStepLocked = false;
2015-07-10 12:30:08 +00:00
}
2015-12-10 13:48:43 +00:00
,disableButtons: function (disable)
{
2017-10-20 17:09:06 +00:00
this.$.confirmAgency.disabled = disable;
this.$.confirmDelivery.disabled = disable;
this.$.confirmPickup.disabled = disable;
2015-12-10 13:48:43 +00:00
}
2015-07-15 13:39:07 +00:00
,onConfirmClick: function ()
2015-07-10 12:30:08 +00:00
{
2015-12-10 13:48:43 +00:00
this.disableButtons (true);
2017-04-07 11:00:33 +00:00
var query = 'CALL basketConfigure (#date, #method, #agency, #address)';
2015-07-15 13:39:07 +00:00
this.conn.execQuery (query,
2017-10-20 17:09:06 +00:00
this.onBasketConfigured.bind (this), this.$.lot.params);
2015-07-10 12:30:08 +00:00
}
2015-07-15 13:39:07 +00:00
,onBasketConfigured: function (resultSet)
2015-07-10 12:30:08 +00:00
{
2015-12-10 13:48:43 +00:00
this.disableButtons (false);
2015-07-15 13:39:07 +00:00
if (!resultSet.fetchResult ())
return;
2017-10-20 17:09:06 +00:00
if (this.$.orderForm.numRows > 0)
2015-08-17 18:02:14 +00:00
Htk.Toast.showMessage (_('OrderUpdated'));
2015-07-15 13:39:07 +00:00
else
2015-08-17 18:02:14 +00:00
Htk.Toast.showMessage (_('OrderStarted'));
2017-04-07 11:00:33 +00:00
this.hash.setAll ({form: 'ecomerce/catalog'});
2015-07-10 12:30:08 +00:00
}
,onCancelClick: function ()
{
2017-10-20 17:09:06 +00:00
if (this.$.orderForm.numRows > 0)
window.history.back();
2015-07-15 13:39:07 +00:00
else
2017-04-05 14:06:07 +00:00
this.hash.setAll ({'form': 'ecomerce/orders'});
2015-07-10 12:30:08 +00:00
}
2015-07-15 13:39:07 +00:00
,agencySteps: ['method', 'date', 'address', 'agency', 'confirm-agency']
,deliverySteps: ['method', 'date', 'address', null, 'confirm-delivery']
2016-05-04 14:36:51 +00:00
,pickupSteps: ['method', 'date', 'address', 'pickup', 'confirm-pickup']
,stepFunc: function (stepIndex)
{
2015-07-03 05:49:45 +00:00
var steps;
var isDelivery;
2017-10-20 17:09:06 +00:00
switch (this.$.rgMethod.value)
2015-07-03 05:49:45 +00:00
{
case 'AGENCY':
steps = this.agencySteps;
isDelivery = true;
break;
case 'DELIVERY':
steps = this.deliverySteps;
isDelivery = true;
break;
case 'PICKUP':
default:
steps = this.pickupSteps;
isDelivery = false;
break;
}
var stepId = steps[stepIndex];
2015-07-10 12:30:08 +00:00
if (!stepId)
return null;
switch (stepId)
{
2015-07-10 12:30:08 +00:00
case 'date':
2017-10-20 17:09:06 +00:00
Vn.Node.setText (this.$.dateQuestion, isDelivery ?
_('OrderDateDeliveryQuestion'):
_('OrderDatePickupQuestion'));
2017-10-20 17:09:06 +00:00
this.$.calendar.goToSelectedMonth ();
2015-07-10 12:30:08 +00:00
break;
case 'agency':
case 'pickup':
2017-10-20 17:09:06 +00:00
this.$.agencies.refresh ();
2015-07-10 12:30:08 +00:00
break;
}
2015-07-10 12:30:08 +00:00
2017-10-20 17:09:06 +00:00
return this.$[stepId +'Step'];
2015-02-01 03:21:54 +00:00
}
2015-07-03 05:49:45 +00:00
,onFieldChange: function ()
{
2015-07-10 12:30:08 +00:00
if (!this.autoStepLocked)
2015-07-03 05:49:45 +00:00
setTimeout (this.goNextStep.bind (this), 75);
}
2015-07-23 15:58:48 +00:00
,goNextStep: function ()
{
2017-10-20 17:09:06 +00:00
this.$.assistant.moveNext ();
2015-07-23 15:58:48 +00:00
}
,addressRenderer: function (builder, form)
{
2017-10-20 17:09:06 +00:00
builder.$.address.addEventListener ('click',
2015-07-23 15:58:48 +00:00
this.onAddressClick.bind (this, form.get ('id')));
}
2015-07-23 15:58:48 +00:00
,onAddressClick: function (addressId)
{
2017-10-20 17:09:06 +00:00
this.$.lot.set ('address', addressId);
2015-07-03 05:49:45 +00:00
this.goNextStep ();
}
2015-07-23 15:58:48 +00:00
,onAddressChange: function ()
{
2015-07-23 15:58:48 +00:00
if (this.selectedNode)
Vn.Node.removeClass (this.selectedNode, 'selected');
2017-10-20 17:09:06 +00:00
var row = this.$.addresses.search ('id', this.$.lot.get ('address'));
2015-07-23 15:58:48 +00:00
if (row != -1)
{
2017-10-20 17:09:06 +00:00
var builder = this.$.repeater.getScope (row);
2015-07-23 15:58:48 +00:00
2017-10-20 17:09:06 +00:00
this.selectedNode = builder.$.address;
2015-07-23 15:58:48 +00:00
Vn.Node.addClass (this.selectedNode, 'selected');
}
2017-10-20 17:09:06 +00:00
this.$.addressForm.row = row;
}
2015-07-15 13:39:07 +00:00
2015-08-17 18:02:14 +00:00
,onAgenciesReady: function (model)
{
if (model.ready && model.numRows == 0)
Htk.Toast.showError (_('NoAgeciesAvailableForDate'));
}
,onWarehousesReady: function (model)
{
if (model.ready && model.numRows == 0)
Htk.Toast.showError (_('NoWarehousesAvailableForDate'));
}
2015-07-15 13:39:07 +00:00
,calendarRestrict: function (date)
{
return date.getTime () >= this.today.getTime ();
2015-07-15 13:39:07 +00:00
}
2015-02-01 03:21:54 +00:00
});