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 93c40692d851c5662559176a0b85f085da5052ab..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")
@@ -29,23 +29,11 @@ cj(function($) {
             })
           });
         }
-        if (ui.tab.hasClass('livePage') && CRM.config.ajax_popups_enabled) {
+        if (ui.tab.hasClass('livePage') && CRM.config.ajaxPopupsEnabled) {
           ui.panel
             .off('click.crmLivePage')
-            .on('click.crmLivePage', 'a.button, a.action-item', function() {
-              var url = $(this).attr('href');
-              // only follow real links not javascript buttons
-              if (url === '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) {
-                return;
-              }
-              CRM.loadForm(url, {
-                openInline: 'a:not("[href=#], .no-popup")'
-              }).on('crmFormSuccess', function(e, data) {
-                  // Refresh when form completes
-                  ui.panel.crmSnippet('refresh');
-                });
-              return false;
-            });
+            .on('click.crmLivePage', 'a.button, a.action-item', CRM.popup)
+            .on('crmPopupFormSuccess.crmLivePage', 'a.button, a.action-item', CRM.refreshParent);
         }
         ui.panel
           .off('.tabInfo')
@@ -77,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
@@ -93,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
@@ -120,4 +119,4 @@ cj(function($) {
       $panel.data("civiCrmSnippet") && $panel.crmSnippet('destroy');
     }
   };
-})(cj);
+})(CRM.$);