From 31b8ac8219ad42907bbae6f8817ef145ea0379df Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 22 Mar 2013 21:12:40 -0700 Subject: [PATCH] Fix default location type CRM-12157 --- CRM/Import/Form/MapField.php | 12 +++--------- templates/CRM/Import/Form/MapTable.tpl | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CRM/Import/Form/MapField.php b/CRM/Import/Form/MapField.php index 15df99eade..0ae89564fc 100644 --- a/CRM/Import/Form/MapField.php +++ b/CRM/Import/Form/MapField.php @@ -339,19 +339,13 @@ class CRM_Import_Form_MapField extends CRM_Core_Form { $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); - /* FIXME: dirty hack to make the default option show up first. This - * avoids a mozilla browser bug with defaults on dynamically constructed - * selector widgets. */ - + // Pass default location to js if ($defaultLocationType) { - $defaultLocation = $this->_location_types[$defaultLocationType->id]; - unset($this->_location_types[$defaultLocationType->id]); - $this->_location_types = array( - $defaultLocationType->id => $defaultLocation) + $this->_location_types; + $this->assign('defaultLocationType', $defaultLocationType->id); + $this->assign('defaultLocationTypeLabel', $this->_location_types[$defaultLocationType->id]); } /* Initialize all field usages to false */ - foreach ($mapperKeys as $key) { $this->_fieldUsed[$key] = FALSE; } diff --git a/templates/CRM/Import/Form/MapTable.tpl b/templates/CRM/Import/Form/MapTable.tpl index 7692fe7935..795635cd4d 100644 --- a/templates/CRM/Import/Form/MapTable.tpl +++ b/templates/CRM/Import/Form/MapTable.tpl @@ -165,6 +165,24 @@ cj('select[id^="mapper"][id$="[0]"]').addClass('huge'); {/literal} {include file="CRM/common/highLightImport.tpl" relationship=true} + + {* // Set default location type *} + {literal} + cj(function() { + var defaultLocationType = "{/literal}{$defaultLocationType}{literal}"; + if (defaultLocationType.length) { + cj('#map-field').on('change', 'select[id^="mapper"][id$="_0"]', function() { + var select = cj(this).next(); + cj('option', select).each(function() { + if (cj(this).attr('value') == defaultLocationType + && cj(this).text() == "{/literal}{$defaultLocationTypeLabel}{literal}") { + select.val(defaultLocationType); + } + }); + }); + } + }); + {/literal} {/if} -- 2.25.1