X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=templates%2FCRM%2Fcommon%2FTabHeader.js;h=ba514b81268fb2719b1485a598b685f1240a61c7;hb=15ef6755486645b38e8a89e2fed7210dbc4f4713;hp=f45929ff931f149d25abe14fa9657af050c07903;hpb=bb6057fa6225d130e58abf4b570401eab367e98d;p=civicrm-core.git diff --git a/templates/CRM/common/TabHeader.js b/templates/CRM/common/TabHeader.js index f45929ff93..ba514b8126 100644 --- a/templates/CRM/common/TabHeader.js +++ b/templates/CRM/common/TabHeader.js @@ -23,9 +23,9 @@ CRM.$(function($) { params.autoClose = params.openInline = params.cancelButton = params.refreshAction = false; ui.panel.on('crmFormLoad', function() { // Hack: "Save and done" and "Cancel" buttons submit without ajax - $('.cancel.crm-form-submit, input[name$=upload_done]', this).on('click', function(e) { + $('.cancel.crm-form-submit, button[name$=upload_done]', this).on('click', function(e) { $(this).closest('form').ajaxFormUnbind(); - }) + }); }); } if (ui.tab.hasClass('livePage') && CRM.config.ajaxPopupsEnabled) { @@ -69,7 +69,7 @@ CRM.$(function($) { */ CRM.tabHeader.getActiveTab = function() { return $('.ui-tabs-active', '#mainTabContainer'); - } + }; /** * Make a given tab the active one @@ -84,22 +84,39 @@ CRM.$(function($) { * @returns panel jQuery object */ CRM.tabHeader.getTabPanel = function(tab) { - return $('#' + $(tab).attr('aria-controls')); + var selector = $(tab).attr('aria-controls'); + return selector ? $('#' + selector) : $(); }; - CRM.tabHeader.getCount = function(tab) { - return parseInt($(tab).find('a em').text(), 10); + /** + * @param tab jQuery selector + * @returns {string|null} + */ + function getCountClass(tab) { + var $tab = $(tab), + css = $tab.attr('class') || '', + val = css.match(/(crm-count-\d+)/); + return val && val.length ? val[0] : null; } + /** + * @param tab jQuery selector + * @returns {Number|null} + */ + CRM.tabHeader.getCount = function(tab) { + var cssClass = getCountClass(tab); + return cssClass ? parseInt(cssClass.slice(10), 10) : null; + }; + /** * Update the counter in a tab * @param tab jQuery selector - * @param count number + * @param count {Number} */ CRM.tabHeader.updateCount = function(tab, count) { - var oldClass = $(tab).attr('class').match(/(crm-count-\d+)/); + var oldClass = getCountClass(tab); if (oldClass) { - $(tab).removeClass(oldClass[0]); + $(tab).removeClass(oldClass); } $(tab) .addClass('crm-count-' + count) @@ -107,15 +124,26 @@ CRM.$(function($) { }; /** - * Clears tab content so that 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 { - $panel.data("civiCrmSnippet") && $panel.crmSnippet('destroy'); + } + 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'); } }; })(CRM.$);