add filter based on entity types for profile builder
authorkurund <kurund@civicrm.org>
Fri, 24 Jan 2014 08:44:01 +0000 (00:44 -0800)
committerkurund <kurund@civicrm.org>
Fri, 24 Jan 2014 08:44:01 +0000 (00:44 -0800)
CRM/Campaign/Form/Survey/Questions.php
CRM/Contribute/Form/ContributionPage/Custom.php
CRM/Contribute/Form/ContributionPage/Settings.php
js/jquery/jquery.crmProfileSelector.js
js/model/crm.uf.js
js/view/crm.designer.js
templates/CRM/UF/Page/ProfileTemplates.tpl

index 5f83230d026e3a86a1076ab21e121317b1e68cad..a9ec2f13251350f910296a7bdf95081ac57b1f29 100644 (file)
@@ -94,7 +94,7 @@ class CRM_Campaign_Form_Survey_Questions extends CRM_Campaign_Form_Survey {
       'ActivityType' => array($subTypeId),
     );
     $entities = array(
-      array('entity_name' => 'individual_1', 'entity_type' => 'IndividualModel'),
+      array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'),
       array('entity_name' => 'activity_1', 'entity_type' => 'ActivityModel', 'entity_sub_type' => $subTypeId),
     );
     $this->addProfileSelector('contact_profile_id', ts('Contact Info'), $allowCoreTypes, $allowSubTypes, $entities);
index ee6fbaa891f5700b6e1e91c86b9f26b80d955876..2b402fe7e6640533929082ed36cd4f48e7fea21d 100644 (file)
@@ -48,7 +48,7 @@ class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_Co
 
     // Register 'individual_1' model
     $entities = array();
-    $entities[] = array('entity_name' => 'individual_1', 'entity_type' => 'IndividualModel');
+    $entities[] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel');
     $allowCoreTypes = array_merge(array('Contact', 'Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual'));
     $allowSubTypes = array();
 
index d30646557fb50ebf3466da482076d64d178c9fc8..5addc702291f2bce6d257a289ffa0ad089385b26 100644 (file)
@@ -222,20 +222,19 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
     );
 
     $entities = array(
-      array('entity_name' => 'individual_1',
-        'entity_type' => 'IndividualModel'
-      ),
-      array('entity_name' => 'organization_1',
-        'entity_type' => 'OrganizationModel'
-      ),
-      array('entity_name' => 'household_1',
-        'entity_type' => 'HouseholdModel'
+      array(
+        'entity_name' => 'contact_1',
+        'entity_type' => 'IndividualModel',
       ),
     );
+
     $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType::subTypes('Individual'));
     $allowSubTypes = array();
 
     $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities);
