Commit 972e23db authored by eileen's avatar eileen Committed by JKingsnorth

CRM-19492 disable location settings if the relevant checkbox is not enabled

parent 643f3121
......@@ -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,
......
......@@ -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('[');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment