Commit 42d2dc5b authored by Jamie McClelland's avatar Jamie McClelland

major refactoring to pair mathing group with matching field.

This tightens our matching query to ensure we don't have any
accidental matches.
parent 2090d965
cj(document).ready( function() {
showHideEmailPetition();
populateUserMessageFieldOptions();
checkProfileIncludesMessage();
cj("input#email_petition").click( function() { showHideEmailPetition(); });
cj("#profile_id").change( function() { populateUserMessageFieldOptions(); });
cj("#user_message").change( function() { checkProfileIncludesMessage(); });
});
function populateUserMessageFieldOptions() {
var actProfile = cj("#profile_id").val();
var selected = cj('#message_field').val();
var options = {};
cj('#user_message').val('');
cj('#user_message').empty();
cj('#message_field').empty();
if(actProfile) {
CRM.api("UFField","get",{ "uf_group_id" : actProfile },{ success:function (data) {
if(data['is_error'] == 0) {
cj('#message_field').append('<option value="">--Choose one--</option>');
cj.each(data["values"], function(key, value) {
cj('#user_message').append('<option value="' + key + '">' + value['label'] + '</option>');
cj('#message_field').append('<option value="' + value['field_name'] + '">' + value['label'] + '</option>');
});
cj('#message_field').val(selected);
}
}});
}
else {
options[''] = "No activity profile selected.";
cj('#user_message').append('<option value="">No activity profile selected.</option>');
cj('#message_field').append('<option value="">No activity profile selected.</option>');
}
}
function checkProfileIncludesMessage() {
cj("#profileMissingMessage").remove();
var actProfile = cj("#profile_id").val();
CRM.api("UFField","get",{ "sequential" :"1", "uf_group_id" : actProfile },{ success:function (data){
var msgField = cj("#user_message").val();
if (msgField) {
var fieldinfo = cj.inArray(msgField, data["values"])
var matchfield = false;
cj.each(data["values"], function(key, value) {
if (value["field_name"] == "custom_"+msgField) {
matchfield = true;
return true;
}
});
if (!matchfield) {
cj("#user_message").after("<div id='profileMissingMessage' style='background-color: #FF9999; border: 1px solid #CC3333; display: inline-block; font-size: 85%; margin-left: 1ex; padding: 0.5ex; vertical-align: top;'>" + ts("This field is not in the activity profile you selected") + "</div>");
}
}
}
});
}
function showHideEmailPetition() {
if( cj("input#email_petition").attr("checked") ) {
cj("tr.crm-campaign-survey-form-block-location_type_id").show("fast");
cj("tr.crm-campaign-survey-form-block-recipient_options").show("fast");
cj("tr.crm-campaign-survey-form-block-user_message").show("fast");
cj("tr.crm-campaign-survey-form-block-message_field").show("fast");
cj("tr.crm-campaign-survey-form-block-default_message").show("fast");
cj("tr.crm-campaign-survey-form-block-subject").show("fast");
} else {
cj("tr.crm-campaign-survey-form-block-location_type_id").hide("fast");
cj("tr.crm-campaign-survey-form-block-recipient_options").hide("fast");
cj("tr.crm-campaign-survey-form-block-user_message").hide("fast");
cj("tr.crm-campaign-survey-form-block-message_field").hide("fast");
cj("tr.crm-campaign-survey-form-block-default_message").hide("fast");
cj("tr.crm-campaign-survey-form-block-subject").hide("fast");
}
......
This diff is collapsed.
......@@ -3,6 +3,6 @@
ALTER TABLE civicrm_petition_email DROP COLUMN `recipient_email`;
ALTER TABLE civicrm_petition_email DROP COLUMN `recipient_name`;
ALTER TABLE civicrm_petition_email ADD COLUMN `group_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The ID of the CiviCRM Group representing the petition targets.' AFTER petition_id;
ALTER TABLE civicrm_petition_email CHANGE COLUMN message_field message_field varchar(128);
ALTER TABLE civicrm_petition_email ADD COLUMN `location_type_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The location type that should be used when selecting the target email address.' AFTER group_id;
......@@ -4,10 +4,9 @@
CREATE TABLE IF NOT EXISTS `civicrm_petition_email` (
`petition_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The SID of the petition.',
`group_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The ID of the CiviCRM Group representing the petition targets.',
`location_type_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The location type that should be used when selecting the target email address.',
`default_message` text COMMENT 'The default message for the petition',
`message_field` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The ID of the custom field used for petition messages.',
`message_field` varchar(128) COMMENT 'The name of the custom field used for petition messages.',
`subject` varchar(128) DEFAULT NULL COMMENT 'The subject line for outgoing emails.',
`recipients` text COMMENT 'The name and email address of additional targets that should receive a copy of all petitions signed, separated by line breaks.',
PRIMARY KEY (`petition_id`),
......
......@@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_petition_email_matching_field` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'The unique ID of the email field.',
`petition_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The SID of the petition.',
`matching_field` text COMMENT 'The name of the field that should match between petition signer and target.',
`matching_group_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The group that should match against this field.',
PRIMARY KEY (`id`),
KEY `petition_id` (`petition_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores the fields used to match petition signers and targets.';
......
......@@ -13,9 +13,9 @@
<td class="view-value">{$form.default_message.html}
<div class="description">{ts}Enter the default message to be included in the email.{/ts}</div></td>
</tr>
<tr class="crm-campaign-survey-form-block-user_message">
<td class="label">{$form.user_message.label}</td>
<td class="view-value">{$form.user_message.html}
<tr class="crm-campaign-survey-form-block-message_field">
<td class="label">{$form.message_field.label}</td>
<td class="view-value">{$form.message_field.html}
<div class="description">{ts}Select a field that will have the signer's custom message. Make sure it is included in the Activity Profile you selected.{/ts}</div></td>
</tr>
......@@ -27,22 +27,40 @@
<h3 class="petition-email-header">Dynamic Method</h3>
<div class="petition-email-recipient-option-description">The dynamic method allows you to choose different petition recipients depending on who is filling out the petition. To use the dynamic method, you must first put your targets into a group. Then specify the group below, and the fields that must match between the person filling out the petition and the target contact.</div>
<div class="label">{$form.group_id.label}</div>
<div class="view-value">{$form.group_id.html}</div>
<div class="description">{ts}Select the group containing the contacts that you want to receive the petition.{/ts}</div>
<div class="label">{$form.matching_fields.label}</div>
<div class="view-value">{$form.matching_fields.html}</div>
<div class="description">
{ts}If the user and the target have the same value for this field (even if the value is empty), then the user's petition will be sent to the matching target.{/ts}
{if $petitionemail_matching_fields_count eq 0}
{ts}No fields are configured to be used as matching fields. Please <a href={$petitionemail_profile_edit_link}>add fields to the petitionemail profile</a>.{/ts}
{else}
{ts}Don't see the field you want to use? You can <a href={$petitionemail_profile_edit_link}>add more fields to the petitionemail profile</a> and they will show up here.{/ts}
{/if}
</div>
<div class="petition-email-recipient-option-description">The dynamic method allows you to choose different petition recipients depending on who is filling out the petition. To use the dynamic method, you must first put your targets into a group. Then specify the group below, and the field that must match between the person filling out the petition and the target contact. You can choose up to three group/field combinations.</div>
<table id="petition-email-dynamic-method">
<tr>
<td>{ts}Target Group{/ts}</td>
<td></td>
<td>{ts}Matching field{/ts}</td>
</tr>
<tr>
<td class="view-value">
<div class="petitionemail-matching-group_id">{$form.matching_group_id1.html}</div>
<div class="petitionemail-matching-group_id">{$form.matching_group_id2.html}</div>
<div class="petitionemail-matching-group_id">{$form.matching_group_id3.html}</div>
</td>
<td>
<div class="petitionemail-use-with">{ts}match using:{/ts}</div>
<div class="petitionemail-use-with">{ts}match using:{/ts}</div>
<div class="petitionemail-use-with">{ts}match using:{/ts}</div>
</td>
<td class="view-value">
<div class="petitionemail-matching-fields">{$form.matching_field1.html}</div>
<div class="petitionemail-matching-fields">{$form.matching_field2.html}</div>
<div class="petitionemail-matching-fields">{$form.matching_field3.html}</div>
</td>
</tr>
<tr>
<td colspan="3" class="description">{ts}Select the group containing the contacts that you want to receive the petition along with the field that should match between the petition signer and the target in this group. If the user and the target have the same value for this field, then the user's petition will be sent to the matching target.{/ts}
{if $petitionemail_matching_fields_count eq 0}
{ts}No fields are configured to be used as matching fields. Please <a href={$petitionemail_profile_edit_link}>add fields to the petitionemail profile</a>.{/ts}
{else}
{ts}Don't see the field you want to use? You can <a href={$petitionemail_profile_edit_link}>add more fields to the petitionemail profile</a> and they will show up here.{/ts}
{/if}
</td>
</tr>
</table>
<div class="label">{$form.location_type_id.label}</div>
<div class="view-value">{$form.location_type_id.html}</div>
<div class="description">{ts}A target contact can have more than one email address. Choose the email location that should be used when sending the petition{/ts}</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment