diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-04-18 18:20:40 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-04-18 18:20:40 +0200 |
| commit | fed775bc0c2d70463206bbdddd3cce9ae8469e6a (patch) | |
| tree | 03fd8410a57a49c39658f1ba184e29ccef5b3291 /addons/web_editor | |
| parent | 4d2e22bc392f27d920542e6ca025273080e5df77 (diff) | |
| parent | 8c64159b8847dc465a21415c085d6526d280be02 (diff) | |
[MERGE] forward port branch 11.0 up to 8c64159b884
Diffstat (limited to 'addons/web_editor')
| -rw-r--r-- | addons/web_editor/controllers/main.py | 4 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/backend/fields.js | 84 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/editor/rte.summernote.js | 10 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/widgets/widgets.js | 13 |
4 files changed, 106 insertions, 5 deletions
diff --git a/addons/web_editor/controllers/main.py b/addons/web_editor/controllers/main.py index 68051f8c07c..2174dae0b90 100644 --- a/addons/web_editor/controllers/main.py +++ b/addons/web_editor/controllers/main.py @@ -164,7 +164,7 @@ class Web_Editor(http.Controller): 'datas_fname': datas_fname, 'type': 'url', 'url': url, - 'public': True, + 'public': res_model == 'ir.ui.view', 'res_id': res_id, 'res_model': res_model, }) @@ -195,7 +195,7 @@ class Web_Editor(http.Controller): 'name': name, 'datas': base64.b64encode(data), 'datas_fname': datas_fname, - 'public': True, + 'public': res_model == 'ir.ui.view', 'res_id': res_id, 'res_model': res_model, }) diff --git a/addons/web_editor/static/src/js/backend/fields.js b/addons/web_editor/static/src/js/backend/fields.js index d3d601bac73..d874771f939 100644 --- a/addons/web_editor/static/src/js/backend/fields.js +++ b/addons/web_editor/static/src/js/backend/fields.js @@ -84,11 +84,49 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend(TranslatableFieldMi //-------------------------------------------------------------------------- /** + * Returns the domain for attachments used in media dialog. + * We look for attachments related to the current document. If there is a value for the model + * field, it is used to search attachments, and the attachments from the current document are + * filtered to display only user-created documents. + * In the case of a wizard such as mail, we have the documents uploaded and those of the model + * + * @private + * @returns {Array} "ir.attachment" odoo domain. + */ + _getAttachmentsDomain: function () { + var domain = ['|', ['id', 'in', _.pluck(this.attachments, 'id')]]; + var attachedDocumentDomain = [ + '&', + ['res_model', '=', this.model], + ['res_id', '=', this.res_id|0] + ]; + // if the document is not yet created, do not see the documents of other users + if (!this.res_id) { + attachedDocumentDomain.unshift('&'); + attachedDocumentDomain.push(['create_uid', '=', session.uid]); + } + if (this.recordData.model) { + var relatedDomain = ['&', + ['res_model', '=', this.recordData.model], + ['res_id', '=', this.recordData.res_id|0]]; + if (!this.recordData.res_id) { + relatedDomain.unshift('&'); + relatedDomain.push(['create_uid', '=', session.uid]); + } + domain = domain.concat(['|'], attachedDocumentDomain, relatedDomain); + } else { + domain = domain.concat(attachedDocumentDomain); + } + return domain; + }, + /** * @private * @returns {Object} the summernote configuration */ _getSummernoteConfig: function () { var summernoteConfig = { + model: this.model, + id: this.res_id, focus: false, height: 180, toolbar: [ @@ -107,6 +145,22 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend(TranslatableFieldMi lang: "odoo", onChange: this._doDebouncedAction.bind(this), }; + + var fieldNameAttachment =_.chain(this.recordData) + .pairs() + .find(function (value) { + return _.isObject(value[1]) && value[1].model === "ir.attachment"; + }) + .first() + .value(); + + if (fieldNameAttachment) { + this.fieldNameAttachment = fieldNameAttachment; + this.attachments = []; + summernoteConfig.onImageUpload = this._onImageUpload.bind(this); + summernoteConfig.getMediaDomain = this._getAttachmentsDomain.bind(this); + } + if (config.debug) { summernoteConfig.toolbar.splice(7, 0, ['view', ['codeview']]); } @@ -125,6 +179,34 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend(TranslatableFieldMi return this.$content.html(); }, /** + * trigger_up 'field_changed' add record into the "ir.attachment" field found in the view. + * This method is called when an image is uploaded by the media dialog. + * + * For e.g. when sending email, this allows people to add attachments with the content + * editor interface and that they appear in the attachment list. + * The new documents being attached to the email, they will not be erased by the CRON + * when closing the wizard. + * + * @private + */ + _onImageUpload: function (attachments) { + var self = this; + attachments = _.filter(attachments, function (attachment) { + return !_.findWhere(self.attachments, {id: attachment.id}); + }); + if (!attachments.length) { + return; + } + this.attachments = this.attachments.concat(attachments); + this.trigger_up('field_changed', { + dataPointID: this.dataPointID, + changes: _.object([this.fieldNameAttachment], [{ + operation: 'ADD_M2M', + ids: attachments + }]) + }); + }, + /** * @override * @private */ @@ -134,8 +216,6 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend(TranslatableFieldMi this.$textarea.summernote(this._getSummernoteConfig()); this.$content = this.$('.note-editable:first'); this.$content.html(this._textToHtml(this.value)); - this.$content.data('oe-id', this.recordData.res_id || this.res_id); - this.$content.data('oe-model', this.recordData.model || this.model); // trigger a mouseup to refresh the editor toolbar this.$content.trigger('mouseup'); if (this.nodeOptions['style-inline']) { diff --git a/addons/web_editor/static/src/js/editor/rte.summernote.js b/addons/web_editor/static/src/js/editor/rte.summernote.js index fb4d6fc7206..f6e2ac63aa9 100644 --- a/addons/web_editor/static/src/js/editor/rte.summernote.js +++ b/addons/web_editor/static/src/js/editor/rte.summernote.js @@ -397,6 +397,7 @@ eventHandler.modules.imageDialog.showImageDialog = function ($editable) { media: media, options: { lastFilters: ['background'], + onUpload: $editable.data('callbacks').onImageUpload, }, }); return new $.Deferred().reject(); @@ -788,6 +789,14 @@ eventHandler.attach = function (oLayoutInfo, options) { $(document).on("keyup", reRangeSelectKey); var clone_data = false; + + if (options.model) { + oLayoutInfo.editable().data({'oe-model': options.model, 'oe-id': options.id}); + } + if (options.getMediaDomain) { + oLayoutInfo.editable().data('oe-media-domain', options.getMediaDomain); + } + var $node = oLayoutInfo.editor(); if ($node.data('oe-model') || $node.data('oe-translation-id')) { $node.on('content_changed', function () { @@ -1089,6 +1098,7 @@ var SummernoteManager = Class.extend(mixins.EventDispatcherMixin, { _.extend({ res_model: data.$editable.data('oe-model'), res_id: data.$editable.data('oe-id'), + domain: data.$editable.data('oe-media-domain'), }, data.options), data.$editable, data.media diff --git a/addons/web_editor/static/src/js/widgets/widgets.js b/addons/web_editor/static/src/js/widgets/widgets.js index 53df66e9ba7..f7c1c808016 100644 --- a/addons/web_editor/static/src/js/widgets/widgets.js +++ b/addons/web_editor/static/src/js/widgets/widgets.js @@ -209,7 +209,9 @@ var ImageWidget = MediaWidget.extend({ this.options = options; this.accept = options.accept || (options.document ? '*/*' : 'image/*'); - if (options.res_id) { + if (options.domain) { + this.domain = typeof options.domain === 'function' ? options.domain() : options.domain; + } else if (options.res_id) { this.domain = ['|', '&', ['res_model', '=', options.res_model], ['res_id', '=', options.res_id], ['res_model', '=', 'ir.ui.view']]; @@ -330,6 +332,11 @@ var ImageWidget = MediaWidget.extend({ self.$media.css(style); } + if (self.options.onUpload) { + // We consider that when selecting an image it is as if we upload it in the html content. + self.options.onUpload([img]); + } + return self.media; }); }, @@ -504,6 +511,10 @@ var ImageWidget = MediaWidget.extend({ _processFile(attachments[i], error); } + if (self.options.onUpload) { + self.options.onUpload(attachments); + } + function _processFile(attachment, error) { var $button = self.$('.o_upload_image_button'); if (!error) { |
