mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[ADD] web_view_calendar_column
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
odoo.define('web_view_calendar_column.CalendarController', function (require) {
|
||||
"use strict";
|
||||
|
||||
var CalendarController = require('web.CalendarController');
|
||||
|
||||
CalendarController.include({
|
||||
_onOpenCreate: function (event) {
|
||||
if (event.data.resource && event.data.resource.id) {
|
||||
var value = event.data.resource.id;
|
||||
if (this.model.fields[this.model.fieldColumn].type === 'many2one')
|
||||
value = parseInt(value);
|
||||
this.context['default_'+ this.model.fieldColumn] = value;
|
||||
}
|
||||
else
|
||||
this.context['default_'+ this.model.fieldColumn] = false;
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
});
|
||||
57
web_view_calendar_column/static/src/js/calendar_model.js
Normal file
57
web_view_calendar_column/static/src/js/calendar_model.js
Normal file
@@ -0,0 +1,57 @@
|
||||
odoo.define('web_view_calendar_column.CalendarModel', function (require) {
|
||||
"use strict";
|
||||
|
||||
var CalendarModel = require('web.CalendarModel');
|
||||
var session = require('web.session');
|
||||
var core = require('web.core');
|
||||
var qweb = core.qweb;
|
||||
var _t = core._t;
|
||||
|
||||
CalendarModel.include({
|
||||
load: function (params) {
|
||||
this.fieldColumn = params.fieldColumn;
|
||||
this.forceColumns = params.forceColumns;
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
_loadCalendar: function () {
|
||||
var self = this;
|
||||
return this._super.apply(this, arguments).then(function () {
|
||||
self._compute_columns(self.data, self.data.data);
|
||||
});
|
||||
},
|
||||
_compute_columns: function (element, events) {
|
||||
if (this.fieldColumn && this.forceColumns) {
|
||||
this.data.columns = this.forceColumns;
|
||||
}
|
||||
else if (this.fieldColumn) {
|
||||
var fieldName = this.fieldColumn;
|
||||
var columns = {}
|
||||
var elements = events;
|
||||
_.each(events, function (event) {
|
||||
var value = event.record[fieldName];
|
||||
var key = _.isArray(value) ? value[0] : value;
|
||||
columns[key] = _.isArray(value) ? value[1] : value;
|
||||
});
|
||||
this.data.columns = columns;
|
||||
}
|
||||
},
|
||||
_recordToCalendarEvent: function (evt) {
|
||||
var result = this._super.apply(this, arguments);
|
||||
var value = evt[this.fieldColumn];
|
||||
result.resourceId = _.isArray(value) ? value[0] : value;
|
||||
return result;
|
||||
},
|
||||
_getFullCalendarOptions: function () {
|
||||
var result = this._super.apply(this, arguments);
|
||||
if (this.fieldColumn)
|
||||
result.resources = [];
|
||||
return result;
|
||||
},
|
||||
calendarEventToRecord: function (event) {
|
||||
var result = this._super.apply(this, arguments);
|
||||
if (event.resourceId)
|
||||
result[this.fieldColumn] = event.resourceId;
|
||||
return result;
|
||||
},
|
||||
});
|
||||
});
|
||||
92
web_view_calendar_column/static/src/js/calendar_renderer.js
Normal file
92
web_view_calendar_column/static/src/js/calendar_renderer.js
Normal file
@@ -0,0 +1,92 @@
|
||||
odoo.define('web_view_calendar_column.CalendarRenderer', function (require) {
|
||||
"use strict";
|
||||
|
||||
var CalendarRenderer = require('web.CalendarRenderer');
|
||||
var core = require('web.core');
|
||||
var qweb = core.qweb;
|
||||
var _t = core._t;
|
||||
CalendarRenderer.include({
|
||||
_initCalendar: function () {
|
||||
var self = this;
|
||||
|
||||
this.$calendar = this.$(".o_calendar_widget");
|
||||
|
||||
// This seems like a workaround but apparently passing the locale
|
||||
// in the options is not enough. We should initialize it beforehand
|
||||
var locale = moment.locale();
|
||||
$.fullCalendar.locale(locale);
|
||||
|
||||
//Documentation here : http://arshaw.com/fullcalendar/docs/
|
||||
var fc_options = $.extend({}, this.state.fc_options, {
|
||||
eventDrop: function (event) {
|
||||
self.trigger_up('dropRecord', event);
|
||||
},
|
||||
eventResize: function (event) {
|
||||
self.trigger_up('updateRecord', event);
|
||||
},
|
||||
eventClick: function (event) {
|
||||
self.trigger_up('openEvent', event);
|
||||
self.$calendar.fullCalendar('unselect');
|
||||
},
|
||||
select: function (target_date, end_date, event, _js_event, resource) {
|
||||
var data = {'start': target_date, 'end': end_date, 'resource': resource};
|
||||
if (self.state.context.default_name) {
|
||||
data.title = self.state.context.default_name;
|
||||
}
|
||||
self.trigger_up('openCreate', data);
|
||||
self.$calendar.fullCalendar('unselect');
|
||||
},
|
||||
eventRender: function (event, element) {
|
||||
var $render = $(self._eventRender(event));
|
||||
event.title = $render.find('.o_field_type_char:first').text();
|
||||
element.find('.fc-content').html($render.html());
|
||||
element.addClass($render.attr('class'));
|
||||
var display_hour = '';
|
||||
if (!event.allDay) {
|
||||
var start = event.r_start || event.start;
|
||||
var end = event.r_end || event.end;
|
||||
var timeFormat = _t.database.parameters.time_format.search("%H") != -1 ? 'HH:mm': 'h:mma';
|
||||
display_hour = start.format(timeFormat) + ' - ' + end.format(timeFormat);
|
||||
if (display_hour === '00:00 - 00:00') {
|
||||
display_hour = _t('All day');
|
||||
}
|
||||
}
|
||||
element.find('.fc-content .fc-time').text(display_hour);
|
||||
},
|
||||
// Dirty hack to ensure a correct first render
|
||||
eventAfterAllRender: function () {
|
||||
$(window).trigger('resize');
|
||||
},
|
||||
viewRender: function (view) {
|
||||
// compute mode from view.name which is either 'month', 'agendaWeek' or 'agendaDay'
|
||||
var mode = view.name === 'month' ? 'month' : (view.name === 'agendaWeek' ? 'week' : 'day');
|
||||
// compute title: in week mode, display the week number
|
||||
var title = mode === 'week' ? view.intervalStart.week() : view.title;
|
||||
self.trigger_up('viewUpdated', {
|
||||
mode: mode,
|
||||
title: title,
|
||||
});
|
||||
},
|
||||
//eventResourceEditable: true, // except for between resources
|
||||
height: 'parent',
|
||||
unselectAuto: false,
|
||||
locale: locale, // reset locale when fullcalendar has already been instanciated before now
|
||||
});
|
||||
|
||||
this.$calendar.fullCalendar(fc_options);
|
||||
},
|
||||
_renderEvents: function () {
|
||||
var self = this;
|
||||
this.$calendar.fullCalendar('removeEvents');
|
||||
if (this.state.columns)
|
||||
_.each(Object.entries(this.state.columns), function (column) {
|
||||
self.$calendar.fullCalendar('addResource', {
|
||||
id: column[0],
|
||||
title: column[1]
|
||||
});
|
||||
});
|
||||
this.$calendar.fullCalendar(
|
||||
'addEventSource', this.state.data);
|
||||
},
|
||||
});
|
||||
});
|
||||
28
web_view_calendar_column/static/src/js/calendar_view.js
Normal file
28
web_view_calendar_column/static/src/js/calendar_view.js
Normal file
@@ -0,0 +1,28 @@
|
||||
odoo.define('web_view_calendar_column.CalendarView', function (require) {
|
||||
"use strict";
|
||||
|
||||
var CalendarView = require('web.CalendarView');
|
||||
|
||||
CalendarView.include({
|
||||
jsLibs: [
|
||||
'/web/static/lib/fullcalendar/js/fullcalendar.js',
|
||||
'/web_view_calendar_column/static/lib/scheduler.min.js'
|
||||
],
|
||||
cssLibs: [
|
||||
'/web/static/lib/fullcalendar/css/fullcalendar.css',
|
||||
'/web_view_calendar_column/static/lib/scheduler.min.css'
|
||||
],
|
||||
init: function (viewInfo, params) {
|
||||
this._super.apply(this, arguments);
|
||||
var arch = viewInfo.arch;
|
||||
var fieldNames = this.loadParams.fieldNames;
|
||||
if (params.context.column) {
|
||||
var fieldName = params.context.column;
|
||||
fieldNames.push(fieldName);
|
||||
}
|
||||
this.loadParams.fieldColumn = params.context.column;
|
||||
this.loadParams.fieldNames = _.uniq(fieldNames);
|
||||
this.loadParams.forceColumns = params.context.force_columns;
|
||||
},
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user