diff --git a/addons/hr_holidays/static/src/js/time_off_calendar.js b/addons/hr_holidays/static/src/js/time_off_calendar.js index 03db8ffc202..967f893d72e 100644 --- a/addons/hr_holidays/static/src/js/time_off_calendar.js +++ b/addons/hr_holidays/static/src/js/time_off_calendar.js @@ -9,6 +9,7 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { var CalendarModel = require("web.CalendarModel"); var CalendarView = require("web.CalendarView"); var dialogs = require('web.view_dialogs'); + var Dialog = require('web.Dialog'); var viewRegistry = require('web.view_registry'); var _t = core._t; @@ -73,6 +74,35 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { } }, + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + */ + _getFormDialogOptions(self, event) { + var options = this._super(self, event); + // Get the time off data from the event + var timeoffData = event.target.state.data.filter((timeOff) => timeOff.id === parseInt(event.data._id)); + // Take the record associated to the timeoffData and read its state to hide or not the Delete button + var timeoffState = timeoffData[0].record.state; + if(timeoffState && ['validate', 'refuse'].indexOf(timeoffState) === -1) { + options.deletable = true; + options.removeButtonText = _t("Delete"); + options.on_remove = function() { + Dialog.confirm(self, _t("Are you sure you want to delete this record ?"), { + confirm_callback: function () { + self.model.deleteRecords(self._getEventId(event), self.modelName).then(function () { + self.reload(); + }); + } + }); + }; + } + return options; + }, + //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- @@ -147,6 +177,17 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { }); }, + _onOpenCreate: function() { + var self = this; + this._super(...arguments); + if(this.previousOpen) { + this.previousOpen.on('closed', this, function(ev){ + // we reload as record can be created or modified (sent, unpublished, ...) + self.reload(); + }); + } + }, + /** * @override */ diff --git a/addons/web/static/src/legacy/js/views/calendar/calendar_controller.js b/addons/web/static/src/legacy/js/views/calendar/calendar_controller.js index 2618a1ca68d..2caa8387f2d 100644 --- a/addons/web/static/src/legacy/js/views/calendar/calendar_controller.js +++ b/addons/web/static/src/legacy/js/views/calendar/calendar_controller.js @@ -179,6 +179,34 @@ var CalendarController = AbstractController.extend({ return this.model.updateRecord(record).then(reload, reload); }, + /** + * @private + */ + _getEventId(event) { + var id = event.data._id; + id = id && parseInt(id).toString() === id ? parseInt(id) : id; + return id; + }, + + /** + * @private + */ + _getFormDialogOptions: function(self, event) { + var id = this._getEventId(event); + return { + res_model: self.modelName, + res_id: id || null, + context: event.context || self.context, + title: _.str.sprintf(_t("Open: %s"), event.data.title), + on_saved: function () { + if (event.data.on_save) { + event.data.on_save(); + } + self.reload(); + }, + }; + }, + //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- @@ -412,8 +440,7 @@ var CalendarController = AbstractController.extend({ */ _onOpenEvent: function (event) { var self = this; - var id = event.data._id; - id = id && parseInt(id).toString() === id ? parseInt(id) : id; + var id = self._getEventId(event); if (!this.eventOpenPopup) { this._rpc({ @@ -435,18 +462,8 @@ var CalendarController = AbstractController.extend({ return; } - var options = { - res_model: self.modelName, - res_id: id || null, - context: event.context || self.context, - title: _.str.sprintf(_t("Open: %s"), event.data.title), - on_saved: function () { - if (event.data.on_save) { - event.data.on_save(); - } - self.reload(); - }, - }; + var options = self._getFormDialogOptions(self, event); + if (this.formViewId) { options.view_id = parseInt(this.formViewId); } diff --git a/addons/web/static/src/legacy/js/views/view_dialogs.js b/addons/web/static/src/legacy/js/views/view_dialogs.js index cd60f3281aa..bc79f37a154 100644 --- a/addons/web/static/src/legacy/js/views/view_dialogs.js +++ b/addons/web/static/src/legacy/js/views/view_dialogs.js @@ -292,7 +292,7 @@ var FormViewDialog = ViewDialog.extend({ _setRemoveButtonOption(options, btnClasses) { const self = this; options.buttons.push({ - text: _t("Remove"), + text: options.removeButtonText || _t("Remove"), classes: 'btn-secondary ' + btnClasses, click: function() { self._remove().then(self.close.bind(self));