Migrate date field to datepicker on ChangeCaseType form
authorColeman Watts <coleman@civicrm.org>
Mon, 25 Feb 2019 19:12:54 +0000 (14:12 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 25 Feb 2019 19:12:54 +0000 (14:12 -0500)
CRM/Case/Form/Activity/ChangeCaseType.php
templates/CRM/Case/Form/Activity/ChangeCaseType.tpl

index 42c2f5bc59b6ff94aa0084fce82a301cf673120d..53fa4a051bbe1405541be445d2384ce9bb4ee825 100644 (file)
@@ -61,8 +61,7 @@ class CRM_Case_Form_Activity_ChangeCaseType {
 
     $defaults['is_reset_timeline'] = 1;
 
-    $defaults['reset_date_time'] = array();
-    list($defaults['reset_date_time'], $defaults['reset_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
+    $defaults['reset_date_time'] = date('Y-m-d H:i:s');
     $defaults['case_type_id'] = $form->_caseTypeId;
 
     return $defaults;
@@ -88,8 +87,8 @@ class CRM_Case_Form_Activity_ChangeCaseType {
     $form->addField('case_type_id', array('context' => 'create', 'entity' => 'Case'));
 
     // timeline
-    $form->addYesNo('is_reset_timeline', ts('Reset Case Timeline?'), NULL, TRUE, array('onclick' => "return showHideByValue('is_reset_timeline','','resetTimeline','table-row','radio',false);"));
-    $form->addDateTime('reset_date_time', ts('Reset Start Date'), FALSE, array('formatType' => 'activityDateTime'));
+    $form->addYesNo('is_reset_timeline', ts('Reset Case Timeline?'), NULL, TRUE);
+    $form->add('datepicker', 'reset_date_time', ts('Reset Start Date'), NULL, FALSE, ['allowClear' => FALSE]);
   }
 
   /**
@@ -123,10 +122,6 @@ class CRM_Case_Form_Activity_ChangeCaseType {
     if (CRM_Utils_Array::value('is_reset_timeline', $params) == 0) {
       unset($params['reset_date_time']);
     }
-    else {
-      // store the date with proper format
-      $params['reset_date_time'] = CRM_Utils_Date::processDate($params['reset_date_time'], $params['reset_date_time_time']);
-    }
   }
 
   /**
index 000cccb578e184a37eed1facd6b83b6556868561..34630c50f516d875d3cccb3f35a21ec4679be81b 100644 (file)
   <td class="label">{$form.is_reset_timeline.label}</td>
   <td>{$form.is_reset_timeline.html}</td>
     </tr>
-    <tr class="crm-case-changecasetype-form-block-reset_date_time" id="resetTimeline">
-        <td class="label">{$form.reset_date_time.label}</td>
-        <td>{include file="CRM/common/jcalendar.tpl" elementName=reset_date_time}</td>
+    <tr class="crm-case-changecasetype-form-block-reset_date_time">
+        <td class="label">{$form.reset_date_time.label} <span class="crm-marker">*</span></td>
+        <td>{$form.reset_date_time.html}</td>
     </tr>
-
-{include file="CRM/common/showHideByFieldValue.tpl"
-trigger_field_id    ="is_reset_timeline"
-trigger_value       = true
-target_element_id   ="resetTimeline"
-target_element_type ="table-row"
-field_type          ="radio"
-invert              = 0
-}
   </div>
+{literal}
+  <script type="text/javascript">
+    CRM.$(function($) {
+      var $form = $('form.{/literal}{$form.formClass}{literal}');
+      $('input[name=is_reset_timeline]', $form).click(function() {
+        $('.crm-case-changecasetype-form-block-reset_date_time').toggle($(this).val() === '1');
+      })
+    })
+  </script>
+{/literal}