[IMP] web: add 'create' attribute to calendar view

Previously it was always possible to create within the calendar view.
For some modules this did not make sense and lead to confusing behavior,
for example: a new model instance created in the calendar view that was
not viewable in the calendar view, but was viewable in other views. By
adding a 'create' attribute (to be used in view xml), we allow users to
choose whether or not they want a calendar view to be able to create.

Note that this change does not affect the edit ability of calendar views
for existing instances.

Part of
Task: 2126530
This commit is contained in:
Tiffany Chang (tic)
2020-01-03 10:34:54 +00:00
parent ae7f574e54
commit 3e37ec8844
4 changed files with 101 additions and 2 deletions
@@ -146,7 +146,7 @@ var CalendarView = AbstractView.extend({
this.loadParams.fields = fields;
this.loadParams.fieldsInfo = viewInfo.fieldsInfo;
this.loadParams.editable = !fields[mapping.date_start].readonly;
this.loadParams.creatable = true;
this.loadParams.creatable = this.controllerParams.activeActions.create;
this.loadParams.eventLimit = eventLimit;
this.loadParams.fieldColor = attrs.color;
@@ -3078,6 +3078,102 @@ QUnit.module('Views', {
calendar.destroy();
});
QUnit.test('edit record and attempt to create a record with "create" attribute set to false', async function (assert) {
assert.expect(8);
var calendar = await createCalendarView({
View: CalendarView,
model: 'event',
data: this.data,
arch:
'<calendar class="o_calendar_test" '+
'string="Events" '+
'event_open_popup="true" '+
'create="false" '+
'date_start="start" '+
'date_stop="stop" '+
'mode="month"/>',
archs: archs,
mockRPC: function (route, args) {
if (args.method === 'write') {
assert.deepEqual(args.args[1], {name: 'event 4 modified'}, "should update the record");
}
return this._super.apply(this, arguments);
},
viewOptions: {
initialDate: initialDate,
},
});
// editing existing events should still be possible
// click on an existing event to open the formViewDialog
await testUtils.dom.click(calendar.$('.fc-event:contains(event 4) .fc-content'));
assert.ok(calendar.$('.o_cw_popover').length, "should open a popover clicking on event");
assert.ok(calendar.$('.o_cw_popover .o_cw_popover_edit').length, "popover should have an edit button");
assert.ok(calendar.$('.o_cw_popover .o_cw_popover_delete').length, "popover should have a delete button");
assert.ok(calendar.$('.o_cw_popover .o_cw_popover_close').length, "popover should have a close button");
await testUtils.dom.click(calendar.$('.o_cw_popover .o_cw_popover_edit'));
assert.ok($('.modal-body').length, "should open the form view in dialog when click on edit");
await testUtils.fields.editInput($('.modal-body input:first'), 'event 4 modified');
await testUtils.dom.click($('.modal-footer button.btn:contains(Save)'));
assert.notOk($('.modal-body').length, "save button should close the modal");
// creating an event should not be possible
// attempt to create a new event with create set to false
var $cell = calendar.$('.fc-day-grid .fc-row:eq(2) .fc-day:eq(2)');
testUtils.dom.triggerMouseEvent($cell, "mousedown");
testUtils.dom.triggerMouseEvent($cell, "mouseup");
await testUtils.nextTick();
assert.notOk($('.modal-sm').length, "shouldn't open a quick create dialog for creating a new event with create attribute set to false");
calendar.destroy();
});
QUnit.test('attempt to create record with "create" and "quick_add" attributes set to false', async function (assert) {
assert.expect(1);
var calendar = await createCalendarView({
View: CalendarView,
model: 'event',
data: this.data,
arch:
'<calendar class="o_calendar_test" '+
'string="Events" '+
'create="false" '+
'event_open_popup="true" '+
'quick_add="false" '+
'date_start="start" '+
'date_stop="stop" '+
'mode="month"/>',
archs: archs,
viewOptions: {
initialDate: initialDate,
},
});
// attempt to create a new event with create set to false
var $cell = calendar.$('.fc-day-grid .fc-row:eq(5) .fc-day:eq(2)');
testUtils.dom.triggerMouseEvent($cell, "mousedown");
testUtils.dom.triggerMouseEvent($cell, "mouseup");
await testUtils.nextTick();
assert.strictEqual($('.modal').length, 0, "shouldn't open a form view for creating a new event with create attribute set to false");
calendar.destroy();
});
});
});
+3 -1
View File
@@ -907,7 +907,9 @@ calendar view are:
``mode``
Default display mode when loading the calendar.
Possible attributes are: ``day``, ``week``, ``month``
``create``
allows *dis*\ abling the corresponding action in the view by setting the
corresponding attribute to ``false``
``<field>``
declares fields to aggregate or to use in kanban *logic*. If the field is
simply displayed in the calendar cards.
+1
View File
@@ -22,6 +22,7 @@
<rng:optional><rng:attribute name="js_class"/></rng:optional>
<rng:optional><rng:attribute name="hide_time"/></rng:optional>
<rng:optional><rng:attribute name="hide_date"/></rng:optional>
<rng:optional><rng:attribute name="create"/></rng:optional>
<rng:optional>
<rng:attribute name="mode">
<rng:choice>