Upgrade age_asof_date to datepicker in search
authorColeman Watts <coleman@civicrm.org>
Mon, 25 Feb 2019 23:55:44 +0000 (18:55 -0500)
committerColeman Watts <coleman@civicrm.org>
Wed, 27 Feb 2019 15:07:32 +0000 (10:07 -0500)
CRM/Contact/Form/Search/Criteria.php
CRM/Upgrade/Incremental/Base.php
CRM/Upgrade/Incremental/SmartGroups.php
CRM/Upgrade/Incremental/php/FiveEleven.php
CRM/Upgrade/Incremental/php/FiveTwelve.php
templates/CRM/Core/AgeRange.tpl
tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php

index 019ee5f3dac2eb5e12840308a79c11cc9de5bb1b..7862472f7f709e4f9d84ae1926a38cbc6abd1ff4 100644 (file)
@@ -494,7 +494,7 @@ class CRM_Contact_Form_Search_Criteria {
   }
 
   /**
-   * @param $form
+   * @param CRM_Core_Form_Search $form
    */
   public static function demographics(&$form) {
     $form->add('hidden', 'hidden_demographics', 1);
@@ -509,11 +509,11 @@ class CRM_Contact_Form_Search_Criteria {
     }
     $form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('allowClear', TRUE);
 
-    $form->add('text', 'age_low', ts('Min Age'), array('size' => 6));
+    $form->add('number', 'age_low', ts('Min Age'), ['class' => 'four', 'min' => 0]);
     $form->addRule('age_low', ts('Please enter a positive integer'), 'positiveInteger');
-    $form->add('text', 'age_high', ts('Max Age'), array('size' => 6));
+    $form->add('number', 'age_high', ts('Max Age'), ['class' => 'four', 'min' => 0]);
     $form->addRule('age_high', ts('Please enter a positive integer'), 'positiveInteger');
-    $form->addDate('age_asof_date', ts('Age as of Date'), FALSE, array('formatType' => 'searchDate'));
+    $form->add('datepicker', 'age_asof_date', ts('As of'), NULL, FALSE, ['time' => FALSE]);
 
     CRM_Core_Form_Date::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
 
index 5a7770673bec79002e41fabdae7b3c2461c0e3db..4d53374bd264605b8148d4221d4e2bddff367d40 100644 (file)
@@ -199,13 +199,13 @@ class CRM_Upgrade_Incremental_Base {
    * Do any relevant smart group updates.
    *
    * @param CRM_Queue_TaskContext $ctx
-   * @param string $version
+   * @param array $actions
    *
    * @return bool
    */
-  public function updateSmartGroups($ctx, $version) {
-    $groupUpdateObject = new CRM_Upgrade_Incremental_SmartGroups($version);
-    $groupUpdateObject->updateGroups();
+  public function updateSmartGroups($ctx, $actions) {
+    $groupUpdateObject = new CRM_Upgrade_Incremental_SmartGroups();
+    $groupUpdateObject->updateGroups($actions);
     return TRUE;
   }
 
index c22daf39416a6482624a85b3edd8efea07a8c5f8..c2161f43022389a91ab15bf5a3f7132a70b98ba8 100644 (file)
 class CRM_Upgrade_Incremental_SmartGroups {
 
   /**
-   * Version we are upgrading to.
-   *
-   * @var string
-   */
-  protected $upgradeVersion;
-
-  /**
-   * @return string
-   */
-  public function getUpgradeVersion() {
-    return $this->upgradeVersion;
-  }
-
-  /**
-   * @param string $upgradeVersion
-   */
-  public function setUpgradeVersion($upgradeVersion) {
-    $this->upgradeVersion = $upgradeVersion;
-  }
-
-  /**
-   * CRM_Upgrade_Incremental_MessageTemplates constructor.
-   *
-   * @param string $upgradeVersion
-   */
-  public function __construct($upgradeVersion) {
-    $this->setUpgradeVersion($upgradeVersion);
-  }
-
-  /**
-   * Get any conversions required for saved smart groups.
-   *
-   * @return array
+   * Perform updates specified by upgrade function.
    */
-  public function getSmartGroupConversions() {
-    return [
-      [
-        'version' => '5.11.alpha1',
-        'upgrade_descriptors' => [ts('Upgrade grant smart groups to datepicker format')],
-        'actions' => [
-          'function' => 'datepickerConversion',
-          'fields' => [
-            'grant_application_received_date',
-            'grant_decision_date',
-            'grant_money_transfer_date',
-            'grant_due_date'
-          ]
-        ]
-      ]
-    ];
+  public function updateGroups($actions) {
+    foreach ($actions as $func => $fields) {
+      $this->{$func}($fields);
+    }
   }
 
   /**
@@ -118,33 +74,6 @@ class CRM_Upgrade_Incremental_SmartGroups {
     }
   }
 
-  /**
-   * Update message templates.
-   */
-  public function updateGroups() {
-    $conversions = $this->getSmartGroupConversionsToApply();
-    foreach ($conversions as $conversion) {
-      $function = $conversion['function'];
-      $this->{$function}($conversion['fields']);
-    }
-  }
-
-  /**
-   * Get any required template updates.
-   *
-   * @return array
-   */
-  public function getSmartGroupConversionsToApply() {
-    $conversions = $this->getSmartGroupConversions();
-    $return = [];
-    foreach ($conversions as $conversion) {
-      if ($conversion['version'] === $this->getUpgradeVersion()) {
-        $return[] = $conversion['actions'];
-      }
-    }
-    return $return;
-  }
-
   /**
    * Get converted date value.
    *
index 1335f4ed353e0c2f075b73674812ccaa3fca2eb6..ed3e296d03a61e1d3ff645198a8dc54c78f13140 100644 (file)
@@ -74,7 +74,14 @@ class CRM_Upgrade_Incremental_php_FiveEleven extends CRM_Upgrade_Incremental_Bas
    */
   public function upgrade_5_11_alpha1($rev) {
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
-    $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', $rev);
+    $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
+      'datepickerConversion' => [
+        'grant_application_received_date',
+        'grant_decision_date',
+        'grant_money_transfer_date',
+        'grant_due_date'
+      ]
+    ]);
   }
 
 }
index 6cea3934b1eee46c1cd632852a7a261fc5b34f2f..e514d65329878b2e036977cd58a227aa61cd35cc 100644 (file)
@@ -67,21 +67,18 @@ class CRM_Upgrade_Incremental_php_FiveTwelve extends CRM_Upgrade_Incremental_Bas
    * (change the x in the function name):
    */
 
-  //  /**
-  //   * Upgrade function.
-  //   *
-  //   * @param string $rev
-  //   */
-  //  public function upgrade_5_0_x($rev) {
-  //    $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
-  //    $this->addTask('Do the foo change', 'taskFoo', ...);
-  //    // Additional tasks here...
-  //    // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
-  //    // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
-  //  }
-
-  // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
-  //   return TRUE;
-  // }
+  /**
+   * Upgrade function.
+   *
+   * @param string $rev
+   */
+  public function upgrade_5_12_alpha1($rev) {
+    $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
+    $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
+      'datepickerConversion' => [
+        'age_asof_date',
+      ]
+    ]);
+  }
 
 }
