Skip to content

Commit

Permalink
Migrate to a datepicker range
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Dec 4, 2018
1 parent dddca45 commit ac4397a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 38 deletions.
28 changes: 28 additions & 0 deletions CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,34 @@ public function addDateRange($name, $from = '_from', $to = '_to', $label = 'From
}
}

/**
* Add a search for a range using date picker fields.
*
* @param string $fieldName
* @param string $label
* @param string $dateFormat
* @param bool $required
*/
public function addDatePickerRange($fieldName, $label, $required = FALSE, $fromLabel = 'From', $toLabel = 'To', $dateFormat ='') {

$options = array(
'' => ts('- any -'),
0 => ts('Choose Date Range'),
) + CRM_Core_OptionGroup::values('relative_date_filters');

$this->add('select',
"{$fieldName}_relative",
$label,
$options,
$required,
NULL
);
$attributes = ['format' => 'searchDate'];
$extra = ['time' => FALSE];
$this->add('datepicker', $fieldName . '_low', ts($fromLabel), $attributes, $required, $extra);
$this->add('datepicker', $fieldName . '_high', ts($toLabel), $attributes, $required, $extra);
}

/**
* Based on form action, return a string representing the api action.
* Used by addField method.
Expand Down
3 changes: 1 addition & 2 deletions CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public function addFormFieldsFromMetadata() {
foreach ($fields as $fieldName => $fieldSpec) {
if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE) {
// Assuming time is false for now as we are not checking for date-time fields as yet.
$this->add('datepicker', $fieldName . '_low', $fieldSpec['title'], [], FALSE, ['time' => FALSE]);
$this->add('datepicker', $fieldName . '_high', $fieldSpec['title'], [], FALSE, ['time' => FALSE]);
$this->addDatePickerRange($fieldName, $fieldSpec['title'], FALSE);
}
else {
$this->addField($fieldName, ['entity' => $entity]);
Expand Down
57 changes: 57 additions & 0 deletions templates/CRM/Core/DatePickerRange.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{*this is included inside a table row*}
{assign var=relativeName value=$fieldName|cat:"_relative"}

<td colspan=2>
{$form.$relativeName.label}
{$form.$relativeName.html}<br />
<span class="crm-absolute-date-range">
<span class="crm-absolute-date-from">
{assign var=fromName value=$fieldName|cat:$from}
{$form.$fromName.label}
{$form.$fromName.html}
</span>
<span class="crm-absolute-date-to">
{assign var=toName value=$fieldName|cat:$to}
{$form.$toName.label}
{$form.$toName.html}
</span>
</span>
{literal}
<script type="text/javascript">
cj("#{/literal}{$relativeName}{literal}").change(function() {
var n = cj(this).parent().parent();
if (cj(this).val() == "0") {
cj(".crm-absolute-date-range", n).show();
} else {
cj(".crm-absolute-date-range", n).hide();
cj(':text', n).val('');
}
}).change();
</script>
{/literal}
</td>
44 changes: 8 additions & 36 deletions templates/CRM/Grant/Form/Search/Common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,48 +50,20 @@
</td>
</tr>
<tr>
<td>
{$form.grant_application_received_date_low.label}<br />
{$form.grant_application_received_date_low.html}
</td>
<td colspan="2">
{$form.grant_application_received_date_high.label}<br />
{$form.grant_application_received_date_high.html}
&nbsp;{$form.grant_application_received_notset.html}&nbsp;&nbsp;{$form.grant_application_received_notset.label}
</td>
{include file="CRM/Core/DatePickerRange.tpl" fieldName="grant_application_received_date" from='_low' to='_high'}
&nbsp;{$form.grant_application_received_notset.html}&nbsp;&nbsp;{$form.grant_application_received_notset.label}
</tr>
<tr>
<td>
{$form.grant_decision_date_low.label}<br />
{$form.grant_decision_date_low.html}
</td>
<td colspan="2">
{$form.grant_decision_date_high.label}<br />
{$form.grant_decision_date_high.html}
&nbsp;{$form.grant_decision_date_notset.html}&nbsp;&nbsp;{$form.grant_decision_date_notset.label}
</td>
{include file="CRM/Core/DatePickerRange.tpl" fieldName="grant_decision_date" from='_low' to='_high'}
&nbsp;{$form.grant_decision_date_notset.html}&nbsp;&nbsp;{$form.grant_decision_date_notset.label}
</tr>
<tr>
<td>
{$form.grant_money_transfer_date_low.label}<br />
{$form.grant_money_transfer_date_low.html}
</td>
<td colspan="2">
{$form.grant_money_transfer_date_high.label}<br />
{$form.grant_money_transfer_date_high.html}
&nbsp;{$form.grant_money_transfer_date_notset.html}&nbsp;&nbsp;{$form.grant_money_transfer_date_notset.label}
</td>
{include file="CRM/Core/DatePickerRange.tpl" fieldName="grant_money_transfer_date" from='_low' to='_high'}
&nbsp;{$form.grant_money_transfer_date_notset.html}&nbsp;&nbsp;{$form.grant_money_transfer_date_notset.label}
</tr>
<tr>
<td>
{$form.grant_due_date_low.label}<br />
{$form.grant_due_date_low.html}
</td>
<td colspan="2">
{$form.grant_due_date_high.label}<br />
{$form.grant_due_date_high.html}
&nbsp;{$form.grant_due_date_notset.html}&nbsp;&nbsp;{$form.grant_due_date_notset.label}
</td>
{include file="CRM/Core/DatePickerRange.tpl" fieldName="grant_due_date" from='_low' to='_high'}
&nbsp;{$form.grant_due_date_notset.html}&nbsp;&nbsp;{$form.grant_due_date_notset.label}
</tr>
{if $grantGroupTree}
<tr>
Expand Down

0 comments on commit ac4397a

Please sign in to comment.