Created
March 18, 2020 11:51
-
-
Save Edzelopez/827a96575fbe84358d087d2848fc91d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/CRM/Aoservicelisting/Form/ProviderApplicationForm.php b/CRM/Aoservicelisting/Form/ProviderApplicationForm.php | |
index a0b0b30..b1cf85c 100644 | |
--- a/CRM/Aoservicelisting/Form/ProviderApplicationForm.php | |
+++ b/CRM/Aoservicelisting/Form/ProviderApplicationForm.php | |
@@ -300,13 +300,16 @@ class CRM_Aoservicelisting_Form_ProviderApplicationForm extends CRM_Aoservicelis | |
} | |
} | |
} | |
+ $flag = FALSE; | |
if ($values['listing_type'] == 1 && count($setValues) > 1 ) { | |
$errors[REGULATED_SERVICE_CF] = E::ts('You have selected more than one registered service'); | |
+ $flag = TRUE; | |
} | |
if ($values['listing_type'] == 2 && count($setValues) > $staffMemberCount) { | |
$errors[REGULATED_SERVICE_CF] = E::ts('Ensure you have entered all the staff members that match the registered services'); | |
+ $flag = TRUE; | |
} | |
- if (!empty($missingRegulators)) { | |
+ if (!empty($missingRegulators) && !$flag) { | |
$errors[REGULATED_SERVICE_CF] = E::ts('No Staff members have been entered for %1 regulated services', [1 => implode(', ', $missingRegulators)]); | |
} | |
diff --git a/templates/CRM/Aoservicelisting/Form/ProviderApplicationForm.tpl b/templates/CRM/Aoservicelisting/Form/ProviderApplicationForm.tpl | |
index e61e958..ff14fb8 100644 | |
--- a/templates/CRM/Aoservicelisting/Form/ProviderApplicationForm.tpl | |
+++ b/templates/CRM/Aoservicelisting/Form/ProviderApplicationForm.tpl | |
@@ -247,6 +247,58 @@ | |
} | |
}); | |
} | |
+ | |
+ // Add domains as default values. | |
+ var services = $('#editrow-custom_863 input[type=checkbox]'); | |
+ showStaff(services.filter(':checked').length, services.filter(':checked')); | |
+ services.change(function() { // while you're at it listen for change rather than click, this is in case something else modifies the checkbox | |
+ var checked = parseInt(services.filter(':checked').length); | |
+ var unchecked = parseInt(services.filter(':not(:checked)').length); | |
+ showStaff(checked, services.filter(':checked')); | |
+ hideStaff(unchecked, checked); | |
+ }); | |
+ | |
+ function showStaff(countcheck, service) { | |
+ if (countcheck) { | |
+ for (var i=1; i<=countcheck; i++) { | |
+ $('#staff_member-' + i).removeClass('hiddenElement'); | |
+ } | |
+ var count = 1; | |
+ service.each(function(i, v) { | |
+ var id = v.getAttribute('id'); | |
+ var label = $('label[for="' + id + '"]').html(); | |
+ var field = parseInt(id.split('_').pop()); | |
+ if (field) { | |
+ CRM.api3('OptionValue', 'getvalue', { | |
+ "sequential": 1, | |
+ "return": "label", | |
+ "option_group_id": "regulator_url_mapping", | |
+ "value": field | |
+ }).then(function(result) { | |
+ if (result.result) { | |
+ $('#staff_record_regulator_' + count).val('https://www.' + result.result); | |
+ $('.crm-label-' + count).remove(); | |
+ $('#staff_member-' + count).find('div.crm-section:nth-child(3)').append('<div class="content crm-label-' + count + '">' + label + '</div>'); | |
+ count++; | |
+ } | |
+ }, function(error) { | |
+ // oops | |
+ }); | |
+ } | |
+ }); | |
+ } | |
+ } | |
+ | |
+ function hideStaff(unchecked, checked) { | |
+ for (i=checked+1; i<=unchecked; i++) { | |
+ if (!$('#staff_member-' + i).hasClass('hiddenElement') && i > 1) { | |
+ $('#staff_member-' + i).addClass('hiddenElement'); | |
+ $('#staff_record_regulator_' + i).val(''); | |
+ } | |
+ } | |
+ } | |
+ // End domain default values | |
+ | |
$('#custom_863_3').on('change', function() { | |
if ($(this).prop('checked')) { | |
$('#camp_session-1, #camp-section').removeClass('hiddenElement'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment