diff options
| author | Christophe Matthieu <chm@odoo.com> | 2017-05-02 17:10:25 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2017-05-04 17:19:25 +0200 |
| commit | 9500f8d3f77d0e3e5bb392d2991ccb7af81f1bae (patch) | |
| tree | 3ddc8d8811afc900d5d7a3554edae7236a340f79 /addons/web/static/src/js | |
| parent | 27ff895dfd92619d496f67c8b11cb76277bf62d2 (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)
Diffstat (limited to 'addons/web/static/src/js')
4 files changed, 57 insertions, 38 deletions
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()); }, }); |
