[FIX] web: with begin date is readonly event can be created but not modified
This commit is contained in:
committed by
Aaron Bohy
parent
7bb12de1c6
commit
cd78695126
@@ -23,6 +23,7 @@ var CalendarController = AbstractController.extend({
|
||||
confirm_on_delete: true,
|
||||
}),
|
||||
custom_events: _.extend({}, AbstractController.prototype.custom_events, {
|
||||
quickCreate: '_onQuickCreate',
|
||||
openCreate: '_onOpenCreate',
|
||||
openEvent: '_onOpenEvent',
|
||||
dropRecord: '_onDropRecord',
|
||||
@@ -146,6 +147,33 @@ var CalendarController = AbstractController.extend({
|
||||
_onDropRecord: function (event) {
|
||||
this._updateRecord(event.data);
|
||||
},
|
||||
/**
|
||||
* Handles saving data coming from quick create box
|
||||
*
|
||||
* @private
|
||||
* @param {OdooEvent} event
|
||||
*/
|
||||
_onQuickCreate: function (event) {
|
||||
var self = this;
|
||||
var data = this.model.calendarEventToRecord(event.data.data);
|
||||
var options = event.data.options;
|
||||
return this._rpc({
|
||||
model: this.model.modelName,
|
||||
method: 'create',
|
||||
args: [$.extend({}, this.quick.data_template, data)],
|
||||
context: _.pick(options, 'context'),
|
||||
})
|
||||
.then(function (id) {
|
||||
self.quick.destroy();
|
||||
self.quick = null;
|
||||
self.reload(id);
|
||||
}, function () {
|
||||
// This will occurs if there are some more fields required
|
||||
data.disable_quick_create = true;
|
||||
data.on_save = this.destroy.bind(this);
|
||||
self._onOpenCreate({data: data});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @param {OdooEvent} event
|
||||
*/
|
||||
@@ -173,13 +201,14 @@ var CalendarController = AbstractController.extend({
|
||||
|
||||
if(!options.disable_quick_create && !event.data.disable_quick_create) {
|
||||
if (this.quick != null) {
|
||||
return this.quick.close();
|
||||
this.quick.destroy();
|
||||
this.quick = null;
|
||||
return;
|
||||
}
|
||||
var model = this.modelName;
|
||||
var quick = new QuickCreate(this, model, true, options, data, event.data);
|
||||
quick.on('added', this, this.reload.bind(this));
|
||||
quick.open();
|
||||
quick.focus();
|
||||
this.quick = new QuickCreate(this, true, options, data, event.data);
|
||||
this.quick.on('added', this, this.reload.bind(this));
|
||||
this.quick.open();
|
||||
this.quick.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -161,6 +161,7 @@ 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;
|
||||
|
||||
// display more button when there are too much event on one day
|
||||
this.eventLimit = params.eventLimit;
|
||||
@@ -319,7 +320,7 @@ return AbstractModel.extend({
|
||||
return {
|
||||
defaultView: (this.mode === "month")? "month" : ((this.mode === "week")? "agendaWeek" : ((this.mode === "day")? "agendaDay" : "agendaWeek")),
|
||||
header: false,
|
||||
selectable: this.editable && this.create_right,
|
||||
selectable: this.creatable && this.create_right,
|
||||
selectHelper: true,
|
||||
editable: this.editable,
|
||||
droppable: true,
|
||||
|
||||
@@ -20,14 +20,12 @@ var QuickCreate = Dialog.extend({
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Widget} parent
|
||||
* @param {string} modelName
|
||||
* @param {any} buttons
|
||||
* @param {any} options
|
||||
* @param {any} data_template
|
||||
* @param {any} data_calendar
|
||||
* @param {Object} buttons
|
||||
* @param {Object} options
|
||||
* @param {Object} data_template
|
||||
* @param {Object} dataCalendar
|
||||
*/
|
||||
init: function (parent, modelName, buttons, options, data_template, data_calendar) {
|
||||
this.modelName = modelName;
|
||||
init: function (parent, buttons, options, data_template, dataCalendar) {
|
||||
this._buttons = buttons || false;
|
||||
this.options = options;
|
||||
|
||||
@@ -41,15 +39,15 @@ var QuickCreate = Dialog.extend({
|
||||
size: 'small',
|
||||
buttons: this._buttons ? [
|
||||
{text: _t("Create"), classes: 'btn-primary', click: function () {
|
||||
if (!self._quickAdd()) {
|
||||
if (!self._quickAdd(dataCalendar)) {
|
||||
self.focus();
|
||||
}
|
||||
}},
|
||||
{text: _t("Edit"), click: function () {
|
||||
data_calendar.disable_quick_create = true;
|
||||
data_calendar.title = self.$input.val().trim();
|
||||
data_calendar.on_save = self.destroy.bind(self);
|
||||
self.trigger_up('openCreate', data_calendar);
|
||||
dataCalendar.disable_quick_create = true;
|
||||
dataCalendar.title = self.$input.val().trim();
|
||||
dataCalendar.on_save = self.destroy.bind(self);
|
||||
self.trigger_up('openCreate', dataCalendar);
|
||||
}},
|
||||
{text: _t("Cancel"), close: true},
|
||||
] : [],
|
||||
@@ -67,10 +65,6 @@ var QuickCreate = Dialog.extend({
|
||||
this.slow_create();
|
||||
return;
|
||||
}
|
||||
this.on('added', this, function () {
|
||||
self.close();
|
||||
});
|
||||
|
||||
this.$input = this.$('input').keyup(function enterHandler (e) {
|
||||
if(e.keyCode === $.ui.keyCode.ENTER) {
|
||||
self.$input.off('keyup', enterHandler);
|
||||
@@ -113,29 +107,10 @@ var QuickCreate = Dialog.extend({
|
||||
/**
|
||||
* Gathers data from the quick create dialog a launch quick_create(data) method
|
||||
*/
|
||||
_quickAdd: function () {
|
||||
_quickAdd: function (dataCalendar) {
|
||||
var val = this.$input.val().trim();
|
||||
return (val)? this._quickCreate({'name': val}, this.options) : false;
|
||||
},
|
||||
/**
|
||||
* Handles saving data coming from quick create box
|
||||
*/
|
||||
_quickCreate: function (data, options) {
|
||||
var self = this;
|
||||
return this._rpc({
|
||||
model: this.modelName,
|
||||
method: 'create',
|
||||
args: [$.extend({}, this.data_template, data)],
|
||||
context: _.pick(options, 'context'),
|
||||
})
|
||||
.then(function (id) {
|
||||
self.trigger('added', id);
|
||||
self.$input.val("");
|
||||
}, function (r, event) {
|
||||
event.preventDefault();
|
||||
// This will occurs if there are some more fields required
|
||||
self.slow_create(data);
|
||||
});
|
||||
dataCalendar.title = val;
|
||||
return (val)? this.trigger_up('quickCreate', {data: dataCalendar, options: this.options}) : false;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -125,6 +125,7 @@ var CalendarView = AbstractView.extend({
|
||||
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.eventLimit = eventLimit;
|
||||
this.loadParams.field_color = attrs.color;
|
||||
|
||||
@@ -132,7 +133,6 @@ var CalendarView = AbstractView.extend({
|
||||
this.loadParams.mode = attrs.mode;
|
||||
this.loadParams.scale_zoom = attrs.scale_zoom;
|
||||
this.loadParams.initialDate = params.initialDate || new Date();
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -885,6 +885,10 @@ var MockServer = Class.extend({
|
||||
for (var field_changed in values) {
|
||||
var field = this.data[model].fields[field_changed];
|
||||
var value = values[field_changed];
|
||||
if (!field) {
|
||||
console.warn("Mock: Can't write on field '" + field_changed + "' on model '" + model + "' (field is undefined)");
|
||||
continue;
|
||||
}
|
||||
if (_.contains(['one2many', 'many2many'], field.type)) {
|
||||
// convert commands
|
||||
_.each(value, function (command) {
|
||||
|
||||
@@ -276,7 +276,7 @@ QUnit.module('Views', {
|
||||
$('.modal-body input:first').val('new event in quick create').trigger('input');
|
||||
$('.modal button.btn:contains(Create)').trigger('click');
|
||||
|
||||
assert.ok(calendar.$('.fc-event:contains(new event in quick create)').length, "should display the new record");
|
||||
assert.strictEqual(calendar.$('.fc-event:contains(new event in quick create)').length, 1, "should display the new record");
|
||||
assert.strictEqual(calendar.$('td.fc-event-container[colspan]').length, 2, "should the new record have only one day");
|
||||
|
||||
// create a new event with 2 days
|
||||
|
||||
Reference in New Issue
Block a user