From 419da22d50c1dbc1d7442137b7fdcee8ba63fb73 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 18 Jun 2014 16:27:45 +1000 Subject: [PATCH] Enable event player reordering --- assets/css/admin.css | 12 ++++++++++++ assets/js/admin/sportspress-admin.js | 6 ++++++ .../class-sp-meta-box-event-performance.php | 12 ++++++------ includes/sp-core-functions.php | 15 ++++++++++++--- templates/event-performance.php | 10 +++++----- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 93e410c9..304018f2 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -226,6 +226,18 @@ table.widefat select.sp-outcome { width: 100%; } +table.widefat.sp-sortable-table tbody tr { + cursor: move; +} + +table.widefat.sp-sortable-table tr { + background-color: #fff; +} + +table.widefat.sp-sortable-table tr:nth-child(2n-1) { + background-color: #f9f9f9; +} + .sp-admin-config-table th, .sp-admin-config-table td { padding: 8px 10px; diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js index 79b37c3c..7296ac14 100644 --- a/assets/js/admin/sportspress-admin.js +++ b/assets/js/admin/sportspress-admin.js @@ -24,6 +24,7 @@ jQuery(document).ready(function($){ // Activate auto key placeholder $("#poststuff #title").keyup(); + // 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(); @@ -233,6 +234,11 @@ jQuery(document).ready(function($){ // Trigger check check $(".sp-data-table").trigger("checkCheck"); + // Sortable tables + $(".sp-sortable-table tbody").sortable({ + axis: "y" + }); + // Video embed $(".sp-add-video").click(function() { $(this).closest("fieldset").hide().siblings(".sp-video-field").show(); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php index d1eb6146..bdb855ca 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php @@ -55,7 +55,7 @@ class SP_Meta_Box_Event_Performance { public static function table( $labels = array(), $columns = array(), $data = array(), $team_id, $has_checkboxes = false ) { ?>
- +
@@ -77,12 +77,11 @@ class SP_Meta_Box_Event_Performance { $player_performance ): if ( !$player_id ) continue; $number = get_post_meta( $player_id, 'sp_number', true ); ?> - + $label ): @@ -98,10 +97,11 @@ class SP_Meta_Box_Event_Performance { - + + + $label ): @@ -113,7 +113,7 @@ class SP_Meta_Box_Event_Performance { - +
#
   
$value ): + if ( in_array( $key, $keys ) ): + $output[ $key ] = $value; + endif; + endforeach; + foreach ( $keys as $key ): - if ( is_array( $values ) && array_key_exists( $key, $values ) ) - $output[ $key ] = $values[ $key ]; - else + if ( ! array_key_exists( $key, $output ) ) $output[ $key ] = array(); endforeach; + return $output; } } diff --git a/templates/event-performance.php b/templates/event-performance.php index 86302f87..a307450a 100644 --- a/templates/event-performance.php +++ b/templates/event-performance.php @@ -13,15 +13,15 @@ if ( ! isset( $id ) ) $id = get_the_ID(); $event = new SP_Event( $id ); -$data = $event->performance(); +$performance = $event->performance(); // The first row should be column labels -$labels = $data[0]; +$labels = $performance[0]; // Remove the first row to leave us with the actual data -unset( $data[0] ); +unset( $performance[0] ); -$data = array_filter( $data ); +$performance = array_filter( $performance ); $teams = (array)get_post_meta( $id, 'sp_team', false ); $status = $event->status(); @@ -41,7 +41,7 @@ foreach( $teams as $index => $team_id ): $totals = array(); - $data = sp_array_combine( $players, sp_array_value( $data, $team_id, array() ) ); + $data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) ); ?>