Fix "Location is used by Other Event" warning
authorChristian Wach <needle@haystack.co.uk>
Sat, 26 Mar 2022 00:54:42 +0000 (00:54 +0000)
committerChristian Wach <needle@haystack.co.uk>
Sat, 26 Mar 2022 00:54:42 +0000 (00:54 +0000)
templates/CRM/Event/Form/ManageEvent/Location.tpl

index 4f9074269e58c15a6459e7932e978132c9507887..47a76afc27f90d8661bef7bfdd82a0107c1507e1 100644 (file)
@@ -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() {
                 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);
                   }
           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() {
         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');
           }