Add team option to countdown widget close #43

This commit is contained in:
Brian Miyaji
2014-08-23 19:52:51 +10:00
parent aa98f74fbc
commit 091c2a33ff
5 changed files with 64 additions and 6 deletions

View File

@@ -82,6 +82,27 @@ jQuery(document).ready(function($){
// Trigger tab filter // Trigger tab filter
$(".sp-tab-panel").siblings(".sp-tab-select").find("select").change(); $(".sp-tab-panel").siblings(".sp-tab-select").find("select").change();
// Dropdown filter
$(".sp-dropdown-target").siblings(".sp-dropdown-filter").find("select").change(function() {
var val = $(this).val();
var filter = ".sp-filter-"+val;
var $filters = $(this).closest(".sp-dropdown-filter").siblings(".sp-dropdown-filter");
if($filters.length) {
$filters.each(function() {
filterval = $(this).find("select").val();
if(filterval !== undefined)
filter += ".sp-filter-"+filterval;
});
}
$target = $(this).closest(".sp-dropdown-filter").siblings(".sp-dropdown-target").find("select");
$target.find(".sp-post").prop("disabled", true).each(function() {
$(this).filter(filter).prop("disabled", false);
});
});
// Trigger dropdown filter
$(".sp-dropdown-target").siblings(".sp-dropdown-filter").find("select").change();
// Filter show all action links // Filter show all action links
$(".sp-tab-panel").find(".sp-post input:checked").each(function() { $(".sp-tab-panel").find(".sp-post input:checked").each(function() {
$(this).prop("disabled", false).closest("li").show().siblings(".sp-not-found-container").hide().siblings(".sp-show-all-container").show(); $(this).prop("disabled", false).closest("li").show().siblings(".sp-not-found-container").hide().siblings(".sp-show-all-container").show();

View File

@@ -17,6 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*/ */
function sp_get_screen_ids() { function sp_get_screen_ids() {
return apply_filters( 'sportspress_screen_ids', array( return apply_filters( 'sportspress_screen_ids', array(
'widgets',
'dashboard', 'dashboard',
'dashboard_page_sp-about', 'dashboard_page_sp-about',
'toplevel_page_sportspress', 'toplevel_page_sportspress',

View File

@@ -560,6 +560,7 @@ if ( !function_exists( 'sp_dropdown_pages' ) ) {
'property' => null, 'property' => null,
'placeholder' => null, 'placeholder' => null,
'chosen' => false, 'chosen' => false,
'filter' => false,
); );
$args = array_merge( $defaults, $args ); $args = array_merge( $defaults, $args );
@@ -586,6 +587,9 @@ if ( !function_exists( 'sp_dropdown_pages' ) ) {
$chosen = $args['chosen']; $chosen = $args['chosen'];
unset( $args['chosen'] ); unset( $args['chosen'] );
$filter = $args['filter'];
unset( $args['filter'] );
$posts = get_posts( $args ); $posts = get_posts( $args );
if ( $posts || $args['prepend_options'] || $args['append_options'] ): if ( $posts || $args['prepend_options'] || $args['append_options'] ):
@@ -623,7 +627,17 @@ if ( !function_exists( 'sp_dropdown_pages' ) ) {
$selected_prop = selected( $this_value, $selected, false ); $selected_prop = selected( $this_value, $selected, false );
endif; endif;
printf( '<option value="%s" %s>%s</option>', $this_value, $selected_prop, $post->post_title . ( $args['show_dates'] ? ' (' . $post->post_date . ')' : '' ) ); if ( $filter !== false ):
$class = 'sp-post sp-filter-0';
$filter_values = get_post_meta( $post->ID, $filter, false );
foreach ( $filter_values as $filter_value ):
$class .= ' sp-filter-' . $filter_value;
endforeach;
else:
$class = '';
endif;
printf( '<option value="%s" class="%s" %s>%s</option>', $this_value, $class, $selected_prop, $post->post_title . ( $args['show_dates'] ? ' (' . $post->post_date . ')' : '' ) );
endforeach; endforeach;
wp_reset_postdata(); wp_reset_postdata();

View File

@@ -9,19 +9,21 @@ class SP_Widget_Countdown extends WP_Widget {
function widget( $args, $instance ) { function widget( $args, $instance ) {
extract($args); extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? null : $instance['title'], $instance, $this->id_base); $title = apply_filters('widget_title', empty($instance['title']) ? null : $instance['title'], $instance, $this->id_base);
$team = empty($instance['team']) ? null : $instance['team'];
$id = empty($instance['id']) ? null : $instance['id']; $id = empty($instance['id']) ? null : $instance['id'];
$show_venue = empty($instance['show_venue']) ? false : $instance['show_venue']; $show_venue = empty($instance['show_venue']) ? false : $instance['show_venue'];
$show_league = empty($instance['show_league']) ? false : $instance['show_league']; $show_league = empty($instance['show_league']) ? false : $instance['show_league'];
echo $before_widget; echo $before_widget;
if ( $title ) if ( $title )
echo $before_title . $title . $after_title; echo $before_title . $title . $after_title;
sp_get_template( 'countdown.php', array( 'id' => $id, 'show_venue' => $show_venue, 'show_league' => $show_league ) ); sp_get_template( 'countdown.php', array( 'team' => $team, 'id' => $id, 'show_venue' => $show_venue, 'show_league' => $show_league ) );
echo $after_widget; echo $after_widget;
} }
function update( $new_instance, $old_instance ) { function update( $new_instance, $old_instance ) {
$instance = $old_instance; $instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']); $instance['title'] = strip_tags($new_instance['title']);
$instance['team'] = intval($new_instance['team']);
$instance['id'] = intval($new_instance['id']); $instance['id'] = intval($new_instance['id']);
$instance['show_venue'] = intval($new_instance['show_venue']); $instance['show_venue'] = intval($new_instance['show_venue']);
$instance['show_league'] = intval($new_instance['show_league']); $instance['show_league'] = intval($new_instance['show_league']);
@@ -30,8 +32,9 @@ class SP_Widget_Countdown extends WP_Widget {
} }
function form( $instance ) { function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'show_venue' => false, 'show_league' => false ) ); $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'team' => '', 'id' => '', 'show_venue' => false, 'show_league' => false ) );
$title = strip_tags($instance['title']); $title = strip_tags($instance['title']);
$team = intval($instance['team']);
$id = intval($instance['id']); $id = intval($instance['id']);
$show_venue = intval($instance['show_venue']); $show_venue = intval($instance['show_venue']);
$show_league = intval($instance['show_league']); $show_league = intval($instance['show_league']);
@@ -39,7 +42,24 @@ class SP_Widget_Countdown extends WP_Widget {
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label> <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Event', 'sportspress' ) ); ?></label> <p class="sp-dropdown-filter"><label for="<?php echo $this->get_field_id('team'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Team', 'sportspress' ) ); ?></label>
<?php
$args = array(
'post_type' => 'sp_team',
'name' => $this->get_field_name('team'),
'id' => $this->get_field_id('team'),
'selected' => $team,
'show_option_all' => __( 'All', 'sportspress' ),
'values' => 'ID',
'class' => 'widefat',
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p class="sp-dropdown-target"><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Event', 'sportspress' ) ); ?></label>
<?php <?php
$args = array( $args = array(
'post_type' => 'sp_event', 'post_type' => 'sp_event',
@@ -51,6 +71,7 @@ class SP_Widget_Countdown extends WP_Widget {
'class' => 'widefat', 'class' => 'widefat',
'show_dates' => true, 'show_dates' => true,
'post_status' => 'future', 'post_status' => 'future',
'filter' => 'sp_team',
); );
if ( ! sp_dropdown_pages( $args ) ): if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_event', __( 'Add New', 'sportspress' ) ); sp_post_adder( 'sp_event', __( 'Add New', 'sportspress' ) );

View File

@@ -10,6 +10,7 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$defaults = array( $defaults = array(
'team' => null,
'id' => null, 'id' => null,
'live' => get_option( 'sportspress_enable_live_countdowns', 'yes' ) == 'yes' ? true : false, 'live' => get_option( 'sportspress_enable_live_countdowns', 'yes' ) == 'yes' ? true : false,
); );
@@ -19,7 +20,7 @@ if ( isset( $id ) ):
else: else:
$args = array(); $args = array();
if ( isset( $team ) ) if ( isset( $team ) )
$args = array( 'key' => 'sp_team', 'value' => $team ); $args = array( array( 'key' => 'sp_team', 'value' => $team ) );
$post = sp_get_next_event( $args ); $post = sp_get_next_event( $args );
endif; endif;
@@ -66,4 +67,4 @@ if ( ! isset( $post ) ) return;
<span><?php echo sprintf( '%02s', $i ); ?> <small><?php _e( 'mins', 'sportspress' ); ?></small></span> <span><?php echo sprintf( '%02s', $i ); ?> <small><?php _e( 'mins', 'sportspress' ); ?></small></span>
<span><?php echo sprintf( '%02s', $s ); ?> <small><?php _e( 'secs', 'sportspress' ); ?></small></span> <span><?php echo sprintf( '%02s', $s ); ?> <small><?php _e( 'secs', 'sportspress' ); ?></small></span>
</time></p> </time></p>
</div> </div>