'required' => TRUE,
),
'source_contact_id' => array(
- 'type' => 'text',
+ 'type' => 'entityRef',
'label' => ts('Added By'),
'required' => FALSE
),
+ 'target_contact_id' => array(
+ 'type' => 'entityRef',
+ 'label' => ts('With Contact'),
+ 'attributes' => array('multiple' => TRUE, 'create' => TRUE)
+ ),
+ 'assignee_contact_id' => array(
+ 'type' => 'entityRef',
+ 'label' => ts('Assigned To'),
+ 'attributes' => array('multiple' => TRUE),
+ ),
+ 'followup_assignee_contact_id' => array(
+ 'type' => 'entityRef',
+ 'label' => ts('Assigned To'),
+ 'attributes' => array('multiple' => TRUE),
+ ),
'followup_activity_type_id' => array(
'type' => 'select',
'label' => ts('Followup Activity'),
// if we're editing...
if (isset($this->_activityId)) {
-
- if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) {
- $target_contact_value = explode(';', trim($defaults['target_contact_value']));
- $target_contact = array_combine(array_unique($defaults['target_contact']), $target_contact_value);
-
- if ($this->_action & CRM_Core_Action::VIEW) {
- $this->assign('target_contact', $target_contact);
- }
- else {
- //this assigned variable is used by newcontact creation widget to set defaults
- $this->assign('prePopulateData', $this->formatContactValues($target_contact));
- }
- }
-
- if (!CRM_Utils_Array::crmIsEmptyArray($defaults['assignee_contact'])) {
- $assignee_contact_value = explode(';', trim($defaults['assignee_contact_value']));
- $assignee_contact = array_combine($defaults['assignee_contact'], $assignee_contact_value);
-
- if ($this->_action & CRM_Core_Action::VIEW) {
- $this->assign('assignee_contact', $assignee_contact);
- }
- else {
- $this->assign('assignee_contact', $this->formatContactValues($assignee_contact));
- }
- }
-
if (empty($defaults['activity_date_time'])) {
list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
}
) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime');
}
- //set the assignee contact count to template
- if (!empty($defaults['assignee_contact'])) {
- $this->assign('assigneeContactCount', count($defaults['assignee_contact']));
- }
- else {
- $this->assign('assigneeContactCount', 1);
- }
-
- //set the target contact count to template
- if (!empty($defaults['target_contact'])) {
- $this->assign('targetContactCount', count($defaults['target_contact']));
- }
- else {
- $this->assign('targetContactCount', 1);
- }
-
if ($this->_context != 'standalone') {
$this->assign('target_contact_value',
CRM_Utils_Array::value('target_contact_value', $defaults)
);
}
+ // Fixme: why are we getting the wrong keys from upstream?
+ $defaults['target_contact_id'] = $defaults['target_contact'];
+ $defaults['assignee_contact_id'] = $defaults['assignee_contact'];
+
// set default tags if exists
$defaults['tag'] = CRM_Core_BAO_EntityTag::getTag($this->_activityId, 'civicrm_activity');
}
else {
// if it's a new activity, we need to set default values for associated contact fields
- // since those are jQuery fields, unfortunately we cannot use defaults directly
$this->_sourceContactId = $this->_currentUserId;
$this->_targetContactId = $this->_currentlyViewedContactId;
- $target_contact = array();
$defaults['source_contact_id'] = $this->_sourceContactId;
- if ($this->_context != 'standalone' && isset($this->_targetContactId)) {
- $target_contact[$this->_targetContactId] = self::_getDisplayNameById($this->_targetContactId);
- }
-
- //this assigned variable is used by newcontact creation widget to set defaults
- $this->assign('prePopulateData', $this->formatContactValues($target_contact));
+ $defaults['target_contact_id'] = $this->_targetContactId;
list($defaults['activity_date_time'], $defaults['activity_date_time_time']) =
CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
return $defaults;
}
- /**
- * Function to format contact values before assigning to autocomplete widget
- *
- * @param array $contactNames associated array of contact name and ids
- *
- * @return json encoded object
- * @private
- */
- function formatContactValues(&$contactNames) {
- //format target/assignee contact
- $formatContacts = array();
- foreach ($contactNames as $id => $name) {
- $formatContacts[] = array(
- 'id' => $id,
- 'name' => $name
- );
- }
-
- return json_encode($formatContacts);
- }
-
public function buildQuickForm() {
if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) {
//enable form element (ActivityLinks sets this true)
return;
}
- if (!$this->_single && !empty($this->_contactIds)) {
- $withArray = array();
- foreach ($this->_contactIds as $contactId) {
- $withDisplayName = self::_getDisplayNameById($contactId);
- $withArray[] = "\"$withDisplayName\" ";
- }
- $this->assign('with', implode(', ', $withArray));
- }
-
if ($this->_cdType) {
return CRM_Custom_Form_CustomData::buildQuickForm($this);
}
$this->addWysiwyg($field, $values['label'], $attribute, $required);
}
elseif ($values['type'] == 'select' && empty($attribute)) {
- $this->addSelect($field, array(), $required);
+ $this->addSelect($field, array('entity' => 'activity'), $required);
+ }
+ elseif ($values['type'] == 'entityRef') {
+ $this->addEntityRef($field, $values['label'], $attribute, $required);
}
- elseif ($field != 'source_contact_id') {
+ else {
$this->add($values['type'], $field, $values['label'], $attribute, $required);
}
}
CRM_Campaign_BAO_Campaign::accessCampaign()
) {
$buildEngagementLevel = TRUE;
- $this->addSelect('engagement_level');
+ $this->addSelect('engagement_level',array('entity' => 'activity'));
$this->addRule('engagement_level',
ts('Please enter the engagement index as a number (integers only).'),
'positiveInteger'
);
// Only admins and case-workers can change the activity source
if (!CRM_Core_Permission::check('administer CiviCRM') && $this->_context != 'caseActivity') {
- $sourceContactField->freeze();
+ $this->getElement('source_contact_id')->freeze();
}
- CRM_Contact_Form_NewContact::buildQuickForm($this);
-
- $this->add('text', 'assignee_contact_id', ts('assignee'));
- $this->add( 'text', 'followup_assignee_contact_id', ts('assignee'));
-
//need to assign custom data type and subtype to the template
$this->assign('customDataType', 'Activity');
$this->assign('customDataSubType', $this->_activityTypeId);
// store the date with proper format
$params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
- // format with contact (target contact) values
- if (isset($params['contact'][1])) {
- $params['target_contact_id'] = explode(',', $params['contact'][1]);
- }
- else {
- $params['target_contact_id'] = array();
- }
-
- // assigning formated value to related variable
- if (!empty($params['assignee_contact_id'])) {
- $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']);
+ // format params as arrays
+ foreach (array('target', 'assignee', 'followup_assignee') as $name) {
+ if (!empty($params["{$name}_contact_id"])) {
+ $params["{$name}_contact_id"] = explode(',', $params["{$name}_contact_id"]);
+ }
+ else {
+ $params["{$name}_contact_id"] = array();
+ }
}
- else {
- $params['assignee_contact_id'] = array();
- }
- // civicrm-10043 - 14/12/13
- if (!empty($params['followup_assignee_contact_id'])) {
- $params['followup_assignee_contact_id'] = explode( ',', $params['followup_assignee_contact_id'] );
- }
- else {
- $params['followup_assignee_contact_id'] = array( );
- }
// get ids for associated contacts
if (!$params['source_contact_id']) {
</tr>
<tr class="crm-activity-form-block-target_contact_id">
- {if $single eq false}
- <td class="label">{ts}With Contact(s){/ts}</td>
- <td class="view-value" style="white-space: normal">
- {$with|escape}
- <br/>
- {$form.is_multi_activity.html} {$form.is_multi_activity.label} {help id="id-is_multi_activity"}
- </td>
- {elseif $action neq 4}
- <td class="label">{ts}With Contact{/ts}</td>
+ <td class="label">{$form.target_contact_id.label}</td>
<td class="view-value">
- {include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true multiClient=true parent="activity" showNewSelect=true}
+ {$form.target_contact_id.html}
{if $action eq 1}
<br/>
{$form.is_multi_activity.html} {$form.is_multi_activity.label} {help id="id-is_multi_activity"}
{/if}
</td>
- {else}
- <td class="label">{ts}With Contact{/ts}</td>
- <td class="view-value" style="white-space: normal">
- {foreach from=$target_contact key=id item=name}
- <a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=$id"}">{$name}</a>;
- {/foreach}
- </td>
- {/if}
</tr>
<tr class="crm-activity-form-block-assignee_contact_id">
- {if $action eq 4}
- <td class="label">{ts}Assigned To{/ts}</td><td class="view-value">
- {foreach from=$assignee_contact key=id item=name}
- <a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=$id"}">{$name}</a>;
- {/foreach}
- </td>
- {else}
- <td class="label">{ts}Assigned To{/ts}</td>
+ <td class="label">{$form.assignee_contact_id.label}</td>
<td>
- <a href="#" class="button" id="swap_target_assignee" title="{ts}Swap Target and Assignee Contacts{/ts}" style="float:right;">
- <span>
- <div class="icon swap-icon"></div>
- </span>
+ {$form.assignee_contact_id.html}
+ {if $action neq 4}
+ <a href="#" class="crm-hover-button" id="swap_target_assignee" title="{ts}Swap Target and Assignee Contacts{/ts}" style="position:relative; bottom: 1em;">
+ <span><div class="icon swap-icon"></div></span>
</a>
- {$form.assignee_contact_id.html}<br />
+ {/if}
+ <br />
{edit}
<span class="description">{ts}You can optionally assign this activity to someone. Assigned activities will appear in their Activities listing at CiviCRM Home.{/ts}
{if $activityAssigneeNotification}
</span>
{/edit}
</td>
- {/if}
</tr>
{if $activityTypeFile}
<td>{$form.followup_activity_subject.html|crmAddClass:huge}</td>
</tr>
<tr>
- <td class="label">{ts}Assign To{/ts}</td>
+ <td class="label">{$form.followup_assignee_contact_id.label}</td>
<td>{$form.followup_assignee_contact_id.html}
{edit}<span class="description">{ts}You can optionally assign this activity to someone. Assigned activities will appear in their Activities listing at CiviCRM Home.{/ts}
</span>
</div><!-- /.crm-accordion-wrapper -->
{literal}
<script type="text/javascript">
- cj(function() {
+ cj(function($) {
cj().crmAccordions();
cj('.crm-accordion-body').each( function() {
//open tab if form rule throws error
cj(this).parent('.collapsed').crmAccordionToggle();
}
});
- });
- cj('#swap_target_assignee').click( function() {
- var assignees = cj('input#assignee_contact_id').tokenInput("get");
- var targets = cj('input#contact_1').tokenInput("get");
- cj('#assignee_contact_id').tokenInput("clear");
- cj('#contact_1').tokenInput("clear");
- cj(assignees).each( function() {
- cj('#contact_1').tokenInput("add", this);
- });
- cj(targets).each( function() {
- cj('#assignee_contact_id').tokenInput("add", this);
+ $('#swap_target_assignee').click(function() {
+ var assignees = $('#assignee_contact_id').select2("data");
+ var targets = $('#target_contact_id').select2("data");
+ $('#assignee_contact_id').select2("data", targets);
+ $('#target_contact_id').select2("data", assignees);
+ return false;
});
- return false;
});
</script>
{/literal}