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
|
|
|
|
2015-07-10 12:30:08 +00:00
|
|
|
,activate: function ()
|
|
|
|
{
|
|
|
|
this.autoStepLocked = true;
|
2015-07-23 15:58:48 +00:00
|
|
|
|
|
|
|
this.today = new Date ();
|
|
|
|
this.today.setHours (0,0,0,0);
|
2015-07-10 12:30:08 +00:00
|
|
|
}
|
2015-07-15 13:39:07 +00:00
|
|
|
|
|
|
|
,onValuesReady: function ()
|
2015-07-10 12:30:08 +00:00
|
|
|
{
|
2015-07-15 13:39:07 +00:00
|
|
|
var orderForm = this.$('order-form');
|
|
|
|
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;
|
2015-08-27 14:04:34 +00:00
|
|
|
|
|
|
|
var date;
|
|
|
|
|
2015-07-15 13:39:07 +00:00
|
|
|
if (orderForm.numRows > 0)
|
|
|
|
{
|
|
|
|
var i = orderForm;
|
2015-08-27 14:04:34 +00:00
|
|
|
date = i.get ('date_send');
|
2015-07-15 13:39:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
var i = defaultsForm;
|
2015-08-27 14:04:34 +00:00
|
|
|
|
|
|
|
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-04-07 11:00:33 +00:00
|
|
|
this.$('lot').assign ({
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
this.$('confirm-agency').disabled = disable;
|
|
|
|
this.$('confirm-delivery').disabled = disable;
|
|
|
|
this.$('confirm-pickup').disabled = disable;
|
|
|
|
}
|
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-04-07 11:00:33 +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;
|
|
|
|
|
|
|
|
if (this.$('order-form').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'));
|
2015-09-30 06:45:42 +00:00
|
|
|
|
2017-04-07 11:00:33 +00:00
|
|
|
this.hash.setAll ({form: 'ecomerce/catalog'});
|
2015-07-10 12:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,onCancelClick: function ()
|
|
|
|
{
|
2015-07-15 13:39:07 +00:00
|
|
|
if (this.$('order-form').numRows > 0)
|
2015-09-30 06:45:42 +00:00
|
|
|
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-06-30 12:06:19 +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']
|
2015-06-30 12:06:19 +00:00
|
|
|
|
|
|
|
,stepFunc: function (stepIndex)
|
|
|
|
{
|
2015-07-03 05:49:45 +00:00
|
|
|
var steps;
|
|
|
|
var isDelivery;
|
|
|
|
|
2015-07-15 13:39:07 +00:00
|
|
|
switch (this.$('rg-method').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;
|
|
|
|
}
|
|
|
|
|
2015-06-30 12:06:19 +00:00
|
|
|
var stepId = steps[stepIndex];
|
|
|
|
|
2015-07-10 12:30:08 +00:00
|
|
|
if (!stepId)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
switch (stepId)
|
2015-06-30 12:06:19 +00:00
|
|
|
{
|
2015-07-10 12:30:08 +00:00
|
|
|
case 'date':
|
2015-06-30 12:06:19 +00:00
|
|
|
Vn.Node.setText (this.$('date-question'), isDelivery ?
|
|
|
|
_('OrderDateDeliveryQuestion'):
|
|
|
|
_('OrderDatePickupQuestion'));
|
|
|
|
this.$('calendar').goToSelectedMonth ();
|
2015-07-10 12:30:08 +00:00
|
|
|
break;
|
|
|
|
case 'agency':
|
|
|
|
case 'pickup':
|
2017-04-08 11:42:27 +00:00
|
|
|
this.$('agencies').refresh ();
|
2015-07-10 12:30:08 +00:00
|
|
|
break;
|
2015-06-30 12:06:19 +00:00
|
|
|
}
|
2015-07-10 12:30:08 +00:00
|
|
|
|
|
|
|
return this.$(stepId +'-step');
|
2015-02-01 03:21:54 +00:00
|
|
|
}
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2015-07-03 05:49:45 +00:00
|
|
|
,onFieldChange: function ()
|
2015-03-27 19:10:49 +00:00
|
|
|
{
|
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-03-27 19:10:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 15:58:48 +00:00
|
|
|
,goNextStep: function ()
|
|
|
|
{
|
|
|
|
this.$('assistant').moveNext ();
|
|
|
|
}
|
|
|
|
|
|
|
|
,addressRenderer: function (builder, form)
|
2015-03-27 19:10:49 +00:00
|
|
|
{
|
2015-07-23 15:58:48 +00:00
|
|
|
builder.$('address').addEventListener ('click',
|
|
|
|
this.onAddressClick.bind (this, form.get ('id')));
|
2015-06-30 12:06:19 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 15:58:48 +00:00
|
|
|
,onAddressClick: function (addressId)
|
2015-06-30 12:06:19 +00:00
|
|
|
{
|
2017-04-07 11:00:33 +00:00
|
|
|
this.$('lot').set ('address', addressId);
|
2015-07-03 05:49:45 +00:00
|
|
|
this.goNextStep ();
|
2015-06-30 12:06:19 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 15:58:48 +00:00
|
|
|
,onAddressChange: function ()
|
2015-06-30 12:06:19 +00:00
|
|
|
{
|
2015-07-23 15:58:48 +00:00
|
|
|
if (this.selectedNode)
|
|
|
|
Vn.Node.removeClass (this.selectedNode, 'selected');
|
|
|
|
|
2017-04-07 11:00:33 +00:00
|
|
|
var row = this.$('addresses').search ('id', this.$('lot').get ('address'));
|
2015-07-23 15:58:48 +00:00
|
|
|
|
|
|
|
if (row != -1)
|
|
|
|
{
|
|
|
|
var builder = this.$('repeater').getBuilder (row);
|
|
|
|
|
|
|
|
this.selectedNode = builder.$('address');
|
|
|
|
Vn.Node.addClass (this.selectedNode, 'selected');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$('address-form').row = row;
|
2015-06-30 12:06:19 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2016-10-28 07:43:51 +00:00
|
|
|
return date.getTime () >= this.today.getTime ();
|
2015-07-15 13:39:07 +00:00
|
|
|
}
|
2015-02-01 03:21:54 +00:00
|
|
|
});
|
|
|
|
|