Skip to content
Permalink
Browse files

Replace date selection dropdown boxes with datetime picker

Fixes #8957
  • Loading branch information
syncguru authored and vboctor committed Feb 10, 2017
1 parent 6511b27 commit 1721c39a81e561553ee2bd999a81e71d6189d24e
Showing with 73 additions and 109 deletions.
  1. +1 −1 core/date_api.php
  2. +4 −0 core/filter_constants_inc.php
  3. +35 −83 core/filter_form_api.php
  4. +33 −25 js/common.js
@@ -244,7 +244,7 @@ function print_date_selection_set( $p_name, $p_format, $p_date = 0, $p_default_d

$t_disable = '';
if( $p_default_disable == true ) {
$t_disable = ' disabled="disabled"';
$t_disable = ' readonly="readonly"';
}
$t_blank_line = '';
if( $p_allow_blank == true ) {
@@ -40,6 +40,8 @@
define( 'FILTER_PROPERTY_DATE_SUBMITTED_END_MONTH', 'end_month' );
define( 'FILTER_PROPERTY_DATE_SUBMITTED_END_YEAR', 'end_year' );
define( 'FILTER_PROPERTY_FILTER_BY_DATE_SUBMITTED', 'filter_by_date' ); #do_filter_by_date
define( 'FILTER_PROPERTY_FILTER_BY_START_DATE_SUBMITTED', 'filter_by_start_date' );
define( 'FILTER_PROPERTY_FILTER_BY_END_DATE_SUBMITTED', 'filter_by_end_date' );

define( 'FILTER_PROPERTY_LAST_UPDATED_START_DAY', 'last_updated_start_day' );
define( 'FILTER_PROPERTY_LAST_UPDATED_START_MONTH', 'last_updated_start_month' );
@@ -48,6 +50,8 @@
define( 'FILTER_PROPERTY_LAST_UPDATED_END_MONTH', 'last_updated_end_month' );
define( 'FILTER_PROPERTY_LAST_UPDATED_END_YEAR', 'last_updated_end_year' );
define( 'FILTER_PROPERTY_FILTER_BY_LAST_UPDATED_DATE', 'filter_by_last_updated_date' ); #do_filter_by_last_updated_date
define( 'FILTER_PROPERTY_FILTER_BY_LAST_UPDATED_START_DATE', 'filter_by_last_updated_start_date' );
define( 'FILTER_PROPERTY_FILTER_BY_LAST_UPDATED_END_DATE', 'filter_by_last_updated_end_date' );

define( 'FILTER_PROPERTY_RELATIONSHIP_TYPE', 'relationship_type' );
define( 'FILTER_PROPERTY_RELATIONSHIP_BUG', 'relationship_bug' );
@@ -1307,7 +1307,7 @@ function print_filter_do_filter_by_date( $p_hide_checkbox = false, array $p_filt
<?php

if( ON != $p_filter[FILTER_PROPERTY_FILTER_BY_DATE_SUBMITTED] ) {
$t_menu_disabled = ' disabled="disabled" ';
$t_menu_readonly = ' readonly="readonly" ';
}
}
?>
@@ -1318,26 +1318,14 @@ function print_filter_do_filter_by_date( $p_hide_checkbox = false, array $p_filt
<?php echo lang_get( 'start_date_label' )?>
</td>
<td class="nowrap">
<?php
$t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
foreach( $t_chars as $t_char ) {
if( strcasecmp( $t_char, 'M' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_DATE_SUBMITTED_START_MONTH, '"', $t_menu_disabled, '>';
print_month_option_list( $p_filter[FILTER_PROPERTY_DATE_SUBMITTED_START_MONTH] );
print "</select>\n";
}
if( strcasecmp( $t_char, 'D' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_DATE_SUBMITTED_START_DAY, '"', $t_menu_disabled, '>';
print_day_option_list( $p_filter[FILTER_PROPERTY_DATE_SUBMITTED_START_DAY] );
print "</select>\n";
}
if( strcasecmp( $t_char, 'Y' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_DATE_SUBMITTED_START_YEAR, '"', $t_menu_disabled, '>';
print_year_option_list( $p_filter[FILTER_PROPERTY_DATE_SUBMITTED_START_YEAR] );
print "</select>\n";
}
}
?>
<?php
echo '<input type="text" name="' . FILTER_PROPERTY_FILTER_BY_START_DATE_SUBMITTED . '" ' .
' class="datetimepicker input-xs" ' . $t_menu_readonly .
' data-picker-locale="' . lang_get_current_datetime_locale() . '"' .
' data-picker-format="' . config_get( 'date_picker_format' ) . '"' .
' size="12" maxlength="12" value="" />';
echo '<i class="fa fa-calendar fa-xlg datetimepicker"></i>';
?>
</td>
</tr>
<!-- End date -->
@@ -1346,26 +1334,14 @@ function print_filter_do_filter_by_date( $p_hide_checkbox = false, array $p_filt
<?php echo lang_get( 'end_date_label' )?>
</td>
<td>
<?php
$t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
foreach( $t_chars as $t_char ) {
if( strcasecmp( $t_char, 'M' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_DATE_SUBMITTED_END_MONTH, '"', $t_menu_disabled, '>';
print_month_option_list( $p_filter[FILTER_PROPERTY_DATE_SUBMITTED_END_MONTH] );
print "</select>\n";
}
if( strcasecmp( $t_char, 'D' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_DATE_SUBMITTED_END_DAY, '"', $t_menu_disabled, '>';
print_day_option_list( $p_filter[FILTER_PROPERTY_DATE_SUBMITTED_END_DAY] );
print "</select>\n";
}
if( strcasecmp( $t_char, 'Y' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_DATE_SUBMITTED_END_YEAR, '"', $t_menu_disabled, '>';
print_year_option_list( $p_filter[FILTER_PROPERTY_DATE_SUBMITTED_END_YEAR] );
print "</select>\n";
}
}
?>
<?php
echo '<input type="text" name="' . FILTER_PROPERTY_FILTER_BY_END_DATE_SUBMITTED . '" ' .
' class="datetimepicker input-xs" ' . $t_menu_readonly .
' data-picker-locale="' . lang_get_current_datetime_locale() . '"' .
' data-picker-format="' . config_get( 'date_picker_format' ) . '"' .
' size="12" maxlength="12" value="" />';
echo '<i class="fa fa-calendar fa-xlg datetimepicker"></i>';
?>
</td>
</tr>
</table>
@@ -1442,7 +1418,7 @@ function print_filter_do_filter_by_last_updated_date( $p_hide_checkbox = false,
?>
<table cellspacing="0" cellpadding="0">
<?php
$t_menu_disabled = '';
$t_menu_readonly = '';
if( !$p_hide_checkbox ) {
?>
<tr>
@@ -1459,7 +1435,7 @@ function print_filter_do_filter_by_last_updated_date( $p_hide_checkbox = false,
<?php

if( ON != $p_filter[FILTER_PROPERTY_FILTER_BY_LAST_UPDATED_DATE] ) {
$t_menu_disabled = ' disabled="disabled" ';
$t_menu_readonly = ' readonly="readonly" ';
}
}
?>
@@ -1470,26 +1446,14 @@ function print_filter_do_filter_by_last_updated_date( $p_hide_checkbox = false,
<?php echo lang_get( 'start_date_label' )?>
</td>
<td class="nowrap">
<?php
$t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
foreach( $t_chars as $t_char ) {
if( strcasecmp( $t_char, 'M' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_LAST_UPDATED_START_MONTH, '"', $t_menu_disabled, '>';
print_month_option_list( $p_filter[FILTER_PROPERTY_LAST_UPDATED_START_MONTH] );
print "</select>\n";
}
if( strcasecmp( $t_char, 'D' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_LAST_UPDATED_START_DAY, '"', $t_menu_disabled, '>';
print_day_option_list( $p_filter[FILTER_PROPERTY_LAST_UPDATED_START_DAY] );
print "</select>\n";
}
if( strcasecmp( $t_char, 'Y' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_LAST_UPDATED_START_YEAR, '"', $t_menu_disabled, '>';
print_year_option_list( $p_filter[FILTER_PROPERTY_LAST_UPDATED_START_YEAR] );
print "</select>\n";
}
}
?>
<?php
echo '<input type="text" name="' . FILTER_PROPERTY_FILTER_BY_LAST_UPDATED_START_DATE . '" ' .
' class="datetimepicker input-xs" ' . $t_menu_readonly .
' data-picker-locale="' . lang_get_current_datetime_locale() . '"' .
' data-picker-format="' . config_get( 'date_picker_format' ) . '"' .
' size="12" maxlength="12" value="" />';
echo '<i class="fa fa-calendar fa-xlg datetimepicker"></i>';
?>
</td>
</tr>
<!-- End date -->
@@ -1498,26 +1462,14 @@ function print_filter_do_filter_by_last_updated_date( $p_hide_checkbox = false,
<?php echo lang_get( 'end_date_label' )?>
</td>
<td>
<?php
$t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
foreach( $t_chars as $t_char ) {
if( strcasecmp( $t_char, 'M' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_LAST_UPDATED_END_MONTH, '"', $t_menu_disabled, '>';
print_month_option_list( $p_filter[FILTER_PROPERTY_LAST_UPDATED_END_MONTH] );
print "</select>\n";
}
if( strcasecmp( $t_char, 'D' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_LAST_UPDATED_END_DAY, '"', $t_menu_disabled, '>';
print_day_option_list( $p_filter[FILTER_PROPERTY_LAST_UPDATED_END_DAY] );
print "</select>\n";
}
if( strcasecmp( $t_char, 'Y' ) == 0 ) {
echo '<select class="input-xs" name="', FILTER_PROPERTY_LAST_UPDATED_END_YEAR, '"', $t_menu_disabled, '>';
print_year_option_list( $p_filter[FILTER_PROPERTY_LAST_UPDATED_END_YEAR] );
print "</select>\n";
}
}
?>
<?php
echo '<input type="text" name="' . FILTER_PROPERTY_FILTER_BY_LAST_UPDATED_END_DATE . '" ' .
' class="datetimepicker input-xs" ' . $t_menu_readonly .
' data-picker-locale="' . lang_get_current_datetime_locale() . '"' .
' data-picker-format="' . config_get( 'date_picker_format' ) . '"' .
' size="12" maxlength="12" value="" />';
echo '<i class="fa fa-calendar fa-xlg datetimepicker"></i>';
?>
</td>
</tr>
</table>
@@ -137,6 +137,9 @@ $(document).ready( function() {
context: $('#' + targetID),
success: function(html) {
$(this).html(html);
$(this).find('input[type=text].datetimepicker').each(function(index, element) {
enableDatTimePicker(this);
});
},
error: function(obj,status,error) {
$(this).html('<span class="error-msg">' + status + ': ' + error + '</span>');
@@ -226,24 +229,7 @@ $(document).ready( function() {
});

$('input[type=text].datetimepicker').each(function(index, element) {
$(this).datetimepicker({
locale: $(this).data('picker-locale'),
format: $(this).data('picker-format'),
useCurrent: false,
icons: {
time: 'fa fa-clock-o',
date: 'fa fa-calendar',
up: 'fa fa-chevron-up',
down: 'fa fa-chevron-down',
previous: 'fa fa-chevron-left',
next: 'fa fa-chevron-right',
today: 'fa fa-arrows ',
clear: 'fa fa-trash',
close: 'fa fa-times'
}
}).next().on(ace.click_event, function() {
$(this).prev().focus();
});
enableDatTimePicker(this);
});

if( $( ".dropzone-form" ).length ) {
@@ -283,32 +269,32 @@ $(document).ready( function() {
$(document).on('change', '.js_switch_date_inputs_trigger', function() {
$(this).closest('table')
.find('select')
.prop('disabled', !$(this).prop('checked'));
.prop('readonly', !$(this).prop('checked'));
});

/* Handle custom field of date type */
$(document).on('change', 'select[name^=custom_field_][name$=_control]', function() {
var table = $(this).closest('table');
switch(this.value) {
case '2': // between
$(table).find("input[name*=_start_date]").prop('disabled', false);
$(table).find("input[name*=_end_date]").prop('disabled', false);
$(table).find("input[name*=_start_date]").prop('readonly', false);
$(table).find("input[name*=_end_date]").prop('readonly', false);
break;

case '3': // on or before
case '4': // before
case '5': // on
case '6': // after
case '7': // on or after
$(table).find("input[name*=_start_date]").prop('disabled', false);
$(table).find("input[name*=_end_date]").prop('disabled', true);
$(table).find("input[name*=_start_date]").prop('readonly', false);
$(table).find("input[name*=_end_date]").prop('readonly', true);
break;

case '0': // any
case '1': // none
default:
$(table).find("input[name*=_start_date]").prop('disabled', true);
$(table).find("input[name*=_end_date]").prop('disabled', true);
$(table).find("input[name*=_start_date]").prop('readonly', true);
$(table).find("input[name*=_end_date]").prop('readonly', true);
break;
}
});
@@ -470,6 +456,28 @@ function toggleDisplay(idTag)
setDisplay( idTag, (document.getElementById(idTag).style.display == 'none')?1:0 );
}

// Datetime picker handler
function enableDatTimePicker( p_element ) {
$(p_element).datetimepicker({
locale: $(p_element).data('picker-locale'),
format: $(p_element).data('picker-format'),
useCurrent: false,
icons: {
time: 'fa fa-clock-o',
date: 'fa fa-calendar',
up: 'fa fa-chevron-up',
down: 'fa fa-chevron-down',
previous: 'fa fa-chevron-left',
next: 'fa fa-chevron-right',
today: 'fa fa-arrows ',
clear: 'fa fa-trash',
close: 'fa fa-times'
}
}).next().on(ace.click_event, function() {
$(this).prev().focus();
});
}

// Dropzone handler
Dropzone.autoDiscover = false;
function enableDropzone( classPrefix, autoUpload ) {

0 comments on commit 1721c39

Please sign in to comment.
You can’t perform that action at this time.