index a76ad74a9720ef7b2096cb90a8e269c35141f576..beddf36277cc73fc61ddad3b987ab1df96971208 100644 (file)
       {$form.$maxName.html}
     </span>
   </span>
-</td>
-<td>
   <span class="crm-age-range-asofdate">
-      {assign var=dateName   value=$fieldName|cat:$date}
-      {$form.$dateName.label}
-      {include file="CRM/common/jcalendar.tpl" elementName=$dateName}
+    {assign var=dateName value=$fieldName|cat:$date}
+    {$form.$dateName.label}
+    {$form.$dateName.html}
   </span>
   {literal}
     <script type="text/javascript">
-      cj(".crm-age-range").change(function() {
-        if (cj('.crm-age-range-min :text').val() || cj('.crm-age-range-max :text').val()) {
-          cj(".crm-age-range-asofdate").show();
-        } else {
-          cj(".crm-age-range-asofdate").hide();
+      CRM.$(function($) {
+        var $form = $('form.{/literal}{$form.formClass}{literal}');
+        function toggleDate() {
+          $(".crm-age-range-asofdate").toggle(!!($('.crm-age-range-min input', $form).val() || $('.crm-age-range-max input', $form).val()));
         }
-      }).change();
+        $('.crm-age-range input', $form).on('keyup change', toggleDate);
+        toggleDate();
+      });
+
     </script>
   {/literal}
 </td>
index 7137e61e94b56ddabeb7d76cd2f2d44630147662..b3a3af74293b9dd088639267c4899857b31671d8 100644 (file)
@@ -90,8 +90,15 @@ class CRM_Upgrade_Incremental_BaseTest extends CiviUnitTestCase {
          ['grant_due_date_low', '=', '01/22/2019'],
        ]
     ]);
-    $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups('5.11.alpha1');
-    $smartGroupConversionObject->updateGroups();
+    $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups();
+    $smartGroupConversionObject->updateGroups([
+      'datepickerConversion' => [
+        'grant_application_received_date',
+        'grant_decision_date',
+        'grant_money_transfer_date',
+        'grant_due_date'
+      ]
+    ]);
     $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []);
     $this->assertEquals('grant_application_received_date_high', $savedSearch['form_values'][0][0]);
     $this->assertEquals('2019-01-20 00:00:00', $savedSearch['form_values'][0][2]);