CRM-15986 fix - Fields attached to different entities in JS profile creator
authormonishdeb <monish.deb@webaccessglobal.com>
Fri, 20 Feb 2015 14:28:50 +0000 (19:58 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Mon, 23 Feb 2015 05:25:33 +0000 (10:55 +0530)
https://issues.civicrm.org/jira/browse/CRM-15986

CRM/UF/Page/ProfileEditor.php
api/v3/UFField.php
js/model/crm.uf.js
js/view/crm.designer.js

index 3a1370570dcf7f4bca05ba884b3f9039269707c2..916dae0ca1a07e2ee7befd443e714a8229519f5c 100644 (file)
@@ -23,6 +23,7 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page {
         return array(
           'PseudoConstant' => array(
             'locationType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'),
+            'websiteType' =>  CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'),
             'phoneType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'),
           ),
           'initialProfileList' => civicrm_api('UFGroup', 'get', array(
@@ -229,6 +230,9 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page {
       if (in_array($fieldName, $locationFields)) {
         $result['schema'][$fieldName]['civiIsLocation'] = TRUE;
       }
+      if ($fieldName == 'url') {
+        $result['schema'][$fieldName]['civiIsWebsite']= TRUE;
+      }
       if (in_array($fieldName, array('phone', 'phone_and_ext'))) {
         // FIXME what about phone_ext?
         $result['schema'][$fieldName]['civiIsPhone'] = TRUE;
index b29527f5dc12038825ff19ed3451ac0069f45458..5c1975a50a70f5262c4d521a4f048c74e2b82ba9 100644 (file)
@@ -51,7 +51,7 @@ function civicrm_api3_uf_field_create($params) {
 
   $field_type       = CRM_Utils_Array::value('field_type', $params);
   $field_name       = CRM_Utils_Array::value('field_name', $params);
-  $location_type_id = CRM_Utils_Array::value('location_type_id', $params);
+  $location_type_id = CRM_Utils_Array::value('location_type_id', $params, CRM_Utils_Array::value('website_type_id', $params));
   $phone_type       = CRM_Utils_Array::value('phone_type_id', $params, CRM_Utils_Array::value('phone_type', $params));
 
   if (!CRM_Core_BAO_UFField::isValidFieldName($field_name)) {
index 9ed880d157e988927164f0d5c9ac3326b460ba65..cc81507931a7eb63ec21b7e74750651c384206d6 100644 (file)
   var PHONE_TYPES = _.map(CRM.PseudoConstant.phoneType, function(value, key) {
     return {val: key, label: value};
   });
+
+  var WEBSITE_TYPES = _.map(CRM.PseudoConstant.websiteType, function(value, key) {
+    return {val: key, label: value};
+  });
   var DEFAULT_PHONE_TYPE_ID = PHONE_TYPES[0].val;
+  var DEFAULT_WEBSITE_TYPE_ID = WEBSITE_TYPES[0].val;
 
   /**
    * Add a help link to a form label
         type: 'Select',
         options: LOCATION_TYPES
       },
+      'website_type_id': {
+        title: ts('Website Type'),
+        type: 'Select',
+        options: WEBSITE_TYPES
+      },
       'phone_type_id': {
         title: ts('Phone Type'),
         type: 'Select',
       if (fieldSchema && fieldSchema.civiIsLocation && !this.get('location_type_id')) {
         this.set('location_type_id', DEFAULT_LOCATION_TYPE_ID);
       }
+      if (fieldSchema && fieldSchema.civiIsWebsite && !this.get('website_type_id')) {
+        this.set('website_type_id', DEFAULT_WEBSITE_TYPE_ID);
+      }
       if (fieldSchema && fieldSchema.civiIsPhone && !this.get('phone_type_id')) {
         this.set('phone_type_id', DEFAULT_PHONE_TYPE_ID);
       }
     getSignature: function() {
       return this.get("entity_name") +
         '::' + this.get("field_name") +
-        '::' + (this.get("location_type_id") ? this.get("location_type_id") : '') +
+        '::' + (this.get("location_type_id") ? this.get("location_type_id") : this.get("website_type_id") ? this.get("website_type_id") : '') +
         '::' + (this.get("phone_type_id") ? this.get("phone_type_id") : '');
     },
 
       if (fieldSchema.civiIsLocation) {
         limit *= LOCATION_TYPES.length;
       }
+      if (fieldSchema.civiIsWebsite) {
+        limit *= WEBSITE_TYPES.length;
+      }
       if (fieldSchema.civiIsPhone) {
         limit *= PHONE_TYPES.length;
       }
     },
     watchDuplicates: function(model, collection, options) {
       model.on('change:location_type_id', this.markDuplicates, this);
+      model.on('change:website_type_id', this.markDuplicates, this);
       model.on('change:phone_type_id', this.markDuplicates, this);
       this.markDuplicates();
     },
     unwatchDuplicates: function(model, collection, options) {
       model.off('change:location_type_id', this.markDuplicates, this);
+      model.off('change:website_type_id', this.markDuplicates, this);
       model.off('change:phone_type_id', this.markDuplicates, this);
       this.markDuplicates();
     },
index 51ca8a570652223758d7c39935d08b3b0534075b..5614e5222c61d66cf25b7d0f6be0a6b533090725 100644 (file)
       if (this.options.fieldSchema.civiIsPhone) {
         result = result + '-' + CRM.PseudoConstant.phoneType[this.model.get('phone_type_id')];
       }
+      if (this.options.fieldSchema.civiIsWebsite) {
+        result = result + '-' + CRM.PseudoConstant.websiteType[this.model.get('website_type_id')];
+      }
       if (this.options.fieldSchema.civiIsLocation) {
         var locType = this.model.get('location_type_id') ? CRM.PseudoConstant.locationType[this.model.get('location_type_id')] : ts('Primary');
         result = result + ' (' + locType + ')';
   CRM.Designer.UFFieldDetailView = Backbone.View.extend({
     initialize: function() {
       // FIXME: hide/display 'in_selector' if 'visibility' is one of the public options
-      var fields = ['location_type_id', 'phone_type_id', 'label', 'is_multi_summary', 'is_required', 'is_view', 'visibility', 'in_selector', 'is_searchable', 'help_pre', 'help_post', 'is_active'];
+      var fields = ['location_type_id', 'website_type_id', 'phone_type_id', 'label', 'is_multi_summary', 'is_required', 'is_view', 'visibility', 'in_selector', 'is_searchable', 'help_pre', 'help_post', 'is_active'];
       if (! this.options.fieldSchema.civiIsLocation) {
         fields = _.without(fields, 'location_type_id');
       }
+      if (! this.options.fieldSchema.civiIsWebsite) {
+        fields = _.without(fields, 'website_type_id');
+      }
       if (! this.options.fieldSchema.civiIsPhone) {
         fields = _.without(fields, 'phone_type_id');
       }