CRM-13966 - Migrate activity source_contact_id to use select2
authorColeman Watts <coleman@civicrm.org>
Sun, 2 Feb 2014 05:07:10 +0000 (21:07 -0800)
committerColeman Watts <coleman@civicrm.org>
Sun, 2 Feb 2014 05:07:10 +0000 (21:07 -0800)
CRM/Activity/Form/Activity.php
CRM/Campaign/BAO/Campaign.php
CRM/Case/Form/Activity.php
CRM/Contact/Form/Task/EmailCommon.php
templates/CRM/Activity/Form/Activity.tpl
templates/CRM/Activity/Form/ActivityJs.tpl
templates/CRM/Case/Form/Activity.tpl
templates/CRM/Contribute/Form/ContributionPage/Settings.tpl

index 1b0fcc307ca480525db9a1d94c100bfe9b730503..0a73464eaf95e0e001f6a69986c87565f5ac1512 100644 (file)
@@ -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;
index e2b163d08263893b3f07af1a2cb23db0424f4122..f3f227989c84f657474020fc5628141a61b9d40b 100644 (file)
@@ -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) {
index eec34dd03e21bc2d4dc48121d08934aaa9d02ba3..eb0d6fcc6465a97de5eaf99a6aabafc3d5acf8d6 100644 (file)
@@ -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)) {
index 232c890535735ea26d8818895376e147a31e82af..1cd6b8f6afe6ae1e15642f99337d5a52ead131fc 100644 (file)
@@ -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);
 
index 0a6f7720f4f4be177febeae5f0d4130e674c507b..4f78cc630e6631dec92746294d08a50c44a6b7ba 100644 (file)
@@ -77,7 +77,7 @@
   <tr class="crm-activity-form-block-source_contact_id">
     <td class="label">{$form.source_contact_id.label}</td>
     <td class="view-value">
-      {if $admin and $action neq 4}{$form.source_contact_id.html} {else} {$source_contact_value} {/if}
+      {$form.source_contact_id.html}
     </td>
   </tr>
 
             <div class="icon swap-icon"></div>
           </span>
         </a>
-        {$form.assignee_contact_id.html}
+        {$form.assignee_contact_id.html}<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}
index e8753aa6e276c671bfd6e62e29cdfed1cc06821b..6f73d0d80d9a79bd9795b5107e4dcf212577d40f 100644 (file)
        }
 
   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(''); } });
   });
 
   /**
index 3cfb2cb5bab9af9f848262c7802c530d946f9fad..da2660c4e5f5094dc96658516c95224410f9bbe4 100644 (file)
     </tr>
     <tr class="crm-case-activity-form-block-assignee_contact_id">
       <td class="label">{ts}Assigned To{/ts}</td>
-      <td>{$form.assignee_contact_id.html}
+      <td>{$form.assignee_contact_id.html}<br />
         {edit}
           <span class="description">
           {ts}You can optionally assign this activity to someone.{/ts}
index 54d8327c642e7ee464ffa859f0e63cfaa944ee92..c6e24d5d9ec7c19a92a1735e807f723207cd5b23 100644 (file)
           {$form.soft_credit_types.label}
       </td>
       <td>
-          <dt style="text-align:left;">{$form.soft_credit_types.html}</dt>
+          <dt style="text-align:left;">{$form.soft_credit_types.html|crmAddClass:huge}</dt>
           <dd>
               <a class="optionvalue-link" href="#" title='Click to edit available soft credit types'>
                   <span class="batch-edit"></span>