Extract selectedChild tabheader functionality and enable for Manage Events
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Thu, 16 Aug 2018 16:41:54 +0000 (17:41 +0100)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Wed, 10 Oct 2018 08:30:35 +0000 (09:30 +0100)
12 files changed:
CRM/Admin/Page/MessageTemplates.php
CRM/Contact/Page/View/Summary.php
CRM/Core/Page/Basic.php
CRM/Event/Form/ManageEvent/Repeat.php
CRM/Event/Form/ManageEvent/TabHeader.php
CRM/UF/Page/Group.php
templates/CRM/Admin/Page/Extensions.tpl
templates/CRM/Admin/Page/MessageTemplates.tpl
templates/CRM/Contribute/Page/Tab.tpl
templates/CRM/Event/Form/ManageEvent/Tab.tpl
templates/CRM/UF/Page/Group.tpl
templates/CRM/common/TabSelected.tpl [new file with mode: 0644]

index 1fdc8dc65a50dc8b746c244e64ac509fe565e71c..be658e66bedf2d95e7bcdd7f22cc72119222ea80 100644 (file)
@@ -187,22 +187,13 @@ class CRM_Admin_Page_MessageTemplates extends CRM_Core_Page_Basic {
    * @throws Exception
    */
   public function run($args = NULL, $pageArgs = NULL, $sort = NULL) {
+    $id = $this->getIdAndAction();
     // handle the revert action and offload the rest to parent
-    if (CRM_Utils_Request::retrieve('action', 'String', $this) & CRM_Core_Action::REVERT) {
-
-      $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
-      if (!$this->checkPermission($id, NULL)) {
-        CRM_Core_Error::fatal(ts('You do not have permission to revert this template.'));
-      }
-
+    if ($this->_action & CRM_Core_Action::REVERT) {
       $this->_revertedId = $id;
-
       CRM_Core_BAO_MessageTemplate::revert($id);
     }
-    $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this);
-    if (in_array($selectedChild, array('user', 'workflow'))) {
-      $this->assign('selectedChild', $selectedChild);
-    }
+
     return parent::run($args, $pageArgs, $sort);
   }
 
index d41da69d8f866a77dadcc5bd554470e1eb888d0d..9f1611285f0c0455358e6f9abd299e1ce2f228f6 100644 (file)
@@ -122,7 +122,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
       ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
       ->addSetting(array(
         'summaryPrint' => array('mode' => $this->_print),
-        'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary')),
+        'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, 'summary')),
       ));
     $this->assign('summaryPrint', $this->_print);
     $session = CRM_Core_Session::singleton();
index fe3f1652cb9855c0178fc5fb6140c947712658d9..48af5ebf531b7443d39a3fb8c4483db36a803b65 100644 (file)
@@ -171,11 +171,14 @@ abstract class CRM_Core_Page_Basic extends CRM_Core_Page {
    *
    * @return int
    *   The ID if present, or 0.
+   * @throws \CRM_Core_Exception
    */
   public function getIdAndAction() {
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     $this->assign('action', $this->_action);
 
+    $this->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this));
+
     // get 'id' if present
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
 
index 495522b2a2aa3113c97114aa5a270d306e96771d..abd824acf89acafd760dcf8ce4ff58a9c585df32 100644 (file)
@@ -110,7 +110,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
       unset($params['id']);
 
       $url = 'civicrm/event/manage/repeat';
