diff --git a/application/Espo/Resources/metadata/entityDefs/Note.json b/application/Espo/Resources/metadata/entityDefs/Note.json index 1e46923360..f9ad625deb 100644 --- a/application/Espo/Resources/metadata/entityDefs/Note.json +++ b/application/Espo/Resources/metadata/entityDefs/Note.json @@ -2,7 +2,8 @@ "fields": { "post": { "type": "text", - "rows": 30 + "rows": 30, + "view": "views/note/fields/post" }, "data": { "type": "jsonObject", diff --git a/client/src/views/note/fields/post.js b/client/src/views/note/fields/post.js index 4dacc9d045..695ed73633 100644 --- a/client/src/views/note/fields/post.js +++ b/client/src/views/note/fields/post.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('views/note/fields/post', ['views/fields/text', 'lib!Textcomplete'], function (Dep, Textcomplete) { +define('views/note/fields/post', ['views/fields/text', 'lib!Textcomplete'], function (Dep, Textcomplete) { return Dep.extend({ @@ -81,6 +81,19 @@ Espo.define('views/note/fields/post', ['views/fields/text', 'lib!Textcomplete'], $textarea.off('drop'); $textarea.off('dragover'); $textarea.off('dragleave'); + $textarea.off('paste'); + + $textarea.on('paste', function (e) { + var items = e.originalEvent.clipboardData.items; + if (items) { + for (var i = 0; i < items.length; i++) { + if (!~items[i].type.indexOf('image')) continue; + var blob = items[i].getAsFile(); + + this.trigger('add-files', [blob]); + } + } + }.bind(this)); this.$textarea.on('drop', function (e) { e.preventDefault(); @@ -115,7 +128,7 @@ Espo.define('views/note/fields/post', ['views/fields/text', 'lib!Textcomplete'], return url; }.bind(this); - if (assignmentPermission !== 'no') { + if (assignmentPermission !== 'no' && this.model.isNew()) { this.$element.textcomplete([{ match: /(^|\s)@(\w*)$/, search: function (term, callback) { diff --git a/client/src/views/note/modals/edit.js b/client/src/views/note/modals/edit.js index f31c591d7c..2844369239 100644 --- a/client/src/views/note/modals/edit.js +++ b/client/src/views/note/modals/edit.js @@ -26,11 +26,29 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('views/note/modals/edit', 'views/modals/edit', function (Dep) { +define('views/note/modals/edit', 'views/modals/edit', function (Dep) { return Dep.extend({ - fullFormDisabled: true + fullFormDisabled: true, + + setup: function () { + Dep.prototype.setup.call(this); + this.once('ready', function () { + var recordView = this.getView('edit') || this.getView('record'); + if (recordView) { + var fieldView = recordView.getFieldView('post'); + if (fieldView) { + this.listenTo(fieldView, 'add-files', function (files) { + var attachmentsView = recordView.getFieldView('attachments'); + if (attachmentsView) { + recordView.getFieldView('attachments').uploadFiles(files); + } + }, this); + } + } + }, this); + }, }); }); diff --git a/client/src/views/stream/panel.js b/client/src/views/stream/panel.js index 13009b8133..9670cdaed9 100644 --- a/client/src/views/stream/panel.js +++ b/client/src/views/stream/panel.js @@ -206,6 +206,8 @@ define('views/stream/panel', ['views/record/panels/relationship', 'lib!Textcompl }, model: this.seed, placeholderText: this.placeholderText + }, function (view) { + this.initPostEvents(view); }); this.createCollection(function () { this.wait(false); @@ -304,6 +306,12 @@ define('views/stream/panel', ['views/record/panels/relationship', 'lib!Textcompl }, this); }, + initPostEvents: function (view) { + this.listenTo(view, 'add-files', function (files) { + this.getView('attachments').uploadFiles(files); + }, this); + }, + afterRender: function () { this.$textarea = this.$el.find('textarea[data-name="post"]'); this.$attachments = this.$el.find('div.attachments'); @@ -322,33 +330,6 @@ define('views/stream/panel', ['views/record/panels/relationship', 'lib!Textcompl this.$el.find('.action[data-action="switchInternalMode"]').addClass('enabled'); } - $textarea.off('drop'); - $textarea.off('dragover'); - $textarea.off('dragleave'); - - $textarea.on('drop', function (e) { - e.preventDefault(); - e.stopPropagation(); - var e = e.originalEvent; - if (e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length) { - this.getView('attachments').uploadFiles(e.dataTransfer.files); - this.enablePostingMode(); - } - this.$textarea.attr('placeholder', originalPlaceholderText); - }.bind(this)); - - var originalPlaceholderText = this.$textarea.attr('placeholder'); - - $textarea.on('dragover', function (e) { - e.preventDefault(); - this.$textarea.attr('placeholder', this.translate('dropToAttach', 'messages')); - }.bind(this)); - - $textarea.on('dragleave', function (e) { - e.preventDefault(); - this.$textarea.attr('placeholder', originalPlaceholderText); - }.bind(this)); - var collection = this.collection; this.listenToOnce(collection, 'sync', function () { diff --git a/client/src/views/stream/record/edit.js b/client/src/views/stream/record/edit.js index da415b9435..9d4b10f703 100644 --- a/client/src/views/stream/record/edit.js +++ b/client/src/views/stream/record/edit.js @@ -203,6 +203,7 @@ Espo.define('views/stream/record/edit', 'views/record/base', function (Dep) { var postView = this.getFieldView('post'); if (postView) { + this.stopListening(postView, 'add-files'); this.listenTo(postView, 'add-files', function (files) { this.enablePostingMode(); var attachmentsView = this.getFieldView('attachments');