X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=templates%2FCRM%2Fcommon%2FTabHeader.js;h=82c19815e039c202bb7e671862d2df45570e7fa1;hb=cf7754d71abb04c50f7501894881da003baa7f59;hp=cb19b23a920635928f0de06cce631eaaafeb24f8;hpb=021da9cd67825c3a2ad1356fa08c4daa716f976a;p=civicrm-core.git diff --git a/templates/CRM/common/TabHeader.js b/templates/CRM/common/TabHeader.js index cb19b23a92..82c19815e0 100644 --- a/templates/CRM/common/TabHeader.js +++ b/templates/CRM/common/TabHeader.js @@ -4,15 +4,14 @@ * 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") .on('tabsbeforeactivate', function(e, ui) { - // Warn of unsaved changes - requires formNavigate.tpl to be included in each tab - if (!global_formNavigate) { + // CRM-14353 - Warn of unsaved changes for all forms except those which have opted out + if (CRM.utils.initialValueChanged($('form:not([data-warn-changes=false])', ui.oldPanel))) { CRM.alert(ts('Your changes in the %1 tab have not been saved.', {1: ui.oldTab.text()}), ts('Unsaved Changes'), 'warning'); - global_formNavigate = true; } }) .on('tabsbeforeload', function(e, ui) { @@ -33,10 +32,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 +64,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 +87,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 +118,4 @@ cj(function($) { $panel.data("civiCrmSnippet") && $panel.crmSnippet('destroy'); } }; -})(cj); +})(CRM.$);