From c50f55b5be2d39dad729fb03d2dad7e6ac0e217f Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 15 Nov 2013 10:45:35 -0800 Subject: [PATCH] CRM-11864 - Contribution profiles - Add new drag-n-drop ui --- CRM/Contribute/Form/ContributionPage.php | 8 ++++ .../Form/ContributionPage/Custom.php | 42 ++++++++-------- js/jquery/jquery.crmProfileSelector.js | 2 +- .../Form/ContributionPage/Custom.tpl | 48 ++----------------- 4 files changed, 37 insertions(+), 63 deletions(-) diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index 71198cbee0..78b4373201 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -131,6 +131,14 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { } $this->set('values', $this->_values); } + + // Preload libraries required by the "Profiles" tab + $schemas = array('IndividualModel', 'ContributionModel'); + if (in_array('CiviMember', CRM_Core_Config::singleton()->enableComponents)) { + $schemas[] = 'MembershipModel'; + } + CRM_UF_Page_ProfileEditor::registerProfileScripts(); + CRM_UF_Page_ProfileEditor::registerSchemas($schemas); } /** diff --git a/CRM/Contribute/Form/ContributionPage/Custom.php b/CRM/Contribute/Form/ContributionPage/Custom.php index e50ed4a01b..86c3ded504 100644 --- a/CRM/Contribute/Form/ContributionPage/Custom.php +++ b/CRM/Contribute/Form/ContributionPage/Custom.php @@ -45,26 +45,29 @@ class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_Co * @access public */ public function buildQuickForm() { - $types = array_merge(array('Contact', 'Individual', 'Contribution', 'Membership'), - CRM_Contact_BAO_ContactType::subTypes('Individual') - ); - - $profiles = CRM_Core_BAO_UFGroup::getProfiles($types); - $excludeTypes = array('Organization', 'Household', 'Participant', 'Activity'); - - $excludeProfiles = CRM_Core_BAO_UFGroup::getProfiles($excludeTypes); - foreach ($excludeProfiles as $key => $value) { - if (array_key_exists( $key, $profiles)) { - unset($profiles[$key]); - } - } - if (empty($profiles)) { - $this->assign('noProfile', TRUE); + // Register 'contact_1' + $entities = array(); + $entities[] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'); + $allowCoreTypes = array_merge(array('Contact', 'Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual')); + $allowSubTypes = array(); + + // Register 'contribution_1' + $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'financial_type_id'); + $allowCoreTypes[] = 'Contribution'; + // $allowSubTypes['ContributionType'] = array($financialTypeId); + $entities[] = array('entity_name' => 'contribution_1', 'entity_type' => 'ContributionModel', 'entity_sub_type' => $financialTypeId); + + // If applicable, register 'membership_1' + $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); + if ($member && $member['is_active']) { + $entities[] = array('entity_name' => 'membership_1', 'entity_type' => 'MembershipModel', 'entity_sub_type' => $member['membership_type_default']); + $allowCoreTypes[] = 'Membership'; + $allowSubTypes['MembershipType'] = explode(',', $member['membership_types']); } - $this->add('select', 'custom_pre_id', ts('Include Profile') . '
' . ts('(top of page)'), array('' => ts('- select -')) + $profiles); - $this->add('select', 'custom_post_id', ts('Include Profile') . '
' . ts('(bottom of page)'), array('' => ts('- select -')) + $profiles); + $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities); + $this->addProfileSelector('custom_post_id', ts('Include Profile') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id); @@ -94,8 +97,9 @@ class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_Co 'entity_id' => $this->_id, ); list($defaults['custom_pre_id'], - $defaults['custom_post_id'] - ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); + $second) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); + $defaults['custom_post_id'] = $second ? array_shift($second) : ''; + return $defaults; } diff --git a/js/jquery/jquery.crmProfileSelector.js b/js/jquery/jquery.crmProfileSelector.js index 6b8babacbe..e150277535 100644 --- a/js/jquery/jquery.crmProfileSelector.js +++ b/js/jquery/jquery.crmProfileSelector.js @@ -59,7 +59,7 @@ $('.crm-profile-selector').each(function(){ $(this).crmProfileSelector({ groupTypeFilter: $(this).attr('data-group-type'), - entities: eval('(' + $(this).attr('data-entities') + ')') + entities: $(this).data('entities') }); }); }; diff --git a/templates/CRM/Contribute/Form/ContributionPage/Custom.tpl b/templates/CRM/Contribute/Form/ContributionPage/Custom.tpl index ff9d829963..055222b21f 100644 --- a/templates/CRM/Contribute/Form/ContributionPage/Custom.tpl +++ b/templates/CRM/Contribute/Form/ContributionPage/Custom.tpl @@ -25,62 +25,24 @@ *}
-

{ts}You may want to collect information from contributors beyond what is required to make a contribution. For example, you may want to inquire about volunteer availability and skills. Add any number of fields to your contribution form by selecting CiviCRM Profiles (collections of fields) to include at the beginning of the page, and/or at the bottom.{/ts}

- - {capture assign=crmURL}{crmURL p='civicrm/admin/uf/group' q="reset=1&action=browse"}{/capture} - {if $noProfile} -
- {ts 1=$crmURL 2=Profile}No Profile(s) have been configured / enabled for your site. You need to first configure » %2(s).{/ts} {docURL page="user/the-user-interface/profiles"} -
- {else} -

{ts 1=$crmURL}You can use existing CiviCRM Profiles on your page - OR create profile(s) specifically for use in Online Contribution pages. Go to Administer CiviCRM Profiles if you need to review, modify or create profiles (you can come back at any time to select or update the Profile(s) used for this page).{/ts}

- {/if} +

{ts}You may want to collect information from contributors beyond what is required to make a contribution. For example, you may want to inquire about volunteer availability and skills. Add any number of fields to your contribution form by selecting CiviCRM Profiles (collections of fields) to include at the beginning of the page, and/or at the bottom.{/ts} {help id="contrib-profile"}

-{if ! $noProfile}
{include file="CRM/common/formButtons.tpl" location="top"}
- - - - - -
{$form.custom_pre_id.label} {$form.custom_pre_id.html} 
- {ts}Include additional fields in this online contribution page by configuring and selecting a CiviCRM Profile to be included above the billing information (but after the introductory message, amounts, and honoree section).{/ts}{help id="contrib-profile"} +
{$form.custom_pre_id.html} + {ts}Profile to be included above the billing information (but after the introductory message, amounts, and honoree section).{/ts}
{$form.custom_post_id.label} {$form.custom_post_id.html} 
- {ts}Include additional fields in this online contribution page by configuring and selecting a CiviCRM Profile to be included at the bottom of the page.{/ts} +
{$form.custom_post_id.html} + {ts}Profile to be included at the bottom of the page.{/ts}
{ts}Click here for new profile{/ts}
-{/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}
- -{*include profile link function*} -{include file="CRM/common/buildProfileLink.tpl"} - -{literal} - -{/literal} - -{* include jscript to warn if unsaved form field changes *} -{include file="CRM/common/formNavigate.tpl"} -- 2.25.1