Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract selectedChild tabheader functionality and enable for Manage Events #12747

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions CRM/Admin/Page/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,13 @@ public function action(&$object, $action, &$values, &$links, $permission, $force
* @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);
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Page/View/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function 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();
Expand Down
3 changes: 3 additions & 0 deletions CRM/Core/Page/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,14 @@ public function run() {
*
* @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);

Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/ManageEvent/Repeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function postProcess() {
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(
Expand Down
5 changes: 4 additions & 1 deletion CRM/Event/Form/ManageEvent/TabHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -235,7 +238,7 @@ public static function getCurrentTab($tabs) {

if (is_array($tabs)) {
foreach ($tabs as $subPage => $pageVal) {
if ($pageVal['current'] === TRUE) {
if (CRM_Utils_Array::value('current', $pageVal) === TRUE) {
$current = $subPage;
break;
}
Expand Down
6 changes: 1 addition & 5 deletions CRM/UF/Page/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ public static function &actionLinks() {
* 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
Expand All @@ -160,7 +156,7 @@ public function run() {

// 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
);
Expand Down
15 changes: 1 addition & 14 deletions templates/CRM/Admin/Page/Extensions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,7 @@
</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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class addition is lost in this change (intentionally or otherwise) - however, I think the selectedChild doesn't actually work on extensions with or without this patch -it does with this

diff --git a/CRM/Admin/Page/Extensions.php b/CRM/Admin/Page/Extensions.php
index a2d5e9cbad..eb556d4afb 100644
--- a/CRM/Admin/Page/Extensions.php
+++ b/CRM/Admin/Page/Extensions.php
@@ -56,6 +56,7 @@ class CRM_Admin_Page_Extensions extends CRM_Core_Page_Basic {

 $destination = urlencode($destination);
 $this->assign('destination', $destination);
  • $this->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this));
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class loss also affects ContributionPage

});
{/literal}
</script>
{include file="CRM/common/TabSelected.tpl" defaultTab="summary"}

{* Refresh buttons *}
{literal}
Expand Down
11 changes: 1 addition & 10 deletions templates/CRM/Admin/Page/MessageTemplates.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,7 @@
{/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">
Expand Down
12 changes: 1 addition & 11 deletions templates/CRM/Contribute/Page/Tab.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,8 @@
<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"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out how to select the recurring subtab (before or after this change)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton No, you can't :-( But maybe once this abstraction is in place we might be able to look at it


{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}">
Expand Down
1 change: 1 addition & 0 deletions templates/CRM/Event/Form/ManageEvent/Tab.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire @eileenmcnaughton Currently this line breaks the manage event URLs if selectedChild is not appended to it. Eg

https://dmaster.demo.civicrm.org/civicrm/event/manage/fee?reset=1&action=update&id=3 goes to the settings page instead of opening the fee tab. Similarly all the configuration links from the manage event page goes to the settings page.

Maybe, we should just

  • remove this line from the file or
  • append selectedChild to the links in Manage Event Page. But we already specify the tab name in the link before the query string eg civicrm/event/manage/fee?reset=1.
  • Format the links to look like civicrm/event/manage?..selectedChild=fee (might need xml/upgrade changes along with fixing the links in core).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire @jitendrapurohit maybe we should assign defaultTab from php?

@mattwire I think this needs to be fixed in the rc

Copy link
Contributor Author

@mattwire mattwire Nov 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. So before this PR the selectedChild stuff didn't work for events at all. Events is the only one that specifies the tab as part of the link.

  1. remove this line from the file

Specifying the "defaultTab" is standard across all usages of the tab selector code and is meant to be a fallback default if selectedChild is not defined.

  1. append selectedChild to the links in Manage Event Page. But we already specify the tab name in the link before the query string eg civicrm/event/manage/fee?reset=1.

This is probably the easiest / safest way to resolve this, unless we assign defaultTab from PHP in 1.

  1. Format the links to look like civicrm/event/manage?..selectedChild=fee (might need xml/upgrade changes along with fixing the links in core).

This would be more standard and is what we should probably aspire to for consistency, but is also much more likely to cause breakage.

13 changes: 2 additions & 11 deletions templates/CRM/UF/Page/Group.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,8 @@
</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 *}
Expand Down
12 changes: 12 additions & 0 deletions templates/CRM/common/TabSelected.tpl
Original file line number Diff line number Diff line change
@@ -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>