CRM-16019 - Switch custom fields to use crmDatepicker
authorColeman Watts <coleman@civicrm.org>
Mon, 21 Dec 2015 02:35:46 +0000 (21:35 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 22 Dec 2015 03:30:47 +0000 (22:30 -0500)
CRM/Contact/Form/Search/Criteria.php
CRM/Core/BAO/CustomField.php
CRM/Core/BAO/CustomGroup.php
CRM/Core/Form.php
js/Common.js
templates/CRM/Contact/Form/Edit/Address/CustomField.tpl
templates/CRM/Custom/Form/CustomField.tpl
templates/CRM/Custom/Form/Preview.tpl
templates/CRM/Custom/Form/Search.tpl
templates/CRM/UF/Form/Preview.tpl

index 15163ee9cca6d4cb233a465baae7a278a788a4e8..9c0e424ad55656745e88ea48339966cf26a214ba 100644 (file)
@@ -533,16 +533,11 @@ class CRM_Contact_Form_Search_Criteria {
       foreach ($group['fields'] as $field) {
         $fieldId = $field['id'];
         $elementName = 'custom_' . $fieldId;
-        if ($field['data_type'] == 'Date' && $field['is_search_range']) {
-          CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE);
-        }
-        else {
-          CRM_Core_BAO_CustomField::addQuickFormElement($form,
-            $elementName,
-            $fieldId,
-            FALSE, FALSE, TRUE
-          );
-        }
+        CRM_Core_BAO_CustomField::addQuickFormElement($form,
+          $elementName,
+          $fieldId,
+          FALSE, FALSE, TRUE
+        );
       }
     }
   }
index 022a8236695510c2b27490a2ae230e9f7df77634..b43cf5fe9d3c30907e4074cf7feea94f8c764b55 100644 (file)
@@ -835,7 +835,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
       $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array(
         'field' => "custom_$fieldId",
         'context' => $search ? 'search' : 'create',
-      ), array()));
+      )), array());
 
       // Consolidate widget types to simplify the below switch statement
       if ($search || ($widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE)) {
@@ -909,37 +909,19 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         break;
 
       case 'Select Date':
+        $attr = array('data-crm-custom' => $dataCrmCustomVal);
+        $params = array(
+          'date' => $field->date_format,
+          'minDate' => isset($field->start_date_years) ? (date('Y') - $field->start_date_years) . '-01-01' : NULL,
+          'maxDate' => isset($field->end_date_years) ? (date('Y') + $field->end_date_years) . '-01-01' : NULL,
+          'time' => $field->time_format ? $field->time_format * 12 : FALSE,
+        );
         if ($field->is_search_range && $search) {
-          $qf->addDate($elementName . '_from', $label . ' - ' . ts('From'), FALSE,
-            array(
-              'format' => $field->date_format,
-              'timeFormat' => $field->time_format,
-              'startOffset' => $field->start_date_years,
-              'endOffset' => $field->end_date_years,
-              'data-crm-custom' => $dataCrmCustomVal,
-            )
-          );
-
-          $qf->addDate($elementName . '_to', ts('To'), FALSE,
-            array(
-              'format' => $field->date_format,
-              'timeFormat' => $field->time_format,
-              'startOffset' => $field->start_date_years,
-              'endOffset' => $field->end_date_years,
-              'data-crm-custom' => $dataCrmCustomVal,
-            )
-          );
+          $qf->add('datepicker', $elementName . '_from', $label, $attr + array('placeholder' => ts('From')), FALSE, $params);
+          $qf->add('datepicker', $elementName . '_to', NULL, $attr + array('placeholder' => ts('To')), FALSE, $params);
         }
         else {
-          $required = $useRequired && !$search;
-
-          $qf->addDate($elementName, $label, $required, array(
-            'format' => $field->date_format,
-            'timeFormat' => $field->time_format,
-            'startOffset' => $field->start_date_years,
-            'endOffset' => $field->end_date_years,
-            'data-crm-custom' => $dataCrmCustomVal,
-          ));
+          $qf->add('datepicker', $elementName, $label, $attr, $useRequired && !$search, $params);
         }
         break;
 
@@ -1370,17 +1352,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         }
         break;
 
