Enable league table adjustments
This commit is contained in:
@@ -215,13 +215,13 @@ table.widefat.sp-data-table a.dashicons {
|
||||
line-height: 27px;
|
||||
}
|
||||
|
||||
table.widefat.sp-data-table a.sp-edit-name {
|
||||
table.widefat.sp-data-table a.sp-edit {
|
||||
-moz-opacity: 0;
|
||||
opacity: 0;
|
||||
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
|
||||
}
|
||||
|
||||
table.widefat.sp-data-table tr:hover a.sp-edit-name {
|
||||
table.widefat.sp-data-table tr:hover a.sp-edit {
|
||||
-moz-opacity: 1;
|
||||
opacity: 1;
|
||||
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
|
||||
|
||||
@@ -45,6 +45,12 @@ jQuery(document).ready(function($){
|
||||
$el.show();
|
||||
});
|
||||
|
||||
// Table switcher
|
||||
$(".sp-table-panel").siblings(".sp-table-bar").find("a").click(function() {
|
||||
$(this).closest("li").find("a").addClass("current").closest("li").siblings().find("a").removeClass("current").closest(".sp-table-bar").siblings($(this).attr("href")).show().siblings(".sp-table-panel").hide();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Tab switcher
|
||||
$(".sp-tab-panel").siblings(".sp-tab-bar").find("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();
|
||||
@@ -63,7 +69,6 @@ jQuery(document).ready(function($){
|
||||
filter += ".sp-filter-"+filterval;
|
||||
});
|
||||
}
|
||||
console.log( filter );
|
||||
$panel = $(this).closest(".sp-tab-select").siblings(".sp-tab-panel")
|
||||
$panel.find(".sp-post").hide(0, function() {
|
||||
$(this).find("input").prop("disabled", true);
|
||||
@@ -97,45 +102,64 @@ jQuery(document).ready(function($){
|
||||
// Activate self-cloning
|
||||
$(".sp-clone:last").find("select").change();
|
||||
|
||||
// Name editor
|
||||
$(".sp-data-table .sp-default-name").click(function() {
|
||||
$(this).hide().siblings(".sp-custom-name").show().find(".sp-custom-name-input").focus();
|
||||
// Custom value editor
|
||||
$(".sp-data-table .sp-default-value").click(function() {
|
||||
$(this).hide().siblings(".sp-custom-value").show().find(".sp-custom-value-input").focus();
|
||||
});
|
||||
|
||||
// Name editor save
|
||||
$(".sp-data-table .sp-custom-name .sp-save").click(function() {
|
||||
$val = $(this).siblings(".sp-custom-name-input").val();
|
||||
if($val == "") $val = $(this).siblings(".sp-custom-name-input").attr("placeholder");
|
||||
$(this).closest(".sp-custom-name").hide().siblings(".sp-default-name").show().find(".sp-default-name-input").html($val);
|
||||
// Define custom value editor saving
|
||||
$(".sp-data-table .sp-custom-value .sp-custom-value-input").on("saveInput", function() {
|
||||
$val = $(this).val();
|
||||
if($val == "") $val = $(this).attr("placeholder");
|
||||
$(this).closest(".sp-custom-value").hide().siblings(".sp-default-value").show().find(".sp-default-value-input").html($val);
|
||||
});
|
||||
|
||||
// Name editor cancel
|
||||
$(".sp-data-table .sp-custom-name .sp-cancel").click(function() {
|
||||
$val = $(this).closest(".sp-custom-name").siblings(".sp-default-name").find(".sp-default-name-input").html();
|
||||
$el = $(this).siblings(".sp-custom-name-input");
|
||||
if($val == $el.attr("placeholder")) $el.val("");
|
||||
else $el.val($val);
|
||||
$(this).closest(".sp-custom-name").hide().siblings(".sp-default-name").show();
|
||||
// Define custom value editor cancellation
|
||||
$(".sp-data-table .sp-custom-value .sp-custom-value-input").on("cancelInput", function() {
|
||||
$val = $(this).closest(".sp-custom-value").siblings(".sp-default-value").find(".sp-default-value-input").html();
|
||||
if($val == $(this).attr("placeholder")) $(this).val("");
|
||||
else $(this).val($val);
|
||||
$(this).closest(".sp-custom-value").hide().siblings(".sp-default-value").show();
|
||||
});
|
||||
|
||||
// Prevent name editor input from submitting form
|
||||
$(".sp-data-table .sp-custom-name .sp-custom-name-input").keypress(function(event) {
|
||||
// Custom value editor save
|
||||
$(".sp-data-table .sp-custom-value .sp-save").click(function() {
|
||||
$(this).siblings(".sp-custom-value-input").trigger("saveInput");
|
||||
});
|
||||
|
||||
// Custom value editor cancel
|
||||
$(".sp-data-table .sp-custom-value .sp-cancel").click(function() {
|
||||
$(this).siblings(".sp-custom-value-input").trigger("cancelInput");
|
||||
});
|
||||
|
||||
// Prevent custom value editor input from submitting form
|
||||
$(".sp-data-table .sp-custom-value .sp-custom-value-input").keypress(function(event) {
|
||||
if(event.keyCode == 13){
|
||||
event.preventDefault();
|
||||
$(this).siblings(".sp-save").click();
|
||||
$(this).trigger("saveInput");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Cancel name editor form on escape
|
||||
$(".sp-data-table .sp-custom-name .sp-custom-name-input").keyup(function(event) {
|
||||
// Cancel custom value editor form on escape
|
||||
$(".sp-data-table .sp-custom-value .sp-custom-value-input").keyup(function(event) {
|
||||
if(event.keyCode == 27){
|
||||
event.preventDefault();
|
||||
$(this).siblings(".sp-cancel").click();
|
||||
$(this).trigger("cancelInput");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Data table adjustments
|
||||
$(".sp-table-adjustments input").change(function() {
|
||||
matrix = $(this).attr("data-matrix");
|
||||
$el = $(this).closest(".sp-table-adjustments").siblings(".sp-table-values").find("input[data-matrix="+matrix+"]");
|
||||
placeholder = parseFloat($el.attr("data-placeholder"));
|
||||
adjustment = parseFloat($(this).val()) - parseFloat($el.attr("data-adjustment"));
|
||||
if(!isNaN(adjustment)) placeholder += adjustment;
|
||||
$el.attr("placeholder", placeholder);
|
||||
});
|
||||
|
||||
// Data table keyboard navigation
|
||||
$(".sp-data-table tbody tr td input:text").keydown(function(event) {
|
||||
if(! $(this).parent().hasClass("chosen-search") && [37,38,39,40].indexOf(event.keyCode) > -1){
|
||||
|
||||
@@ -20,7 +20,8 @@ class SP_Meta_Box_Table_Data {
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
list( $columns, $usecolumns, $data, $placeholders, $merged ) = sp_get_league_table_data( $post->ID, true );
|
||||
sp_edit_league_table( $columns, $usecolumns, $data, $placeholders );
|
||||
$adjustments = get_post_meta( $post->ID, 'sp_adjustments', true );
|
||||
sp_edit_league_table( $columns, $usecolumns, $data, $placeholders, $adjustments );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,6 +29,7 @@ class SP_Meta_Box_Table_Data {
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
|
||||
update_post_meta( $post_id, 'sp_adjustments', sp_array_value( $_POST, 'sp_adjustments', array() ) );
|
||||
update_post_meta( $post_id, 'sp_teams', sp_array_value( $_POST, 'sp_teams', array() ) );
|
||||
}
|
||||
}
|
||||
@@ -937,12 +937,16 @@ if ( !function_exists( 'sp_edit_calendar_table' ) ) {
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_edit_league_table' ) ) {
|
||||
function sp_edit_league_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array() ) {
|
||||
function sp_edit_league_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array() ) {
|
||||
if ( is_array( $usecolumns ) )
|
||||
$usecolumns = array_filter( $usecolumns );
|
||||
$show_team_logo = get_option( 'sportspress_table_show_logos', false );
|
||||
?>
|
||||
<div class="sp-data-table-container">
|
||||
<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>
|
||||
<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>
|
||||
@@ -963,7 +967,6 @@ if ( !function_exists( 'sp_edit_league_table' ) ) {
|
||||
if ( !$team_id )
|
||||
continue;
|
||||
|
||||
$div = get_term( $team_id, 'sp_season' );
|
||||
$default_name = sp_array_value( $team_stats, 'name', '' );
|
||||
if ( $default_name == null )
|
||||
$default_name = get_the_title( $team_id );
|
||||
@@ -971,12 +974,12 @@ if ( !function_exists( 'sp_edit_league_table' ) ) {
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php if ( $show_team_logo ) echo get_the_post_thumbnail( $team_id, 'sportspress-fit-icon' ); ?>
|
||||
<span class="sp-default-name">
|
||||
<span class="sp-default-name-input"><?php echo $default_name; ?></span>
|
||||
<a class="dashicons dashicons-edit sp-edit-name" title="<?php _e( 'Edit', 'sportspress' ); ?>"></a>
|
||||
<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-name">
|
||||
<input type="text" name="sp_teams[<?php echo $team_id; ?>][name]" class="name sp-custom-name-input" value="<?php echo sp_array_value( $team_stats, 'name', '' ); ?>" placeholder="<?php echo get_the_title( $team_id ); ?>" size="6">
|
||||
<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 sp_array_value( $team_stats, 'name', '' ); ?>" placeholder="<?php echo 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>
|
||||
@@ -985,7 +988,51 @@ if ( !function_exists( 'sp_edit_league_table' ) ) {
|
||||
$value = sp_array_value( $team_stats, $column, '' );
|
||||
$placeholder = sp_array_value( sp_array_value( $placeholders, $team_id, array() ), $column, 0 );
|
||||
?>
|
||||
<td><input type="text" name="sp_teams[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
|
||||
<td><input type="text" name="sp_teams[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" data-placeholder="<?php echo $placeholder; ?>" data-matrix="<?php echo $team_id; ?>_<?php echo $column; ?>" data-adjustment="<?php echo sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $column, 0 ); ?>" /></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
else:
|
||||
?>
|
||||
<tr class="sp-row alternate">
|
||||
<td colspan="<?php $colspan = sizeof( $columns ) + 1; echo $colspan; ?>">
|
||||
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="sp-data-table-container sp-table-panel sp-table-adjustments hidden" id="sp-table-adjustments">
|
||||
<table class="widefat sp-data-table sp-league-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
||||
<?php foreach ( $columns as $key => $label ): ?>
|
||||
<th><?php echo $label; ?></th>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
if ( is_array( $data ) && sizeof( $data ) > 0 ):
|
||||
$i = 0;
|
||||
foreach ( $data as $team_id => $team_stats ):
|
||||
if ( !$team_id )
|
||||
continue;
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php echo get_the_title( $team_id ); ?>
|
||||
</td>
|
||||
<?php foreach( $columns as $column => $label ):
|
||||
$value = sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $column, '' );
|
||||
?>
|
||||
<td><input type="text" name="sp_adjustments[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" data-matrix="<?php echo $team_id; ?>_<?php echo $column; ?>" /></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<?php
|
||||
@@ -1829,6 +1876,7 @@ if ( !function_exists( 'sp_get_league_table_data' ) ) {
|
||||
$team_ids = (array)get_post_meta( $post_id, 'sp_team', false );
|
||||
$table_stats = (array)get_post_meta( $post_id, 'sp_teams', true );
|
||||
$usecolumns = get_post_meta( $post_id, 'sp_columns', true );
|
||||
$adjustments = get_post_meta( $post_id, 'sp_adjustments', true );
|
||||
|
||||
// Get labels from result variables
|
||||
$result_labels = (array)sp_get_var_labels( 'sp_result' );
|
||||
@@ -2053,7 +2101,14 @@ if ( !function_exists( 'sp_get_league_table_data' ) ) {
|
||||
|
||||
foreach ( $stats as $stat ):
|
||||
if ( sp_array_value( $placeholders[ $team_id ], $stat->post_name, '' ) == '' ):
|
||||
$placeholders[ $team_id ][ $stat->post_name ] = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision );
|
||||
|
||||
// Solve
|
||||
$placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision );
|
||||
|
||||
// Adjustments
|
||||
$placeholder += sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $stat->post_name, 0 );
|
||||
|
||||
$placeholders[ $team_id ][ $stat->post_name ] = $placeholder;
|
||||
endif;
|
||||
endforeach;
|
||||
endforeach;
|
||||
|
||||
Reference in New Issue
Block a user