Skip to content

Commit

Permalink
Merge pull request civicrm#11264 from seanmadsen/CRM-21419-activity-s…
Browse files Browse the repository at this point in the history
…eparation

CRM-21419 Prevent users from accidentally creating a single activity when they want multiple
  • Loading branch information
colemanw authored and sluc23 committed Jan 10, 2018
2 parents 9dc673d + 6c32071 commit 3ebc9c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
17 changes: 16 additions & 1 deletion CRM/Activity/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,14 @@ public function buildQuickForm() {

// this option should be available only during add mode
if ($this->_action != CRM_Core_Action::UPDATE) {
$this->add('advcheckbox', 'is_multi_activity', ts('Create a separate activity for each contact.'));
$this->addRadio(
'separation',
ts('Activity Separation'),
array(
'separate' => ts('Create separate activities for each contact'),
'combined' => ts('Create one activity with all contacts together'),
)
);
}

$this->addRule('duration',
Expand Down Expand Up @@ -832,6 +839,12 @@ public static function formRule($fields, $files, $self) {
if ((!empty($fields['followup_activity_subject']) || !empty($fields['followup_date'])) && empty($fields['followup_activity_type_id'])) {
$errors['followup_activity_subject'] = ts('Follow-up Activity type is a required field.');
}
$actionIsAdd = $self->_action == CRM_Core_Action::ADD;
$hasMultipleTargetContacts = !empty($fields['target_contact_id']) && strpos($fields['target_contact_id'], ',') !== FALSE;
$separationFieldIsEmpty = empty($fields['separation']);
if ($actionIsAdd && $hasMultipleTargetContacts && $separationFieldIsEmpty) {
$errors['separation'] = ts('Activity Separation is a required field.');
}
return $errors;
}

Expand Down Expand Up @@ -916,6 +929,8 @@ public function postProcess($params = NULL) {
$this->_activityId
);

$params['is_multi_activity'] = CRM_Utils_Array::value('separation', $params) == 'separate';

$activity = array();
if (!empty($params['is_multi_activity']) &&
!CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id'])
Expand Down
9 changes: 5 additions & 4 deletions templates/CRM/Activity/Form/Activity.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{htxt id="id-is_multi_activity-title"}
{ts}Create Separate Activity Records?{/ts}
{htxt id="separation-title"}
{ts}Activity Separation{/ts}
{/htxt}
{htxt id="id-is_multi_activity"}
<p>{ts}By default a single activity record will be created and linked to all the contacts listed above. However, if you think you might be editing the activity later - and entering different information for different contacts - check this box to create separate activity records.{/ts}</p>
{htxt id="separation"}
<p>{ts}With separate activities, you can enter different activity information for different contacts after creating the activities.{/ts}</p>
<p>{ts}With a single activity, the activity information cannot be customized for each contact.{/ts}</p>
{/htxt}

{htxt id="assignee_contact_id"}
Expand Down
12 changes: 7 additions & 5 deletions templates/CRM/Activity/Form/Activity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@
<td class="label">{$form.target_contact_id.label}</td>
<td class="view-value">
{$form.target_contact_id.html}
{if $action eq 1 or $single eq false}
<div class="crm-is-multi-activity-wrapper">
{$form.is_multi_activity.html}&nbsp;{$form.is_multi_activity.label} {help id="id-is_multi_activity"}
</div>
{/if}
</td>
</tr>

{if $action eq 1 or $single eq false}
<tr class="crm-activity-form-block-separation crm-is-multi-activity-wrapper">
<td class="label">{$form.separation.label}</td>
<td>{$form.separation.html} {help id="separation"}</td>
</tr>
{/if}

<tr class="crm-activity-form-block-assignee_contact_id">
<td class="label">
{$form.assignee_contact_id.label}
Expand Down

0 comments on commit 3ebc9c6

Please sign in to comment.