From: JKingsnorth Date: Wed, 17 Aug 2016 12:57:53 +0000 (+0100) Subject: Refactor out onChange attribute on merge screen X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=edf8e092db1ba4f958fc754e5337453f24b35ab1;p=civicrm-core.git Refactor out onChange attribute on merge screen --- diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index c12653c30c..f994219486 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1249,18 +1249,11 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m // Provide a select drop-down for the location's location type // eg: Home, Work... - $js = NULL; - if ($blockInfo['hasLocation']) { // Load the location options for this entity $locationOptions = civicrm_api3($blockName, 'getoptions', array('field' => 'location_type_id')); - // JS lookup 'main' contact's location (if there are any) - if (!empty($locations['main'][$blockName])) { - $js = array('onChange' => "mergeBlock('$blockName', this, $count, 'locTypeId' );"); - } - $thisLocId = $value['location_type_id']; // Put this field's location type at the top of the list @@ -1274,7 +1267,6 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m "location_blocks[$blockName][$count][locTypeId]", NULL, $defaultLocId + $tmpIdList, - $js, ); // Add the relevant information to the $migrationInfo @@ -1292,18 +1284,11 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m // Provide a select drop-down for the location's type/provider // eg websites: Google+, Facebook... - $js = NULL; - if ($blockInfo['hasType']) { // Load the type options for this entity $typeOptions = civicrm_api3($blockName, 'getoptions', array('field' => $blockInfo['hasType'])); - // CRM-17556 Set up JS lookup of 'main' contact's value by type - if (!empty($locations['main'][$blockName])) { - $js = array('onChange' => "mergeBlock('$blockName', this, $count, 'typeTypeId' );"); - } - $thisTypeId = CRM_Utils_Array::value($blockInfo['hasType'], $value); // Put this field's location type at the top of the list @@ -1317,7 +1302,6 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m "location_blocks[$blockName][$count][typeTypeId]", NULL, $defaultTypeId + $tmpIdList, - $js, ); // Add the information to the migrationInfo diff --git a/templates/CRM/Contact/Form/Merge.tpl b/templates/CRM/Contact/Form/Merge.tpl index 618d69196b..d830fc3636 100644 --- a/templates/CRM/Contact/Form/Merge.tpl +++ b/templates/CRM/Contact/Form/Merge.tpl @@ -259,7 +259,7 @@ // Look for a matching block on the main contact var mainBlockId = 0; var mainBlockDisplay = ''; - var mainBlock = findBlock(allBlock, blockname, locTypeId, typeTypeId); + var mainBlock = findBlock(blockname, locTypeId, typeTypeId); // Create appropriate label / add new link after changing the block if (mainBlock == false) { @@ -290,8 +290,6 @@ * Look for a matching 'main' contact location block by entity, location and * type * - * @param allBlock array - * All location blocks on the main contact record. * @param entName string * The entity name to lookup. * @param locationID int @@ -303,7 +301,7 @@ * Returns false if no match, otherwise an object with the location ID and * display value. */ - function findBlock(allBlock, entName, locationID, typeID) { + function findBlock(entName, locationID, typeID) { var entityArray = allBlock[entName]; var result = false; for (var i = 0; i < entityArray.length; i++) { @@ -361,6 +359,16 @@ $('tr.merge-row-equal').toggle(); }); + // Call mergeBlock whenever a location type is changed + jQuery('select[id^="location_blocks_"]').change(function(){ + // All the information we need is held in the id, separated by underscores + var idSplit = this.id.split('_'); + // Lookup the main value, if any are available + if (allBlock[idSplit[2]] != undefined) { + mergeBlock(idSplit[2], this, idSplit[3], idSplit[4]); + } + }); + });