From: Christian Wach Date: Sat, 26 Mar 2022 00:54:42 +0000 (+0000) Subject: Fix "Location is used by Other Event" warning X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=546afbd8b19fbf2e32ec2857e44eb2ead8704f6a;p=civicrm-core.git Fix "Location is used by Other Event" warning --- diff --git a/templates/CRM/Event/Form/ManageEvent/Location.tpl b/templates/CRM/Event/Form/ManageEvent/Location.tpl index 4f9074269e..47a76afc27 100644 --- a/templates/CRM/Event/Form/ManageEvent/Location.tpl +++ b/templates/CRM/Event/Form/ManageEvent/Location.tpl @@ -88,7 +88,7 @@ dataType: 'json', success: function(data) { var selectLocBlockId = $('#loc_event_id').val(); - // Only change state when options are loaded + // Only change state when options are loaded. if (data.address_1_state_province_id) { var defaultState = data.address_1_state_province_id; $('#address_1_state_province_id', $form).one('crmOptionsUpdated', function() { @@ -100,7 +100,8 @@ if ( i == 'count_loc_used' ) { if ( ((selectLocBlockId == locBlockId) && data.count_loc_used > 1) || ((selectLocBlockId != locBlockId) && data.count_loc_used > 0) ) { - displayMessage(data.count_loc_used); + // Counts retrieved via AJAX are already "other" Event counts. + displayMessage(parseInt(data.count_loc_used) + 1); } else { displayMessage(0); } @@ -117,12 +118,12 @@ var createNew = document.getElementsByName("location_option")[0].checked; if (createNew) { $('#existingLoc', $form).hide(); - //clear all location fields values. + // Clear all location fields values. if (clear !== false) { $(":input[id *= 'address_1_'], :input[id *= 'email_1_'], :input[id *= 'phone_1_']", $form).val("").change(); {/literal}{if $config->defaultContactCountry} {if $config->defaultContactStateProvince} - // Set default state once options are loaded + // Set default state once options are loaded. var defaultState = {$config->defaultContactStateProvince} {literal} $('#address_1_state_province_id', $form).one('crmOptionsUpdated', function() { @@ -147,9 +148,14 @@ showLocFields(false); function displayMessage(count) { - if (count) { - var msg = {/literal}'{ts escape="js" 1="%1"}This location is used by %1 other events. Modifying location information will change values for all events.{/ts}'{literal}; - $('#locUsedMsg', $form).text(ts(msg, {1: count})).addClass('status'); + if (parseInt(count) > 1) { + var otherCount = parseInt(count) - 1; + if (otherCount > 1) { + var msg = {/literal}'{ts escape="js" 1="%1"}This location is used by %1 other events. Modifying location information will change values for all events.{/ts}'{literal}; + } else { + var msg = {/literal}'{ts escape="js" 1="%1"}This location is used by %1 other event. Modifying location information will also change values for that event.{/ts}'{literal}; + } + $('#locUsedMsg', $form).text(ts(msg, {1: otherCount})).addClass('status'); } else { $('#locUsedMsg', $form).text(' ').removeClass('status'); }