diff options
| author | jbm-odoo <jbm@odoo.com> | 2018-12-13 11:10:15 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2019-01-21 11:29:30 +0000 |
| commit | a3daff6bc121a42bf293ca91b8f522c26bac7c8a (patch) | |
| tree | 7cdc12fc34bf66068e51970bb60f946c06c30a7e /addons/hr_holidays/static/src/js | |
| parent | 344877a0813a915344a230f1aaf1f932f2f9d5cb (diff) | |
[IMP] hr_holidays: Rename 'leave' into 'time off' + add dashboard
Purpose
=======
We need to use an international word to define holidays and leaves, rename everything into Time Off.
Employees needs a good dashboard and leaves summary
Specification
=============
1/ Add a new dashboard: https://balsamiq.cloud/sm5j0d/pg5w04r
Create a new dashboard with a calendar and a summary of all time off and time off request
2/ Rename leaves into Time Off everywhere
3/ Improve general usability
TaskID: 1916871
closes odoo/odoo#29634
Diffstat (limited to 'addons/hr_holidays/static/src/js')
| -rw-r--r-- | addons/hr_holidays/static/src/js/time_off_calendar.js | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/addons/hr_holidays/static/src/js/time_off_calendar.js b/addons/hr_holidays/static/src/js/time_off_calendar.js new file mode 100644 index 00000000000..de9feca1225 --- /dev/null +++ b/addons/hr_holidays/static/src/js/time_off_calendar.js @@ -0,0 +1,192 @@ +odoo.define('hr_holidays.dashboard.view_custo', function(require) { + 'use strict'; + + var core = require('web.core'); + var CalendarController = require("web.CalendarController"); + var CalendarView = require("web.CalendarView"); + var viewRegistry = require('web.view_registry'); + + var _t = core._t; + var QWeb = core.qweb; + + + var TimeOffCalendarController = CalendarController.extend({ + events: _.extend({}, CalendarController.prototype.events, { + 'click .o_header_calendar_button_prev': '_onPrev', + 'click .o_header_calendar_button_next': '_onNext', + 'click .btn-time-off': '_onNewTimeOff', + 'click .btn-allocation': '_onNewAllocation', + }), + + /** + * @override + */ + start: function () { + var self = this; + return this._super.apply(this, arguments).then(function () { + self.$el.find('.o_calendar_sidebar_container').remove(); + self._renderSummaryTimeOff(); + self.$(".o_calendar_widget").fullCalendar('option', 'contentHeight', 500); + }); + }, + + /** + * Override to add correct date in header of calendar + * + * @override + */ + update: function () { + var self = this; + return this._super.apply(this, arguments).then(function () { + self._updateSummaryTimeOff(); + }); + }, + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * Render the buttons and add new button about + * times off and allocations request + * + * @override + */ + + renderButtons: function ($node) { + this.$buttons = $(QWeb.render('hr_holidays.dashboard.calendar.button', { + time_off: _t('New Time Off Request'), + request: _t('New Allocation Request'), + })); + + if ($node) { + this.$buttons.appendTo($node); + } else { + this.$('.o_calendar_buttons').replaceWith(this.$buttons); + } + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Create a header for calendar with previous and next month button. + * Add month and year on the header + * + * @private + */ + _renderCalendarHeader: function () { + this.$el.find('.fc-week-number').remove(); + + if (!this.$('#header_calendar_leaves').length) { + var current_month = this.model.data.target_date.format('MMMM YYYY'); + var header = $(QWeb.render('hr_holidays.dashboard.calendar.header', { + current_month: current_month, + })); + + this.$el.find('.fc-widget-header').find('thead').prepend(header); + } + }, + + /** + * Create a summary of all time off and requests allocations + * + * @private + */ + _renderSummaryTimeOff: function () { + var leave_state = '<div class="o_form_view"><div class="o_form_sheet_bg"><div class="o_form_sheet"><div id="counter_leaves" class="row">'; + leave_state += '</div></div></div></div>'; + this.$el.find('.o_calendar_container').before( + $(leave_state) + ); + + this._updateSummaryTimeOff(); + }, + + /** + * Create a summary of all time off and requests allocations + * + * @private + */ + _updateSummaryTimeOff: function () { + var self = this; + + this._renderCalendarHeader(); + + return this._rpc({ + model: 'hr.leave.type', + method: 'get_days_all_request', + args: [this.context], + }) + .then(function (leaves) { + $('#counter_leaves').children().remove(); + for (var leave in leaves){ + var leave_box = $('<div class="col text-center border-right"><h1 class="text-nowrap"></h1><h3></h3></div>'); + var content = leaves[leave][1]; + var leave_count = leave_box.find('h1'); + leave_box.append(leave_count.text( + leaves[leave][2] !== 'no' ? content.virtual_remaining_leaves + " / " + content.max_leaves : -content.virtual_remaining_leaves + )); + var leave_name = leave_box.find('h3'); + leave_name.text(leaves[leave][0]); + leave_box.append(leave_name); + $('#counter_leaves').append(leave_box); + } + $('#counter_leaves').children().last().removeClass('border-right'); + + self.$el.find('.o_calendar_container').appendTo(self.$el.find('.o_form_sheet')); + }); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Action: create a new time off request + * + * @private + */ + _onNewTimeOff: function () { + var self = this; + this.do_action({ + type: 'ir.actions.act_window', + res_model: 'hr.leave', + view_type: 'form', + views: [[false,'form']], + target: 'new', + }, { + on_close: function () { + self.reload(); + } + }); + }, + + /** + * Action: create a new allocation request + * + * @private + */ + _onNewAllocation: function () { + this.do_action({ + type: 'ir.actions.act_window', + res_model: 'hr.leave.allocation', + view_type: 'form', + views: [[false,'form']], + target: 'new', + }), { + on_close: function () { + self.reload(); + } + }; + }, + }); + var TimeOffCalendarView = CalendarView.extend({ + config: _.extend({}, CalendarView.prototype.config, { + Controller: TimeOffCalendarController, + }), + }); + + viewRegistry.add('time_off_calendar', TimeOffCalendarView); +});
\ No newline at end of file |
