Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Selection of Date Range #33

Merged
merged 11 commits into from
Aug 16, 2014
6 changes: 5 additions & 1 deletion ui/css/messages.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
border-left-color: #ffba00;
}

div#fakerpress-min-date, div#fakerpress-max-date, .dashicon-date {
div#fakerpress-min-date, div#fakerpress-max-date, .dashicon-date, div#fakerpress-date-selection {
float:left;
}

div#fakerpress-date-selection {
margin-right:5px;
}

.dashicon-date {
height: 25px;
line-height: 26px;
Expand Down
37 changes: 37 additions & 0 deletions ui/js/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
}
});
});

$( '.field-date-selection' ).each(function(){
var $select = $(this);
$select.select2({ width: 200 });
});
});
}( jQuery ) );

Expand All @@ -23,6 +28,38 @@
$( '.field-datepicker' ).datepicker( {
constrainInput: false
} );

var $minDate = $( '.field-min-date' ),
$maxDate = $( '.field-max-date' ),
$minDiv = $( '#fakerpress-min-date' ),
$maxDiv = $( '#fakerpress-max-date' ),
$dateField = $('.field-date-selection');

$('.fakerpress-range-group').each(function(){
$dateField.on({
'change': function(e){
var dataMin = $(this).find(':selected').data('min'),
dataMax = $(this).find(':selected').data('max'),
max = $(this).parent($minDiv).siblings($maxDiv),
min = $(this).parent($maxDiv).siblings($minDiv);

min.find($minDate).datepicker( 'option', 'maxDate', dataMin ).val( dataMin );
max.find($maxDate).datepicker( 'option', 'minDate', dataMax ).val( dataMax );
}
})
$minDate.on({
'change': function(e){
var max = $(this).parent($minDiv).siblings($maxDiv);
max.find($maxDate).datepicker( 'option', 'minDate', $(this).val() );
}
}),
$maxDate.on({
'change': function(e){
var min = $(this).parent($maxDiv).siblings($minDiv);
min.find($minDate).datepicker( 'option', 'maxDate', $(this).val() );
}
})
})
});
}( jQuery ) );

Expand Down
75 changes: 68 additions & 7 deletions view/comments.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
<?php // Mount the carbon values for dates
$_json_date_selection_output = array(
array(
'id' => 'today',
'text' => esc_attr__( 'Today', 'fakerpress' ),
'min' => Carbon::today(),
'max' => Carbon::today(),
),
array(
'id' => 'yesterday',
'text' => esc_attr__( 'Yesterday', 'fakerpress' ),
'min' => Carbon::yesterday(),
'max' => Carbon::yesterday(),
),
array(
'id' => 'tomorrow',
'text' => esc_attr__( 'Tomorrow', 'fakerpress' ),
'min' => Carbon::tomorrow(),
'max' => Carbon::tomorrow(),
),
array(
'id' => 'this week',
'text' => esc_attr__( 'This week', 'fakerpress' ),
'min' => Carbon::today()->subDays( 7 ),
'max' => Carbon::today(),
),
array(
'id' => 'this month',
'text' => esc_attr__( 'This month', 'fakerpress' ),
'min' => Carbon::today()->day( 1 ),
'max' => Carbon::today(),
),
array(
'id' => 'this year',
'text' => esc_attr__( 'This year', 'fakerpress' ),
'min' => Carbon::today()->day( 1 )->month( 1 ),
'max' => Carbon::today(),
),
array(
'id' => 'last 15 days',
'text' => esc_attr__( 'Last 15 days', 'fakerpress' ),
'min' => Carbon::today()->subDays( 15 ),
'max' => Carbon::today(),
),
array(
'id' => 'next 15 days',
'text' => esc_attr__( 'Next 15 Days', 'fakerpress' ),
'min' => Carbon::today(),
'max' => Carbon::today()->addDays( 15 ),
),
); ?>

<div class='wrap'>
<h2><?php echo esc_attr( \FakerPress\Admin::$view->title ); ?></h2>

Expand All @@ -17,14 +69,23 @@
<tr>
<th scope="row"><label for="fakerpress_max_date"><?php _e( 'Date', 'fakerpress' ); ?></label></th>
<td>
<div id="fakerpress-min-date">
<input style='width: 150px;' class='field-datepicker' type='text' max='25' min='1' placeholder='<?php esc_attr_e( 'dd/mm/aaaa', 'fakerpress' ); ?>' value='' name='fakerpress_min_date' />
</div>
<div class="dashicons dashicons-arrow-right-alt2 dashicon-date"></div>
<div id="fakerpress-max-date">
<input style='width: 150px;' class='field-datepicker' type='text' max='25' min='1' placeholder='<?php esc_attr_e( 'dd/mm/aaaa', 'fakerpress' ); ?>' value='' name='fakerpress_max_date' />
<div class='fakerpress-range-group'>
<div id="fakerpress-date-selection">
<select class='field-date-selection' name='fakerpress_date_selection'>
<?php foreach ($_json_date_selection_output as $option) { ?>
<option data-min="<?php echo date( 'm/d/Y', strtotime( $option['min'] ) ); ?>" data-max="<?php echo date( 'm/d/Y', strtotime( $option['max'] ) ); ?>" value="<?php echo $option['text']; ?>"><?php echo $option['text']; ?></option>
<?php } ?>
</select>
</div>
<div id="fakerpress-min-date">
<input style='width: 150px;' class='field-datepicker field-min-date' type='text' placeholder='<?php esc_attr_e( 'mm/dd/yyyy', 'fakerpress' ); ?>' value='' name='fakerpress_min_date' />
</div>
<div class="dashicons dashicons-arrow-right-alt2 dashicon-date"></div>
<div id="fakerpress-max-date">
<input style='width: 150px;' class='field-datepicker field-max-date' type='text' placeholder='<?php esc_attr_e( 'mm/dd/yyyy', 'fakerpress' ); ?>' value='' name='fakerpress_max_date' />
</div>
</div>
<p class="description-date"><?php _e( 'Choose the range for the comments dates.', 'fakerpress' ); ?></p>
<p class="description-date"><?php _e( 'Choose the range for the posts dates.', 'fakerpress' ); ?></p>
</td>
</tr>
</tbody>
Expand Down
77 changes: 70 additions & 7 deletions view/posts.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace FakerPress;

