X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fjquery%2Fjquery.crmProfileSelector.js;h=bb09f4335139770429cc6f2bc9daf0945cefc23c;hb=58cb13f8bfa693af1dcf19e5eb24e13d77da2d14;hp=f97333552078d0ca177ef23e89e6ad5d0fa202a5;hpb=a5d44edbee5498fa4195c5f3571db6b820185fa8;p=civicrm-core.git diff --git a/js/jquery/jquery.crmProfileSelector.js b/js/jquery/jquery.crmProfileSelector.js index f973335520..bb09f43351 100644 --- a/js/jquery/jquery.crmProfileSelector.js +++ b/js/jquery/jquery.crmProfileSelector.js @@ -28,16 +28,46 @@ var matchingUfGroups, $select = $(this).hide().addClass('rendered'); + var validTypesId = []; + var usedByFilter = null; if (options.groupTypeFilter) { matchingUfGroups = ufGroupCollection.subcollection({ filter: function(ufGroupModel) { - return ufGroupModel.checkGroupType(options.groupTypeFilter); + //CRM-16915 - filter with module used by the profile + if (!$.isEmptyObject(options.usedByFilter)) { + usedByFilter = options.usedByFilter; + } + return ufGroupModel.checkGroupType(options.groupTypeFilter, options.allowAllSubtypes, usedByFilter); } }); } else { matchingUfGroups = ufGroupCollection; } + //CRM-15427 check for valid subtypes raise a warning if not valid + if (options.allowAllSubtypes && $.isEmptyObject(validTypesId)) { + validTypes = ufGroupCollection.subcollection({ + filter: function(ufGroupModel) { + return ufGroupModel.checkGroupType(options.groupTypeFilter); + } + }); + _.each(validTypes.models, function(validTypesattr) { + validTypesId.push(validTypesattr.id); + }); + } + if (!$.isEmptyObject(validTypesId) && $.inArray($select.val(), validTypesId) == -1) { + var civiComponent; + if (options.groupTypeFilter.indexOf('Membership') !== -1) { + civiComponent = 'Membership'; + } + else if (options.groupTypeFilter.indexOf('Participant') !== -1) { + civiComponent = 'Event'; + } + else { + civiComponent = 'Contribution'; + } + CRM.alert(ts('The selected profile is using a custom field which is not assigned to the "%1" being configured.', {1: civiComponent}), ts('Warning')); + } var view = new CRM.ProfileSelector.View({ ufGroupId: $select.val(), ufGroupCollection: matchingUfGroups, @@ -58,7 +88,10 @@ $('.crm-profile-selector:not(.rendered)', this).each(function() { $(this).crmProfileSelector({ groupTypeFilter: $(this).data('groupType'), - entities: $(this).data('entities') + entities: $(this).data('entities'), + //CRM-15427 + allowAllSubtypes: $(this).data('default'), + usedByFilter: $(this).data('usedfor') }); }); });