Skip to content

Commit

Permalink
Fix salesagility#10570 - Email Signature Compose View Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ojs87 committed Nov 6, 2024
1 parent e572230 commit b8ba07b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
12 changes: 6 additions & 6 deletions modules/Emails/EmailsControllerActionGetFromFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public function handleActionGetFromFields(Email $email, InboundEmail $ie)
$ie->email = $email;
$ieAccounts = $ie->retrieveAllByGroupIdWithGroupAccounts($this->currentUser->id);
$accountSignatures = $this->currentUser->getPreference('account_signatures', 'Emails');
$showFolders = sugar_unserialize(base64_decode($this->currentUser->getPreference('showFolders', 'Emails')));
$showFolders = sugar_unserialize(base64_decode($this->currentUser->getPreference('showFolders', 'Emails'))) ?: [];
$emailSignatures = $this->getEmailSignatures($accountSignatures);
$defaultEmailSignature = $this->getDefaultSignatures();
$prependSignature = $this->currentUser->getPreference('signature_prepend');
$prependSignature = $this->currentUser->getPreference('signature_prepend') ?? false;
$dataAddresses = $this->collector->collectDataAddressesFromIEAccounts(
$ieAccounts,
$showFolders,
Expand All @@ -103,7 +103,7 @@ public function handleActionGetFromFields(Email $email, InboundEmail $ie)

$dataAddresses = $dataAddresses ?? [];

$this->addOutboundEmailAccounts($dataAddresses);
$this->addOutboundEmailAccounts($dataAddresses, $prependSignature, $defaultEmailSignature);

$dataEncoded = json_encode(array('data' => $dataAddresses), JSON_UNESCAPED_UNICODE);
$results = mb_convert_encoding($dataEncoded, 'ISO-8859-1');
Expand Down Expand Up @@ -178,7 +178,7 @@ protected function getDefaultSignatures()
* @param array $dataAddresses
* @return void
*/
protected function addOutboundEmailAccounts(array &$dataAddresses): void
protected function addOutboundEmailAccounts(array &$dataAddresses, bool $prependSignature = false, array $defaultEmailSignature = []): void
{
/** @var OutboundEmailAccounts $outboundAccount */
$outboundAccount = BeanFactory::newBean('OutboundEmailAccounts');
Expand All @@ -195,7 +195,7 @@ protected function addOutboundEmailAccounts(array &$dataAddresses): void
$replyToAddress = $userOutboundAccount->getReplyToAddress();
$replyToName = $userOutboundAccount->getReplyToName();
$type = $userOutboundAccount->type ?? '';
$signature = $userOutboundAccount->signature ?? '';
$signature = $defaultEmailSignature['signature_html'] ?? $userOutboundAccount->signature ?? '';
$isPersonal = $type === 'user';
$isGroup = $type === 'group';
$entry = [
Expand All @@ -209,7 +209,7 @@ protected function addOutboundEmailAccounts(array &$dataAddresses): void
'reply_to' => $replyToAddress,
'reply_to_name' => $replyToName
],
'prepend' => false,
'prepend' => $prependSignature,
'isPersonalEmailAccount' => $isPersonal,
'isGroupEmailAccount' => $isGroup,
'emailSignatures' => [
Expand Down
15 changes: 10 additions & 5 deletions modules/Emails/EmailsDataAddressCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ protected function fillDataAddress($dataAddresses, $defaultEmailSignature, $prep
);
$dataAddressesWithUserAddressesAndSystem = $this->fillDataAddressWithSystemMailerSettings(
$dataAddressesWithUserAddresses,
$defaultEmailSignature
$defaultEmailSignature,
$prependSignature
);

return
Expand Down Expand Up @@ -661,9 +662,10 @@ protected function getCollectDataAddressArrayFromUserAddresses(
*
* @param array $dataAddresses
* @param array $defaultEmailSignature
* @param boolean $prependSignature
* @return array
*/
protected function fillDataAddressWithSystemMailerSettings($dataAddresses, $defaultEmailSignature)
protected function fillDataAddressWithSystemMailerSettings($dataAddresses, $defaultEmailSignature, $prependSignature)
{
$this->setOe(new OutboundEmail());
if ($this->getOe()->isAllowUserAccessToSystemDefaultOutbound()) {
Expand All @@ -674,7 +676,8 @@ protected function fillDataAddressWithSystemMailerSettings($dataAddresses, $defa
$system->smtp_from_name,
$system->smtp_from_addr,
$system->mail_smtpuser,
$defaultEmailSignature
$defaultEmailSignature,
$prependSignature
);
}

Expand Down Expand Up @@ -744,6 +747,7 @@ protected function getOe()
* @param string $fromAddr
* @param string $mailUser
* @param array $defaultEmailSignature
* @param boolean $prependSignature
* @return array
*/
protected function getFillDataAddressArray(
Expand All @@ -752,7 +756,8 @@ protected function getFillDataAddressArray(
$fromName,
$fromAddr,
$mailUser,
$defaultEmailSignature
$defaultEmailSignature,
bool $prependSignature
) {
$dataAddress = new EmailsDataAddress();

Expand All @@ -763,7 +768,7 @@ protected function getFillDataAddressArray(
$fromAddr,
$fromName,
false,
false,
$prependSignature,
true,
$id,
$name,
Expand Down
45 changes: 37 additions & 8 deletions modules/Emails/include/ComposeView/EmailsComposeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
*/
self.prependSignature = false;

/**
* Determines if a Signature has already been added to the message
* @type {boolean}
*/
self.signatureAdded = false;

/**
* Defines the buttons that are displayed when the user focuses in on a to, cc and bcc field.
*
Expand Down Expand Up @@ -347,7 +353,19 @@

return false;
};


/**
* Remove any existing signature element class in the email thread
* @type {self.removeExistingSignatureClass}
*/

$.fn.EmailsComposeView.removeExistingSignatureClass = self.removeExistingSignatureClass = function() {
let body = tinymce.activeEditor.getContent();
let $body = $('<div>').append($(body));
let $signatureElement = $body.find('div.email-signature-element');
$signatureElement.removeClass('email-signature-element');
tinymce.activeEditor.setContent($body.html(), {format: 'html'})
}

$.fn.EmailsComposeView.updateSignature = self.updateSignature = function ($selected) {
if(!$selected) {
Expand All @@ -362,9 +380,13 @@

var body = tinymce.activeEditor.getContent();
if (body !== '' && $(body).hasClass('email-signature-element')) {
var $body = $(body);
var $existingSignature = $body.find('.email-signature-element');
$existingSignature.remove();
var $body = $('<div>').append($(body));
var $existingSignature = $body.find('div.email-signature-element');
if(self.prependSignature) {
$existingSignature.outerText = '';
} else {
$existingSignature.remove();
}
tinymce.activeEditor.setContent($body.html(), {format: 'html'});
}

Expand Down Expand Up @@ -1301,11 +1323,16 @@
$(self).trigger('emailComposeViewGetFromFields');


if (tinymce.initialized === true) {
if (tinymce.initialized === true && !self.signatureAdded) {
self.removeExistingSignatureClass();
self.updateSignature();
} else if(tinymce.EditorManager && tinymce.EditorManager.activeEditor) {
self.signatureAdded = true;
} else if(tinymce.EditorManager && tinymce.EditorManager.activeEditor && !self.signatureAdded) {
tinymce.EditorManager.activeEditor.on('init', function(e) {
self.removeExistingSignatureClass();
self.updateSignature();
self.signatureAdded = true;

});
}
}
Expand Down Expand Up @@ -1357,11 +1384,13 @@

var intervalCheckTinymce = window.setInterval(function () {
var isFromPopulated = $('#from_addr_name').prop("tagName").toLowerCase() === 'select';
if (tinymce.editors.length > 0 && isFromPopulated === true) {
if (tinymce.editors.length > 0 && isFromPopulated === true && !self.signatureAdded) {
self.removeExistingSignatureClass();
self.updateSignature();
self.signatureAdded = true;
clearInterval(intervalCheckTinymce);
}
}, 300);
}, 500);

tinymce.init(opts.tinyMceOptions);

Expand Down

0 comments on commit b8ba07b

Please sign in to comment.