-      case 'Select Date':
-        if ($value) {
-          list($defaults[$elementName], $defaults[$elementName . '_time']) = CRM_Utils_Date::setDateDefaults(
-            $value,
-            NULL,
-            $customField->date_format,
-            $customField->time_format
-          );
-        }
-        break;
-
       case 'Autocomplete-Select':
         if ($customField->data_type == 'ContactReference') {
           if (is_numeric($value)) {
index f27a4563417f47c7f3285f670e2ba9d99624a259..dafb03aed759e8f8b15f0ccf8b2eae9952283cbd 100644 (file)
@@ -1366,23 +1366,6 @@ ORDER BY civicrm_custom_group.weight,
             }
             break;
 
-          case 'Select Date':
-            if (isset($value)) {
-              if (empty($field['time_format'])) {
-                list($defaults[$elementName]) = CRM_Utils_Date::setDateDefaults($value, NULL,
-                  $field['date_format']
-                );
-              }
-              else {
-                $timeElement = $elementName . '_time';
-                if (substr($elementName, -1) == ']') {
-                  $timeElement = substr($elementName, 0, -1) . '_time]';
-                }
-                list($defaults[$elementName], $defaults[$timeElement]) = CRM_Utils_Date::setDateDefaults($value, NULL, $field['date_format'], $field['time_format']);
-              }
-            }
-            break;
-
           case 'Multi-Select Country':
           case 'Multi-Select State/Province':
             if (isset($value)) {
@@ -1561,9 +1544,6 @@ ORDER BY civicrm_custom_group.weight,
   public static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = FALSE, $prefix = '') {
     $form->assign_by_ref("{$prefix}groupTree", $groupTree);
 
-    // this is fix for date field
-    $form->assign('currentYear', date('Y'));
-
     foreach ($groupTree as $id => $group) {
       CRM_Core_ShowHideBlocks::links($form, $group['title'], '', '');
       foreach ($group['fields'] as $field) {
index 57619a4ce1e82d2f58243a6346ff2f4885f2d4b8..c387db99a67f18d8951d48a8b3174666c2e98085 100644 (file)
@@ -1699,13 +1699,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Add date.
    *
-   * @code
-   * // if you need time
-   * $attributes = array(
-   *   'addTime' => true,
-   *   'formatType' => 'relative' or 'birth' etc check advanced date settings
-   * );
-   * @endcode
+   * @deprecated
+   * Use $this->add('datepicker', ...) instead.
    *
    * @param string $name
    *   Name of the element.
@@ -1795,7 +1790,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   }
 
   /**
-   *  Function that will add date and time.
+   * Function that will add date and time.
+   *
+   * @deprecated
+   * Use $this->add('datepicker', ...) instead.
    *
    * @param string $name
    * @param string $label
index 6a3577806376ead3c5cdda2e3e927d6f82e56625..2dbf522b22906527c718617b9cd8611043e0a2c0 100644 (file)
@@ -643,8 +643,10 @@ if (!CRM.vars) CRM.vars = {};
         copyAttributes($dataField, $dateField, ['placeholder', 'style', 'class', 'disabled']);
         $dateField.addClass('crm-form-text crm-form-date');
         settings.date = typeof settings.date === 'string' ? settings.date : CRM.config.dateInputFormat;
-        settings.changeMonth = _.includes('m', settings.date);
-        settings.changeYear = _.includes('y', settings.date);
+        settings.changeMonth = _.includes(settings.date, 'm');
+        settings.changeYear = _.includes(settings.date, 'y');
+        settings.minDate = settings.minDate ? CRM.utils.makeDate(settings.minDate) : null;
+        settings.maxDate = settings.maxDate ? CRM.utils.makeDate(settings.maxDate) : null;
         $dateField.datepicker(settings).change(updateDataField);
       }
       // Rudimentary validation. TODO: Roll into use of jQUery validate and ui.datepicker.validation
index 9b785e2e19d974d2e9dc03841fd9603a1713d139..8a1bade7d3e3415ebab2540d5761404547629db6 100644 (file)
         <tr>
             <td class="label">{$form.address.$blockId.$element_name.label}</td>
             <td class="html-adjust">
-                {if $element.data_type neq 'Date'}
-                    {$form.address.$blockId.$element_name.html}&nbsp;
-                {elseif $element.skip_calendar NEQ true }
-                    {include file="CRM/common/jcalendar.tpl" blockId=$blockId blockSection='address' elementName=$element_name}
-                {/if}
+                {$form.address.$blockId.$element_name.html}&nbsp;
 
                 {if $element.data_type eq 'File'}
                     {if $element.element_value.data}
index 2199c2a2be7d53562a2dc3721db6330d72b1ae8a..43cf47a6abcdf062e208a947efeec3e3ab7ec4e9 100644 (file)
         <tr class="custom_field-row {$element.element_name}-row">
             <td class="label">{$form.$element_name.label}{if $element.help_post}{help id=$element.id file="CRM/Custom/Form/CustomField.hlp" title=$element.label}{/if}</td>
             <td class="html-adjust">
-                {if $element.data_type neq 'Date' OR ($element.data_type eq 'Date' AND $element.is_view eq 1)}
-                    {$form.$element_name.html}&nbsp;
-                {elseif $element.skip_calendar NEQ true}
-                    {include file="CRM/common/jcalendar.tpl" elementName=$element_name}
-                {/if}
-
+                {$form.$element_name.html}&nbsp;
                 {if $element.data_type eq 'File'}
                     {if $element.element_value.data}
                       <div class="crm-attachment-wrapper crm-entity" id="file_{$element_name}">
index eddedc94dcba28666ef06651ca95bd670c48cc53..b8bcfd0a3032959daba770193efa400beb3cc075 100644 (file)
         <tr>
           <td class="label">{$form.$element_name.label}{if $element.help_post}{help id=$element.id file="CRM/Custom/Form/CustomField.hlp" title=$form.$element_name.label}{/if}</td>
         <td>
-      {if $element.data_type neq 'Date'}
-            {$form.$element_name.html}&nbsp;
-        {elseif $element.skip_calendar NEQ true }
-            {include file="CRM/common/jcalendar.tpl" elementName=$element_name}
-        {/if}
+          {$form.$element_name.html}&nbsp;
       {if $element.html_type eq 'Autocomplete-Select'}
           {if $element.data_type eq 'ContactReference'}
                   {include file="CRM/Custom/Form/ContactReference.tpl"}
index bda7ef3bbce74d0e52cea61cd51ed8c144b38210..0f69732785701f95a2a86f0f6afe23a9796613ab 100644 (file)
                 {assign var="element_name_from" value=$element_name|cat:"_from"}
                 {assign var="element_name_to" value=$element_name|cat:"_to"}
                 <tr>
-                {if $element.data_type neq 'Date'}
                     <td class="label">{$form.$element_name_from.label}</td><td>
                     {$form.$element_name_from.html|crmAddClass:six}
                     &nbsp;&nbsp;{$form.$element_name_to.label}&nbsp;&nbsp;{$form.$element_name_to.html|crmAddClass:six}
-                {elseif $element.skip_calendar NEQ true }
-                    <td class="label"><label for='{$element_name}'>{$element.label}</label>
-                    {include file="CRM/Core/DateRange.tpl" fieldName=$element_name from='_from' to='_to'}</td><td>
-                {/if}
             {else}
                 <td class="label">{$form.$element_name.label}</td><td>
-                {if $element.data_type neq 'Date'}
-                    {$form.$element_name.html}
-                {elseif $element.skip_calendar NEQ true }
-                    {include file="CRM/common/jcalendar.tpl" elementName=$element_name}
-                {/if}
+                  {$form.$element_name.html}
                 {if !empty($form.$operator_name)}
                   <span class="crm-multivalue-search-op" for="{$element_name}">{$form.$operator_name.html}</span>
                   {assign var="add_multivalue_js" value=true}
index 239b1d68f9877079df54ae5d0405c83afe0196b0..024fbf0273a5b6da00216b3d62649372e12d295c 100644 (file)
                 {include file="CRM/Contact/Form/Edit/TagsAndGroups.tpl" type=$n}
               {elseif $n eq 'email_greeting' or  $n eq 'postal_greeting' or $n eq 'addressee'}
                 {include file="CRM/Profile/Form/GreetingType.tpl"}
-              {elseif ( $field.data_type eq 'Date' AND $element.skip_calendar NEQ true ) or
-                ( $n|substr:-5:5 eq '_date' ) or ( $field.name eq 'activity_date_time' )  }
+              {elseif ( $n|substr:-5:5 eq '_date' ) or ( $field.name eq 'activity_date_time' )  }
                 {include file="CRM/common/jcalendar.tpl" elementName=$form.$n.name}
               {elseif $n|substr:0:5 eq 'phone'}
                 {assign var="phone_ext_field" value=$n|replace:'phone':'phone_ext'}