CRM-16811 - Support markup fields in popup profile editor
authorColeman Watts <coleman@civicrm.org>
Wed, 8 Jul 2015 17:52:13 +0000 (13:52 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 8 Jul 2015 17:52:13 +0000 (13:52 -0400)
CRM/UF/Page/ProfileEditor.php
api/v3/UFField.php
js/model/crm.designer.js
js/model/crm.uf.js
js/view/crm.designer.js

index dec8daa8d99a52ea08698ab63cbb6a5729749896..4a3709832d87c4208c251c4b872e5a9621e170b9 100644 (file)
@@ -102,10 +102,10 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page {
 
     $entityTypes = array_unique($entityTypes);
     $availableFields = NULL;
+    $civiSchema = array();
     foreach ($entityTypes as $entityType) {
       if (!$availableFields) {
         $availableFields = CRM_Core_BAO_UFField::getAvailableFieldsFlat();
-        //dpm($availableFields);
       }
       switch ($entityType) {
         case 'IndividualModel':
@@ -177,6 +177,26 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page {
       }
     }
 
+    // Adding the oddball "formatting" field here because there's no other place to put it
+    foreach (array('Individual', 'Organization', 'Household') as $type) {
+      if (isset($civiSchema[$type . 'Model'])) {
+        $civiSchema[$type . 'Model']['schema'] += array(
+          'formatting' => array(
+            'type' => 'Markup',
+            'title' => ts('Free HTML'),
+            'civiFieldType' => 'Formatting',
+            'section' => 'formatting',
+          ),
+        );
+        $civiSchema[$type . 'Model']['sections'] += array(
+          'formatting' => array(
+            'title' => ts('Formatting'),
+            'is_addable' => FALSE,
+          ),
+        );
+      }
+    }
+
     return $civiSchema;
   }
 
index 0db78222f5d44e80efeb77c500e736ba8b7da3d5..bcb58c0f404d157cf977708cb1aacc22dbab9dc8 100644 (file)
@@ -54,7 +54,7 @@ function civicrm_api3_uf_field_create($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)) {
+  if (strpos($field_name, 'formatting') !== 0 && !CRM_Core_BAO_UFField::isValidFieldName($field_name)) {
     throw new API_Exception('The field_name is not valid');
   }
   $params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
index 2553b157f618f28df4b7bbe3d0db16c5114574df..752cf86415c8fb75292ce486a7400b7ccc2341c7 100644 (file)
@@ -70,7 +70,9 @@
         label: this.getLabel(),
         entity_name: this.get('entityName'),
         field_type: this.getFieldSchema().civiFieldType,
-        field_name: this.get('fieldName')
+        // For some reason the 'formatting' field gets a random number appended in core so we mimic that here.
+        // TODO: Why?
+        field_name: this.get('fieldName') == 'formatting' ? 'formatting_' + (Math.floor(Math.random() * 8999) + 1000) : this.get('fieldName')
       });
       return model;
     }
@@ -95,6 +97,9 @@
      * @return {CRM.Designer.PaletteFieldModel}
      */
     getFieldByName: function(entityName, fieldName) {
+      if (fieldName.indexOf('formatting') === 0) {
+        fieldName = 'formatting';
+      }
       return this.find(function(paletteFieldModel) {
         return ((!entityName || paletteFieldModel.get('entityName') == entityName) && paletteFieldModel.get('fieldName') == fieldName);
       });
index cc81507931a7eb63ec21b7e74750651c384206d6..99d456e539467b76c1de659b596ec1bfe1e4e6c6 100644 (file)
@@ -97,6 +97,7 @@
       case 'Individual':
       case 'Organization':
       case 'Household':
+      case 'Formatting':
         return 'contact_1';
       case 'Activity':
         return 'activity_1';
       }
     },
     initialize: function() {
+      if (this.get('field_name').indexOf('formatting') === 0) {
+        this.schema.help_pre.title = ts('Markup');
+      }
       this.set('entity_name', CRM.UF.guessEntityName(this.get('field_type')));
       this.on("rel:ufGroupModel", this.applyDefaults, this);
       this.on('change', watchChanges);
       var entity_name = ufFieldModel.get('entity_name'),
         field_name = ufFieldModel.get('field_name'),
         fieldSchema = this.getRel('ufGroupModel').getFieldSchema(ufFieldModel.get('entity_name'), ufFieldModel.get('field_name'));
-
+      if (field_name.indexOf('formatting') === 0) {
+        return true;
+      }
       if (! fieldSchema) {
         return false;
       }
       return ufEntity.getModelClass();
     },
     getFieldSchema: function(entity_name, field_name) {
+      if (field_name.indexOf('formatting') === 0) {
+        field_name = 'formatting';
+      }
       var modelClass = this.getModelClass(entity_name);
       var fieldSchema = modelClass.prototype.schema[field_name];
       if (!fieldSchema) {
-        if (console.log) {
-          console.log('Failed to locate field: ' + entity_name + "." + field_name);
-        }
+        CRM.console('warn', 'Failed to locate field: ' + entity_name + "." + field_name);
         return null;
       }
       return fieldSchema;
index 1dc087c6b0b1364665ebeb6cef28266a4a3e607f..0be0f213409a73098de164d06374d7c722da715b 100644 (file)
       if (!this.options.fieldSchema.civiIsMultiple) {
         fields = _.without(fields, 'is_multi_summary');
       }
+      if (this.options.fieldSchema.type == 'Markup') {
+        fields = _.without(fields, 'is_required', 'is_view', 'visibility', 'in_selector', 'is_searchable', 'help_post');
+      }
 
       this.form = new Backbone.Form({
         model: this.model,
 
       if (!this.model.isInSelectorAllowed() && this.model.get('in_selector') != "0") {
         this.model.set('in_selector', "0");
-        this.form.setValue('in_selector', "0");
+        if (this.form.fields.in_selector) {
+          this.form.setValue('in_selector', "0");
+        }
         // TODO: It might be nicer if we didn't completely discard in_selector -- e.g.
         // if the value could be restored when the user isInSelectorAllowed becomes true
         // again. However, I haven't found a simple way to do this.