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();
}
* @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);
}
}
$this->_entityType
);
+ $this->log();
+
// reset the group contact cache for this group
CRM_Contact_BAO_GroupContactCache::remove();
}
$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);
}
{else}
<div class="messages status no-popup">
<div class="icon inform-icon"></div>
- {ts}No modifications have been logged for this contact.{/ts}
+ {ts}None found.{/ts}
</div>
{/if}
</div>
_.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);
};
/**
- * 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');
}