[IMP] hr_holidays: delete from dashboard in year view
Previously, the land page of Time Off was month view. When you select a leave from Month's view, you can edit/delete it directly. Now, the land page is Year's view, and you can open the modal form of the leave, but it's not possible to delete it. Add a delete button on the form view of the leave from the year's view of the dashboard task-2638305 closes odoo/odoo#76080 Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user