// Register 'contribution_1'
$financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'financial_type_id');
$allowCoreTypes[] = 'Contribution';
- // $allowSubTypes['ContributionType'] = array($financialTypeId);
- $entities[] = array('entity_name' => 'contribution_1', 'entity_type' => 'ContributionModel', 'entity_sub_type' => $financialTypeId);
+ //CRM-15427
+ $allowSubTypes['ContributionType'] = array($financialTypeId);
+ $entities[] = array('entity_name' => 'contribution_1', 'entity_type' => 'ContributionModel', 'entity_sub_type' => '*');
// If applicable, register 'membership_1'
$member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
if ($member && $member['is_active']) {
- $entities[] = array('entity_name' => 'membership_1', 'entity_type' => 'MembershipModel', 'entity_sub_type' => $member['membership_type_default']);
+ //CRM-15427
+ $entities[] = array('entity_name' => 'membership_1', 'entity_type' => 'MembershipModel', 'entity_sub_type' => '*');
$allowCoreTypes[] = 'Membership';
$allowSubTypes['MembershipType'] = explode(',', $member['membership_types']);
}
-
- $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities);
- $this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities);
+ //CRM-15427
+ $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE);
+ $this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE);
$this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id);
$groupTypeExpr .= implode(',', $coreTypes);
}
if ($subTypes) {
- if (count($subTypes) > 1) {
- throw new CRM_Core_Exception("Multiple subtype filtering is not currently supported by widget.");
- }
+ //CRM-15427 Allow Multiple subtype filtering
+ //if (count($subTypes) > 1) {
+ //throw new CRM_Core_Exception("Multiple subtype filtering is not currently supported by widget.");
+ //}
foreach ($subTypes as $subType => $subTypeIds) {
$groupTypeExpr .= $delim . $subType . ':' . implode(':', $subTypeIds);
}
* @param string $allowCoreTypes only present a UFGroup if its group_type includes a subset of $allowCoreTypes; e.g. 'Individual', 'Activity'
* @param string $allowSubTypes only present a UFGroup if its group_type is compatible with $allowSubypes
* @param array $entities
+ * @param bool $default //CRM-15427
*/
- function addProfileSelector($name, $label, $allowCoreTypes, $allowSubTypes, $entities) {
+ function addProfileSelector($name, $label, $allowCoreTypes, $allowSubTypes, $entities, $default = FALSE) {
// Output widget
// FIXME: Instead of adhoc serialization, use a single json_encode()
CRM_UF_Page_ProfileEditor::registerProfileScripts();
// Note: client treats ';;' as equivalent to \0, and ';;' works better in HTML
'data-group-type' => CRM_Core_BAO_UFGroup::encodeGroupType($allowCoreTypes, $allowSubTypes, ';;'),
'data-entities' => json_encode($entities),
+ //CRM-15427
+ 'data-default' => $default,
));
}
$form->addWysiwyg('footer_text', ts('Footer Text'), $footerAttribs);
extract( self::getProfileSelectorTypes() );
+ //CRM-15427
+ $form->addProfileSelector( 'custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
+ $form->addProfileSelector( 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
- $form->addProfileSelector( 'custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
- $form->addProfileSelector( 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
-
- $form->addProfileSelector( 'additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
- $form->addProfileSelector( 'additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
+ $form->addProfileSelector( 'additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
+ $form->addProfileSelector( 'additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
}
/**
$configs['allowCoreTypes'][] = 'Contact';
$configs['allowCoreTypes'][] = 'Individual';
$configs['allowCoreTypes'][] = 'Participant';
+ //CRM-15427
+ $participantEventType = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $_GET['id'], 'event_type_id', 'id');
+ $participantRole = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $_GET['id'], 'default_role_id');
+ $configs['allowSubTypes']['ParticipantEventName'] = array($_GET['id']);
+ $configs['allowSubTypes']['ParticipantEventType'] = array($participantEventType);
+ $configs['allowSubTypes']['ParticipantRole'] = array($participantRole);
$configs['profileEntities'][] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel');
- $configs['profileEntities'][] = array('entity_name' => 'participant_1', 'entity_type' => 'ParticipantModel');
+ $configs['profileEntities'][] = array('entity_name' => 'participant_1', 'entity_type' => 'ParticipantModel', 'entity_sub_type' => '*');
return $configs;
}
var matchingUfGroups,
$select = $(this).hide().addClass('rendered');
+ var validTypesId = [];
if (options.groupTypeFilter) {
matchingUfGroups = ufGroupCollection.subcollection({
filter: function(ufGroupModel) {
- return ufGroupModel.checkGroupType(options.groupTypeFilter);
+ return ufGroupModel.checkGroupType(options.groupTypeFilter, options.allowAllSubtypes);
}
});
} 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 '+civiComponent+' being configured.'),ts('Warning'));
+ }
var view = new CRM.ProfileSelector.View({
ufGroupId: $select.val(),
ufGroupCollection: matchingUfGroups,
$('.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')
});
});
});
});
}
+ //CRM-15427 Allow Multiple subtype filtering
if (subTypesExpr && subTypesExpr != '') {
- var subTypes = subTypesExpr.split(':');
- var subTypeKey = subTypes.shift();
- typeList.subTypes[subTypeKey] = {};
- _.each(subTypes, function(subTypeId){
- typeList.subTypes[subTypeKey][subTypeId] = true;
- });
+ 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;
};
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;
* 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 = false) {
var allMatched = true;
if (! this.get('group_type') || 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() {