From 75d7eff23ade0fbd86763c51ff487ec685f94fc3 Mon Sep 17 00:00:00 2001
From: Uma <uma.s@vtiger.com>
Date: Wed, 5 Aug 2020 12:24:49 +0530
Subject: [PATCH] Fixes #1370 Send,Save email modals

---
 languages/en_us/Vtiger.php                    |  1 +
 layouts/v7/modules/Emails/SendEmailResult.tpl |  6 ++++-
 layouts/v7/resources/helper.js                | 24 +++++++++++++++----
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/languages/en_us/Vtiger.php b/languages/en_us/Vtiger.php
index 6d0caecee..e44eabc3c 100644
--- a/languages/en_us/Vtiger.php
+++ b/languages/en_us/Vtiger.php
@@ -1312,6 +1312,7 @@ $languageStrings = array(
 	'LBL_VTIGER6_RETIREMENT_NOTICE' => 'This version will be retired on Feb 15th 2016',
 	'ModTracker' => 'Updates',
 	'LBL_MAIL_SENT_SUCCESSFULLY' => 'Mail Sent Successfully',
+        'LBL_MAIL_SAVED_SUCCESSFULLY' => 'Mail Saved Successfully',
 	'LBL_FAILED_TO_SEND' => 'Failed to Send',
 
 	'LBL_ESSENTIALS' => 'Essentials',
diff --git a/layouts/v7/modules/Emails/SendEmailResult.tpl b/layouts/v7/modules/Emails/SendEmailResult.tpl
index 7f8e0a20b..135c42d13 100644
--- a/layouts/v7/modules/Emails/SendEmailResult.tpl
+++ b/layouts/v7/modules/Emails/SendEmailResult.tpl
@@ -16,7 +16,11 @@
 		<div class="modal-body">
 			{if $SUCCESS}
 				<div class="mailSentSuccessfully" data-relatedload="{$RELATED_LOAD}">
-					{vtranslate('LBL_MAIL_SENT_SUCCESSFULLY')}
+                                    {if $FLAG eq 'SENT'}
+                                        {vtranslate('LBL_MAIL_SENT_SUCCESSFULLY')}
+                                    {else}
+                                        {vtranslate('LBL_MAIL_SAVED_SUCCESSFULLY')}
+                                    {/if}
 				</div>
 				{if $FLAG}
 					<input type="hidden" id="flag" value="{$FLAG}">
diff --git a/layouts/v7/resources/helper.js b/layouts/v7/resources/helper.js
index 79b3564f9..599f06a7c 100644
--- a/layouts/v7/resources/helper.js
+++ b/layouts/v7/resources/helper.js
@@ -446,10 +446,10 @@ jQuery.Class("Vtiger_Helper_Js",{
         var cb = params.cb;
         var container = jQuery('.myModal');
 		
-		container.on('hidden.bs.modal',function() {
+        container.one('hidden.bs.modal',function() {
 			container.html('');
 			window.onbeforeunload = null;
-		});
+        });
 		
         if(typeof cb === "function") {
             container.off('shown.bs.modal');
@@ -793,6 +793,13 @@ jQuery.Class("Vtiger_Helper_Js",{
         if(typeof params === "undefined") {
             params = {};
         }
+        
+        // we should hide all existing modal's
+        var hideModals = (typeof params.hideModals !== 'undefined') ? params.hideModals : true;
+        if(hideModals) {
+            this.hideModal();
+        }
+
         var defaultParams = app.helper.defaultModalParams();
         params = jQuery.extend(defaultParams,params);
 
@@ -800,9 +807,16 @@ jQuery.Class("Vtiger_Helper_Js",{
         if(jQuery('#popupModal').length) return;
         var container = jQuery('<div id="popupModal" class="modal"></div>');
 		
-		container.on('hidden.bs.modal',function() {
-			container.html('').remove();
-		});
+	container.on('hidden.bs.modal',function() {
+            /**
+             * if tabindex = -1 then browser will set focus to that element. 
+             * Loading another modal(this has tabindex = -1) on a modal is not moving the focus to new modal.
+             * We can't remove tabindex from the modals in tpl. So, this is a work around(removing index on show and adding on hide).
+             */ 
+            jQuery('#helpPageOverlay').attr('tabindex','-1');
+                container.html('');
+                window.onbeforeunload = null;
+        });
 		
         if(typeof cb === "function") {
             container.off('shown.bs.modal');
-- 
GitLab