diff --git a/assets/css/admin.css b/assets/css/admin.css index 13d0886c..94abe6ff 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -53,6 +53,27 @@ content: "\f453"; } +.post-type-sp_event .sp-event-status:before { + color: #82878c; + font: 400 20px/1 dashicons; + speak: none; + display: inline-block; + padding: 0 2px 0 0; + top: 0; + left: -1px; + position: relative; + vertical-align: top; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + text-decoration: none!important; + content: "\f469"; +} + +.post-type-sp_event .sp-event-status-select { + line-height: 1.5em; + margin-top: 3px; +} + .sp-link:before { font: normal 20px/1 dashicons; speak: none; diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js index a4f05ce6..0a35e301 100644 --- a/assets/js/admin/sportspress-admin.js +++ b/assets/js/admin/sportspress-admin.js @@ -775,4 +775,33 @@ jQuery(document).ready(function($){ } }); }); + + // Event status selector + $('.sp-edit-event-status').click(function(e) { + e.preventDefault(); + $select = $(this).siblings('.sp-event-status-select'); + if ( $select.is(':hidden') ) { + $select.slideDown( 'fast', function() { + $select.find( 'input[type="radio"]' ).first().focus(); + } ); + $(this).hide(); + } + }); + + $('.sp-save-event-status').click(function(e) { + e.preventDefault(); + $select = $(this).closest('.sp-event-status-select'); + $input = $select.find('input[name=sp_status]:checked'); + val = $input.val(); + label = $input.data('sp-event-status'); + $select.slideUp('fast').siblings('.sp-edit-event-status').show().siblings('.sp-event-status').find('.sp-event-status-display').data('sp-event-status', val).html(label); + }); + + $('.sp-cancel-event-status').click(function(e) { + e.preventDefault(); + $select = $(this).closest('.sp-event-status-select'); + val = $select.siblings('.sp-event-status').find('.sp-event-status-display').data('sp-event-status'); + $select.find('input[value='+val+']').attr('checked', true); + $select.slideUp('fast').siblings('.sp-edit-event-status').show(); + }); }); \ No newline at end of file diff --git a/modules/sportspress-event-status.php b/modules/sportspress-event-status.php new file mode 100644 index 00000000..0d66b7f7 --- /dev/null +++ b/modules/sportspress-event-status.php @@ -0,0 +1,109 @@ +define_constants(); + + // Define statuses + $this->get_statuses(); + + add_action( 'post_submitbox_misc_actions', array( $this, 'section' ) ); + add_action( 'sportspress_process_sp_event_meta', array( $this, 'save' ), 10, 1 ); + } + + /** + * Define constants. + */ + private function define_constants() { + if ( !defined( 'SP_EVENT_STATUS_VERSION' ) ) + define( 'SP_EVENT_STATUS_VERSION', '2.1' ); + + if ( !defined( 'SP_EVENT_STATUS_URL' ) ) + define( 'SP_EVENT_STATUS_URL', plugin_dir_url( __FILE__ ) ); + + if ( !defined( 'SP_EVENT_STATUS_DIR' ) ) + define( 'SP_EVENT_STATUS_DIR', plugin_dir_path( __FILE__ ) ); + } + + /** + * Define statuses. + */ + private function get_statuses() { + $this->statuses = apply_filters( 'sportspress_event_statuses', array( + 'ok' => __( 'On time', 'sportspress' ), + 'tbd' => __( 'To be determined', 'sportspress' ) . ' (' . __( 'TBD', 'sportspress' ) . ')', + 'cancelled' => __( 'Cancelled', 'sportspress' ), + 'postponed' => __( 'Postponed', 'sportspress' ), + ) ); + } + + /** + * Add status section to submit box. + */ + public function section() { + if ( 'sp_event' !== get_post_type() ) return; + $status = get_post_meta( get_the_ID(), 'sp_status', true ); + if ( ! $status ) $status = 'ok'; + ?> +