From 1a228b4c87a7c5a9d4bced9a28000557d5660e64 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 20 Feb 2015 19:58:50 +0530 Subject: [PATCH] CRM-15986 fix - Fields attached to different entities in JS profile creator https://issues.civicrm.org/jira/browse/CRM-15986 --- CRM/UF/Page/ProfileEditor.php | 4 ++++ api/v3/UFField.php | 2 +- js/model/crm.uf.js | 20 +++++++++++++++++++- js/view/crm.designer.js | 8 +++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CRM/UF/Page/ProfileEditor.php b/CRM/UF/Page/ProfileEditor.php index 3a1370570d..916dae0ca1 100644 --- a/CRM/UF/Page/ProfileEditor.php +++ b/CRM/UF/Page/ProfileEditor.php @@ -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; diff --git a/api/v3/UFField.php b/api/v3/UFField.php index b29527f5dc..5c1975a50a 100644 --- a/api/v3/UFField.php +++ b/api/v3/UFField.php @@ -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)) { diff --git a/js/model/crm.uf.js b/js/model/crm.uf.js index 9ed880d157..cc81507931 100644 --- a/js/model/crm.uf.js +++ b/js/model/crm.uf.js @@ -21,7 +21,12 @@ 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 @@ -198,6 +203,11 @@ 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', @@ -222,6 +232,9 @@ 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); } @@ -247,7 +260,7 @@ 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") : ''); }, @@ -308,6 +321,9 @@ if (fieldSchema.civiIsLocation) { limit *= LOCATION_TYPES.length; } + if (fieldSchema.civiIsWebsite) { + limit *= WEBSITE_TYPES.length; + } if (fieldSchema.civiIsPhone) { limit *= PHONE_TYPES.length; } @@ -315,11 +331,13 @@ }, 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(); }, diff --git a/js/view/crm.designer.js b/js/view/crm.designer.js index 51ca8a5706..5614e5222c 100644 --- a/js/view/crm.designer.js +++ b/js/view/crm.designer.js @@ -710,6 +710,9 @@ 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 + ')'; @@ -744,10 +747,13 @@ 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'); } -- 2.25.1