From b4efde7a3911581453f276278d4c81f58a86fe58 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 22 Jan 2015 14:10:47 -0500 Subject: [PATCH] CRM-15858 - Fix changeLog display of custom data --- CRM/Contact/Form/CustomData.php | 11 ++++++ CRM/Contact/Form/Inline.php | 39 ++++++++++++++-------- CRM/Contact/Form/Inline/CustomData.php | 2 ++ CRM/Contact/Page/View/Log.php | 2 ++ templates/CRM/Contact/Page/View/Log.tpl | 2 +- templates/CRM/Contact/Page/View/Summary.js | 31 +++++++++++------ templates/CRM/common/TabHeader.js | 14 ++++++-- 7 files changed, 73 insertions(+), 28 deletions(-) diff --git a/CRM/Contact/Form/CustomData.php b/CRM/Contact/Form/CustomData.php index 893c53d275..1f2f8c536b 100644 --- a/CRM/Contact/Form/CustomData.php +++ b/CRM/Contact/Form/CustomData.php @@ -310,6 +310,17 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { CRM_Core_Session::singleton() ->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/cd/edit', "reset=1&type={$this->_contactType}&groupID={$this->_groupID}&entityID={$this->_tableID}&cgcount={$cgcount}&multiRecordDisplay=single&mode=add")); } + + // Add entry in the log table + CRM_Core_BAO_Log::register($this->_tableID, + 'civicrm_contact', + $this->_tableID + ); + + if (CRM_Core_Resources::isAjaxMode()) { + $this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_tableID); + } + // reset the group contact cache for this group CRM_Contact_BAO_GroupContactCache::remove(); } diff --git a/CRM/Contact/Form/Inline.php b/CRM/Contact/Form/Inline.php index 7c376ad3ad..c41dc3d035 100644 --- a/CRM/Contact/Form/Inline.php +++ b/CRM/Contact/Form/Inline.php @@ -141,26 +141,37 @@ abstract class CRM_Contact_Form_Inline extends CRM_Core_Form { * @return void */ protected function response() { + $this->ajaxResponse = array_merge( + self::renderFooter($this->_contactId), + $this->ajaxResponse, + CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId) + ); + // Note: Post hooks will be called by CRM_Core_Form::mainProcess + } + + /** + * Render changelog footer markup for a contact and supply count + * Needed for refreshing the contact summary screen + * + * @param int $cid + * @param bool $includeCount + * @return array + */ + static function renderFooter($cid, $includeCount = TRUE) { // Load changelog footer from template $smarty = CRM_Core_Smarty::singleton(); - $smarty->assign('contactId', $this->_contactId); - $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'external_identifier')); - $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact')); + $smarty->assign('contactId', $cid); + $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier')); + $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($cid, 'civicrm_contact')); $viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_view_options', TRUE ); $smarty->assign('changeLog', $viewOptions['log']); - $this->ajaxResponse = array_merge( - array( - 'changeLog' => array( - 'count' => CRM_Contact_BAO_Contact::getCountComponent('log', $this->_contactId), - 'markup' => $smarty->fetch('CRM/common/contactFooter.tpl'), - ), - ), - $this->ajaxResponse, - CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId) - ); - // Note: Post hooks will be called by CRM_Core_Form::mainProcess + $ret = array('markup' => $smarty->fetch('CRM/common/contactFooter.tpl')); + if ($includeCount) { + $ret['count'] = CRM_Contact_BAO_Contact::getCountComponent('log', $cid); + } + return array('changeLog' => $ret); } } diff --git a/CRM/Contact/Form/Inline/CustomData.php b/CRM/Contact/Form/Inline/CustomData.php index 8a55e3eecf..9916cf895b 100644 --- a/CRM/Contact/Form/Inline/CustomData.php +++ b/CRM/Contact/Form/Inline/CustomData.php @@ -102,6 +102,8 @@ class CRM_Contact_Form_Inline_CustomData extends CRM_Contact_Form_Inline { $this->_entityType ); + $this->log(); + // reset the group contact cache for this group CRM_Contact_BAO_GroupContactCache::remove(); diff --git a/CRM/Contact/Page/View/Log.php b/CRM/Contact/Page/View/Log.php index 7403765adc..991599affd 100644 --- a/CRM/Contact/Page/View/Log.php +++ b/CRM/Contact/Page/View/Log.php @@ -69,6 +69,8 @@ class CRM_Contact_Page_View_Log extends CRM_Core_Page { } $this->assign('logCount', count($logEntries)); + $this->ajaxResponse['tabCount'] = count($logEntries); + $this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_contactId, FALSE); $this->assign_by_ref('log', $logEntries); } diff --git a/templates/CRM/Contact/Page/View/Log.tpl b/templates/CRM/Contact/Page/View/Log.tpl index f7bff7863a..852de47a85 100644 --- a/templates/CRM/Contact/Page/View/Log.tpl +++ b/templates/CRM/Contact/Page/View/Log.tpl @@ -44,7 +44,7 @@ {else}
  - {ts}No modifications have been logged for this contact.{/ts} + {ts}None found.{/ts}
{/if} diff --git a/templates/CRM/Contact/Page/View/Summary.js b/templates/CRM/Contact/Page/View/Summary.js index 2680b9aa89..b864e30e15 100644 --- a/templates/CRM/Contact/Page/View/Summary.js +++ b/templates/CRM/Contact/Page/View/Summary.js @@ -91,15 +91,6 @@ _.each(update, reloadBlock); CRM.status(ts('Saved')); } - // Update changelog tab and contact footer - if (response.changeLog && response.changeLog.count) { - CRM.tabHeader.updateCount('#tab_log', response.changeLog.count); - } - $("#crm-record-log").replaceWith(response.changeLog.markup); - // Refresh tab contents - Simple logging - if (!CRM.reloadChangeLogTab && $('#changeLog').closest('.ui-tabs-panel').data('civiCrmSnippet')) { - $('#changeLog').closest('.ui-tabs-panel').crmSnippet('destroy'); - } } else { // Handle formRule error @@ -320,9 +311,27 @@ } $('#crm-contact-actions-list').hide(); }) + .on('crmFormSuccess crmLoad', function(e, data) { + // Update changelog tab and contact footer + if (data && data.changeLog) { + if (data.changeLog.count) { + CRM.tabHeader.updateCount('#tab_log', data.changeLog.count); + } + if (data.changeLog.markup) { + $("#crm-record-log").replaceWith(data.changeLog.markup); + } + } + }) .on('crmFormSuccess', function(e, data) { - // Reload changelog whenever an inline or popup form submits - CRM.reloadChangeLogTab && CRM.reloadChangeLogTab(); + // Refresh changeLog - advanced logging + if (CRM.reloadChangeLogTab) { + CRM.reloadChangeLogTab(); + } + // Refresh changeLog - simple logging + // If we didn't get a changelog count in the response, force refresh the changelog tab to populate it + else { + CRM.tabHeader.resetTab('#tab_log', !(data && data.changeLog && data.changeLog.count)); + } // Refresh dependent blocks if (data && data.reloadBlocks) { _.each(data.reloadBlocks, reloadBlock); diff --git a/templates/CRM/common/TabHeader.js b/templates/CRM/common/TabHeader.js index 429ec7660f..9433900c20 100644 --- a/templates/CRM/common/TabHeader.js +++ b/templates/CRM/common/TabHeader.js @@ -124,14 +124,24 @@ CRM.$(function($) { }; /** - * Refresh tab immediately if it is active, otherwise ensure it will be refreshed next time the user clicks on it + * Refresh tab immediately if it is active (or force=true) + * otherwise ensure it will be refreshed next time the user clicks on it + * * @param tab + * @param force */ - CRM.tabHeader.resetTab = function(tab) { + CRM.tabHeader.resetTab = function(tab, force) { var $panel = CRM.tabHeader.getTabPanel(tab); if ($(tab).hasClass('ui-tabs-active')) { $panel.crmSnippet('refresh'); } + else if (force) { + if ($panel.data("civiCrmSnippet")) { + $panel.crmSnippet('refresh'); + } else { + $("#mainTabContainer").trigger('tabsbeforeload', [{panel: $panel, tab: $(tab)}]); + } + } else if ($panel.data("civiCrmSnippet")) { $panel.crmSnippet('destroy'); } -- 2.25.1