From f1cffcae3848e48fa6ff770946fcbf7b19f24a76 Mon Sep 17 00:00:00 2001 From: yuri Date: Thu, 7 Jul 2016 17:08:05 +0300 Subject: [PATCH] email actions --- .../email-folder/modals/select-folder.js | 7 +- client/src/views/email/record/detail.js | 73 ++++++++++++++++++- client/src/views/email/record/list.js | 2 +- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/client/src/views/email-folder/modals/select-folder.js b/client/src/views/email-folder/modals/select-folder.js index 3fef3a9bcb..8540fc8c21 100644 --- a/client/src/views/email-folder/modals/select-folder.js +++ b/client/src/views/email-folder/modals/select-folder.js @@ -46,7 +46,12 @@ Espo.define('views/email-folder/modals/select-folder', 'views/modal', function ( events: { 'click a[data-action="selectFolder"]': function (e) { var id = $(e.currentTarget).data('id'); - this.trigger('select', id); + var model = this.collection.get(id); + var name = this.translate('inbox', 'presetFilters', 'Email'); + if (model) { + name = model.get('name'); + } + this.trigger('select', id, name); this.close(); }, }, diff --git a/client/src/views/email/record/detail.js b/client/src/views/email/record/detail.js index ccaeb1429b..d17c367259 100644 --- a/client/src/views/email/record/detail.js +++ b/client/src/views/email/record/detail.js @@ -43,7 +43,7 @@ Espo.define('views/email/record/detail', 'views/record/detail', function (Dep) { } if (this.model.get('status') == 'Archived') { - if (this.model.get('createdById') == 'system' || !this.model.get('createdById')) { + if (this.model.get('createdById') == 'system' || !this.model.get('createdById') || this.model.get('isImported')) { isRestricted = true; } } @@ -90,6 +90,20 @@ Espo.define('views/email/record/detail', 'views/record/detail', function (Dep) { 'name': 'markAsNotImportant', 'hidden': !this.model.get('isImportant') }); + this.dropdownItemList.push({ + 'label': 'Move to Trash', + 'name': 'moveToTrash', + 'hidden': this.model.get('inTrash') + }); + this.dropdownItemList.push({ + 'label': 'Retrieve from Trash', + 'name': 'retrieveFromTrash', + 'hidden': !this.model.get('inTrash') + }); + this.dropdownItemList.push({ + 'label': 'Move to Folder', + 'name': 'moveToFolder' + }); } this.listenTo(this.model, 'change:isImportant', function () { @@ -102,6 +116,16 @@ Espo.define('views/email/record/detail', 'views/record/detail', function (Dep) { } }, this); + this.listenTo(this.model, 'change:inTrash', function () { + if (this.model.get('inTrash')) { + this.hideActionItem('moveToTrash'); + this.showActionItem('retrieveFromTrash'); + } else { + this.hideActionItem('retrieveFromTrash'); + this.showActionItem('moveToTrash'); + } + }, this); + this.listenTo(this.model, 'reply', function () { this.showField('replies'); this.model.fetch(); @@ -130,8 +154,53 @@ Espo.define('views/email/record/detail', 'views/record/detail', function (Dep) { this.model.set('isImportant', false); }, + actionMoveToTrash: function () { + $.ajax({ + url: 'Email/action/moveToTrash', + type: 'POST', + data: JSON.stringify({ + id: this.model.id + }) + }).then(function () { + Espo.Ui.warning(this.translate('Moved to Trash', 'labels', 'Email')); + }.bind(this)); + this.model.set('inTrash', true); + }, + + actionRetrieveFromTrash: function () { + $.ajax({ + url: 'Email/action/retrieveFromTrash', + type: 'POST', + data: JSON.stringify({ + id: this.model.id + }) + }).then(function () { + Espo.Ui.warning(this.translate('Retrieved from Trash', 'labels', 'Email')); + }.bind(this)); + this.model.set('inTrash', false); + }, + + actionMoveToFolder: function () { + this.createView('dialog', 'views/email-folder/modals/select-folder', {}, function (view) { + view.render(); + this.listenToOnce(view, 'select', function (folderId, folderName) { + this.clearView('dialog'); + this.ajaxPostRequest('Email/action/moveToFolder', { + id: this.model.id, + folderId: folderId + }).then(function () { + if (folderId === 'inbox') { + folderId = null; + } + this.model.set('folderId', folderId); + Espo.Ui.success(this.translate('Done')); + }.bind(this)); + }, this); + }, this); + }, + actionShowBodyPlain: function () { - this.createView('bodyPlain', 'Email.Modals.BodyPlain', { + this.createView('bodyPlain', 'views/email/modals/body-plain', { model: this.model }, function (view) { view.render(); diff --git a/client/src/views/email/record/list.js b/client/src/views/email/record/list.js index 3bc3c56037..471d9ef0ad 100644 --- a/client/src/views/email/record/list.js +++ b/client/src/views/email/record/list.js @@ -257,7 +257,7 @@ Espo.define('views/email/record/list', 'views/record/list', function (Dep) { id: id, folderId: folderId }).then(function () { - Espo.Ui.warning(this.translate('Done')); + Espo.Ui.success(this.translate('Done')); this.collection.fetch(); }.bind(this)); }, this);