CRM-15858 - Fix changeLog display of custom data
authorColeman Watts <coleman@civicrm.org>
Thu, 22 Jan 2015 19:10:47 +0000 (14:10 -0500)
committerColeman Watts <coleman@civicrm.org>
Thu, 22 Jan 2015 19:10:47 +0000 (14:10 -0500)
CRM/Contact/Form/CustomData.php
CRM/Contact/Form/Inline.php
CRM/Contact/Form/Inline/CustomData.php
CRM/Contact/Page/View/Log.php
templates/CRM/Contact/Page/View/Log.tpl
templates/CRM/Contact/Page/View/Summary.js
templates/CRM/common/TabHeader.js

index 893c53d2751e3841a6b7663f4545f9392e8318b1..1f2f8c536bc2cdf059180853707f8273721da431 100644 (file)
@@ -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();
   }
index 7c376ad3ad45be554eb47d83daa1145b3e3f2bc6..c41dc3d035857eae0493a1a1afe3b10c037704df 100644 (file)
@@ -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);
   }
 
 }
index 8a55e3eecf83d5d4107e4d271614874d32115370..9916cf895bd07553310570dab5cff35449a71eec 100644 (file)
@@ -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();
 
index 7403765adcf8a1d1b56c480d2ec7909700ba874b..991599affd7ed8ce38d923df8fca57c1b78f941f 100644 (file)
@@ -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);
   }
 
index f7bff7863a25b2cc56efa8c16838d0dcacd581f4..852de47a858f3540a245c2eda6075d37a4a8cc4d 100644 (file)
@@ -44,7 +44,7 @@
      {else}
      <div class="messages status no-popup">
       <div class="icon inform-icon"></div> &nbsp;
-      {ts}No modifications have been logged for this contact.{/ts}
+      {ts}None found.{/ts}
      </div>
      {/if}
     </div>
index 2680b9aa899071e3833ec01597635a38ece7e120..b864e30e15841069aae9c5c786812ffc7082ffe6 100644 (file)
         _.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
         }
         $('#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);
index 429ec7660fa399349a44d94bddeec4a59464b323..9433900c20df626e16eeb1bbe5c8994b1ca8be3c 100644 (file)
@@ -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');
     }