X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fmodel%2Fcrm.uf.js;h=9ed880d157e988927164f0d5c9ac3326b460ba65;hb=fb079bbfc490982a09751b5e1f6ac94ba499e573;hp=e72c8383c58aa7efb4e010c571b29955f5adbc2a;hpb=9cc8b9b246a371b9621a8279545258073fbd0e48;p=civicrm-core.git diff --git a/js/model/crm.uf.js b/js/model/crm.uf.js index e72c8383c5..9ed880d157 100644 --- a/js/model/crm.uf.js +++ b/js/model/crm.uf.js @@ -48,19 +48,33 @@ 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; }; @@ -90,9 +104,14 @@ 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. @@ -226,10 +245,10 @@ * @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") : ''); }, /** @@ -379,7 +398,8 @@ 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; @@ -476,14 +496,14 @@ }, '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': { @@ -510,7 +530,7 @@ options: YESNO }, 'is_proximity_search': { - title: ts('Proximity search'), + title: ts('Proximity Search'), help: ts('FIXME'), type: 'Select', options: YESNO // FIXME @@ -578,7 +598,7 @@ ufGroupModel: this }); paletteFieldCollection.sync = function(method, model, options) { - options || (options = {}); + if (!options) options = {}; // console.log(method, model, options); switch (method) { case 'read': @@ -593,6 +613,8 @@ case 'create': case 'update': case 'delete': + throw 'Unsupported method: ' + method; + default: throw 'Unsupported method: ' + method; } @@ -647,11 +669,14 @@ * 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; } @@ -665,22 +690,25 @@ } }); - // 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() {