diff --git a/application/Espo/Modules/Crm/Resources/i18n/en_US/Email.json b/application/Espo/Modules/Crm/Resources/i18n/en_US/Email.json index 58739b6703..b5e4fbe32c 100644 --- a/application/Espo/Modules/Crm/Resources/i18n/en_US/Email.json +++ b/application/Espo/Modules/Crm/Resources/i18n/en_US/Email.json @@ -2,6 +2,7 @@ "labels": { "Create Lead": "Create Lead", "Create Contact": "Create Contact", - "Create Task": "Create Task" + "Create Task": "Create Task", + "Create Case": "Create Case" } } diff --git a/application/Espo/Modules/Crm/Services/CaseObj.php b/application/Espo/Modules/Crm/Services/CaseObj.php index 1d41fe9452..235731919d 100644 --- a/application/Espo/Modules/Crm/Services/CaseObj.php +++ b/application/Espo/Modules/Crm/Services/CaseObj.php @@ -33,5 +33,20 @@ class CaseObj extends \Espo\Services\Record 'emails' ); + public function afterCreate($entity, array $data) + { + parent::afterCreate($entity, $data); + if (!empty($data['emailId'])) { + $email = $this->getEntityManager()->getEntity('Email', $data['emailId']); + if ($email && !$email->get('parentId')) { + $email->set(array( + 'parentType' => 'Case', + 'parentId' => $entity->id + )); + $this->getEntityManager()->saveEntity($email); + } + } + } + } diff --git a/frontend/client/src/views/email/detail.js b/frontend/client/src/views/email/detail.js index 6fd08388bc..71eb0455ce 100644 --- a/frontend/client/src/views/email/detail.js +++ b/frontend/client/src/views/email/detail.js @@ -63,6 +63,15 @@ Espo.define('Views.Email.Detail', ['Views.Detail', 'EmailHelper'], function (Dep acl: 'edit', aclScope: 'Task' }); + + if (this.model.get('parentType') !== 'Case' || !this.model.get('parentId')) { + this.menu.dropdown.push({ + label: 'Create Case', + action: 'createCase', + acl: 'edit', + aclScope: 'Case' + }); + } }, actionCreateLead: function () { @@ -117,6 +126,35 @@ Espo.define('Views.Email.Detail', ['Views.Detail', 'EmailHelper'], function (Dep }.bind(this)); }, + actionCreateCase: function () { + var attributes = {}; + + if (this.model.get('parentType') == 'Account' && this.model.get('parentId')) { + attributes.accountId = this.model.get('parentId'); + attributes.accountName = this.model.get('parentName'); + attributes.emailsIds = [this.model.id]; + attributes.emailId = this.model.id; + } + attributes.name = this.model.get('name'); + + var viewName = this.getMetadata().get('clientDefs.Case.modalViews.detail') || 'Modals.Edit'; + + this.notify('Loading...'); + this.createView('quickCreate', viewName, { + scope: 'Case', + attributes: attributes, + }, function (view) { + view.render(); + view.notify(false); + view.once('after:save', function () { + this.model.fetch(); + this.removeMenuItem('createCase'); + view.close(); + }.bind(this)); + }.bind(this)); + }, + + actionCreateTask: function () { var attributes = {};