Merge pull request #6539 from joannechester/CRM-16185-rename-date-filters
[civicrm-core.git] / js / model / crm.uf.js
index 0ace2c10ef78f40279c12fe099e50384f05ac829..095acddc0dc8e6ed20d9e443f0ac84bb010db05c 100644 (file)
@@ -97,6 +97,7 @@
       case 'Individual':
       case 'Organization':
       case 'Household':
+      case 'Formatting':
         return 'contact_1';
       case 'Activity':
         return 'activity_1';
       },
       'label': {
         title: ts('Field Label'),
-        type: 'Text'
+        type: 'Text',
+        editorAttrs: {maxlength: 255}
       },
       'location_type_id': {
         title: ts('Location Type'),
       }
     },
     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;
       }
         title: ts('Profile Name'),
         help: ts(''),
         type: 'Text',
+        editorAttrs: {maxlength: 64},
         validators: ['required']
       },
       'group_type': {
           return _.omit(ufFieldModel.toStrictJSON(), ['id', 'uf_group_id']);
         })
       );
-      copy.set('title', ts('%1 (Copy)', {
-        1: copy.get('title')
-      }));
+      var copyLabel = ' ' + ts('(Copy)');
+      copy.set('title', copy.get('title').slice(0, 64 - copyLabel.length) + copyLabel);
       return copy;
     },
     getModelClass: function(entity_name) {
       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;
      * @return {Boolean}
      */
     //CRM-15427
-    checkGroupType: function(validTypesExpr, allowAllSubtypes) {
+    checkGroupType: function(validTypesExpr, allowAllSubtypes, usedByFilter) {
       var allMatched = true;
       allowAllSubtypes = allowAllSubtypes || false;
+      usedByFilter = usedByFilter || null;
       if (_.isEmpty(this.get('group_type'))) {
         return true;
       }
+      if (usedByFilter && _.isEmpty(this.get('module'))) {
+        return false;
+      }
 
       var actualTypes = CRM.UF.parseTypeList(this.get('group_type'));
       var validTypes = CRM.UF.parseTypeList(validTypesExpr);
         }
       });
 
+      // CRM-16915 - filter with usedBy module if specified.
+      if (usedByFilter && this.get('module') != usedByFilter) {
+        allMatched = false;
+      }
       //CRM-15427 allow all subtypes
       if (!$.isEmptyObject(validTypes.subTypes) && !allowAllSubtypes) {
         // Every actual.subType is a valid.subType