Remove the tab selection inline script from TabHeader.tpl
authorColeman Watts <coleman@civicrm.org>
Sat, 28 Nov 2020 19:07:13 +0000 (14:07 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 30 Nov 2020 13:57:13 +0000 (08:57 -0500)
This is part of ongoing cleanup to get the logic for selecting default tab
out of the tpl, which was redundant with the logic already in tabHeader.js.

CRM/Admin/Page/MessageTemplates.php
CRM/Core/Form.php
templates/CRM/Admin/Page/MessageTemplates.tpl
templates/CRM/common/TabHeader.tpl
templates/CRM/common/TabSelected.tpl
tests/phpunit/CRM/Contribute/Form/ContributionTest.php

index 3363ac410fbcee74d488d90325dfa06622d78840..36d52d56b43ed1e9b6ab7ee54b2d27f8955f9932 100644 (file)
@@ -274,6 +274,11 @@ class CRM_Admin_Page_MessageTemplates extends CRM_Core_Page_Basic {
     $this->assign('canEditSystemTemplates', CRM_Core_Permission::check('edit system workflow message templates'));
     $this->assign('canEditMessageTemplates', CRM_Core_Permission::check('edit message templates'));
     $this->assign('canEditUserDrivenMessageTemplates', CRM_Core_Permission::check('edit user-driven message templates'));
+    Civi::resources()
+      ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
+      ->addSetting([
+        'tabSettings' => ['active' => $_GET['selectedChild'] ?? NULL],
+      ]);
   }
 
 }
index 8c49fee8a533511407818235bb95e764a185ea48..6d67ce875fe056495d8ad9523976baf73a865e5b 100644 (file)
@@ -2693,6 +2693,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     if (!empty($selectedChild)) {
       $this->set('selectedChild', $selectedChild);
       $this->assign('selectedChild', $selectedChild);
+      Civi::resources()->addSetting(['tabSettings' => ['active' => $selectedChild]]);
     }
   }
 
index b60355dede5c249e9e019fda75ca156a4cd1332b..0adf34c5b1859e7b4e5cacc444bd1f9b22a660c2 100644 (file)
     {/foreach}
   </div>
 </div>
-{include file="CRM/common/TabHeader.tpl"}
 
 {elseif $action ne 1 and $action ne 2 and $action ne 4 and $action ne 8}
   <div class="messages status no-popup">
index a10aa28ffa0b1c3531b10c169a1c3bc946098a50..1345f31f9a2a3cc1a1058f9a1899414a67d240ce 100644 (file)
@@ -37,4 +37,3 @@
   {/if}
   <div class="clear"></div>
 </div> {* crm-content-block ends here *}
-{include file="CRM/common/TabSelected.tpl" defaultTab="settings"}
index 2b32581b8528f4ff63cf20eb85b63ed3f990182f..573d5ae7c2b177d3f324993f913dfd12984c3f7a 100644 (file)
@@ -1,3 +1,4 @@
+{* DEPRECATED script, should be refactored out and removed *}
 <script type='text/javascript'>
   var selectedTab = '{$defaultTab}';
   var tabContainer = '#mainTabContainer';
index 3ab9be1c36013b005542c678be3f31819c56b5ca..42094065cbb474db7d950151b4742251c0de9775 100644 (file)
@@ -1773,7 +1773,7 @@ Price Field - Price Field 1        1   $ 100.00      $ 100.00
 
     // The page contents load later by ajax, so there's just the surrounding
     // html available now, but we can check at least one thing while we're here.
-    $this->assertStringContainsString("selectedTab = 'widget';", $contents);
+    $this->assertContains("mainTabContainer", $contents);
   }
 
 }