diff options
| author | Gorash <chm@odoo.com> | 2019-08-20 06:23:06 +0000 |
|---|---|---|
| committer | David Monjoie <dmo@odoo.com> | 2019-08-21 18:52:36 +0000 |
| commit | 35b61822a8b12ebbdb455495479df6f2e13db03e (patch) | |
| tree | 999c382ea06b53b8da8d7db2d82e671d831dd856 /addons/web_editor/static/src/js/wysiwyg/plugin/dropzone.js | |
| parent | f14cecfc0a7f401533213aaa968ee233e19d1325 (diff) | |
[REV] wev_editor, website: revert saas-12.2 editor
This commit reverts the saas-12.2 editor by putting back the editor
of Odoo 12.
The saas-12.2 editor was an intermediate work between the previous
editor of Odoo 12 and the new one slated for Odoo 13. It was unstable
but it was supposed to be replaced by the new editor of version 13.
However, since the new editor has been postponed to Odoo 14, the
saas-12.2 one would have been staying in Odoo 13, which would have
been a nightmare to maintain. To avoid this outcome, we chose to
put back the 12.0 editor in its place.
This has the particular advantage that Odoo 13 will share the same
bugfixes as Odoo 12 and 11 as they all run under the same core
editor, while the saas-12.2 one would have been an entirely
different beast to maintain.
This is a partial revert of f2969923.
Part of PR 35677.
Co-authored-by: Nicolas Bayet <nby@odoo.com>
Co-authored-by: Antoine Guenet <age@odoo.com>
Co-authored-by: Christophe Matthieu <chm@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Diffstat (limited to 'addons/web_editor/static/src/js/wysiwyg/plugin/dropzone.js')
| -rw-r--r-- | addons/web_editor/static/src/js/wysiwyg/plugin/dropzone.js | 229 |
1 files changed, 0 insertions, 229 deletions
diff --git a/addons/web_editor/static/src/js/wysiwyg/plugin/dropzone.js b/addons/web_editor/static/src/js/wysiwyg/plugin/dropzone.js deleted file mode 100644 index a88fc50fc7f..00000000000 --- a/addons/web_editor/static/src/js/wysiwyg/plugin/dropzone.js +++ /dev/null @@ -1,229 +0,0 @@ -odoo.define('web_editor.wysiwyg.plugin.dropzone', function (require) { -'use strict'; - -var core = require('web.core'); -var Plugins = require('web_editor.wysiwyg.plugins'); -var registry = require('web_editor.wysiwyg.plugin.registry'); -var utils = require('web.utils'); - -var _t = core._t; -var dom = $.summernote.dom; - -var DropzonePlugin = Plugins.dropzone.extend({ - //-------------------------------------------------------------------------- - // Public summernote module API - //-------------------------------------------------------------------------- - - /** - * Disable Summernote's handling of drop events. - */ - attachDragAndDropEvent: function () { - this._super.apply(this, arguments); - this.$dropzone.off('drop'); - this.$dropzone.on('dragenter', this._onDragenter.bind(this)); - this.$dropzone.on('drop', this._onDrop.bind(this)); - }, - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * Clean up then drops HTML or plain text into the editor. - * - * @private - * @param {String} html - * @param {Boolean} textOnly true to allow only dropping plain text - */ - _dropHTML: function (html, textOnly) { - this.context.invoke('editor.beforeCommand'); - - // Clean up - var nodes = this.context.invoke('TextPlugin.prepareClipboardData', html); - - // Delete selection - this.context.invoke('HelperPlugin.deleteSelection'); - - // Insert the nodes - this.context.invoke('TextPlugin.pasteNodes', nodes, textOnly); - this.context.invoke('HelperPlugin.normalize'); - this.context.invoke('editor.saveRange'); - - this.context.invoke('editor.afterCommand'); - }, - /** - * Drop images into the editor: save them as attachments. - * - * @private - * @param {File[]]} files (images only) - */ - _dropImages: function (files) { - var self = this; - this.context.invoke('editor.beforeCommand'); - var range = this.context.invoke('editor.createRange'); - - var spinners = []; - var images = []; - var defs = []; - _.each(files, function (file) { - // Add spinner - var spinner = $('<span class="fa fa-spinner fa-spin">').attr('data-filename', file.name)[0]; - self.context.invoke('editor.hidePopover'); - if (range.sc.tagName) { - if (range.so >= dom.nodeLength(range.sc)) { - $(range.sc).append(spinner); - } else { - $(range.sc.childNodes[range.so]).before(spinner); - } - } else { - range.sc.splitText(range.so); - $(range.sc).after(spinner); - } - spinners.push(spinner); - - // save images as attachments - var def = new Promise(function (resolve) { - // Get image's Base64 string - utils.getDataURLFromFile(file).then(function (result) { - self._uploadImage(result, file.name).then(function (attachment) { - // Make the HTML - var image = self.document.createElement('img'); - image.setAttribute('style', 'width: 100%;'); - image.src = '/web/content/' + attachment.id + '/' + attachment.name; - image.alt = attachment.name; - $(spinner).replaceWith(image); - images.push(image); - resolve(image); - $(image).trigger('dropped'); - }); - }); - }); - defs.push(def); - }); - - this.trigger_up('drop_images', { - spinners: spinners, - promises: defs, - }); - - Promise.all(defs).then(function () { - var defs = []; - $(images).each(function () { - if (!this.height) { - var def = new Promise(function (resolve) { - $(this).one('load error abort', resolve); - }); - defs.push(def); - } - }); - Promise.all(defs).then(function () { - if (images.length === 1) { - range = self.context.invoke('editor.setRange', _.last(images), 0); - range.select(); - self.context.invoke('editor.saveRange'); - self.context.invoke('editor.afterCommand'); - self.context.invoke('MediaPlugin.updatePopoverAfterEdit', images[0]); - } else { - self.context.invoke('editor.afterCommand'); - } - }); - }); - }, - /** - * Upload an image from its Base64 representation. - * - * @private - * @param {String} imageBase64 - * @param {String} fileName - * @returns {Promise} - */ - _uploadImage: function (imageBase64, fileName) { - var options = {}; - this.trigger_up('getRecordInfo', { - recordInfo: options, - type: 'media', - callback: function (recordInfo) { - _.defaults(options, recordInfo); - }, - }); - - return this._rpc({ - route: '/web_editor/attachment/add_data', - params: { - 'data': imageBase64.split(';base64,').pop(), - 'name': fileName, - 'res_id': options.res_id || 0, - 'res_model': options.res_model, - }, - }); - }, - /** - * @private - * @param {JQueryEvent} e - */ - _onDragenter: function (e) { - var range = this.context.invoke('editor.createRange'); - if (!this.editable.contains(range.sc)) { - var node = this.editable; - if (node && node.firstChild) { - node = node.firstChild; - } - range = this.context.invoke('editor.setRange', node, 0, node, 0); - range.select(); - } - }, - /** - * @private - * @param {JQueryEvent} e - */ - _onDrop: function (e) { - e.preventDefault(); - - this.$editor.removeClass('dragover'); - - if (this.options.disableDragAndDrop) { - return; - } - var dataTransfer = e.originalEvent.dataTransfer; - - if (!this._canDropHere()) { - this.context.invoke('HelperPlugin.notify', _t("Not a dropzone"), _t("Dropping is prohibited in this area.")); - return; - } - - if (dataTransfer.getData('text/html')) { - this._dropHTML(dataTransfer.getData('text/html')); - return; - } - if (dataTransfer.files.length) { - var images = []; - _.each(dataTransfer.files, function (file) { - if (file.type.indexOf('image') !== -1) { - images.push(file); - } - }); - if (!images.length || images.length < dataTransfer.files.length) { - this.context.invoke('HelperPlugin.notify', _t("Unsupported file type"), _t("Images are the only file types that can be dropped.")); - } - if (images.length) { - this._dropImages(images); - } - } - }, - /** - * Return true if dropping is allowed at the current range. - * - * @private - * @returns {Boolean} - */ - _canDropHere: function () { - var range = this.context.invoke('editor.createRange'); - return this.options.isEditableNode(range.sc); - }, -}); - -registry.add('dropzone', DropzonePlugin); - -return DropzonePlugin; - -}); |
