CRM-11864 - Contribution profiles - Add new drag-n-drop ui
authorColeman Watts <coleman@civicrm.org>
Fri, 15 Nov 2013 18:45:35 +0000 (10:45 -0800)
committerColeman Watts <coleman@civicrm.org>
Sun, 17 Nov 2013 01:09:00 +0000 (17:09 -0800)
CRM/Contribute/Form/ContributionPage.php
CRM/Contribute/Form/ContributionPage/Custom.php
js/jquery/jquery.crmProfileSelector.js
templates/CRM/Contribute/Form/ContributionPage/Custom.tpl

index 71198cbee0a9533892cc006aca2c014ff4a67ce7..78b43732012226a18716724685f0f73c73b6cc80 100644 (file)
@@ -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);
   }
 
   /**
index e50ed4a01b5d032c08124065620ee1899db28154..86c3ded5043a58a9acf27603d071cc21d669156a 100644 (file)
@@ -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') . '<br />' . ts('(top of page)'), array('' => ts('- select -')) + $profiles);
-    $this->add('select', 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), array('' => ts('- select -')) + $profiles);
+    $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities);
+    $this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . 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;
   }
index 6b8babacbe53261eb454d370fe2cbb95ecf307de..e150277535074de3f3130e9a849d4c9ed1dce306 100644 (file)
@@ -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')
       });
     });
   };
index ff9d829963fa93e6a5e92f06a7114962c95b817b..055222b21f49de029ae725b8082b1feb93a3bd27 100644 (file)
 *}
 <div class="crm-block crm-form-block crm-contribution-contributionpage-custom-form-block">
 <div id="help">
-    <p>{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}</p>
-
-        {capture assign=crmURL}{crmURL p='civicrm/admin/uf/group' q="reset=1&action=browse"}{/capture}
-    {if $noProfile} 
-        <div class="status message"> 
-            {ts 1=$crmURL 2=Profile}No Profile(s) have been configured / enabled for your site. You need to first configure <a href="%1"><strong>&raquo; %2</a>(s).{/ts} {docURL page="user/the-user-interface/profiles"}
-        </div>
-    {else}
-        <p>{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 <a href='%1'>Administer CiviCRM Profiles</a> 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}</p>
-    {/if}
+    <p>{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"}</p>
 </div>
-{if ! $noProfile} 
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
     <table class="form-layout-compressed">
     <tr class="crm-contribution-contributionpage-custom-form-block-custom_pre_id">
        <td class="label">{$form.custom_pre_id.label}
        </td>
-       <td class="html-adjust">{$form.custom_pre_id.html}&nbsp;<span class="profile-links"></span><br />
-          <span class="description">{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"}</span>
+       <td class="html-adjust">{$form.custom_pre_id.html}
+          <span class="description">{ts}Profile to be included above the billing information (but after the introductory message, amounts, and honoree section).{/ts}</span>
           </td>
     </tr>
     <tr class="crm-contribution-contributionpage-custom-form-block-custom_post_id">
        <td class="label">{$form.custom_post_id.label}
        </td>
-       <td class="html-adjust">{$form.custom_post_id.html}&nbsp;<span class="profile-links"></span><br/>
-          <span class="description">{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}</span>
+       <td class="html-adjust">{$form.custom_post_id.html}
+          <span class="description">{ts}Profile to be included at the bottom of the page.{/ts}</span>
        </td>
     </tr>
-    <tr class='crm-contribution-contributionpage-custom-form--block-create-new-profile'>
-        <td class="label"></td>
-        <td><a href="{crmURL p='civicrm/admin/uf/group/add' q='reset=1&action=add'}" target="_blank">{ts}Click here for new profile{/ts}</td>
-    </tr>
 </table>
-{/if}
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 </div>
-
-{*include profile link function*}
-{include file="CRM/common/buildProfileLink.tpl"}
-
-{literal}
-<script type="text/javascript">
-    //show edit profile field links
-    cj(function() {
-        // show edit for profile
-        cj('select[id^="custom_p"]').change( function( ) {
-            buildLinks( cj(this), cj(this).val());
-        });
-        
-        // make sure we set edit links for profile when form loads
-        cj('select[id^="custom_p"]').each( function(e) {
-            buildLinks( cj(this), cj(this).val()); 
-        });
-    });
-</script>
-{/literal}
-
-{* include jscript to warn if unsaved form field changes *}
-{include file="CRM/common/formNavigate.tpl"}