Skip to content
Snippets Groups Projects
Commit d65de14c authored by lobo's avatar lobo
Browse files

Merge pull request #399 from agh1/batch-countrystatecounty-4.3

copy of batch-countrystatecounty for 4.3
parents 75a0f31e fddb3858
Branches
Tags
No related merge requests found
......@@ -67,6 +67,12 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task {
* when not to reset sort_name
*/
protected $_preserveDefault = TRUE;
/**
* the internal QF names for the state/country/county fields
*/
protected $_stateCountryCountyFields = array();
/**
* build all the data structures needed to build the form
......@@ -139,11 +145,21 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task {
'organization_name',
'household_name',
);
$stateCountryMap = array();
foreach ($this->_contactIds as $contactId) {
$profileFields = $this->_fields;
CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId);
foreach ($profileFields as $name => $field) {
// Link state to country, county to state per location per contact
list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
$stateCountryMap["$index-$contactId"][$prefixName] = "field_{$contactId}_{$field['name']}";
$this->_stateCountryCountyFields["$index-$contactId"][$prefixName] = "field[{$contactId}][{$field['name']}]";
}
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
if (in_array($field['name'], $preserveDefaultsArray)) {
......@@ -151,6 +167,10 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task {
}
}
}
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
$this->assign('fields', $this->_fields);
......@@ -191,6 +211,9 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task {
}
$this->assign('sortName', $sortName);
// now fix all state country selectors
CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults, $this->_stateCountryCountyFields);
return $defaults;
}
......
......@@ -663,11 +663,13 @@ ORDER BY civicrm_address.is_primary DESC, civicrm_address.location_type_id DESC,
$config->stateCountryMap = array_merge($config->stateCountryMap, $stateCountryMap);
}
static function fixAllStateSelects(&$form, &$defaults) {
static function fixAllStateSelects(&$form, $defaults, $batchFieldNames = false) {
$config = CRM_Core_Config::singleton();
$map = is_array($batchFieldNames) ? $batchFieldNames : $config->stateCountryMap;
if (!empty($config->stateCountryMap)) {
foreach ($config->stateCountryMap as $index => $match) {
if (!empty($map)) {
foreach ($map as $index => $match) {
if (
array_key_exists('state_province', $match) &&
array_key_exists('country', $match)
......
......@@ -43,7 +43,21 @@
callbackURL = {/literal}"{crmURL p='civicrm/ajax/jqState' h=0}"{literal}
cj( '#' + countryID ).chainSelect( '#' + stateProvinceID, callbackURL, null );
cj( '#' + countryID ).chainSelect(
'#' + stateProvinceID,
callbackURL,
{
before : function (target) {
if (typeof(setdefault) === "undefined") { setdefault = new Array(); }
targetid = cj(target).attr("id");
eval('setdefault[targetid] = cj(target).val()');
},
after : function(target) {
targetid = cj(target).attr("id");
cj(target).val(setdefault[targetid]);
}
}
);
});
{/literal}
{/if}
......@@ -63,7 +77,19 @@
callbackURL = {/literal}"{crmURL p='civicrm/ajax/jqCounty' h=0}"{literal}
cj( '#' + stateProvinceID ).chainSelect( '#' + countyID, callbackURL, null );
cj( '#' + stateProvinceID ).chainSelect( '#' + countyID, callbackURL,
{
before : function (target) {
if (typeof(setdefault) === "undefined") { setdefault = new Array(); }
targetid = cj(target).attr("id");
eval('setdefault[targetid] = cj(target).val()');
},
after : function(target) {
targetid = cj(target).attr("id");
cj(target).val(setdefault[targetid]);
}
}
);
});
{/literal}
{/if}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment