summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2017-05-02 17:10:25 +0200
committerChristophe Matthieu <chm@odoo.com>2017-05-04 17:19:25 +0200
commit9500f8d3f77d0e3e5bb392d2991ccb7af81f1bae (patch)
tree3ddc8d8811afc900d5d7a3554edae7236a340f79
parent27ff895dfd92619d496f67c8b11cb76277bf62d2 (diff)
[IMP] web: add 'event_open_popup' option on calendar view
If the option 'event_open_popup' is set to true, then the calendar view will open events (or records) in a FormViewDialog. Otherwise, it will open events in a new form view (with a do_action)
-rw-r--r--addons/calendar/static/src/xml/base_calendar.xml2
-rw-r--r--addons/calendar/views/calendar_views.xml4
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_controller.js69
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_model.js10
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_quick_create.js4
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_view.js12
-rw-r--r--addons/web/static/tests/views/calendar_tests.js81
-rw-r--r--doc/reference/views.rst4
-rw-r--r--odoo/addons/base/rng/view.rng1
9 files changed, 141 insertions, 46 deletions
diff --git a/addons/calendar/static/src/xml/base_calendar.xml b/addons/calendar/static/src/xml/base_calendar.xml
index f39f247c9f5..ac6bfcd2945 100644
--- a/addons/calendar/static/src/xml/base_calendar.xml
+++ b/addons/calendar/static/src/xml/base_calendar.xml
@@ -2,7 +2,7 @@
<template>
<t t-name="Many2ManyAttendeeTag" t-extend="FieldMany2ManyTag">
<t t-jquery="span:first" t-operation="prepend">
- <span t-attf-class="o_calendar_invitation #{attendeesData[el_index].status}"/>
+ <span t-if="attendeesData[el_index]" t-attf-class="o_calendar_invitation #{attendeesData[el_index].status}"/>
</t>
</t>
diff --git a/addons/calendar/views/calendar_views.xml b/addons/calendar/views/calendar_views.xml
index 731e7f1e387..ed2d32df4e5 100644
--- a/addons/calendar/views/calendar_views.xml
+++ b/addons/calendar/views/calendar_views.xml
@@ -264,7 +264,9 @@
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<calendar string="Meetings" date_start="start" date_stop="stop" date_delay="duration" all_day="allday"
- readonly_form_view_id="%(calendar.view_calendar_event_form_popup)s" event_limit="3"
+ readonly_form_view_id="%(calendar.view_calendar_event_form_popup)s"
+ event_open_popup="true"
+ event_limit="3"
color="partner_id">
<field name="name"/>
<field name="partner_ids" write_model="calendar.contacts" write_field="partner_id" avatar_field="image_small"/>
diff --git a/addons/web/static/src/js/views/calendar/calendar_controller.js b/addons/web/static/src/js/views/calendar/calendar_controller.js
index c7064ab6618..7e668b79dc0 100644
--- a/addons/web/static/src/js/views/calendar/calendar_controller.js
+++ b/addons/web/static/src/js/views/calendar/calendar_controller.js
@@ -19,9 +19,6 @@ var _t = core._t;
var QWeb = core.qweb;
var CalendarController = AbstractController.extend({
- defaults: _.extend({}, AbstractController.prototype.defaults, {
- confirm_on_delete: true,
- }),
custom_events: _.extend({}, AbstractController.prototype.custom_events, {
quickCreate: '_onQuickCreate',
openCreate: '_onOpenCreate',
@@ -42,9 +39,9 @@ var CalendarController = AbstractController.extend({
init: function (parent, model, renderer, params) {
this._super.apply(this, arguments);
this.current_start = null;
- this.quick_add_pop = params.quick_add_pop;
- this.disable_quick_create = params.disable_quick_create;
- this.confirm_on_delete = params.confirm_on_delete;
+ this.quickAddPop = params.quickAddPop;
+ this.disableQuickCreate = params.disableQuickCreate;
+ this.eventOpenPopup = params.eventOpenPopup;
this.formViewId = params.formViewId;
this.readonlyFormViewId = params.readonlyFormViewId;
this.mapping = params.mapping;
@@ -156,7 +153,7 @@ var CalendarController = AbstractController.extend({
self.reload(id);
}, function () {
// This will occurs if there are some more fields required
- event.data.options.disable_quick_create = true;
+ event.data.options.disableQuickCreate = true;
event.data.data.on_save = self.quick.destroy.bind(self.quick);
self._onOpenCreate(event.data);
});
@@ -192,11 +189,12 @@ var CalendarController = AbstractController.extend({
var options = _.extend({}, this.options, event.options, {context: context});
- if(!options.disable_quick_create && !event.data.disable_quick_create && this.quick_add_pop) {
- if (this.quick != null) {
- this.quick.destroy();
- this.quick = null;
- }
+ if (this.quick != null) {
+ this.quick.destroy();
+ this.quick = null;
+ }
+
+ if(!options.disableQuickCreate && !event.data.disableQuickCreate && this.quickAddPop) {
this.quick = new QuickCreate(this, true, options, data, event.data);
this.quick.on('added', this, this.reload.bind(this));
this.quick.open();
@@ -208,18 +206,28 @@ var CalendarController = AbstractController.extend({
if (this.renderer.arch.attrs.string) {
title += ': ' + this.renderer.arch.attrs.string;
}
- new dialogs.FormViewDialog(self, {
- res_model: this.modelName,
- context: context,
- title: title,
- disable_multiple_selection: true,
- on_saved: function () {
- if (event.data.on_save) {
- event.data.on_save();
- }
- self.reload();
- },
- }).open();
+ if (this.eventOpenPopup) {
+ new dialogs.FormViewDialog(self, {
+ res_model: this.modelName,
+ context: context,
+ title: title,
+ disable_multiple_selection: true,
+ on_saved: function () {
+ if (event.data.on_save) {
+ event.data.on_save();
+ }
+ self.reload();
+ },
+ }).open();
+ } else {
+ this.do_action({
+ type: 'ir.actions.act_window',
+ res_model: this.modelName,
+ views: [[this.formViewId || false, 'form']],
+ target: 'current',
+ context: context,
+ });
+ }
},
/**
* @param {OdooEvent} event
@@ -228,6 +236,19 @@ var CalendarController = AbstractController.extend({
var self = this;
var id = event.data._id;
id = id && parseInt(id).toString() === id ? parseInt(id) : id;
+
+ if (!this.eventOpenPopup) {
+ this.do_action({
+ type: 'ir.actions.act_window',
+ res_id: id,
+ res_model: this.modelName,
+ views: [[this.formViewId || false, 'form']],
+ target: 'current',
+ context: event.context || self.context,
+ });
+ return;
+ }
+
var open_dialog = function (readonly) {
var options = {
res_model: self.modelName,
diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js
index 98bff025035..64eae1f746a 100644
--- a/addons/web/static/src/js/views/calendar/calendar_model.js
+++ b/addons/web/static/src/js/views/calendar/calendar_model.js
@@ -181,13 +181,13 @@ return AbstractModel.extend({
// Check whether the date field is editable (i.e. if the events can be
// dragged and dropped)
this.editable = params.editable;
- this.creatable = params.creatable;
+ this.creatable = this.editable;
// display more button when there are too much event on one day
this.eventLimit = params.eventLimit;
// fields to display color, e.g.: user_id.partner_id
- this.field_color = params.field_color;
+ this.fieldColor = params.fieldColor;
if (!this.preload_def) {
this.preload_def = $.Deferred();
$.when(
@@ -207,7 +207,7 @@ return AbstractModel.extend({
filters: params.filters,
};
- // Use scale_zoom attribute in xml file to specify zoom timeline (day,week,month)
+ // Use mode attribute in xml file to specify zoom timeline (day,week,month)
// by default month.
this.setDate(params.initialDate, true);
this.setScale(params.mode);
@@ -417,8 +417,8 @@ return AbstractModel.extend({
* @returns {Deferred}
*/
_loadColors: function (element, events) {
- if (this.field_color) {
- var fieldName = this.field_color;
+ if (this.fieldColor) {
+ var fieldName = this.fieldColor;
_.each(events, function (event) {
var value = event.record[fieldName];
event.color_index = _.isArray(value) ? value[0] : value;
diff --git a/addons/web/static/src/js/views/calendar/calendar_quick_create.js b/addons/web/static/src/js/views/calendar/calendar_quick_create.js
index db39fa6bfd6..2e6fcae5cf5 100644
--- a/addons/web/static/src/js/views/calendar/calendar_quick_create.js
+++ b/addons/web/static/src/js/views/calendar/calendar_quick_create.js
@@ -45,7 +45,7 @@ var QuickCreate = Dialog.extend({
}
}},
{text: _t("Edit"), click: function () {
- dataCalendar.disable_quick_create = true;
+ dataCalendar.disableQuickCreate = true;
dataCalendar.title = self.$input.val().trim();
dataCalendar.on_save = self.destroy.bind(self);
self.trigger_up('openCreate', dataCalendar);
@@ -62,7 +62,7 @@ var QuickCreate = Dialog.extend({
start: function () {
var self = this;
- if (this.options.disable_quick_create) {
+ if (this.options.disableQuickCreate) {
this.slow_create();
return;
}
diff --git a/addons/web/static/src/js/views/calendar/calendar_view.js b/addons/web/static/src/js/views/calendar/calendar_view.js
index 27c2b0d11b5..daef6f4fbb0 100644
--- a/addons/web/static/src/js/views/calendar/calendar_view.js
+++ b/addons/web/static/src/js/views/calendar/calendar_view.js
@@ -108,12 +108,12 @@ var CalendarView = AbstractView.extend({
//if quick_add = False, we don't allow quick_add
//if quick_add = not specified in view, we use the default widgets.QuickCreate
//if quick_add = is NOT False and IS specified in view, we this one for widgets.QuickCreate'
- this.controllerParams.quick_add_pop = (!('quick_add' in attrs) || utils.toBoolElse(attrs.quick_add+'', true));
- this.controllerParams.disable_quick_create = params.disable_quick_create || !this.controllerParams.quick_add_pop;
- this.controllerParams.confirm_on_delete = true;
+ this.controllerParams.quickAddPop = (!('quick_add' in attrs) || utils.toBoolElse(attrs.quick_add+'', true));
+ this.controllerParams.disableQuickCreate = params.disable_quick_create || !this.controllerParams.quickAddPop;
// If this field is set ot true, we don't open the event in form view, but in a popup with the view_id passed by this parameter
this.controllerParams.formViewId = !attrs.form_view_id || !utils.toBoolElse(attrs.form_view_id, true) ? false : attrs.form_view_id;
this.controllerParams.readonlyFormViewId = !attrs.readonly_form_view_id || !utils.toBoolElse(attrs.readonly_form_view_id, true) ? false : attrs.readonly_form_view_id;
+ this.controllerParams.eventOpenPopup = utils.toBoolElse(attrs.event_open_popup || '', false);
this.controllerParams.mapping = mapping;
this.controllerParams.context = params.context || {};
@@ -124,14 +124,12 @@ var CalendarView = AbstractView.extend({
this.loadParams.mapping = mapping;
this.loadParams.fields = fields;
this.loadParams.fieldsInfo = viewInfo.fieldsInfo;
- this.loadParams.editable = !this.controllerParams.read_only_mode && !fields[mapping.date_start].readonly;
- this.loadParams.creatable = !this.controllerParams.read_only_mode;
+ this.loadParams.editable = !fields[mapping.date_start].readonly;
this.loadParams.eventLimit = eventLimit;
- this.loadParams.field_color = attrs.color;
+ this.loadParams.fieldColor = attrs.color;
this.loadParams.filters = filters;
this.loadParams.mode = attrs.mode;
- this.loadParams.scale_zoom = attrs.scale_zoom;
this.loadParams.initialDate = moment(params.initialDate || new Date());
},
});
diff --git a/addons/web/static/tests/views/calendar_tests.js b/addons/web/static/tests/views/calendar_tests.js
index 482f3910550..68c37d4013a 100644
--- a/addons/web/static/tests/views/calendar_tests.js
+++ b/addons/web/static/tests/views/calendar_tests.js
@@ -151,7 +151,7 @@ QUnit.module('Views', {
data: this.data,
arch:
'<calendar class="o_calendar_test" '+
- 'scale_zoom="week" '+
+ 'event_open_popup="true" '+
'date_start="start" '+
'date_stop="stop" '+
'all_day="allday" '+
@@ -225,7 +225,7 @@ QUnit.module('Views', {
arch:
'<calendar class="o_calendar_test" '+
'string="Events" ' +
- 'scale_zoom="week" '+
+ 'event_open_popup="true" '+
'date_start="start" '+
'date_stop="stop" '+
'all_day="allday" '+
@@ -360,7 +360,7 @@ QUnit.module('Views', {
data: this.data,
arch:
'<calendar class="o_calendar_test" '+
- 'scale_zoom="week" '+
+ 'event_open_popup="true" '+
'date_start="start" '+
'date_stop="stop" '+
'all_day="allday" '+
@@ -454,7 +454,7 @@ QUnit.module('Views', {
data: this.data,
arch:
'<calendar class="o_calendar_test" '+
- 'scale_zoom="week" '+
+ 'event_open_popup="true" '+
'date_start="start" '+
'date_stop="stop" '+
'all_day="allday" '+
@@ -571,7 +571,7 @@ QUnit.module('Views', {
data: this.data,
arch:
'<calendar class="o_calendar_test" '+
- 'scale_zoom="week" '+
+ 'event_open_popup="true" '+
'date_start="start" '+
'date_stop="stop" '+
'all_day="allday" '+
@@ -629,7 +629,7 @@ QUnit.module('Views', {
data: this.data,
arch:
'<calendar class="o_calendar_test" '+
- 'scale_zoom="week" '+
+ 'event_open_popup="true" '+
'date_start="start" '+
'date_stop="stop" '+
'all_day="allday" '+
@@ -664,6 +664,7 @@ QUnit.module('Views', {
data: this.data,
arch:
'<calendar class="o_calendar_test" '+
+ 'event_open_popup="true" '+
'date_start="start" '+
'date_stop="stop" '+
'all_day="allday"> '+
@@ -680,6 +681,74 @@ QUnit.module('Views', {
calendar.destroy();
});
+
+ QUnit.test('open form view', function (assert) {
+ assert.expect(2);
+
+ var calendar = createView({
+ View: CalendarView,
+ model: 'event',
+ data: this.data,
+ arch:
+ '<calendar class="o_calendar_test" '+
+ 'string="Events" ' +
+ 'date_start="start" '+
+ 'date_stop="stop" '+
+ 'all_day="allday" '+
+ 'mode="month" '+
+ 'readonly_form_view_id="1">'+
+ '<field name="name"/>'+
+ '</calendar>',
+ archs: archs,
+ viewOptions: {
+ initialDate: initialDate,
+ },
+ });
+
+ // click on an existing event to open the form view
+
+ testUtils.intercept(calendar, 'do_action', function (event) {
+ assert.deepEqual(event.data.action,
+ {
+ type: "ir.actions.act_window",
+ res_id: 4,
+ res_model: "event",
+ views: [[false, "form"]],
+ target: "current",
+ context: {}
+ },
+ "should open the form view");
+ });
+ calendar.$('.fc-event:contains(event 4) .fc-content').trigger('click');
+
+ // create a new event and edit it
+
+ var $cell = calendar.$('.fc-day-grid .fc-row:eq(4) .fc-day:eq(2)');
+ testUtils.triggerMouseEvent($cell, "mousedown");
+ testUtils.triggerMouseEvent($cell, "mouseup");
+ $('.modal-body input:first').val('coucou').trigger('input');
+
+ testUtils.intercept(calendar, 'do_action', function (event) {
+ assert.deepEqual(event.data.action,
+ {
+ type: "ir.actions.act_window",
+ res_model: "event",
+ views: [[false, "form"]],
+ target: "current",
+ context: {
+ "default_name": "coucou",
+ "default_start": "2016-12-27 00:00:00",
+ "default_stop": "2016-12-27 00:00:00",
+ "default_allday": true
+ }
+ },
+ "should open the form view with the context default values");
+ });
+
+ $('.modal button.btn:contains(Edit)').trigger('click');
+
+ calendar.destroy();
+ });
});
});
diff --git a/doc/reference/views.rst b/doc/reference/views.rst
index e5b5d8044f8..4dedb51b95c 100644
--- a/doc/reference/views.rst
+++ b/doc/reference/views.rst
@@ -963,6 +963,10 @@ calendar view are:
view to open in readonly mode
``form_view_id``
view to open when the user create or edit an event
+``event_open_popup``
+ If the option 'event_open_popup' is set to true, then the calendar view will
+ open events (or records) in a FormViewDialog. Otherwise, it will open events
+ in a new form view (with a do_action)
``quick_add``
enables quick-event creation on click: only asks the user for a ``name``
and tries to create a new event with just that and the clicked event
diff --git a/odoo/addons/base/rng/view.rng b/odoo/addons/base/rng/view.rng
index 756dee8aeb0..0fb5a0ca9fc 100644
--- a/odoo/addons/base/rng/view.rng
+++ b/odoo/addons/base/rng/view.rng
@@ -638,6 +638,7 @@
<rng:optional><rng:attribute name="event_limit" /></rng:optional>
<rng:optional><rng:attribute name="quick_add" /></rng:optional>
<rng:optional><rng:attribute name="color" /></rng:optional>
+ <rng:optional><rng:attribute name="event_open_popup" /></rng:optional>
<rng:optional>
<rng:attribute name="mode">
<rng:choice>