From a6a4351d0ed45514f4d035c7f07019d60294df54 Mon Sep 17 00:00:00 2001 From: Seamus Lee <seamuslee001@gmail.com> Date: Fri, 9 Jun 2023 12:59:20 +1000 Subject: [PATCH 1/2] Add in Managed Entity to create custom field for Anonymous Donor and add in JS to handle other option fixes --- corvair.php | 6 ++- js/other_option_museum.js | 30 +++++++++++ managed/anonymous_donor_custom_field.mgd.php | 56 ++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 js/other_option_museum.js create mode 100644 managed/anonymous_donor_custom_field.mgd.php diff --git a/corvair.php b/corvair.php index 8600149..fd9d9df 100644 --- a/corvair.php +++ b/corvair.php @@ -34,6 +34,10 @@ function corvair_civicrm_buildForm( $formName, &$form ) { 'template' => 'CRM/Price/Form/CorvairContributeMem.tpl', )); } + // Add in JS to manage clearing out other text field on changes to main selection. + if ($formName === 'CRM_Contribute_Form_Contribution_Main' && $form->getVar('_id') == 19) { + Civi::resources()->addScriptFile('biz.jmaconsulting.corvair', 'js/other_option_museum.js'); + } if ($formName == 'CRM_Event_Form_Registration_AdditionalParticipant' && $form->_eventId == 401) { $user = JFactory::getUser(); $groups = $user->get('groups'); @@ -136,7 +140,7 @@ function corvair_civicrm_postSave_civicrm_membership($dao) { } } } - + function corvair_civicrm_postProcess($formName, &$form) { if (($formName == "CRM_Member_Form_Membership") && ($form->_action & CRM_Core_Action::ADD) && !empty($form->_id)) { if (getValidMemtypes($form->getVar('_memType')) && !checkMemberID($form->_id)) { diff --git a/js/other_option_museum.js b/js/other_option_museum.js new file mode 100644 index 0000000..cc10734 --- /dev/null +++ b/js/other_option_museum.js @@ -0,0 +1,30 @@ +(function($) { + const otherContentSection = $('.other-section'); + const otherContentInput = $(otherContentSection.find('input')); + const priceSetRows = $('.price-set-row'); + const nonOption = null; + priceSetRows.each(function() { + if ($(this).val() == 0) { + nonOption = $(this); + } + }); + nonOption.parent().find('.crm-price-amount-label').text('Other Amount'); + if (!nonOption.prop('checked')) { + otherContentInput.val(''); + calculateText(otherContentInput); + otherContentSection.hide(); + } + else { + otherContentSection.show(); + } + nonOption.on('change', function() { + if ($(this).prop('checked')) { + otherContentSection.show(); + } + else { + $(otherContentInput).val(''); + calculateText(otherContentInput); + otherContentSection.hide(); + } + }) +})(CRM.$) \ No newline at end of file diff --git a/managed/anonymous_donor_custom_field.mgd.php b/managed/anonymous_donor_custom_field.mgd.php new file mode 100644 index 0000000..a728e14 --- /dev/null +++ b/managed/anonymous_donor_custom_field.mgd.php @@ -0,0 +1,56 @@ +<?php + +use CRM_Corvair_ExtensionUtil as E; + +return [ + [ + 'name' =>'corvair_anonymous_donor_custom_group', + 'entity' => 'CustomGroup', + 'update' => 'unmodified', + 'params' => [ + 'name' => 'anonmyous_donor_contribution', + 'title' => E::ts('Anonymous Donor Contribution'), + 'extends' => 'Contribution', + 'extends_entity_column_value' => [], + 'style' => 'Inline', + 'is_active' => 1, + 'is_multiple' => 0, + 'collapse_adv_display' => 0, + 'is_public' => 1, + ], + ], + [ + 'name' => 'anonymous_donation_custom_field', + 'entity' => 'CustomField', + 'update' => 'unmodified', + 'params' => [ + 'label' => E::ts('I prefer to make this donation anonymously'), + 'custom_group_id' => 'anonmyous_donor_contribution', + 'data_type' => 'Boolean', + 'html_type' => 'Radio', + 'default_value' => '0', + 'is_required' => FALSE, + 'is_searchable' => TRUE, + 'is_search_range' => FALSE, + 'weight' => 2, + 'help_pre' => NULL, + 'help_post' => NULL, + 'attributes' => NULL, + 'is_active' => TRUE, + 'is_view' => FALSE, + 'options_per_line' => NULL, + 'text_length' => 255, + 'start_date_years' => NULL, + 'end_date_years' => NULL, + 'date_format' => NULL, + 'time_format' => NULL, + 'note_columns' => 60, + 'note_rows' => 4, + 'option_group_id' => NULL, + 'serialize' => 0, + 'filter' => NULL, + 'in_selector' => FALSE, + 'fk_entity' => NULL, + ], + ], +]; \ No newline at end of file -- GitLab From fa0ba6d6f2f72976577260893cf1006645560515 Mon Sep 17 00:00:00 2001 From: Seamus Lee <seamuslee001@gmail.com> Date: Fri, 9 Jun 2023 13:25:31 +1000 Subject: [PATCH 2/2] Fix issues found in the JS on staging and line endings --- js/other_option_museum.js | 64 ++++++----- managed/anonymous_donor_custom_field.mgd.php | 110 +++++++++---------- 2 files changed, 89 insertions(+), 85 deletions(-) diff --git a/js/other_option_museum.js b/js/other_option_museum.js index cc10734..736b623 100644 --- a/js/other_option_museum.js +++ b/js/other_option_museum.js @@ -1,30 +1,34 @@ -(function($) { - const otherContentSection = $('.other-section'); - const otherContentInput = $(otherContentSection.find('input')); - const priceSetRows = $('.price-set-row'); - const nonOption = null; - priceSetRows.each(function() { - if ($(this).val() == 0) { - nonOption = $(this); - } - }); - nonOption.parent().find('.crm-price-amount-label').text('Other Amount'); - if (!nonOption.prop('checked')) { - otherContentInput.val(''); - calculateText(otherContentInput); - otherContentSection.hide(); - } - else { - otherContentSection.show(); - } - nonOption.on('change', function() { - if ($(this).prop('checked')) { - otherContentSection.show(); - } - else { - $(otherContentInput).val(''); - calculateText(otherContentInput); - otherContentSection.hide(); - } - }) -})(CRM.$) \ No newline at end of file +(function($) { + const otherContentSection = $('.other-section'); + const otherContentInput = $(otherContentSection.find('input')); + const priceSetRows = $('.price-set-row input'); + let noneOptionSection = null; + let noneOptionInput = null; + priceSetRows.each(function() { + if ($(this).val() == 0) { + noneOptionInput = $(this); + noneOptionSection = $(this).parent(); + } + }); + noneOptionSection.find('label').text('Other Amount'); + if (!noneOptionInput.prop('checked')) { + otherContentInput.val(''); + calculateText(otherContentInput); + otherContentSection.hide(); + } + else { + otherContentSection.show(); + } + priceSetRows.each(function() { + $(this).on('change', function() { + if ($(this).prop('checked') && $(this).prop('id') === noneOptionInput.prop('id')) { + otherContentSection.show(); + } + else { + $(otherContentInput).val(''); + calculateText(otherContentInput); + otherContentSection.hide(); + } + }); + }); +})(CRM.$); \ No newline at end of file diff --git a/managed/anonymous_donor_custom_field.mgd.php b/managed/anonymous_donor_custom_field.mgd.php index a728e14..6fbce23 100644 --- a/managed/anonymous_donor_custom_field.mgd.php +++ b/managed/anonymous_donor_custom_field.mgd.php @@ -1,56 +1,56 @@ -<?php - -use CRM_Corvair_ExtensionUtil as E; - -return [ - [ - 'name' =>'corvair_anonymous_donor_custom_group', - 'entity' => 'CustomGroup', - 'update' => 'unmodified', - 'params' => [ - 'name' => 'anonmyous_donor_contribution', - 'title' => E::ts('Anonymous Donor Contribution'), - 'extends' => 'Contribution', - 'extends_entity_column_value' => [], - 'style' => 'Inline', - 'is_active' => 1, - 'is_multiple' => 0, - 'collapse_adv_display' => 0, - 'is_public' => 1, - ], - ], - [ - 'name' => 'anonymous_donation_custom_field', - 'entity' => 'CustomField', - 'update' => 'unmodified', - 'params' => [ - 'label' => E::ts('I prefer to make this donation anonymously'), - 'custom_group_id' => 'anonmyous_donor_contribution', - 'data_type' => 'Boolean', - 'html_type' => 'Radio', - 'default_value' => '0', - 'is_required' => FALSE, - 'is_searchable' => TRUE, - 'is_search_range' => FALSE, - 'weight' => 2, - 'help_pre' => NULL, - 'help_post' => NULL, - 'attributes' => NULL, - 'is_active' => TRUE, - 'is_view' => FALSE, - 'options_per_line' => NULL, - 'text_length' => 255, - 'start_date_years' => NULL, - 'end_date_years' => NULL, - 'date_format' => NULL, - 'time_format' => NULL, - 'note_columns' => 60, - 'note_rows' => 4, - 'option_group_id' => NULL, - 'serialize' => 0, - 'filter' => NULL, - 'in_selector' => FALSE, - 'fk_entity' => NULL, - ], - ], +<?php + +use CRM_Corvair_ExtensionUtil as E; + +return [ + [ + 'name' =>'corvair_anonymous_donor_custom_group', + 'entity' => 'CustomGroup', + 'update' => 'unmodified', + 'params' => [ + 'name' => 'anonmyous_donor_contribution', + 'title' => E::ts('Anonymous Donor Contribution'), + 'extends' => 'Contribution', + 'extends_entity_column_value' => [], + 'style' => 'Inline', + 'is_active' => 1, + 'is_multiple' => 0, + 'collapse_adv_display' => 0, + 'is_public' => 1, + ], + ], + [ + 'name' => 'anonymous_donation_custom_field', + 'entity' => 'CustomField', + 'update' => 'unmodified', + 'params' => [ + 'label' => E::ts('I prefer to make this donation anonymously'), + 'custom_group_id' => 'anonmyous_donor_contribution', + 'data_type' => 'Boolean', + 'html_type' => 'Radio', + 'default_value' => '0', + 'is_required' => FALSE, + 'is_searchable' => TRUE, + 'is_search_range' => FALSE, + 'weight' => 2, + 'help_pre' => NULL, + 'help_post' => NULL, + 'attributes' => NULL, + 'is_active' => TRUE, + 'is_view' => FALSE, + 'options_per_line' => NULL, + 'text_length' => 255, + 'start_date_years' => NULL, + 'end_date_years' => NULL, + 'date_format' => NULL, + 'time_format' => NULL, + 'note_columns' => 60, + 'note_rows' => 4, + 'option_group_id' => NULL, + 'serialize' => 0, + 'filter' => NULL, + 'in_selector' => FALSE, + 'fk_entity' => NULL, + ], + ], ]; \ No newline at end of file -- GitLab