Add filters to table

This commit is contained in:
Brian Miyaji
2017-11-15 00:12:09 +11:00
parent d5098b0ef7
commit 58e57e2ed0
3 changed files with 42 additions and 22 deletions

View File

@@ -39,7 +39,7 @@ class SP_Meta_Box_Table_Data {
/**
* Admin edit table
*/
public static function table( $id, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null ) {
public static function table( $id, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null, $readonly = false ) {
if ( is_array( $usecolumns ) )
$usecolumns = array_filter( $usecolumns );
@@ -53,20 +53,33 @@ class SP_Meta_Box_Table_Data {
$icon_class = 'sp-icon-shield';
}
?>
<input type="hidden" name="sp_highlight" value="0">
<ul class="subsubsub sp-table-bar">
<li><a href="#sp-table-values" class="current"><?php _e( 'Values', 'sportspress' ); ?></a></li> |
<li><a href="#sp-table-adjustments" class=""><?php _e( 'Adjustments', 'sportspress' ); ?></a></li>
</ul>
<?php if ( $readonly ) { ?>
<p>
<strong><?php echo get_the_title( $id ); ?></strong>
<a class="add-new-h2 sp-add-new-h2" href="<?php echo esc_url( admin_url( add_query_arg( array( 'post' => $id, 'action' => 'edit' ), 'post.php' ) ) ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></a>
</p>
<?php } else { ?>
<input type="hidden" name="sp_highlight" value="0">
<ul class="subsubsub sp-table-bar">
<li><a href="#sp-table-values" class="current"><?php _e( 'Values', 'sportspress' ); ?></a></li> |
<li><a href="#sp-table-adjustments" class=""><?php _e( 'Adjustments', 'sportspress' ); ?></a></li>
</ul>
<?php } ?>
<div class="sp-data-table-container sp-table-panel sp-table-values" id="sp-table-values">
<table class="widefat sp-data-table sp-league-table">
<thead>
<tr>
<th class="radio"><span class="dashicons <?php echo $icon_class; ?> sp-tip" title="<?php _e( 'Highlight', 'sportspress' ); ?>"></span></th>
<?php if ( ! $readonly ) { ?>
<th class="radio"><span class="dashicons <?php echo $icon_class; ?> sp-tip" title="<?php _e( 'Highlight', 'sportspress' ); ?>"></span></th>
<?php } ?>
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): ?>
<th><label for="sp_columns_<?php echo $key; ?>">
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
<?php if ( ! $readonly ) { ?>
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
<?php } ?>
<?php echo $label; ?>
</label></th>
<?php endforeach; ?>
@@ -85,25 +98,31 @@ class SP_Meta_Box_Table_Data {
$default_name = get_the_title( $team_id );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td><input type="radio" class="sp-radio-toggle" name="sp_highlight" value="<?php echo $team_id; ?>" <?php checked( $highlight, $team_id ); ?>></td>
<?php if ( ! $readonly ) { ?>
<td><input type="radio" class="sp-radio-toggle" name="sp_highlight" value="<?php echo $team_id; ?>" <?php checked( $highlight, $team_id ); ?> <?php disabled( $readonly ); ?>></td>
<?php } ?>
<td>
<?php if ( $show_team_logo ) echo get_the_post_thumbnail( $team_id, 'sportspress-fit-mini' ); ?>
<span class="sp-default-value">
<span class="sp-default-value-input"><?php echo $default_name; ?></span>
<a class="dashicons dashicons-edit sp-edit" title="<?php _e( 'Edit', 'sportspress' ); ?>"></a>
</span>
<span class="hidden sp-custom-value">
<input type="text" name="sp_teams[<?php echo $team_id; ?>][name]" class="name sp-custom-value-input" value="<?php echo esc_attr( sp_array_value( $team_stats, 'name', '' ) ); ?>" placeholder="<?php echo esc_attr( get_the_title( $team_id ) ); ?>" size="6">
<a class="button button-secondary sp-cancel"><?php _e( 'Cancel', 'sportspress' ); ?></a>
<a class="button button-primary sp-save"><?php _e( 'Save', 'sportspress' ); ?></a>
</span>
<?php if ( $readonly ) { ?>
<?php echo $default_name; ?>
<?php } else { ?>
<span class="sp-default-value">
<span class="sp-default-value-input"><?php echo $default_name; ?></span>
<a class="dashicons dashicons-edit sp-edit" title="<?php _e( 'Edit', 'sportspress' ); ?>"></a>
</span>
<span class="hidden sp-custom-value">
<input type="text" name="sp_teams[<?php echo $team_id; ?>][name]" class="name sp-custom-value-input" value="<?php echo esc_attr( sp_array_value( $team_stats, 'name', '' ) ); ?>" placeholder="<?php echo esc_attr( get_the_title( $team_id ) ); ?>" size="6">
<a class="button button-secondary sp-cancel"><?php _e( 'Cancel', 'sportspress' ); ?></a>
<a class="button button-primary sp-save"><?php _e( 'Save', 'sportspress' ); ?></a>
</span>
<?php } ?>
</td>
<?php foreach( $columns as $column => $label ):
$value = sp_array_value( $team_stats, $column, '' );
$placeholder = sp_array_value( sp_array_value( $placeholders, $team_id, array() ), $column, 0 );
$placeholder = wp_strip_all_tags( $placeholder );
?>
<td><input type="text" name="sp_teams[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" data-placeholder="<?php echo esc_attr( $placeholder ); ?>" data-matrix="<?php echo $team_id; ?>_<?php echo $column; ?>" data-adjustment="<?php echo esc_attr( sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $column, 0 ) ); ?>" /></td>
<td><input type="text" name="sp_teams[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" data-placeholder="<?php echo esc_attr( $placeholder ); ?>" data-matrix="<?php echo $team_id; ?>_<?php echo $column; ?>" data-adjustment="<?php echo esc_attr( sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $column, 0 ) ); ?>" <?php readonly( $readonly ); ?> /></td>
<?php endforeach; ?>
</tr>
<?php
@@ -112,7 +131,7 @@ class SP_Meta_Box_Table_Data {
else:
?>
<tr class="sp-row alternate">
<td colspan="<?php $colspan = sizeof( $columns ) + 2; echo $colspan; ?>">
<td colspan="<?php $colspan = sizeof( $columns ) + ( $readonly ? 1 : 2 ); echo $colspan; ?>">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Data', 'sportspress' ) ); ?>
</td>
</tr>

View File

@@ -72,6 +72,7 @@ class SP_Meta_Box_Table_Details {
foreach ( $taxonomies as $taxonomy ) {
sp_taxonomy_field( $taxonomy, $post, true );
}
do_action( 'sportspress_meta_box_table_details', $post->ID );
?>
<p><strong>
<?php echo sp_get_post_mode_label( $post->ID ); ?>

View File

@@ -1136,14 +1136,14 @@ if ( !function_exists( 'sp_get_var_equations' ) ) {
}
if ( !function_exists( 'sp_post_adder' ) ) {
function sp_post_adder( $post_type = 'post', $label = null ) {
function sp_post_adder( $post_type = 'post', $label = null, $attributes = array() ) {
$obj = get_post_type_object( $post_type );
if ( $label == null )
$label = __( 'Add New', 'sportspress' );
?>
<div id="<?php echo $post_type; ?>-adder">
<h4>
<a title="<?php echo esc_attr( $label ); ?>" href="<?php echo admin_url( 'post-new.php?post_type=' . $post_type ); ?>" target="_blank">
<a title="<?php echo esc_attr( $label ); ?>" href="<?php echo admin_url( add_query_arg( $attributes, 'post-new.php?post_type=' . $post_type ) ); ?>" target="_blank">
+ <?php echo $label; ?>
</a>
</h4>