Fix default location type CRM-12157
authorColeman Watts <coleman@civicrm.org>
Sat, 23 Mar 2013 04:12:40 +0000 (21:12 -0700)
committerColeman Watts <coleman@civicrm.org>
Sat, 23 Mar 2013 04:12:40 +0000 (21:12 -0700)
CRM/Import/Form/MapField.php
templates/CRM/Import/Form/MapTable.tpl

index 15df99eadedce0cff9b31643d7a3232020b33b78..0ae89564fce13eac605db56070a4202d58900f42 100644 (file)
@@ -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;
     }
index 7692fe79350f691e2320f32da5bebd0a386748a8..795635cd4d5c3cbdcb904ea022aa45d043100c56 100644 (file)
             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}
   </script>
     </div>
     {/if}