stream image paste

This commit is contained in:
Yuri Kuznetsov
2020-05-12 18:01:04 +03:00
parent 830ba03448
commit e4eb8794ff
5 changed files with 46 additions and 32 deletions
@@ -2,7 +2,8 @@
"fields": {
"post": {
"type": "text",
"rows": 30
"rows": 30,
"view": "views/note/fields/post"
},
"data": {
"type": "jsonObject",
+15 -2
View File
@@ -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) {
+20 -2
View File
@@ -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);
},
});
});
+8 -27
View File
@@ -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 () {
+1
View File
@@ -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');