Add ability to select different checklist tabs
This commit is contained in:
36
event.php
36
event.php
@@ -28,22 +28,40 @@ add_filter( 'the_posts', 'sp_event_display_scheduled' );
|
||||
function sp_event_meta_init() {
|
||||
remove_meta_box( 'submitdiv', 'sp_event', 'side' );
|
||||
add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' );
|
||||
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_event_team_meta', 'sp_event', 'normal', 'high' );
|
||||
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_event_team_meta', 'sp_event', 'side', 'high' );
|
||||
add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sp_event_article_meta', 'sp_event', 'normal', 'high' );
|
||||
}
|
||||
|
||||
function sp_event_team_meta( $post ) {
|
||||
$limit = get_option( 'sp_event_team_count' );
|
||||
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0);
|
||||
$scores = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_score', false ), 0, $limit ), $limit, 0);
|
||||
for ( $i = 0; $i < $limit; $i++ ):
|
||||
$selected = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0);
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sportspress[sp_team][]',
|
||||
'selected' => $selected[ $i ]
|
||||
);
|
||||
wp_dropdown_pages( $args );
|
||||
?>
|
||||
<div>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sportspress[sp_team][]',
|
||||
'class' => 'sportspress-pages',
|
||||
'selected' => $teams[ $i ]
|
||||
);
|
||||
wp_dropdown_pages( $args );
|
||||
?>
|
||||
<input name="sportspress[sp_score][]" type="text" placeholder="<?php _e( 'Score', 'sportspress' ); ?>" size="4" value="<?php echo $scores[ $i ]; ?>" />
|
||||
</p>
|
||||
<ul id="sportspress-tabs" class="wp-tab-bar">
|
||||
<li class="wp-tab-active"><a href="#sp_player-all"><?php _e( 'Players', 'sportspress' ); ?></a></li>
|
||||
<li class="wp-tab"><a href="#sp_staff-all"><?php _e( 'Staff', 'sportspress' ); ?></a></li>
|
||||
</ul>
|
||||
<?php
|
||||
sp_post_checklist( $post->ID, 'sp_player', false );
|
||||
sp_post_checklist( $post->ID, 'sp_staff', $i == $limit - 1, 'none' );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
endfor;
|
||||
sp_post_checklist( $post->ID, 'sp_player', true );
|
||||
sp_nonce();
|
||||
}
|
||||
|
||||
|
||||
66
helpers.php
66
helpers.php
@@ -112,47 +112,45 @@ if ( ! function_exists( 'sp_team_logo' ) ) {
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sp_post_checklist' ) ) {
|
||||
function sp_post_checklist( $post_id = null, $meta = 'post', $add_new_item = true ) {
|
||||
function sp_post_checklist( $post_id = null, $meta = 'post', $add_new_item = true, $display = 'block' ) {
|
||||
if ( ! isset( $post_id ) )
|
||||
global $post_id;
|
||||
$obj = get_post_type_object( $meta );
|
||||
?>
|
||||
<div id="posttype-<?php echo $meta; ?>" class="posttypediv">
|
||||
<div id="<?php echo $meta; ?>-all" class="wp-tab-panel">
|
||||
<input type="hidden" value="0" name="sportspress[<?php echo $meta; ?>]" />
|
||||
<ul class="categorychecklist form-no-clear">
|
||||
<?php
|
||||
$selected = (array)get_post_meta( $post_id, $meta, false );
|
||||
$posts = get_pages( array( 'post_type' => $meta, 'number' => 0 ) );
|
||||
if ( empty( $posts ) )
|
||||
$posts = get_posts( array( 'post_type' => $meta, 'numberposts' => 0 ) );
|
||||
foreach ( $posts as $post ):
|
||||
$parents = get_post_ancestors( $post );
|
||||
?>
|
||||
<li>
|
||||
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
|
||||
<label class="selectit">
|
||||
<input type="checkbox" value="<?php echo $post->ID; ?>" name="sportspress[<?php echo $meta; ?>][]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
|
||||
<?php echo $post->post_title; ?>
|
||||
</label>
|
||||
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>
|
||||
</li>
|
||||
<?php
|
||||
endforeach;
|
||||
<div id="<?php echo $meta; ?>-all" class="wp-tab-panel" style="display: <?php echo $display; ?>;">
|
||||
<input type="hidden" value="0" name="sportspress[<?php echo $meta; ?>]" />
|
||||
<ul class="categorychecklist form-no-clear">
|
||||
<?php
|
||||
$selected = (array)get_post_meta( $post_id, $meta, false );
|
||||
$posts = get_pages( array( 'post_type' => $meta, 'number' => 0 ) );
|
||||
if ( empty( $posts ) )
|
||||
$posts = get_posts( array( 'post_type' => $meta, 'numberposts' => 0 ) );
|
||||
foreach ( $posts as $post ):
|
||||
$parents = get_post_ancestors( $post );
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php if ( $add_new_item ): ?>
|
||||
<div id="<?php echo $meta; ?>-adder">
|
||||
<h4>
|
||||
<a title="<?php echo sprintf( esc_attr__( 'Add New %s', 'sportspress' ), esc_attr__( 'Team', 'sportspress' ) ); ?>" href="<?php echo admin_url( 'post-new.php?post_type=' . $meta ); ?>" target="_blank">
|
||||
+ <?php echo sprintf( __( 'Add New %s', 'sportspress' ), $obj->labels->singular_name ); ?>
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<li>
|
||||
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
|
||||
<label class="selectit">
|
||||
<input type="checkbox" value="<?php echo $post->ID; ?>" name="sportspress[<?php echo $meta; ?>][]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
|
||||
<?php echo $post->post_title; ?>
|
||||
</label>
|
||||
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>
|
||||
</li>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php if ( $add_new_item ): ?>
|
||||
<div id="<?php echo $meta; ?>-adder">
|
||||
<h4>
|
||||
<a title="<?php echo sprintf( esc_attr__( 'Add New %s', 'sportspress' ), esc_attr__( 'Team', 'sportspress' ) ); ?>" href="<?php echo admin_url( 'post-new.php?post_type=' . $meta ); ?>" target="_blank">
|
||||
+ <?php echo sprintf( __( 'Add New %s', 'sportspress' ), $obj->labels->singular_name ); ?>
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,3 +1,6 @@
|
||||
jQuery(document).ready(function(){
|
||||
jQuery('.sp_datepicker').datepicker();
|
||||
jQuery(document).ready(function($){
|
||||
$('#sportspress-tabs a').click(function() {
|
||||
$(this).closest('li').removeClass('wp-tab').addClass('wp-tab-active').siblings().removeClass('wp-tab-active').addClass('wp-tab').closest('.wp-tab-bar').siblings($(this).attr('href')).show().siblings('.wp-tab-panel').hide();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user