use Carbon\Carbon;

// Mounte the options for Users
$users = get_users(
array(
Expand Down Expand Up @@ -45,6 +47,58 @@
);
}

// Mount the carbon values for dates
$_json_date_selection_output = array(
array(
'id' => 'today',
'text' => esc_attr__( 'Today', 'fakerpress' ),
'min' => Carbon::today(),
'max' => Carbon::today(),
),
array(
'id' => 'yesterday',
'text' => esc_attr__( 'Yesterday', 'fakerpress' ),
'min' => Carbon::yesterday(),
'max' => Carbon::yesterday(),
),
array(
'id' => 'tomorrow',
'text' => esc_attr__( 'Tomorrow', 'fakerpress' ),
'min' => Carbon::tomorrow(),
'max' => Carbon::tomorrow(),
),
array(
'id' => 'this week',
'text' => esc_attr__( 'This week', 'fakerpress' ),
'min' => Carbon::today()->subDays( 7 ),
'max' => Carbon::today(),
),
array(
'id' => 'this month',
'text' => esc_attr__( 'This month', 'fakerpress' ),
'min' => Carbon::today()->day( 1 ),
'max' => Carbon::today(),
),
array(
'id' => 'this year',
'text' => esc_attr__( 'This year', 'fakerpress' ),
'min' => Carbon::today()->day( 1 )->month( 1 ),
'max' => Carbon::today(),
),
array(
'id' => 'last 15 days',
'text' => esc_attr__( 'Last 15 days', 'fakerpress' ),
'min' => Carbon::today()->subDays( 15 ),
'max' => Carbon::today(),
),
array(
'id' => 'next 15 days',
'text' => esc_attr__( 'Next 15 Days', 'fakerpress' ),
'min' => Carbon::today(),
'max' => Carbon::today()->addDays( 15 ),
),
);

// Mount the options for the `comment_status`
$_json_comment_status_output = array(
array(
Expand Down Expand Up @@ -103,14 +157,23 @@
<tr>
<th scope="row"><label for="fakerpress_max_date"><?php _e( 'Date', 'fakerpress' ); ?></label></th>
<td>
<div id="fakerpress-min-date">
<input style='width: 150px;' class='field-datepicker' type='text' placeholder='<?php esc_attr_e( 'mm/dd/yyyy', 'fakerpress' ); ?>' value='' name='fakerpress_min_date' />
</div>
<div class="dashicons dashicons-arrow-right-alt2 dashicon-date"></div>
<div id="fakerpress-max-date">
<input style='width: 150px;' class='field-datepicker' type='text' placeholder='<?php esc_attr_e( 'mm/dd/yyyy', 'fakerpress' ); ?>' value='' name='fakerpress_max_date' />
<div class='fakerpress-range-group'>
<div id="fakerpress-date-selection">
<select class='field-date-selection' name='fakerpress_date_selection'>
<?php foreach ($_json_date_selection_output as $option) { ?>
<option data-min="<?php echo date( 'm/d/Y', strtotime( $option['min'] ) ); ?>" data-max="<?php echo date( 'm/d/Y', strtotime( $option['max'] ) ); ?>" value="<?php echo $option['text']; ?>"><?php echo $option['text']; ?></option>
<?php } ?>
</select>
</div>
<div id="fakerpress-min-date">
<input style='width: 150px;' class='field-datepicker field-min-date' type='text' placeholder='<?php esc_attr_e( 'mm/dd/yyyy', 'fakerpress' ); ?>' value='' name='fakerpress_min_date' />
</div>
<div class="dashicons dashicons-arrow-right-alt2 dashicon-date"></div>
<div id="fakerpress-max-date">
<input style='width: 150px;' class='field-datepicker field-max-date' type='text' placeholder='<?php esc_attr_e( 'mm/dd/yyyy', 'fakerpress' ); ?>' value='' name='fakerpress_max_date' />
</div>
</div>
<p class="description-date"><?php _e( 'Choose the range for the posts dates.', 'fakerpress' ); ?></p>
<p class="description-date description"><?php _e( 'Choose the range for the posts dates.', 'fakerpress' ); ?></p>
</td>
</tr>
<tr>
Expand Down