diff --git a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_renderer.js b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_renderer.js index b3f54e498..ae9617af8 100644 --- a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_renderer.js +++ b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_renderer.js @@ -10,6 +10,7 @@ var Core = require('web.core'), Session = require('web.session'), AbstractRenderer = require('web.AbstractRenderer'), HotelConstants = require('hotel_calendar.Constants'), + MultiCalendar = require('hotel_calendar.MultiCalendar'), //Formats = require('web.formats'), _t = Core._t, @@ -30,33 +31,29 @@ var HotelCalendarView = AbstractRenderer.extend({ _reserv_tooltips: {}, _days_tooltips: [], _last_dates: [false, false], - _hcalendars: [], + _multi_calendar: null, /** VIEW METHODS **/ init: function(parent, state, params) { this._super.apply(this, arguments); + + this._multi_calendar = new MultiCalendar(this); }, start: function () { - return this._super().then(function() { - this.init_calendar_view(); - }.bind(this)); + this._multi_calendar.setElement(this.$el.find('#hcal_widget')); + this._multi_calendar.start(); + this.init_calendar_view(); + return this._super(); }, on_attach_callback: function() { this._super(); - if (this._hcalendar && !this._is_visible) { + if (!this._is_visible) { // FIXME: Workaround for restore "lost" reservations (Drawn when the view is hidden) - setTimeout(function(){ - for (var reserv of this._hcalendar._reservations) { - var style = window.getComputedStyle(reserv._html, null); - if (parseInt(style.width, 10) < 15 || parseInt(style.height, 10) < 15 || parseInt(style.top, 10) === 0) { - this._hcalendar._updateReservation(reserv); - } - } - }.bind(this), 300); + this._multi_calendar.recalculate_reservation_positions(); } }, @@ -130,8 +127,8 @@ var HotelCalendarView = AbstractRenderer.extend({ endOfWeekOffset: this._view_options['eday_week_offset'] || 0 }; - this._hcalendar = new HotelCalendar(containerSelector, options, pricelist, restrictions, this.$el[0]); - this._assign_hcalendar_events(); + //this._hcalendar = new HotelCalendar(containerSelector, options, pricelist, restrictions, this.$el[0]); + //this._assign_hcalendar_events(); }, _assign_hcalendar_events: function() { diff --git a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_view.js b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_view.js index 1a8ecc1b2..1c2b5c7a6 100644 --- a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_view.js +++ b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_view.js @@ -162,7 +162,7 @@ var CalendarMenu = Widget.extend({ var PMSCalendarView = AbstractView.extend({ display_name: _lt('Calendar PMS'), icon: 'fa-calendar', - jsLibs: ['/hotel_calendar/static/src/lib/hcalendar/js/hcalendar.js'], + //jsLibs: [], cssLibs: ['/hotel_calendar/static/src/lib/hcalendar/css/hcalendar.css'], config: { Model: PMSCalendarModel, diff --git a/hotel_calendar/static/src/js/widgets/MultiCalendar.js b/hotel_calendar/static/src/js/widgets/MultiCalendar.js new file mode 100644 index 000000000..42b507b5a --- /dev/null +++ b/hotel_calendar/static/src/js/widgets/MultiCalendar.js @@ -0,0 +1,45 @@ +// Copyright 2018 Alexandre Díaz +// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +odoo.define('hotel_calendar.MultiCalendar', function(require) { + 'use strict'; + + var core = require('web.core'); + var session = require('web.session'); + var Widget = require('web.Widget'); + + var MultiCalendar = Widget.extend({ + _calendars: null, + _active_calendar: -1, + + init: function(parent) { + this._super.apply(this, arguments); + }, + + start: function() { + this._super.apply(this, arguments); + + this.$el.html("

NO CALENDAR DEFINED!

"); + }, + + get_active_calendar: function() { + return this._calendars[this._active_calendar]; + } + + recalculate_reservation_positions: function() { + setTimeout(function(){ + for (var reserv of this._hcalendar._reservations) { + var style = window.getComputedStyle(reserv._html, null); + if (parseInt(style.width, 10) < 15 || parseInt(style.height, 10) < 15 || parseInt(style.top, 10) === 0) { + this.get_active_calendar()._updateReservation(reserv); + } + } + }.bind(this), 200); + }, + + create_calendar: function() { + + }, + }); + + return MultiCalendar; +}); diff --git a/hotel_calendar/views/general.xml b/hotel_calendar/views/general.xml index 7f4181d9d..3ab647615 100644 --- a/hotel_calendar/views/general.xml +++ b/hotel_calendar/views/general.xml @@ -15,6 +15,8 @@ + +