diff --git a/assets/css/admin.css b/assets/css/admin.css
index 0fb36386..e2134740 100644
--- a/assets/css/admin.css
+++ b/assets/css/admin.css
@@ -60,8 +60,8 @@
content: "\f504";
}
-.fixed .column-sp_team .result,
-.sp-calendar-table .result {
+.fixed .column-sp_team .sp-result,
+.sp-calendar-table .sp-result {
background: #888;
color: #fff;
font-size: 11px;
@@ -77,11 +77,16 @@
cursor: pointer;
}
-.fixed .column-sp_team .result:hover,
-.sp-calendar-table .result:hover {
+.fixed .column-sp_team .sp-result:hover,
+.sp-calendar-table .sp-result:hover {
background: #2ea2cc;
}
+.fixed .column-sp_team .sp-edit-result {
+ font-size: 11px;
+ line-height: 1.4em;
+}
+
.fixed .column-sp_format,
.fixed .column-sp_icon,
.fixed .column-sp_number {
diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js
index 608bdf50..32c0d126 100644
--- a/assets/js/admin/sportspress-admin.js
+++ b/assets/js/admin/sportspress-admin.js
@@ -547,6 +547,60 @@ jQuery(document).ready(function($){
});
$(".sp-date-selector select").trigger("change");
+ // Edit inline results
+ $("#the-list").on("click", ".sp-result, .sp-edit-results", function(){
+ team = $(this).data("team");
+ $column = $(this).closest(".column-sp_team");
+ $column.find(".sp-result, .sp-row-actions").hide();
+ $column.find(".sp-edit-result, .sp-inline-edit-save").show();
+ if ( team != undefined ) {
+ $column.find(".sp-edit-result[data-team='"+team+"']").select();
+ }
+ return false;
+ });
+
+ // Cancel inline results
+ $("#the-list").on("click", ".sp-inline-edit-save .cancel", function(){
+ $column = $(this).closest(".column-sp_team");
+ $column.find(".sp-edit-result, .sp-inline-edit-save").hide();
+ $column.find(".sp-result, .sp-row-actions").show();
+ return false;
+ });
+
+ // Save inline results
+ $("#the-list").on("click", ".sp-inline-edit-save .save", function(){
+ $column = $(this).closest(".column-sp_team");
+ results = [];
+ $column.find(".sp-edit-result").each(function() {
+ team = {};
+ team.id = $(this).data("team");
+ team.key = $(this).data("key");
+ team.result = $(this).val();
+ results.push( team );
+ });
+ $.post( ajaxurl, {
+ action: "sp-save-inline-results",
+ post_id: $column.find("input[name='sp_post_id']").val(),
+ results: results,
+ nonce: $("#sp-inline-nonce").val()
+ }, function(response) {
+ $column.find(".sp-edit-result").each(function() {
+ $column.find(".sp-result[data-team='"+$(this).data("team")+"']").html($(this).val());
+ });
+ $column.find(".sp-edit-result, .sp-inline-edit-save").hide();
+ $column.find(".sp-result, .sp-row-actions").show();
+ return false;
+ });
+ });
+
+ // Override inline form submission
+ $("#the-list").on("keypress", ".sp-edit-result", function(e) {
+ if ( e.which == 13 ) {
+ $(this).closest(".column-sp_team").find(".sp-inline-edit-save .save").trigger("click");
+ return false;
+ }
+ });
+
// Fitvids
$(".sp-fitvids").fitVids();
});
\ No newline at end of file
diff --git a/includes/admin/class-sp-admin-ajax.php b/includes/admin/class-sp-admin-ajax.php
index 962f241e..28b878e6 100644
--- a/includes/admin/class-sp-admin-ajax.php
+++ b/includes/admin/class-sp-admin-ajax.php
@@ -19,6 +19,7 @@ class SP_Admin_AJAX {
*/
public function __construct() {
add_action( 'wp_ajax_sp-save-primary-result', array( $this, 'save_primary_result' ), 1 );
+ add_action( 'wp_ajax_sp-save-inline-results', array( $this, 'save_inline_results' ) );
}
/**
@@ -34,6 +35,40 @@ class SP_Admin_AJAX {
update_option( 'sportspress_primary_result', $primary_result );
wp_send_json_success();
}
+
+ /**
+ * Save event results inline.
+ *
+ * @since 1.5
+ */
+ function save_inline_results() {
+ check_ajax_referer( 'sp-save-inline-results', 'nonce' );
+
+ $post_id = sp_array_value( $_POST, 'post_id' );
+ $results = sp_array_value( $_POST, 'results' );
+
+ if ( ! $post_id || ! is_array( $results ) ) {
+ // Return error
+ wp_send_json_error();
+ }
+
+ // Get current results meta
+ $meta = get_post_meta( $post_id, 'sp_results', true );
+
+ foreach ( $results as $result ) {
+ $id = sp_array_value( $result, 'id' );
+ $key = sp_array_value( $result, 'key' );
+ if ( ! $id || ! $key ) continue;
+
+ $meta[ $id ][ $key ] = sp_array_value( $result, 'result' );
+ }
+
+ // Update results
+ update_post_meta( $post_id, 'sp_results', $meta );
+
+ // Return success
+ wp_send_json_success();
+ }
}
return new SP_Admin_AJAX();
diff --git a/includes/admin/post-types/class-sp-admin-cpt-event.php b/includes/admin/post-types/class-sp-admin-cpt-event.php
index 4452795f..0381ff28 100644
--- a/includes/admin/post-types/class-sp-admin-cpt-event.php
+++ b/includes/admin/post-types/class-sp-admin-cpt-event.php
@@ -127,6 +127,7 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
else:
$results = get_post_meta( $post_id, 'sp_results', true );
$main_result = get_option( 'sportspress_primary_result', null );
+ echo '';
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
@@ -140,20 +141,37 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
if ( is_array( $team_results ) ):
end( $team_results );
$team_result = prev( $team_results );
+ $main_result = key( $team_results );
else:
$team_result = null;
endif;
endif;
- if ( $team_result != null ):
+ if ( is_array( $team_results ) ):
unset( $team_results['outcome'] );
$team_results = implode( ' | ', $team_results );
- echo '' . $team_result . ' ';
endif;
+
+ if ( $team_result == null ) $team_result = '-';
+ echo '' . $team_result . '';
+ echo ' ';
echo $team->post_title;
echo '
';
endif;
endforeach;
+ ?>
+