-      $urlParams = "action=update&reset=1&id={$this->_id}";
+      $urlParams = "action=update&reset=1&id={$this->_id}&selectedChild=repeat";
 
       $linkedEntities = array(
         array(
index b2d3b03649a30d12e606b287dca3d9b412484113..e4a19a77e4582b70072ec7eea4658b7e2e342c91 100644 (file)
@@ -42,8 +42,11 @@ class CRM_Event_Form_ManageEvent_TabHeader {
    * @param CRM_Event_Form_ManageEvent $form
    *
    * @return array
+   * @throws \CRM_Core_Exception
    */
   public static function build(&$form) {
+    $form->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $form));
+
     $tabs = $form->get('tabHeader');
     if (!$tabs || empty($_GET['reset'])) {
       $tabs = self::process($form);
@@ -235,7 +238,7 @@ WHERE      e.id = %1
 
     if (is_array($tabs)) {
       foreach ($tabs as $subPage => $pageVal) {
-        if ($pageVal['current'] === TRUE) {
+        if (CRM_Utils_Array::value('current', $pageVal) === TRUE) {
           $current = $subPage;
           break;
         }
index c87feb2e6da3f3394b45a6edbfca044981bee104..0d372bcad74aa3c0d2fb8a2d0e82fa07b55fde33 100644 (file)
@@ -145,10 +145,6 @@ class CRM_UF_Page_Group extends CRM_Core_Page {
    * This method is called after the page is created. It checks for the
    * type of action and executes that action.
    * Finally it calls the parent's run method.
-   *
-   * @param
-   *
-   * @return void
    */
   public function run() {
     // get the requested action
@@ -160,7 +156,7 @@ class CRM_UF_Page_Group extends CRM_Core_Page {
 
     // assign vars to templates
     $this->assign('action', $action);
-    $this->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'String', $this));
+    $this->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this));
     $id = CRM_Utils_Request::retrieve('id', 'Positive',
       $this, FALSE, 0
     );
index fbfcd84894c77b066c3236235fc6d2cbd81d2332..c50ce1b60174f38087a445f13172a3bd612d87b0 100644 (file)
     </script>
     {/literal}
 
-    {* Tab management *}
-    <script type="text/javascript">
-    var selectedTab  = 'summary';
-    {if $selectedChild}selectedTab = "{$selectedChild}";{/if}
-
-    {literal}
-
-    CRM.$(function($) {
-      var tabIndex = $('#tab_' + selectedTab).prevAll().length;
-      $("#mainTabContainer").tabs({active: tabIndex});
-      $(".crm-tab-button").addClass("ui-corner-bottom");
-    });
-    {/literal}
-    </script>
+    {include file="CRM/common/TabSelected.tpl" defaultTab="summary"}
 
     {* Refresh buttons *}
     {literal}
index c8e41a24e4dd862c7480730d7dbc143e4f1c720d..6ab271be39870ec263df32d4340fed4ee970257b 100644 (file)
     {/foreach}
   </div>
 </div>
-  <script type='text/javascript'>
-    var selectedTab = 'user';
-    {if $selectedChild}selectedTab = '{$selectedChild}';{/if}
-    {literal}
-      CRM.$(function($) {
-        var tabIndex = $('#tab_' + selectedTab).prevAll().length
-        $("#mainTabContainer").tabs( {active: tabIndex} );
-      });
-    {/literal}
-  </script>
+{include file="CRM/common/TabSelected.tpl" defaultTab="user"}
 
 {elseif $action ne 1 and $action ne 2 and $action ne 4 and $action ne 8}
   <div class="messages status no-popup">
index 4f989cdf6e6db9c423e9978125e83ba1fe88a443..0d955cb65c554ccc991fe5f9256f078d605bae5f 100644 (file)
     <div class="contact-summary-contribute-tab view-content">
 
       <div id="secondaryTabContainer" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
-        {* Tab management *}
-        <script type="text/javascript">
-          var selectedTab  = 'contributions';
+        {include file="CRM/common/TabSelected.tpl" defaultTab="contributions" tabContainer="#secondaryTabContainer"}
 
-          {literal}
-          CRM.$(function($) {
-            var tabIndex = $('#tab_' + selectedTab).prevAll().length;
-            $("#secondaryTabContainer").tabs({active: tabIndex});
-            $(".crm-tab-button").addClass("ui-corner-bottom");
-          });
-          {/literal}
-        </script>
         <ul class="ui-tabs-nav ui-corner-all ui-helper-reset ui-helper-clearfix ui-widget-header">
           <li id="tab_contributions" class="crm-tab-button ui-corner-all ui-tabs-tab ui-corner-top ui-state-default ui-tab ui-tabs-active ui-state-active">
             <a href="#contributions-subtab" title="{ts}Contributions{/ts}">
index 63baa84349980a4fb4b7797cd9f4098bcf47afc4..6df78f14f8f7bf179b69c1b01975d8354be5c57d 100644 (file)
@@ -107,3 +107,4 @@ CRM.$(function($) {
 </script>
 {/literal}
 {include file="CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl" entityID=$id entityTable="civicrm_event"}
+{include file="CRM/common/TabSelected.tpl" defaultTab="settings"}
index 77b5ea655f59d9c7969d31424d29719fc3c1e205..cdeb8829c175539ad20a5a51aece4b8f4a70d11f 100644 (file)
             </div>
         </div>{* reserved profile*}
 
-  </div> {* maincontainer*}
-  <script type='text/javascript'>
-    var selectedTab = 'user-profiles';
-    {if $selectedChild}selectedTab = '{$selectedChild}';{/if}
-    {literal}
-      CRM.$(function($) {
-        var tabIndex = $('#tab_' + selectedTab).prevAll().length
-        $("#mainTabContainer").tabs( {active: tabIndex} );
-      });
-    {/literal}
-  </script>
+  </div>
+{include file="CRM/common/TabSelected.tpl" defaultTab="user-profiles"}
 
     {else}
     {if $action ne 1} {* When we are adding an item, we should not display this message *}
diff --git a/templates/CRM/common/TabSelected.tpl b/templates/CRM/common/TabSelected.tpl
new file mode 100644 (file)
index 0000000..2b32581
--- /dev/null
@@ -0,0 +1,12 @@
+<script type='text/javascript'>
+  var selectedTab = '{$defaultTab}';
+  var tabContainer = '#mainTabContainer';
+  {if $tabContainer}tabContainer = '{$tabContainer}';{/if}
+  {if $selectedChild}selectedTab = '{$selectedChild}';{/if}
+  {literal}
+  CRM.$(function($) {
+    var tabIndex = $('#tab_' + selectedTab).prevAll().length;
+    $(tabContainer).tabs( {active: tabIndex} );
+  });
+  {/literal}
+</script>