[WIP] Multi-Calendar

This commit is contained in:
QS5ELkMu
2018-12-08 23:47:21 +01:00
parent ec211d6c5b
commit d1d436ed04
4 changed files with 45 additions and 40 deletions

View File

@@ -55,7 +55,7 @@ var PMSCalendarController = AbstractController.extend({
var oparams = [pricelist_id, false, pricelist, {}, {}];
this.model.save_changes(oparams).then(function(results){
$(calendar.btnSaveChanges).removeClass('need-save');
calendar.$el.find('.hcal-input-changed').removeClass('hcal-input-changed');
$(calendar.edtable).find('.hcal-input-changed').removeClass('hcal-input-changed');
});
},
@@ -163,6 +163,7 @@ var PMSCalendarController = AbstractController.extend({
},
_reload_active_calendar: function() {
var self = this;
var filterDates = this.renderer.get_view_filter_dates();
// Clip dates
var dfrom = filterDates[0].clone(),
@@ -181,13 +182,11 @@ var PMSCalendarController = AbstractController.extend({
false
];
this.model.get_calendar_data(oparams).then(function(results){
this._multi_calendar._merge_days_tooltips(results['events']);
this._multi_calendar._reserv_tooltips = _.extend(this._multi_calendar._reserv_tooltips, results['tooltips']);
var reservs = [];
for (var r of results['reservations']) {
var nreserv = new HReservation({
'id': r[1],
'room_id': r[15],
'room_id': r[0],
'title': r[2],
'adults': r[3],
'childrens': r[4],
@@ -208,13 +207,15 @@ var PMSCalendarController = AbstractController.extend({
reservs.push(nreserv);
}
this._multi_calendar.merge_pricelist(results['pricelist']);
this._multi_calendar.merge_restrictions(results['restrictions']);
this._multi_calendar.merge_reservations(reservs);
self._multi_calendar._reserv_tooltips = _.extend(this._multi_calendar._reserv_tooltips, results['tooltips']);
self._multi_calendar.merge_days_tooltips(results['events']);
self._multi_calendar.merge_pricelist(results['pricelist']);
self._multi_calendar.merge_restrictions(results['restrictions']);
self._multi_calendar.merge_reservations(reservs);
this._multi_calendar._assign_extra_info(this._multi_calendar.get_active_calendar());
self._multi_calendar._assign_extra_info(this._multi_calendar.get_active_calendar());
}.bind(this)).then(function(){
this.renderer._last_dates = filterDates;
self.renderer._last_dates = filterDates;
});
},
@@ -574,12 +575,10 @@ var PMSCalendarController = AbstractController.extend({
var need_reload_pricelists = false;
var need_update_counters = false;
var nreservs = []
console.log("BUS!");
for (var notif of notifications) {
if (notif[0][1] === 'hotel.reservation') {
switch (notif[1]['type']) {
case 'reservation':
console.log("BUS RESERVA");
var reserv = notif[1]['reservation'];
// Only show notifications of other users
// if (notif[1]['subtype'] !== 'noshow' && this._view_options['show_notifications'] && notif[1]['userid'] != this.dataset.context.uid) {
@@ -953,7 +952,6 @@ var PMSCalendarController = AbstractController.extend({
if (!date_begin.isSame(this.renderer._last_dates[0].clone().utc(), 'd') || !date_end.isSame(this.renderer._last_dates[1].clone().utc(), 'd')) {
var date_end = $dateTimePickerEnd.data("DateTimePicker").date().set({'hour': 23, 'minute': 59, 'second': 59}).clone().utc();
console.log(date_end);
active_calendar.setStartDate(date_begin, active_calendar.getDateDiffDays(date_begin, date_end), false, function(){
this._reload_active_calendar();
}.bind(this));

View File

@@ -30,7 +30,7 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) {
},
get_calendar: function(index) {
return this._calendars[index];
return this._calendars[index-1];
},
get_tab: function(index) {
@@ -69,16 +69,6 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) {
}
},
update_all_reservations: function() {
for (var calendar of this._calendars) {
this._update_reservations(calendar);
}
},
update_reservations: function(calendar) {
calendar.setReservations(this._dataset['reservations']);
},
replace_reservation: function(newReserv, oldReserv) {
for (var calendar of this._calendars) {
calendar.replaceReservation(newReserv, oldReserv);
@@ -175,7 +165,7 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) {
}
for (var calendar of this._calendars) {
calendar.addReservations(_.clone(this._dataset['reservations']));
calendar.addReservations(this._dataset['reservations']);
}
},
@@ -200,7 +190,7 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) {
this._base);
this._assign_calendar_events(calendar);
this._assign_extra_info(calendar);
calendar.setReservations(_.clone(this._dataset['reservations']));
calendar.setReservations(this._dataset['reservations']);
this._calendars.push(calendar);
return this._calendars.length-1;
},
@@ -210,19 +200,25 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) {
},
_create_tab: function(name, id) {
_create_tab: function(name, id, options) {
var self = this;
var sanitized_id = this._sanitizeId(id);
// '+' Tab
var $tab = $('<a/>', {
var $tab = $('<a/>', _.extend({
id: this._sanitizeId(name),
href: `#${sanitized_id}`,
text: name,
role: 'tab',
}).data('tabindex', this._tabs.length).appendTo($('<li/>').prependTo(this.$tabs));
}, options)).data('tabindex', this._tabs.length).appendTo($('<li/>').prependTo(this.$tabs));
$tab.on('shown.bs.tab', function(ev){
self._active_index = $(ev.target).data('tabindex');
self.recalculate_reservation_positions();
if (ev.relatedTarget) {
var prev_index = $(ev.relatedTarget).data('tabindex');
if (prev_index) {
self.get_calendar(prev_index).cancelSwap();
}
}
});
$tab[0].dataset.toggle = 'tab';
var $panel = $('<div/>', {
@@ -246,7 +242,7 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) {
}).appendTo(this.$el);
// '+' Tab
var [$tab, $panel] = this._create_tab('+', 'default');
var [$tab, $panel] = this._create_tab('+', 'default', {class: 'multi-calendar-tab-plus'});
$tab.on('shown.bs.tab', function(ev){
ev.preventDefault();
var new_calendar_id = self.create_calendar(`Calendar #${self._calendars.length}`);

View File

@@ -488,6 +488,12 @@ input#bookings_search {
margin-bottom: 0.2em;
}
.multi-calendar-tab-plus {
background-color: darkgray;
font-weight: bold;
color: white;
}
.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */

View File

@@ -57,6 +57,7 @@ function HotelCalendar(/*String*/querySelector, /*Dictionary*/options, /*List*/p
paginatorStepsMin: 1,
paginatorStepsMax: 15,
}, options);
this.options.startDate = this.options.startDate.clone();
this.options.startDate.subtract('1', 'd');
// Check correct values
@@ -148,6 +149,15 @@ HotelCalendar.prototype = {
return this._modeSwap;
},
cancelSwap: function() {
if (this._modeSwap !== HotelCalendar.MODE.NONE) {
this._modeSwap = HotelCalendar.MODE.NONE;
this._dispatchEvent('hcalOnCancelSwapReservations');
this._reset_action_reservation();
this._updateHighlightSwapReservations();
}
},
//==== DOMAINS
setDomain: function(/*Int*/section, /*Array*/domain) {
if (this._domains[section] !== domain) {
@@ -205,7 +215,7 @@ HotelCalendar.prototype = {
// Merge
var uzr = [];
for (var r of reservations) {
r = _.clone(r); // HOT-FIX: Multi-Calendar Support
r = r.clone(); // HOT-FIX: Multi-Calendar Support
var rindex = !forced?_.findKey(this._reservations, {'id': r.id}):false;
if (rindex) {
r._html = this._reservations[rindex]._html;
@@ -2433,22 +2443,17 @@ HotelCalendar.prototype = {
if (this.reservationAction.action === HotelCalendar.ACTION.SWAP || this.getSwapMode() !== HotelCalendar.MODE.NONE) {
var needReset = false;
if (ev.keyCode === 27) {
this._dispatchEvent('hcalOnCancelSwapReservations');
needReset = true;
this.cancelSwap();
}
else if (ev.keyCode === 13) {
this._dispatchSwapReservations();
needReset = true;
}
else if (ev.keyCode === 17 && this.getSwapMode() === HotelCalendar.MODE.SWAP_FROM) {
this.setSwapMode(HotelCalendar.MODE.SWAP_TO);
}
if (needReset) {
this._reset_action_reservation();
this._updateHighlightSwapReservations();
this._modeSwap = HotelCalendar.MODE.NONE;
}
else if (ev.keyCode === 17 && this.getSwapMode() === HotelCalendar.MODE.SWAP_FROM) {
this.setSwapMode(HotelCalendar.MODE.SWAP_TO);
}
}
},