Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-30-12-58-23
[civicrm-core.git] / templates / CRM / common / TabHeader.js
index cb19b23a920635928f0de06cce631eaaafeb24f8..8c044d8babaec8494b437db07b3b0330316b8213 100644 (file)
@@ -4,7 +4,7 @@
  * Tabs with class 'ajaxForm' will use CRM.loadForm instead, suitable for most forms
  * Tabs with class 'livePage' will get popup action links, suitable for crud tables
  */
-cj(function($) {
+CRM.$(function($) {
   var tabSettings = CRM.tabSettings || {};
   tabSettings.active = tabSettings.active ? $('#tab_' + tabSettings.active).prevAll().length : 0;
   $("#mainTabContainer")
@@ -33,10 +33,7 @@ cj(function($) {
           ui.panel
             .off('click.crmLivePage')
             .on('click.crmLivePage', 'a.button, a.action-item', CRM.popup)
-            .on('crmPopupFormSuccess.crmLivePage', 'a.button, a.action-item', function() {
-              // Refresh panel when form completes
-              ui.panel.crmSnippet('refresh');
-            });
+            .on('crmPopupFormSuccess.crmLivePage', 'a.button, a.action-item', CRM.refreshParent);
         }
         ui.panel
           .off('.tabInfo')
@@ -68,6 +65,13 @@ cj(function($) {
   // Utility functions
   CRM.tabHeader = CRM.tabHeader || {};
 
+  /**
+   * Return active tab
+   */
+  CRM.tabHeader.getActiveTab = function() {
+    return $('.ui-tabs-active', '#mainTabContainer');
+  }
+
   /**
    * Make a given tab the active one
    * @param tab jQuery selector
@@ -84,6 +88,10 @@ cj(function($) {
     return $('#' + $(tab).attr('aria-controls'));
   };
 
+  CRM.tabHeader.getCount = function(tab) {
+    return parseInt($(tab).find('a em').text(), 10);
+  }
+
   /**
    * Update the counter in a tab
    * @param tab jQuery selector
@@ -111,4 +119,4 @@ cj(function($) {
       $panel.data("civiCrmSnippet") && $panel.crmSnippet('destroy');
     }
   };
-})(cj);
+})(CRM.$);