From f7305cbcb394f20680895eb23937a07ace73cad6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 1 Feb 2014 21:07:10 -0800 Subject: [PATCH] CRM-13966 - Migrate activity source_contact_id to use select2 --- CRM/Activity/Form/Activity.php | 63 ++++--------------- CRM/Campaign/BAO/Campaign.php | 5 +- CRM/Case/Form/Activity.php | 5 +- CRM/Contact/Form/Task/EmailCommon.php | 2 +- templates/CRM/Activity/Form/Activity.tpl | 4 +- templates/CRM/Activity/Form/ActivityJs.tpl | 10 --- templates/CRM/Case/Form/Activity.tpl | 2 +- .../Form/ContributionPage/Settings.tpl | 2 +- 8 files changed, 21 insertions(+), 72 deletions(-) diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index 1b0fcc307c..0a73464eaf 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -510,10 +510,6 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { // if we're editing... if (isset($this->_activityId)) { - $defaults['source_contact_qid'] = CRM_Utils_Array::value('source_contact_id', - $defaults); - $defaults['source_contact_id'] = CRM_Utils_Array::value('source_contact', - $defaults); if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) { $target_contact_value = explode(';', trim($defaults['target_contact_value'])); @@ -573,9 +569,6 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $this->assign('assignee_contact_value', CRM_Utils_Array::value('assignee_contact_value', $defaults) ); - $this->assign('source_contact_value', - CRM_Utils_Array::value('source_contact', $defaults) - ); } // set default tags if exists @@ -588,8 +581,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $this->_targetContactId = $this->_currentlyViewedContactId; $target_contact = array(); - $defaults['source_contact_id'] = self::_getDisplayNameById($this->_sourceContactId); - $defaults['source_contact_qid'] = $this->_sourceContactId; + $defaults['source_contact_id'] = $this->_sourceContactId; if ($this->_context != 'standalone' && isset($this->_targetContactId)) { $target_contact[$this->_targetContactId] = self::_getDisplayNameById($this->_targetContactId); } @@ -690,8 +682,8 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $element = & $this->add('select', 'activity_type_id', ts('Activity Type'), $this->_fields['followup_activity_type_id']['attributes'], FALSE, array( - 'onchange' => - "CRM.buildCustomData( 'Activity', this.value );", + 'onchange' => "CRM.buildCustomData( 'Activity', this.value );", + 'class' => 'crm-select2', ) ); @@ -714,7 +706,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { if ($values['type'] == 'wysiwyg') { $this->addWysiwyg($field, $values['label'], $attribute, $required); } - else { + elseif ($field != 'source_contact_id') { $this->add($values['type'], $field, $values['label'], $attribute, $required); } } @@ -781,13 +773,6 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { //add followup date $this->addDateTime('followup_date', ts('in'), FALSE, array('formatType' => 'activityDateTime')); - //autocomplete url - $dataUrl = CRM_Utils_System::url("civicrm/ajax/rest", - "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=activity&reset=1", - FALSE, NULL, FALSE - ); - $this->assign('dataUrl', $dataUrl); - //tokeninput url $tokenUrl = CRM_Utils_System::url("civicrm/ajax/checkemail", "noemail=1", @@ -795,37 +780,22 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { ); $this->assign('tokenUrl', $tokenUrl); - $admin = CRM_Core_Permission::check('administer CiviCRM'); - //allow to edit source contact field field if context is civicase. - if ($this->_context == 'caseActivity') { - $admin = TRUE; - } - - $this->assign('admin', $admin); - - $sourceContactField = & $this->add($this->_fields['source_contact_id']['type'], + $sourceContactField = $this->addContactRef( 'source_contact_id', $this->_fields['source_contact_id']['label'], - NULL, - $admin + array('class' => 'huge'), + TRUE ); + // Only admins and case-workers can change the activity source + if (!CRM_Core_Permission::check('administer CiviCRM') && $this->_context != 'caseActivity') { + $sourceContactField->freeze(); + } - $followupAssigneeContactField =& $this->add( 'text', 'followup_assignee_contact_id', ts('assignee') ); - - $this->add('hidden', 'source_contact_qid', '', array('id' => 'source_contact_qid')); CRM_Contact_Form_NewContact::buildQuickForm($this); $this->add('text', 'assignee_contact_id', ts('assignee')); $this->add( 'text', 'followup_assignee_contact_id', ts('assignee')); - if ($sourceContactField->getValue()) { - $this->assign('source_contact', $sourceContactField->getValue()); - } - elseif ($this->_currentUserId) { - // we're setting currently LOGGED IN user as source for this activity - $this->assign('source_contact_value', self::_getDisplayNameById($this->_currentUserId)); - } - //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Activity'); $this->assign('customDataSubType', $this->_activityTypeId); @@ -835,7 +805,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { if (!empty($tags)) { $this->add('select', 'tag', ts('Tags'), $tags, FALSE, - array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2') + array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2 huge') ); } @@ -940,12 +910,6 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { if (array_key_exists('activity_type_id', $fields) && empty($fields['activity_type_id'])) { $errors['activity_type_id'] = ts('Activity Type is required field.'); } - //FIX me temp. comment - // make sure if associated contacts exist - - if ($fields['source_contact_id'] && !is_numeric($fields['source_contact_qid'])) { - $errors['source_contact_id'] = ts('Source Contact non-existent!'); - } if (CRM_Utils_Array::value('activity_type_id', $fields) == 3 && CRM_Utils_Array::value('status_id', $fields) == 1 @@ -1051,9 +1015,6 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } - else { - $params['source_contact_id'] = $this->_submitValues['source_contact_qid']; - } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; diff --git a/CRM/Campaign/BAO/Campaign.php b/CRM/Campaign/BAO/Campaign.php index e2b163d082..f3f227989c 100644 --- a/CRM/Campaign/BAO/Campaign.php +++ b/CRM/Campaign/BAO/Campaign.php @@ -563,8 +563,9 @@ INNER JOIN civicrm_group grp ON ( grp.id = campgrp.entity_id ) $campaign = &$form->add('select', 'campaign_id', ts('Campaign'), - array( - '' => ts('- select -')) + $campaigns + array('' => ts('- select -')) + $campaigns, + FALSE, + array('class' => 'crm-select2') ); //lets freeze when user does not has access or campaign is disabled. if (!$isCampaignEnabled || !$hasAccessCampaign) { diff --git a/CRM/Case/Form/Activity.php b/CRM/Case/Form/Activity.php index eec34dd03e..eb0d6fcc64 100644 --- a/CRM/Case/Form/Activity.php +++ b/CRM/Case/Form/Activity.php @@ -262,7 +262,7 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity { public function buildQuickForm() { $this->_fields['source_contact_id']['label'] = ts('Reported By'); - $this->_fields['status_id']['attributes'] = array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(); + unset($this->_fields['status_id']['attributes']['required']); if ($this->_caseType) { $xmlProcessor = new CRM_Case_XMLProcessor_Process(); @@ -401,9 +401,6 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); - if ($params['source_contact_id']) { - $params['source_contact_id'] = $params['source_contact_qid']; - } //set parent id if its edit mode if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) { diff --git a/CRM/Contact/Form/Task/EmailCommon.php b/CRM/Contact/Form/Task/EmailCommon.php index 232c890535..1cd6b8f6af 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -252,7 +252,7 @@ class CRM_Contact_Form_Task_EmailCommon { $form->add('text', 'subject', ts('Subject'), 'size=50 maxlength=254', TRUE); - $form->add('select', 'fromEmailAddress', ts('From'), $form->_fromEmails, TRUE); + $form->add('select', 'fromEmailAddress', ts('From'), $form->_fromEmails, TRUE, array('class' => 'crm-select2 huge')); CRM_Mailing_BAO_Mailing::commonCompose($form); diff --git a/templates/CRM/Activity/Form/Activity.tpl b/templates/CRM/Activity/Form/Activity.tpl index 0a6f7720f4..4f78cc630e 100644 --- a/templates/CRM/Activity/Form/Activity.tpl +++ b/templates/CRM/Activity/Form/Activity.tpl @@ -77,7 +77,7 @@ {$form.source_contact_id.label} - {if $admin and $action neq 4}{$form.source_contact_id.html} {else} {$source_contact_value} {/if} + {$form.source_contact_id.html} @@ -123,7 +123,7 @@
- {$form.assignee_contact_id.html} + {$form.assignee_contact_id.html}
{edit} {ts}You can optionally assign this activity to someone. Assigned activities will appear in their Activities listing at CiviCRM Home.{/ts} {if $activityAssigneeNotification} diff --git a/templates/CRM/Activity/Form/ActivityJs.tpl b/templates/CRM/Activity/Form/ActivityJs.tpl index e8753aa6e2..6f73d0d80d 100644 --- a/templates/CRM/Activity/Form/ActivityJs.tpl +++ b/templates/CRM/Activity/Form/ActivityJs.tpl @@ -56,22 +56,12 @@ } cj(function( ) { - {/literal} - {if $source_contact and $admin and $action neq 4} - {literal} cj( '#source_contact_id' ).val( "{/literal}{$source_contact}{literal}");{/literal} - {/if} - {literal} - - var sourceDataUrl = "{/literal}{$dataUrl}{literal}"; var tokenDataUrl_assignee = "{/literal}{$tokenUrl}&context={$tokenContext}_assignee{literal}"; var hintText = "{/literal}{ts escape='js'}Start typing a name or email address.{/ts}{literal}"; cj( "#assignee_contact_id").tokenInput( tokenDataUrl_assignee, { prePopulate: assignee_contact, theme: 'facebook', hintText: hintText }); cj( "#followup_assignee_contact_id").tokenInput( tokenDataUrl_assignee, { prePopulate: followup_assignee_contact, theme: 'facebook', hintText: hintText }); cj( 'ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px' ); - cj('#source_contact_id').autocomplete( sourceDataUrl, { width : 180, selectFirst : false, hintText: hintText, matchContains: true, minChars: 1, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal} - }).result( function(event, data, formatted) { cj( "#source_contact_qid" ).val( data[1] ); - }).bind( 'click', function( ) { if (!cj("#source_contact_id").val()) { cj( "#source_contact_qid" ).val(''); } }); }); /** diff --git a/templates/CRM/Case/Form/Activity.tpl b/templates/CRM/Case/Form/Activity.tpl index 3cfb2cb5ba..da2660c4e5 100644 --- a/templates/CRM/Case/Form/Activity.tpl +++ b/templates/CRM/Case/Form/Activity.tpl @@ -100,7 +100,7 @@ {ts}Assigned To{/ts} - {$form.assignee_contact_id.html} + {$form.assignee_contact_id.html}
{edit} {ts}You can optionally assign this activity to someone.{/ts} diff --git a/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl b/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl index 54d8327c64..c6e24d5d9e 100644 --- a/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl +++ b/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl @@ -138,7 +138,7 @@ {$form.soft_credit_types.label} -
{$form.soft_credit_types.html}
+
{$form.soft_credit_types.html|crmAddClass:huge}
-- 2.25.1