Add inline result editing
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
@@ -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 '<input type="hidden" name="sp_post_id" value="' . $post_id . '">';
|
||||
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 '<a class="result tips" title="' . $team_results . '" href="' . get_edit_post_link( $post_id ) . '">' . $team_result . '</a> ';
|
||||
endif;
|
||||
|
||||
if ( $team_result == null ) $team_result = '-';
|
||||
echo '<a class="sp-result tips" title="' . $team_results . '" data-team="' . $team_id . '" href="#">' . $team_result . '</a>';
|
||||
echo '<input type="text" class="sp-edit-result hidden small-text" data-team="' . $team_id . '" data-key="' . $main_result . '" value="' . $team_result . '"> ';
|
||||
echo $team->post_title;
|
||||
echo '<br>';
|
||||
endif;
|
||||
endforeach;
|
||||
?>
|
||||
<div class="row-actions sp-row-actions"><span class="inline hide-if-no-js"><a href="#" class="sp-edit-results"><?php _e( 'Edit Results', 'sportspress' ); ?></a></span></div>
|
||||
<p class="inline-edit-save sp-inline-edit-save hidden">
|
||||
<a href="#inline-edit" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
|
||||
<?php wp_nonce_field( 'sp-save-inline-results', 'sp-inline-nonce', false ); ?>
|
||||
<a href="#inline-edit" class="button-primary save alignright"><?php _e( 'Update' ); ?></a>
|
||||
<span class="spinner"></span>
|
||||
<input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
|
||||
<input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
|
||||
<span class="error" style="display:none"></span>
|
||||
<br class="clear" />
|
||||
</p>
|
||||
<?php
|
||||
endif;
|
||||
break;
|
||||
case 'sp_league':
|
||||
|
||||
Reference in New Issue
Block a user