CRM-13863 - Ajax-enable most contact summary tabs
authorColeman Watts <coleman@civicrm.org>
Wed, 1 Jan 2014 22:11:47 +0000 (14:11 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 6 Jan 2014 19:12:28 +0000 (11:12 -0800)
17 files changed:
CRM/Activity/Page/Tab.php
CRM/Case/Page/Tab.php
CRM/Contact/Page/View/GroupContact.php
CRM/Contact/Page/View/Note.php
CRM/Contact/Page/View/Relationship.php
CRM/Contact/Page/View/Summary.php
CRM/Contribute/Page/Tab.php
CRM/Event/Page/Tab.php
CRM/Grant/Page/Tab.php
CRM/Member/Page/Tab.php
CRM/Pledge/Page/Tab.php
templates/CRM/Contact/Page/View/GroupContact.tpl
templates/CRM/Contact/Page/View/Note.tpl
templates/CRM/Contact/Page/View/Summary.js
templates/CRM/Pledge/Page/Tab.tpl
templates/CRM/Tag/Form/Tag.tpl
templates/CRM/common/TabHeader.js

index 970336b1bc5d3cc4f60dbf2b7bb665eecec7874d..2ec117f13bf129674c0700e544188f6985ed851b 100644 (file)
@@ -60,6 +60,7 @@ class CRM_Activity_Page_Tab extends CRM_Core_Page {
     $controller->set('contactId', $this->_contactId);
     $controller->setEmbedded(TRUE);
     $controller->run();
+    $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId);
   }
 
   function edit() {
index 3fde260ac1f81f9ec7fb5795f4a17e70fc5e5f51..63b166d23199865c6de7e7bd4fbaeac6fd549992 100644 (file)
@@ -163,6 +163,7 @@ class CRM_Case_Page_Tab extends CRM_Core_Page {
     if ($this->_contactId) {
       $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
       $this->assign('displayName', $displayName);
+      $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('case', $this->_contactId);
     }
   }
 
index 4091151ff518f001282d0f3742ee2a59dd761132..29fc6425713d05610c82088fdb6f72ad517e3726 100644 (file)
@@ -66,6 +66,8 @@ class CRM_Contact_Page_View_GroupContact extends CRM_Core_Page {
     $contactSmartGroupSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
       'contact_smart_group_display');
     $this->assign('contactSmartGroupSettings', $contactSmartGroupSettings);
+
+    $this->ajaxResponse['tabCount'] = count($in);
   }
 
   /**
index 9a570257ae39c81bf1cd571a6fa5cd5fbf4eb429..1757db6cbec5e608e68db3028fab2b34a44e905e 100644 (file)
@@ -158,6 +158,8 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page {
       $note->id
     );
     $this->assign('commentAction', $commentAction);
+
+    $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('note', $this->_contactId);
   }
 
   /**
@@ -284,7 +286,6 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page {
           'name' => ts('Delete'),
           'url' => 'civicrm/contact/view/note',
           'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
-          'extra' => 'onclick = "if (confirm(\'' . $deleteExtra . '\') ) this.href+=\'&amp;confirmed=1\'; else return false;"',
           'title' => ts('Delete Note'),
         ),
       );
index 06d5d99ee5878e9aaf3e6cfa8c3863e266e70442..b3ab7bd1ada06550025cc40c5a90ee86e629338d 100644 (file)
@@ -171,6 +171,8 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
     // from relationship tab, not from dashboard
     $this->assign('relationshipTabContext', TRUE);
     $this->assign('inactiveRelationships', $inactiveRelationships);
+
+    $this->ajaxResponse['tabCount'] = count($currentRelationships);
   }
 
   /**
index 640d7f20f707638771e4b2dec17920b1df9df59b..f0a5f44ec28e1e0dd1df5607ba357e3624a5b964 100644 (file)
@@ -330,6 +330,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
           'title' => $elem['title'],
           'weight' => $elem['weight'],
           'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId),
+          'class' => 'livePage',
         );
         // make sure to get maximum weight, rest of tabs go after
         // FIXME: not very elegant again
@@ -355,6 +356,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
       ),
       'note' => array(
         'title' => ts('Notes'),
+        'class' => 'livePage',
       ),
       'tag' => array(
         'title' => ts('Tags'),
index bedc1f5f679679af9bdced21f1d890738f5aae83..ca154e71f032fcc7241650c428c7a14a7cbdb7ad 100644 (file)
@@ -265,6 +265,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
     if ($this->_contactId) {
       $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
       $this->assign('displayName', $displayName);
+      $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
     }
   }
 
index 82f3e6917b93f4c575d6018b47a75670eb1b96ef..be4637fd38cb0ddd099eb2950500de24e5bf78a8 100644 (file)
@@ -59,6 +59,7 @@ class CRM_Event_Page_Tab extends CRM_Core_Page {
     if ($this->_contactId) {
       $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
       $this->assign('displayName', $displayName);
+      $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('participant', $this->_contactId);
     }
   }
 
index 85117598515a5fb0ff017d44b35d1a5a318353fa..2befaec62ba60cc15129a0faf56b1e6f0538cede 100644 (file)
@@ -66,6 +66,7 @@ class CRM_Grant_Page_Tab extends CRM_Contact_Page_View {
     if ($this->_contactId) {
       $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
       $this->assign('displayName', $displayName);
+      $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('grant', $this->_contactId);
     }
   }
 
index d62568a4ac5177ac5be9c76a43ac3b7e51d3e645..629aa6d3ad59b2b64ff3bfec05dfd905c68c1e58 100644 (file)
@@ -205,6 +205,7 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
     if ($this->_contactId) {
       $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
       $this->assign('displayName', $displayName);
+      $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId);
     }
   }
 
index 1f6589d36414cbe8fcb7defdec80d1b3ee0ebf02..22b08977261167a454ac9748b40d2922e6718130 100644 (file)
@@ -54,6 +54,7 @@ class CRM_Pledge_Page_Tab extends CRM_Core_Page {
     if ($this->_contactId) {
       $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
       $this->assign('displayName', $displayName);
+      $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('pledge', $this->_contactId);
     }
   }
 
index 811f023246dd892cd225f601c5e2899f2b31d4ef..ccec5fe17fe88e1b0bf0cca74168e81b4e1528a9 100644 (file)
     });
   });
   {/literal}
-  // update count
-  CRM.updateTabCount('#tab_group', {$groupIn|@count});
   // Hack to ensure status msg is properly translated
   CRM.strings.Added = "{ts escape='js'}Added{/ts}";
   CRM.strings.Removed = "{ts escape='js'}Removed{/ts}";
index 2a9dbf73d24658243027b0071a29b6651e5e9e01..d34a4cfc3696655e3200e87b24f514c9f9deb3e2 100644 (file)
@@ -38,7 +38,7 @@
                {include file="CRM/Form/attachment.tpl"}
             {/if}
           </table>
-          <div class="crm-submit-buttons"><input type="button" name='cancel' value="{ts}Done{/ts}" onclick="location.href='{crmURL p='civicrm/contact/view' q='action=browse&selectedChild=note'}';"/></div>
+          <div class="crm-submit-buttons"><input type="submit" class='cancel form-submit' value="{ts}Done{/ts}"/></div>
 
         {if $comments}
         <fieldset>
 
 {/if}
 
-{if $permission EQ 'edit' AND ($action eq 16 or $action eq 4 or $action eq 8)}
+{if $permission EQ 'edit' AND ($action eq 16)}
    <div class="action-link">
    <a accesskey="N" href="{crmURL p='civicrm/contact/view/note' q="cid=`$contactId`&action=add"}" class="button"><span><div class="icon add-icon"></div>{ts}Add Note{/ts}</span></a>
    </div>
 {/if}
 <div class="crm-content-block">
 
-{if $notes}
+{if $notes and $action eq 16}
 
 <script type="text/javascript">
     var commentAction = '{$commentAction|escape:quotes}'
     {/strip}
  </div>
 </div>
-{elseif ! ($action eq 1)}
+{elseif ($action eq 16)}
    <div class="messages status no-popup">
         <div class="icon inform-icon"></div>
-        {capture assign=crmURL}{crmURL p='civicrm/contact/view/note' q="cid=`$contactId`&action=add"}{/capture}
-        {ts 1=$crmURL}There are no Notes for this contact. You can <a accesskey="N" href='%1'>add one</a>.{/ts}
+        {capture assign=link}class="action-item action-item-first" accesskey="N" href="{crmURL p='civicrm/contact/view/note' q="cid=`$contactId`&action=add"}"{/capture}
+        {ts 1=$link}There are no Notes for this contact. You can <a %1>add one</a>.{/ts}
    </div>
 {/if}
 </div>
index 0259a9068071ebd2b30850451d1e40a418c37599..53e8535f5c889cc16d1f0f9c63ae88dc1bcfffcf 100644 (file)
@@ -90,7 +90,7 @@
       }
       // Update changelog tab and contact footer
       if (response.changeLog.count) {
-        CRM.updateTabCount('#tab_log', response.changeLog.count);
+        CRM.tabHeader.updateCount('#tab_log', response.changeLog.count);
       }
       $("#crm-record-log").replaceWith(response.changeLog.markup);
       // Refresh tab contents - Advanced logging
index 5384f640b71747d1504c7fe5d67fb6c527449475..a6844669993afd2b370e82c84251ea3362fe56db 100644 (file)
@@ -32,8 +32,8 @@
 <div id="help">
     {ts 1=$displayName}Pledges received from %1 since inception.{/ts}
     {if $permission EQ 'edit'}
-     {capture assign=newContribURL}{crmURL p="civicrm/contact/view/pledge" q="reset=1&action=add&cid=`$contactId`&context=pledge"}{/capture}
-     {ts 1=$newContribURL}Click <a href='%1'>Add Pledge</a> to record a new pledge received from this contact.{/ts}
+     {capture assign=newContribURL}class="action-item action-item-first" href="{crmURL p="civicrm/contact/view/pledge" q="reset=1&action=add&cid=`$contactId`&context=pledge"}"{/capture}
+     {ts 1=$newContribURL}Click <a %1>Add Pledge</a> to record a new pledge received from this contact.{/ts}
     {/if}
 </div>
 
index 5da30144005bd3a1248806f197d598187d5186d9..a34b70458c1ce1fbd8c33fe78b68ecfc035fa8d6 100644 (file)
@@ -72,7 +72,7 @@
         tags.push($(this).text());
       });
       // showing count of tags in summary tab
-      CRM.updateTabCount('#tab_tag', tags.length);
+      CRM.tabHeader.updateCount('#tab_tag', tags.length);
       // update summary tab
       $("#tags").html(tags.join(', '));
     };
index 7e2543a3ca70319c024860127bb6282f685b8c38..a94d21f38fb8e396052a4ab19d6d3ed97bd2d65e 100644 (file)
@@ -46,6 +46,13 @@ cj(function($) {
               return false;
             });
         }
+        ui.panel
+          .off('crmLoad.tabCount')
+          .on('crmLoad.tabCount', function(e, data) {
+            if (typeof(data.tabCount) !== 'undefined') {
+              CRM.tabHeader.updateCount(ui.tab, data.tabCount);
+            }
+          });
         CRM[method]($('a', ui.tab).attr('href'), params);
       }
       e.preventDefault();
@@ -53,9 +60,11 @@ cj(function($) {
     .tabs(tabSettings);
 });
 (function($) {
-  CRM.updateTabCount = function(tab, count) {
+  // Utility functions
+  CRM.tabHeader = CRM.tabHeader || {};
+  CRM.tabHeader.updateCount = function(tab, count) {
     $(tab)
-      .removeClass($(tab).attr('class').match(/(crm-count-\d+)/)[0])
+      .removeClass($(tab).attr('class').match(/(crm-count-\d+)/)[0] || 'null')
       .addClass('crm-count-' + count)
       .find('a em').html('' + count);
   }