Add auto column argument to sp_data_table

This commit is contained in:
Takumi
2013-07-30 16:00:13 +10:00
parent e91952f8c5
commit f952304818
3 changed files with 19 additions and 12 deletions

View File

@@ -93,7 +93,7 @@ function sp_event_stats_meta( $post ) {
else else
$data[ $id ] = array(); $data[ $id ] = array();
endforeach; endforeach;
sp_data_table( $data, $value, array( 'Player', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ) ); sp_data_table( $data, $value, array( 'Player', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), true, false );
?> ?>
</div> </div>
<?php <?php

View File

@@ -177,7 +177,7 @@ if ( ! function_exists( 'sp_post_checklist' ) ) {
} }
if ( ! function_exists( 'sp_data_table' ) ) { if ( ! function_exists( 'sp_data_table' ) ) {
function sp_data_table( $data = array(), $index = 0, $columns = array( 'Name' ), $total = true ) { function sp_data_table( $data = array(), $index = 0, $columns = array( 'Name' ), $total = true, $auto = true ) {
if ( !is_array( $data ) ) if ( !is_array( $data ) )
$data = array(); $data = array();
?> ?>
@@ -187,7 +187,9 @@ if ( ! function_exists( 'sp_data_table' ) ) {
<?php foreach ( $columns as $column ): ?> <?php foreach ( $columns as $column ): ?>
<th><?php echo $column; ?></th> <th><?php echo $column; ?></th>
<?php endforeach; ?> <?php endforeach; ?>
<th><?php _e( 'Auto', 'sportspress' ); ?></th> <?php if ( $auto ): ?>
<th><?php _e( 'Auto', 'sportspress' ); ?></th>
<?php endif; ?>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -195,10 +197,7 @@ if ( ! function_exists( 'sp_data_table' ) ) {
$i = 0; $i = 0;
foreach ( $data as $key => $values ): foreach ( $data as $key => $values ):
if ( !$key ) continue; if ( !$key ) continue;
if ( array_key_exists( 'auto', $values ) ) $is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : 0;
$auto = (int)$values[ 'auto' ];
else
$auto = 0;
?> ?>
<tr class="sp-post<?php <tr class="sp-post<?php
if ( $i % 2 == 0 ) if ( $i % 2 == 0 )
@@ -211,16 +210,21 @@ if ( ! function_exists( 'sp_data_table' ) ) {
else else
$value = 0; $value = 0;
?> ?>
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>"<?php if ( $auto ) echo ' readonly="readonly"'; ?> /></td> <td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>"<?php if ( $is_auto ) echo ' readonly="readonly"'; ?> /></td>
<?php endfor; ?> <?php endfor; ?>
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][auto]" value="1"<?php if ( $auto ) echo ' checked="checked"'; ?> /></td> <?php if ( $auto ): ?>
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][auto]" value="1"<?php if ( $is_auto ) echo ' checked="checked"'; ?> /></td>
<?php endif; ?>
</tr> </tr>
<?php <?php
$i++; $i++;
endforeach; endforeach;
if ( $total ): if ( $total ):
$values = array_key_exists( 0, $data ) ? $data[0] : array(); $values = array_key_exists( 0, $data ) ? $data[0] : array();
$auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : 0; if ( $auto )
$is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : 0;
else
$is_auto = $i;
?> ?>
<tr<?php <tr<?php
if ( $i % 2 == 0 ) if ( $i % 2 == 0 )
@@ -233,9 +237,11 @@ if ( ! function_exists( 'sp_data_table' ) ) {
else else
$value = 0; $value = 0;
?> ?>
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>"<?php if ( $auto ) echo ' readonly="readonly"'; ?> /></td> <td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>"<?php if ( $is_auto ) echo ' readonly="readonly"'; ?> /></td>
<?php endfor; ?> <?php endfor; ?>
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][0][auto]" value="1"<?php if ( $auto ) echo ' checked="checked"'; ?> /></td> <?php if ( $auto ): ?>
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][0][auto]" value="1"<?php if ( $is_auto ) echo ' checked="checked"'; ?> /></td>
<?php endif; ?>
</tr> </tr>
<?php endif; ?> <?php endif; ?>
</tbody> </tbody>

View File

@@ -32,4 +32,5 @@ jQuery(document).ready(function($){
}).get().join(' vs '); }).get().join(' vs ');
$('input[name=post_title]').val(title); $('input[name=post_title]').val(title);
}); });
}); });