+    CRM_UF_Page_ProfileEditor::registerProfileScripts();
+    CRM_UF_Page_ProfileEditor::registerSchemas(array('OrganizationModel','HouseholdModel'));
+
 
     if (!empty($this->_submitValues['honor_block_is_active'])) {
       $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required');
index 62a0ec7f1c4ae94e83036fa4c72643f4bb434ea9..3c09e7f4608ed1382b8fd5122e7fad3f0eba4ea4 100644 (file)
    * ...
    * cj('.crm-profile-selector').crmProfileSelector({
    *   groupTypeFilter: "Contact,Individual,Activity;;ActivityType:7",
-   *   entities: "individual_1:IndividualModel,activity_1:ActivityModel"
+   *   entities: "contact_1:IndividualModel,activity_1:ActivityModel"
    * });
    *
    * Note: The system does not currently support dynamic entities -- it only supports
-   * a couple of entities named "individual_1" and "activity_1". See also
+   * a couple of entities named "contact_1" and "activity_1". See also
    * CRM.UF.guessEntityName().
    */
   $.fn.crmProfileSelector = function(options) {
index d88578f627c3e77904bfd15fd8e88a9129fcfbca..79d43a7a6da4cb53b0a4186b23fed170c94a3d37 100644 (file)
     switch (field_type) {
       case 'Contact':
       case 'Individual':
-        return 'individual_1';
       case 'Organization':
-        return 'organization_1';
       case 'Household':
-        return 'household_1';
+        return 'contact_1';
       case 'Activity':
         return 'activity_1';
       case 'Contribution':
     },
     resetEntities: function() {
       var ufGroupModel = this;
+      var deleteFieldList = [];
       ufGroupModel.getRel('ufFieldCollection').each(function(ufFieldModel){
         if (!ufFieldModel.getFieldSchema()) {
-          CRM.alert(ts('The data model no longer includes field "%1"! All references to the field have been removed.', {
-            1: ufFieldModel.get('entity_name') + "." + ufFieldModel.get('field_name')
+          CRM.alert(ts('This profile no longer includes field "%1"! All references to the field have been removed.', {
+            1: ufFieldModel.get('label')
           }), '', 'alert', {expires: false});
-          ufFieldModel.destroyLocal();
+          deleteFieldList.push(ufFieldModel);
         }
       });
+
+      _.each(deleteFieldList, function(ufFieldModel) {
+        ufFieldModel.destroyLocal();
+      });
+
       this.getRel('paletteFieldCollection').reset(this.buildPaletteFields());
+
+      // reset to redraw the cancel after entity type is updated.
+      ufGroupModel.getRel('ufFieldCollection').reset(ufGroupModel.getRel('ufFieldCollection').toJSON());
     },
     /**
      *
index fff8dacbd92ce521aca6679be5995ee4cb8dbecb..dccef6abda2f62c6483e9e92bc428333112f4f0c 100644 (file)
       paletteView.model.getRel('ufEntityCollection').each(function(ufEntityModel){
         _.each(ufEntityModel.getSections(), function(section, sectionKey){
 
-          // build filter select
-          if (sectionKey == 'default') {
-            paletteView.$('.crm-contact-types').append('<option value="' + ufEntityModel.get('entity_name') + '">' + section.title + '</option>');
-          }
-
-          if (!paletteView.selectedContactType) {
-            paletteView.selectedContactType = paletteView.$('.crm-contact-types option:first').val();
-          }
           // set selected option as default, since we are rebuilding palette
-          paletteView.$('.crm-contact-types').val(paletteView.selectedContactType).prop('selected','selected');
-
-          if (paletteView.selectedContactType != ufEntityModel.get('entity_name')) {
-            return true;
-          }
+          paletteView.$('.crm-contact-types').val(ufEntityModel.attributes.entity_type).prop('selected','selected');
 
           var entitySection = ufEntityModel.get('entity_name') + '-' + sectionKey;
           var items = [];
       $('.crm-designer-palette-tree').jstree("search", $(event.target).val());
     },
     doSetPaletteEntity: function(event) {
-      this.selectedContactType = $('.crm-contact-types :selected').val();
-      this.render();
+      // loop through entity collection and remove non-valid entity section's
+      var newUfEntityModels = [];
+      this.model.getRel('ufEntityCollection').each(function(oldUfEntityModel){
+        var values = oldUfEntityModel.toJSON();
+        if (values.entity_name == 'contact_1') {
+          values.entity_type = $('.crm-contact-types :selected').val();
+        }
+        newUfEntityModels.push(new CRM.UF.UFEntityModel(values));
+      });
+      this.model.getRel('ufEntityCollection').reset(newUfEntityModels);
     },
     doAddToCanvas: function(event) {
       var paletteFieldModel = this.model.getRel('paletteFieldCollection').get($(event.currentTarget).attr('data-plm-cid'));
       var paletteFieldCollection = this.model.getRel('paletteFieldCollection');
       var paletteFieldModel = paletteFieldCollection.getFieldByName(ufFieldModel.get('entity_name'), ufFieldModel.get('field_name'));
       var isAddable = ufFieldCollection.isAddable(ufFieldModel);
-      this.$('[data-plm-cid='+paletteFieldModel.cid+']').toggleClass('disabled', !isAddable);
+      if (paletteFieldModel) {
+        this.$('[data-plm-cid='+paletteFieldModel.cid+']').toggleClass('disabled', !isAddable);
+      }
     },
     toggleAll: function(event) {
       if ($('.crm-designer-palette-search input').val() == '') {
       this.model.getRel('ufFieldCollection')
         .on('add', this.updatePlaceholder, this)
         .on('remove', this.updatePlaceholder, this)
-        .on('add', this.addUFFieldView, this);
+        .on('add', this.addUFFieldView, this)
+        .on('reset', this.render, this);
     },
     onClose: function() {
       this.model.getRel('ufFieldCollection')
         .off('add', this.updatePlaceholder, this)
         .off('remove', this.updatePlaceholder, this)
-        .off('add', this.addUFFieldView, this);
+        .off('add', this.addUFFieldView, this)
+        .off('reset', this.render, this);
     },
     render: function() {
       var ufFieldCanvasView = this;
index 0456c6148263203dda7662b2d6d7e634cd43d611..f3ecc0f216e4eb22b258e1ce0ba69cac1ee85663 100644 (file)
   <div class="crm-designer-palette">
     <div class="crm-designer-palette-search">
       <div class="crm-filter-objects">
-        <span>{ts}Field Type{/ts}: <select class="crm-contact-types"></select></span>
+        <span>{ts}Field Type{/ts}:
+          <select class="crm-contact-types">
+          <option value="IndividualModel">{ts}Individual{/ts}</option>
+          <option value="OrganizationModel">{ts}Organization{/ts}</option>
+          <option value="HouseholdModel">{ts}Household{/ts}</option>
+          </select>
+        </span>
       </div>
       <hr>
       <input type="text" placeholder="{ts}Search Fields{/ts}" />