From e09a5bb3110b4f0b6dd20c29942fe0f507e6c781 Mon Sep 17 00:00:00 2001 From: Takumi Date: Thu, 1 Aug 2013 00:55:21 +1000 Subject: [PATCH] Improve stats table filters --- event.php | 2 +- globals.php | 3 +++ helpers.php | 49 +++++++++++++--------------------- league.php | 2 +- sportspress-admin.js | 63 ++++++++++++++++++++++++-------------------- table.php | 43 ++++++++++++++++++------------ team.php | 2 +- 7 files changed, 85 insertions(+), 79 deletions(-) diff --git a/event.php b/event.php index d724be45..57230cc0 100644 --- a/event.php +++ b/event.php @@ -84,7 +84,7 @@ function sp_event_stats_meta( $post ) { ?>

- +
%1$s' => __( 'Joined', 'sportspress' ) . ': %1$s', 'Published on: %1$s' => __( 'Joined', 'sportspress' ) . ': %1$s', 'Publish immediately' => __( 'Joined', 'sportspress' ) . ': %1$s' + ), + 'sp_table' => array( + 'Enter title here' => '' ) ); diff --git a/helpers.php b/helpers.php index d5c9ba66..5fa91f49 100644 --- a/helpers.php +++ b/helpers.php @@ -115,7 +115,7 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) { printf( '', $args['show_option_none'] ); } foreach ( $terms as $term ) { - printf( '', $term->slug, selected( true, $args['selected'] == $term->slug ), $term->name ); + printf( '', $term->term_id, selected( true, $args['selected'] == $term->term_id, false ), $term->name ); } print( '' ); } @@ -179,8 +179,14 @@ if ( !function_exists( 'sp_post_checklist' ) ) { $posts = get_posts( array( 'post_type' => $meta, 'numberposts' => 0 ) ); foreach ( $posts as $post ): $parents = get_post_ancestors( $post ); - if ( $filter ) - $filter_values = (array)get_post_meta( $post->ID, $filter, false ) + if ( $filter ): + $filter_values = (array)get_post_meta( $post->ID, $filter, false ); + $terms = (array)get_the_terms( $post->ID, 'sp_league' ); + foreach ( $terms as $term ): + if ( is_object( $term ) && property_exists( $term, 'term_id' ) ) + $filter_values[] = $term->term_id; + endforeach; + endif; ?>
  • + - - - @@ -242,9 +245,8 @@ if ( !function_exists( 'sp_stats_table' ) ) { $i = 0; foreach ( $stats as $key => $values ): if ( !$key ) continue; - $is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : $pagenow == 'post-new.php'; ?> - + - + - - - - > + - + - - - diff --git a/league.php b/league.php index f1b518db..1cb203ff 100644 --- a/league.php +++ b/league.php @@ -2,7 +2,7 @@ function sp_league_tax_init() { $name = __( 'Leagues', 'sportspress' ); $singular_name = __( 'League', 'sportspress' ); - $object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' ); + $object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_list' ); $labels = sp_tax_labels( $name, $singular_name ); $args = array( 'label' => $name, diff --git a/sportspress-admin.js b/sportspress-admin.js index 13a76579..61b1f215 100644 --- a/sportspress-admin.js +++ b/sportspress-admin.js @@ -1,12 +1,12 @@ jQuery(document).ready(function($){ - // Switch tabs + // 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(); return false; }); - // Filter tabs + // Tab filter $('.sp-tab-panel').siblings('.sp-tab-select').find('select').change(function() { var val = $(this).val(); $(this).closest('.sp-tab-select').siblings('.sp-tab-panel').find('.sp-post').hide(0, function() { @@ -17,37 +17,44 @@ jQuery(document).ready(function($){ }); }); - // Activate tab filters + // Trigger tab filter $('.sp-tab-panel').siblings('.sp-tab-select').find('select').change(); - // Data table checkboxes - $('.sp-data-table tr input[type=checkbox]').change(function() { - $el = $(this).closest('tr').find('input[type=text], input[type=number]'); - $el.prop('readonly', $(this).prop('checked')); - if($(this).prop('checked')) { - $el.each(function() { - $(this).val($(this).attr('placeholder')); - }); - } - }) - - // Uncheck auto to edit - $('.sp-data-table tr input[type=text], .sp-data-table tr input[type=text]').click(function() { - $el = $(this).closest('tr').find('input[type=checkbox]'); - if($el.size()) { - $el.prop('checked', false).change(); - } - }) - - // Activate checkboxes - $('.sp-data-table tr input[type=checkbox]').change(); - - // Change title - $('.sp-title-generator select').change(function() { + // Title changer + $('input[name=post_title]').on('updateTitle', function() { title = $('.sp-title-generator select[value!=0]').map(function(){ return $(this).find(':selected').html().replace(/&[^;]+;/g, ''); }).get().join(' vs '); - $('input[name=post_title]').val(title); + $(this).val(title); }); + // Activate title changer + $('.sp-title-generator select').change(function() { + $('input[name=post_title]').trigger('updateTitle'); + }); + + // Total stats calculator + $('.sp-stats-table').on('updateTotals', function() { + $self = $(this); + $self.find('.sp-total input').each(function(i) { + var sum = 0; + $self.find('.sp-post').each(function() { + $el = $($(this).find('input')[i]); + if($el.val() != '') + if($.isNumeric($el.val())) sum += parseInt($el.val(), 10); + else + sum += parseInt($el.attr('placeholder'), 10); + }); + $(this).attr('placeholder', sum); + }); + }); + + // Activate total stats calculator + $('.sp-stats-table .sp-post input').on('keyup', function() { + $(this).closest('.sp-stats-table').trigger('updateTotals'); + }); + + // Trigger total stats calculator + $('.sp-stats-table').trigger('updateTotals'); + }); \ No newline at end of file diff --git a/table.php b/table.php index 88e6ce73..55065589 100644 --- a/table.php +++ b/table.php @@ -35,29 +35,38 @@ function sp_table_meta_init() { } function sp_table_team_meta( $post ) { - sp_post_checklist( $post->ID, 'sp_team' ); - sp_post_adder( 'sp_team' ); + $league = get_post_meta( $post->ID, 'sp_league', true ); + ?> +
    +

    + sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ), + 'taxonomy' => 'sp_league', + 'name' => 'sportspress[sp_league]', + 'selected' => $league + ); + sp_dropdown_taxonomies( $args ); + ?> +

    + ID, 'sp_team', 'block', 'sp_league' ); + sp_post_adder( 'sp_team' ); + ?> +
    + ID, 'sp_team', false ); $stats = (array)get_post_meta( $post->ID, 'sp_stats', true ); - $leagues = (array)get_the_terms( $post->ID, 'sp_league' ); - foreach ( $leagues as $league ): - if ( is_object( $league ) && property_exists( $league, 'term_id' ) ) - $index = $league->term_id; - else - $index = 0; - - $data = sp_array_combine( $teams, sp_array_value( $stats, $index, array() ) ); - - $placeholders = array(); - foreach ( $teams as $team ): - $placeholders[ $team ] = sp_get_stats( $team, 0, $index ); - endforeach; - - sp_stats_table( $data, $placeholders, $index, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false ); + $league = (int)get_post_meta( $post->ID, 'sp_league', true ); + $data = sp_array_combine( $teams, sp_array_value( $stats, $league, array() ) ); + $placeholders = array(); + foreach ( $teams as $team ): + $placeholders[ $team ] = sp_get_stats( $team, 0, $league ); endforeach; + sp_stats_table( $data, $placeholders, $league, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false ); } ?> \ No newline at end of file diff --git a/team.php b/team.php index d0c07ac2..3fb21005 100644 --- a/team.php +++ b/team.php @@ -48,7 +48,7 @@ function sp_team_stats_meta( $post ) { $data = sp_array_combine( $keys, sp_array_value( $stats, 0, array() ) ); ?> -
    />
    />