Updated the hooks positions and params names, optmized the disabled dates calendar
This commit is contained in:
@@ -176,6 +176,10 @@
|
||||
{/if}
|
||||
|
||||
{*Disable Dates Model*}
|
||||
<div id="modal_loader" class="loading_overlay" style="display: none;">
|
||||
<img src="{$link->getMediaLink(($smarty.const._PS_ADMIN_IMG_))}ajax-loader.gif" class="loading-img"/>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="deactiveDatesModal" tabindex="-1" role="dialog" aria-labelledby="deactiveDatesLabel">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
@@ -672,6 +676,9 @@
|
||||
var reason = $(formElem).find('.room_disable_reason').val();
|
||||
var idProduct = $('[name="id_product"]').val();
|
||||
var id_disabled_date = parseInt($(formElem).find('.id_disabled_date').val());
|
||||
if (isNaN(id_disabled_date)) {
|
||||
id_disabled_date = 0;
|
||||
}
|
||||
var event_date_to = new Date(dateTo);
|
||||
// setting the date_to +1 since the full calendar does not includes the date to
|
||||
event_date_to.setDate(event_date_to.getDate() + 1);
|
||||
@@ -691,6 +698,7 @@
|
||||
},
|
||||
dataType: 'JSON',
|
||||
success: function(response) {
|
||||
reason = $.trim(reason);
|
||||
if (response.status) {
|
||||
var validatedEvent = {
|
||||
'id' : DisableDatesModal.getUniqueEventId(),
|
||||
@@ -749,9 +757,10 @@
|
||||
}
|
||||
});
|
||||
},
|
||||
showMessages: function(errors) {
|
||||
$('#deactiveDatesModal .messages-wrap').html(errors);
|
||||
showMessages: function(messages) {
|
||||
$('#deactiveDatesModal .messages-wrap').html(messages);
|
||||
$('#deactiveDatesModal .messages-wrap').show();
|
||||
$('#deactiveDatesModal').animate({ scrollTop: 0 }, 'slow');
|
||||
},
|
||||
hideMessages: function() {
|
||||
$('#deactiveDatesModal .messages-wrap').hide();
|
||||
@@ -793,9 +802,13 @@
|
||||
|
||||
$('#deactiveDatesModal').on('shown.bs.modal', function(e) {
|
||||
calendar.updateSize();
|
||||
$('#modal_loader').hide();
|
||||
$('#deactiveDatesModal').css('visibility', 'visible');
|
||||
});
|
||||
// Disable dates data filling when model open calendar.
|
||||
$('#deactiveDatesModal').on('show.bs.modal', function(e) {
|
||||
$('#deactiveDatesModal').css('visibility', 'hidden');
|
||||
$('#modal_loader').show();
|
||||
DisableDatesModal.resetModalInfo();
|
||||
const triggerRoomRow = $(e.relatedTarget);
|
||||
const idRoom = parseInt($(triggerRoomRow).attr('data-id-room'));
|
||||
@@ -1075,9 +1088,9 @@
|
||||
success: function(response) {
|
||||
if (response.status) {
|
||||
DisableDatesModal.resetModalInfo();
|
||||
if (response.new_disabled_dates.length) {
|
||||
if (response.disabled_dates.length) {
|
||||
var events = [];
|
||||
$.each(response.new_disabled_dates, function(index, value) {
|
||||
$.each(response.disabled_dates, function(index, value) {
|
||||
var eventId = DisableDatesModal.getUniqueEventId();
|
||||
events.push({
|
||||
'id' : eventId,
|
||||
|
||||
@@ -3571,7 +3571,6 @@ class AdminProductsControllerCore extends AdminController
|
||||
if ($roomInfo['floor'] && !Validate::isGenericName($roomInfo['floor'])) {
|
||||
$this->errors[] = sprintf(Tools::displayError('Invalid floor for room %s.'), $roomIndex);
|
||||
}
|
||||
Hook::exec('actionRoomInformationValidate', array('room_information', $roomInfo));
|
||||
if ($roomInfo['id_status'] == HotelRoomInformation::STATUS_INACTIVE) {
|
||||
$objHotelRoomInformation = new HotelRoomInformation();
|
||||
if (count($objHotelRoomInformation->getFutureBookings($roomInfo['id']))) {
|
||||
@@ -3585,6 +3584,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->errors[] = sprintf(Tools::displayError('Please add disable dates for room %s.'), $roomIndex);
|
||||
}
|
||||
}
|
||||
Hook::exec('actionValidateRoomInformation', array('room_information', $roomInfo));
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('Please add at least one room.');
|
||||
@@ -5000,7 +5000,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
die(json_encode($response));
|
||||
}
|
||||
|
||||
public function assignSmartyMessages()
|
||||
public function assignAlerts()
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'errors' => $this->errors,
|
||||
@@ -5040,7 +5040,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
|
||||
$objHotelRoomDisableDates->date_from = $dateFrom;
|
||||
$objHotelRoomDisableDates->date_to = $dateTo;
|
||||
$objHotelRoomDisableDates->reason = Tools::getValue('reason');
|
||||
$objHotelRoomDisableDates->reason = trim(Tools::getValue('reason'));
|
||||
$objHotelRoomInfo->id_status = HotelRoomInformation::STATUS_TEMPORARY_INACTIVE;
|
||||
if ($objHotelRoomInfo->save()
|
||||
&& $objHotelRoomDisableDates->save()
|
||||
@@ -5067,7 +5067,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
$response['status'] = true;
|
||||
}
|
||||
|
||||
$this->assignSmartyMessages();
|
||||
$this->assignAlerts();
|
||||
$response['msg'] = $this->context->smarty->fetch('alerts.tpl');
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
@@ -5087,18 +5087,18 @@ class AdminProductsControllerCore extends AdminController
|
||||
'date_to' => $dateTo,
|
||||
'id_room' => $idRoom
|
||||
);
|
||||
Hook::exec('actionRoomDisabledDatesRemoveBefore', array('disabled_dates_info', $params));
|
||||
if (($disabledDates = $objRoomDisableDates->checkIfRoomAlreadyDisabled($params))
|
||||
&& empty($this->errors)
|
||||
Hook::exec('actionRoomDisabledDatesRemoveBefore', array('disabled_dates', $params));
|
||||
if (empty($this->errors)
|
||||
&& ($disabledDates = $objRoomDisableDates->checkIfRoomAlreadyDisabled($params))
|
||||
) {
|
||||
$newDates = array();
|
||||
foreach ($disabledDates as $data) {
|
||||
$objRoomDisableDates = new HotelRoomDisableDates($data['id']);
|
||||
$newDates[0]['date_from'] = $data['date_from'];
|
||||
foreach ($disabledDates as $disabledDatesInfo) {
|
||||
$objRoomDisableDates = new HotelRoomDisableDates($disabledDatesInfo['id']);
|
||||
$newDates[0]['date_from'] = $disabledDatesInfo['date_from'];
|
||||
$newDates[0]['date_to'] = $params['date_from'];
|
||||
|
||||
$newDates[1]['date_from'] = $params['date_to'];
|
||||
$newDates[1]['date_to'] = date('Y-m-d', strtotime($data['date_to']));
|
||||
$newDates[1]['date_to'] = date('Y-m-d', strtotime($disabledDatesInfo['date_to']));
|
||||
|
||||
if (strtotime($newDates[0]['date_from']) >= strtotime($newDates[0]['date_to'])) {
|
||||
unset($newDates[0]);
|
||||
@@ -5129,7 +5129,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
$response['status'] = false;
|
||||
} else {
|
||||
$response['status'] = true;
|
||||
$this->confirmations[] = $this->l('Selected dates were removed successfully.');
|
||||
$this->confirmations[] = $this->l('Removed successfully.');
|
||||
if ($disabledDates = $objRoomDisableDates->getRoomDisableDates($idRoom)) {
|
||||
foreach ($disabledDates as $disabledDatesKey => $dates) {
|
||||
$disabledDates[$disabledDatesKey]['date_add'] = date('Y-m-d', strtotime($dates['date_add']));
|
||||
@@ -5159,10 +5159,10 @@ class AdminProductsControllerCore extends AdminController
|
||||
$objRoomInfo->save();
|
||||
}
|
||||
|
||||
$response['new_disabled_dates'] = $disabledDates;
|
||||
$response['disabled_dates'] = $disabledDates;
|
||||
}
|
||||
|
||||
$this->assignSmartyMessages();
|
||||
$this->assignAlerts();
|
||||
$response['msg'] = $this->context->smarty->fetch('alerts.tpl');
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
@@ -5195,7 +5195,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->confirmations[] = $this->l('Removed successfully');
|
||||
}
|
||||
|
||||
$this->assignSmartyMessages();
|
||||
$this->assignAlerts();
|
||||
$response['msg'] = $this->context->smarty->fetch('alerts.tpl');
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user