From 972e23dbf603cbee63139143acc2f341fbfc89b1 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 10 Nov 2016 23:28:37 +1300 Subject: [PATCH] CRM-19492 disable location settings if the relevant checkbox is not enabled --- CRM/Contact/Form/Merge.php | 13 +++++++++ templates/CRM/Contact/Form/Merge.tpl | 40 +++++++++++++--------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/CRM/Contact/Form/Merge.php b/CRM/Contact/Form/Merge.php index 003f88e744..9445834f0a 100644 --- a/CRM/Contact/Form/Merge.php +++ b/CRM/Contact/Form/Merge.php @@ -199,6 +199,19 @@ class CRM_Contact_Form_Merge extends CRM_Core_Form { // add elements foreach ($rowsElementsAndInfo['elements'] as $element) { + // We could push this down to the getRowsElementsAndInfo function but it's + // already so overloaded - let's start moving towards doing form-things + // on the form. + if (substr($element[1], 0, 13) === 'move_location') { + $element[4] = array_merge( + (array) CRM_Utils_Array::value(4, $element, array()), + array('data-location' => substr($element[1], 14), 'data-is_location' => TRUE)); + } + if (substr($element[1], 0, 15) === 'location_blocks') { + // @todo We could add some data elements here to make jquery manipulation more straight-forward + // @todo consider enabling if it is an add & defaulting to true. + $element[4] = array_merge((array) CRM_Utils_Array::value(4, $element, array()), array('disabled' => TRUE)); + } $this->addElement($element[0], $element[1], array_key_exists('2', $element) ? $element[2] : NULL, diff --git a/templates/CRM/Contact/Form/Merge.tpl b/templates/CRM/Contact/Form/Merge.tpl index 5afe986721..32baec58f7 100644 --- a/templates/CRM/Contact/Form/Merge.tpl +++ b/templates/CRM/Contact/Form/Merge.tpl @@ -399,29 +399,26 @@ } } - CRM.$(function($) { - - $('table td input.form-checkbox').each(function() { - var ele = null; - var element = $(this).attr('id').split('_',3); + /** + * Toggle the location type and the is_primary on & off depending on whether the merge box is ticked. + * + * @param element + */ + function toggleRelatedLocationFields(element) { + relatedElements = CRM.$(element).parent().siblings('td').find('input,select,label,hidden'); + if (CRM.$(element).is(':checked')) { + relatedElements.removeClass('disabled').attr('disabled', false); - switch ( element['1'] ) { - case 'addressee': - ele = '#' + element['0'] + '_' + element['1']; - break; + } + else { + relatedElements.addClass('disabled').attr('disabled', true); + } - case 'email': - case 'postal': - ele = '#' + element['0'] + '_' + element['1'] + '_' + element['2']; - break; - } + } - if( ele ) { - $(this).on('click', function() { - var val = $(this).prop('checked'); - $('input' + ele + ', input' + ele + '_custom').prop('checked', val); - }); - } + CRM.$(function($) { + $('input.crm-form-checkbox[data-is_location]').on('click', function(){ + toggleRelatedLocationFields(this) }); // Show/hide matching data rows @@ -430,7 +427,8 @@ }); // Call mergeBlock whenever a location type is changed - $('body').on('change', 'select[id$="locTypeId"],select[id$="typeTypeId"],input[id$="[operation]"],input[id$="[set_other_primary]"]', function(event){ + $('select[id$="locTypeId"],select[id$="typeTypeId"],input[id$="[operation]"],input[id$="[set_other_primary]"]').on('change', + function(event){ // All the information we need is held in the id, separated by underscores var nameSplit = this.name.split('['); -- 2.25.1