INFRA-132 - js/model/crm.uf.js - Cleanup empty checks to satisfy jshint
[civicrm-core.git] / js / model / crm.uf.js
index e72c8383c58aa7efb4e010c571b29955f5adbc2a..9ed880d157e988927164f0d5c9ac3326b460ba65 100644 (file)
     var coreTypesExpr = parts[0];
     var subTypesExpr = parts[1];
 
-    if (coreTypesExpr && coreTypesExpr != '') {
+    if (!_.isEmpty(coreTypesExpr)) {
       _.each(coreTypesExpr.split(','), function(coreType){
         typeList.coreTypes[coreType] = true;
       });
     }
 
-    if (subTypesExpr && subTypesExpr != '') {
-      var subTypes = subTypesExpr.split(':');
-      var subTypeKey = subTypes.shift();
-      typeList.subTypes[subTypeKey] = {};
-      _.each(subTypes, function(subTypeId){
-        typeList.subTypes[subTypeKey][subTypeId] = true;
-      });
+    //CRM-15427 Allow Multiple subtype filtering
+    if (!_.isEmpty(subTypesExpr)) {
+      if (subTypesExpr.indexOf(';;') !== -1) {
+        var subTypeparts = subTypesExpr.replace(/;;/g,'\0').split('\0');
+        _.each(subTypeparts, function(subTypepart) {
+          var subTypes = subTypepart.split(':');
+          var subTypeKey = subTypes.shift();
+          typeList.subTypes[subTypeKey] = {};
+          _.each(subTypes, function(subTypeId) {
+            typeList.subTypes[subTypeKey][subTypeId] = true;
+          });
+        });
+      }
+      else {
+        var subTypes = subTypesExpr.split(':');
+        var subTypeKey = subTypes.shift();
+        typeList.subTypes[subTypeKey] = {};
+        _.each(subTypes, function(subTypeId) {
+          typeList.subTypes[subTypeKey][subTypeId] = true;
+        });
+      }
     }
     return typeList;
   };
       case 'Case':
         return 'case_1';
       default:
-        throw "Cannot guess entity name for field_type=" + field_type;
+        if (!$.isEmptyObject(CRM.contactSubTypes) && ($.inArray(field_type,CRM.contactSubTypes) > -1)) {
+          return 'contact_1';
+        }
+        else {
+          throw "Cannot guess entity name for field_type=" + field_type;
+        }
     }
-  }
+  };
 
   /**
    * Represents a field in a customizable form.
      * @return {String}
      */
     getSignature: function() {
-      return this.get("entity_name")
-        + '::' + this.get("field_name")
-        + '::' + (this.get("location_type_id") ? this.get("location_type_id") : '')
-        '::' + (this.get("phone_type_id") ? this.get("phone_type_id") : '');
+      return this.get("entity_name") +
+        '::' + this.get("field_name") +
+        '::' + (this.get("location_type_id") ? this.get("location_type_id") : '') +
+        '::' + (this.get("phone_type_id") ? this.get("phone_type_id") : '');
     },
 
     /**
       return result;
     },
     isSectionEnabled: function(section) {
-      return (!section || !section.extends_entity_column_value || _.contains(section.extends_entity_column_value, this.get('entity_sub_type')));
+      //CRM-15427
+      return (!section || !section.extends_entity_column_value || _.contains(section.extends_entity_column_value, this.get('entity_sub_type')) || this.get('entity_sub_type') == '*');
     },
     getSections: function() {
       var ufEntityModel = this;
       },
       'help_post': {
         title: ts('Post-form Help'),
-        help: ts('Explanatory text displayed at the end of the form.')
-          + ts('Note that this help text is displayed on profile create/edit screens only.'),
+        help: ts('Explanatory text displayed at the end of the form.') +
+        ts('Note that this help text is displayed on profile create/edit screens only.'),
         type: 'TextArea'
       },
       'help_pre': {
-        title: ts('Pre-form Help '),
-        help: ts('Explanatory text displayed at the beginning of the form.')
-          + ts('Note that this help text is displayed on profile create/edit screens only.'),
+        title: ts('Pre-form Help'),
+        help: ts('Explanatory text displayed at the beginning of the form.') +
+        ts('Note that this help text is displayed on profile create/edit screens only.'),
         type: 'TextArea'
       },
       'is_active': {
         options: YESNO
       },
       'is_proximity_search': {
-        title: ts('Proximity search'),
+        title: ts('Proximity Search'),
         help: ts('FIXME'),
         type: 'Select',
         options: YESNO // FIXME
           ufGroupModel: this
         });
         paletteFieldCollection.sync = function(method, model, options) {
-          options || (options = {});
+          if (!options) options = {};
           // console.log(method, model, options);
           switch (method) {
             case 'read':
             case 'create':
             case 'update':
             case 'delete':
+              throw 'Unsupported method: ' + method;
+
             default:
               throw 'Unsupported method: ' + method;
           }
      * Check that the group_type contains *only* the types listed in validTypes
      *
      * @param string validTypesExpr
+     * @param bool allowAllSubtypes
      * @return {Boolean}
      */
-    checkGroupType: function(validTypesExpr) {
+    //CRM-15427
+    checkGroupType: function(validTypesExpr, allowAllSubtypes) {
       var allMatched = true;
-      if (! this.get('group_type') || this.get('group_type') == '') {
+      allowAllSubtypes = allowAllSubtypes || false;
+      if (_.isEmpty(this.get('group_type'))) {
         return true;
       }
 
         }
       });
 
-      // Every actual.subType is a valid.subType
-      _.each(actualTypes.subTypes, function(actualSubTypeIds, actualSubTypeKey) {
-        if (!validTypes.subTypes[actualSubTypeKey]) {
-          allMatched = false;
-          return;
-        }
-        // actualSubTypeIds is a list of all subtypes which can be used by group,
-        // so it's sufficient to match any one of them
-        var subTypeMatched = false;
-        _.each(actualSubTypeIds, function(ignore, actualSubTypeId) {
-          if (validTypes.subTypes[actualSubTypeKey][actualSubTypeId]) {
-            subTypeMatched = true;
+      //CRM-15427 allow all subtypes
+      if (!$.isEmptyObject(validTypes.subTypes) && !allowAllSubtypes) {
+        // Every actual.subType is a valid.subType
+        _.each(actualTypes.subTypes, function(actualSubTypeIds, actualSubTypeKey) {
+          if (!validTypes.subTypes[actualSubTypeKey]) {
+            allMatched = false;
+            return;
           }
+          // actualSubTypeIds is a list of all subtypes which can be used by group,
+          // so it's sufficient to match any one of them
+          var subTypeMatched = false;
+          _.each(actualSubTypeIds, function(ignore, actualSubTypeId) {
+            if (validTypes.subTypes[actualSubTypeKey][actualSubTypeId]) {
+              subTypeMatched = true;
+            }
+          });
+          allMatched = allMatched && subTypeMatched;
         });
-        allMatched = allMatched && subTypeMatched;
-      });
+      }
       return allMatched;
     },
     calculateContactEntityType: function() {