From d6539f93195606970c50c80706a2789ce22e6494 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 28 Dec 2013 20:32:00 -0800 Subject: [PATCH] CRM-13863 - Initial support for ajaxForm tabs --- CRM/Contact/Page/View/Summary.php | 32 +++++++++++++++------ js/Common.js | 10 ++++--- templates/CRM/Contact/Page/View/Summary.tpl | 2 +- templates/CRM/common/TabHeader.js | 15 ++++++++-- templates/CRM/common/TabHeader.tpl | 2 +- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index d561d123e3..640d7f20f7 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -340,24 +340,38 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { } $rest = array( - 'activity' => ts('Activities'), - 'case' => ts('Cases'), - 'rel' => ts('Relationships'), - 'group' => ts('Groups'), - 'note' => ts('Notes'), - 'tag' => ts('Tags'), - 'log' => ts('Change Log'), + 'activity' => array( + 'title' => ts('Activities'), + ), + 'case' => array( + 'title' => ts('Cases'), + ), + 'rel' => array( + 'title' => ts('Relationships'), + ), + 'group' => array( + 'title' => ts('Groups'), + 'class' => 'ajaxForm', + ), + 'note' => array( + 'title' => ts('Notes'), + ), + 'tag' => array( + 'title' => ts('Tags'), + ), + 'log' => array( + 'title' => ts('Change Log'), + ), ); foreach ($rest as $k => $v) { if ($accessCiviCRM && CRM_Utils_Array::value($k, $this->_viewOptions)) { - $allTabs[] = array( + $allTabs[] = $v + array( 'id' => $k, 'url' => CRM_Utils_System::url( "civicrm/contact/view/$k", "reset=1&cid={$this->_contactId}" ), - 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId), ); diff --git a/js/Common.js b/js/Common.js index 3e6feeefe9..a8674d6600 100644 --- a/js/Common.js +++ b/js/Common.js @@ -867,6 +867,7 @@ CRM.validate = CRM.validate || { } return url; }, + // Hack to deal with civicrm legacy sort functionality _handleOrderLinks: function() { var that = this; $('a.crm-weight-arrow', that.element).click(function(e) { @@ -985,18 +986,19 @@ CRM.validate = CRM.validate || { url: data.url.replace(/reset=1[&]?/, ''), dataType: 'json', success: function(response) { - if (response.status == 'success') { + if (response.status === 'success') { $el.crmSnippet('option', 'block') && $el.unblock(); $el.trigger('crmFormSuccess', response); // Reset form for e.g. "save and new" - if (response.userContext && (!settings.autoClose || - (settings.refreshAction && $.inArray(response.buttonName, settings.refreshAction) >= 0))) - { + if (response.userContext && settings.refreshAction && $.inArray(response.buttonName, settings.refreshAction) >= 0) { $el.crmSnippet('option', 'url', response.userContext).crmSnippet('refresh'); } else if ($el.data('uiDialog') && settings.autoClose) { $el.dialog('close'); } + else if (settings.autoClose === false) { + $el.crmSnippet('resetUrl').crmSnippet('refresh'); + } } else { response.url = data.url; diff --git a/templates/CRM/Contact/Page/View/Summary.tpl b/templates/CRM/Contact/Page/View/Summary.tpl index 13291abbd6..6146484d31 100644 --- a/templates/CRM/Contact/Page/View/Summary.tpl +++ b/templates/CRM/Contact/Page/View/Summary.tpl @@ -140,7 +140,7 @@ {foreach from=$allTabs key=tabName item=tabValue} -
  • +
  • {$tabValue.title} {$tabValue.count} diff --git a/templates/CRM/common/TabHeader.js b/templates/CRM/common/TabHeader.js index 948bced38f..56cdcab228 100644 --- a/templates/CRM/common/TabHeader.js +++ b/templates/CRM/common/TabHeader.js @@ -13,9 +13,18 @@ cj(function($) { .on('tabsbeforeload', function(e, ui) { // Use civicrm ajax wrappers rather than the default $.load if (!ui.panel.data("civicrmCrmSnippet")) { - CRM.loadPage($('a', ui.tab).attr('href'), { - target: ui.panel - }) + var method = ui.tab.hasClass('ajaxForm') ? 'loadForm' : 'loadPage'; + var params = {target: ui.panel}; + if (method === 'loadForm') { + params.autoClose = params.openInline = params.cancelButton = params.refreshAction = false; + ui.panel.on('crmFormLoad', function() { + // Hack: "Save and done" and "Cancel" buttons submit without ajax + $('.cancel.form-submit, input[name$=upload_done]', this).on('click', function(e) { + $(this).closest('form').ajaxFormUnbind(); + }) + }); + } + CRM[method]($('a', ui.tab).attr('href'), params); } e.preventDefault(); }) diff --git a/templates/CRM/common/TabHeader.tpl b/templates/CRM/common/TabHeader.tpl index 2ff93a06e0..5f97ad2a6c 100644 --- a/templates/CRM/common/TabHeader.tpl +++ b/templates/CRM/common/TabHeader.tpl @@ -33,7 +33,7 @@