Add drag-and-drop template layout options

This commit is contained in:
Brian Miyaji
2016-04-02 18:39:17 +11:00
parent bd565b16bb
commit e611b00a92
10 changed files with 568 additions and 129 deletions

View File

@@ -23,11 +23,15 @@ class SP_Settings_Events extends SP_Settings_Page {
public function __construct() {
$this->id = 'events';
$this->label = __( 'Events', 'sportspress' );
$this->template = 'event';
$this->templates = SP()->templates->event;
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_current_mode', array( $this, 'current_mode_setting' ) );
add_action( 'sportspress_admin_field_delimiter', array( $this, 'delimiter_setting' ) );
add_action( 'sportspress_admin_field_event_layout', array( $this, 'layout_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
@@ -55,20 +59,15 @@ class SP_Settings_Events extends SP_Settings_Page {
),
apply_filters( 'sportspress_event_template_options', array(
array( 'type' => 'event_layout' ),
array(
'title' => __( 'Display', 'sportspress' ),
'desc' => __( 'Logos', 'sportspress' ),
'id' => 'sportspress_event_show_logos',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Date', 'sportspress' ),
'id' => 'sportspress_event_show_date',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Time', 'sportspress' ),
@@ -77,34 +76,6 @@ class SP_Settings_Events extends SP_Settings_Page {
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Results', 'sportspress' ),
'id' => 'sportspress_event_show_results',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Details', 'sportspress' ),
'id' => 'sportspress_event_show_details',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Venue', 'sportspress' ),
'id' => 'sportspress_event_show_venue',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Scorecard', 'sportspress' ),
'id' => 'sportspress_event_show_performance',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
) ),
array(
@@ -421,8 +392,7 @@ class SP_Settings_Events extends SP_Settings_Page {
* Save settings
*/
public function save() {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
parent::save();
if ( isset( $_POST['sportspress_event_teams_delimiter'] ) )
update_option( 'sportspress_event_teams_delimiter', $_POST['sportspress_event_teams_delimiter'] );

View File

@@ -19,7 +19,8 @@ class SP_Settings_Page {
protected $id = '';
protected $label = '';
protected $template = '';
public $templates = array();
/**
* Add this page to settings
*/
@@ -56,8 +57,69 @@ class SP_Settings_Page {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
if ( $current_section )
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section );
if ( $current_section )
do_action( 'sportspress_update_options_' . $this->template . '_' . $current_section );
if ( ! empty( $this->templates ) )
update_option( 'sportspress_' . $this->template . '_template_order', sp_array_value( $_POST, 'sportspress_' . $this->template . '_template_order', false ) );
if ( isset( $_POST['sportspress_template_visibility'] ) && is_array( $_POST['sportspress_template_visibility'] ) ) {
foreach ( $_POST['sportspress_template_visibility'] as $option => $toggled ) {
if ( $toggled ) {
update_option( $option, 'yes' );
} else {
update_option( $option, 'no' );
}
}
}
}
/**
* Layout settings
*
* @access public
* @return void
*/
public function layout_setting() {
$templates = apply_filters( 'sportspress_' . $this->template . '_templates', $this->templates );
$layout = get_option( 'sportspress_' . $this->template . '_template_order' );
if ( false === $layout ) {
$layout = array_keys( $templates );
}
$templates = array_merge( array_flip( $layout ), $templates );
?>
<tr valign="top">
<th>
<?php _e( 'Layout', 'sportspress' ); ?>
</th>
<td class="sp-sortable-list-container">
<p class="description"><?php _e( 'Drag each item into the order you prefer.', 'sportspress' ); ?></p>
<ul class="sp-layout sp-sortable-list ui-sortable">
<?php foreach ( $templates as $template => $details ) {
$option = sp_array_value( $details, 'option', 'sportspress_' . $this->template . '_show_' . $template );
$visibility = get_option( $option, sp_array_value( $details, 'default', 'yes' ) );
?>
<li>
<div class="sp-item-bar sp-layout-item-bar">
<div class="sp-item-handle sp-layout-item-handle ui-sortable-handle">
<span class="sp-item-title item-title"><?php echo sp_array_value( $details, 'title', ucfirst( $template ) ); ?></span>
<input type="hidden" name="sportspress_<?php echo $this->template; ?>_template_order[]" value="<?php echo $template; ?>">
</div>
<input type="hidden" name="sportspress_template_visibility[<?php echo $option; ?>]" value="0">
<input class="sp-toggle-switch" type="checkbox" name="sportspress_template_visibility[<?php echo $option; ?>]" id="<?php echo $option; ?>" value="1" <?php checked( $visibility, 'yes' ); ?>>
<label for="sportspress_<?php echo $this->template; ?>_show_<?php echo $template; ?>"></label>
</div>
</li>
<?php } ?>
</ul>
</td>
</tr>
<?php
}
}

View File

@@ -23,9 +23,13 @@ class SP_Settings_Players extends SP_Settings_Page {
public function __construct() {
$this->id = 'players';
$this->label = __( 'Players', 'sportspress' );
$this->template = 'player';
$this->templates = SP()->templates->player;
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_player_layout', array( $this, 'layout_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
@@ -37,12 +41,13 @@ class SP_Settings_Players extends SP_Settings_Page {
public function get_settings() {
$settings = array_merge(
array(
array( 'title' => __( 'Player Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'player_options' ),
),
apply_filters( 'sportspress_player_options', array(
array( 'type' => 'player_layout' ),
array(
'title' => __( 'Link', 'sportspress' ),
'desc' => __( 'Link players', 'sportspress' ),
@@ -51,39 +56,6 @@ class SP_Settings_Players extends SP_Settings_Page {
'type' => 'checkbox',
),
array(
'title' => __( 'Display', 'sportspress' ),
'desc' => __( 'Photo', 'sportspress' ),
'id' => 'sportspress_player_show_photo',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Details', 'sportspress' ),
'id' => 'sportspress_player_show_details',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Statistics', 'sportspress' ),
'id' => 'sportspress_player_show_statistics',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Total', 'sportspress' ),
'id' => 'sportspress_player_show_total',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Details', 'sportspress' ),
'desc' => __( 'Nationality', 'sportspress' ),
@@ -156,6 +128,14 @@ class SP_Settings_Players extends SP_Settings_Page {
),
),
array(
'title' => __( 'Total', 'sportspress' ),
'desc' => __( 'Display total', 'sportspress' ),
'id' => 'sportspress_player_show_total',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Nationality', 'sportspress' ),
'desc' => __( 'Display national flags', 'sportspress' ),

View File

@@ -23,9 +23,13 @@ class SP_Settings_Teams extends SP_Settings_Page {
public function __construct() {
$this->id = 'teams';
$this->label = __( 'Teams', 'sportspress' );
$this->template = 'team';
$this->templates = SP()->templates->team;
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_team_layout', array( $this, 'layout_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
@@ -43,6 +47,8 @@ class SP_Settings_Teams extends SP_Settings_Page {
),
apply_filters( 'sportspress_team_options', array(
array( 'type' => 'team_layout' ),
array(
'title' => __( 'Link', 'sportspress' ),
'desc' => __( 'Link teams', 'sportspress' ),
@@ -51,31 +57,6 @@ class SP_Settings_Teams extends SP_Settings_Page {
'type' => 'checkbox',
),
array(
'title' => __( 'Display', 'sportspress' ),
'desc' => __( 'Logo', 'sportspress' ),
'id' => 'sportspress_team_show_logo',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Details', 'sportspress' ),
'id' => 'sportspress_team_show_details',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Visit Site', 'sportspress' ),
'id' => 'sportspress_team_show_link',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Venue', 'sportspress' ),
'desc' => __( 'Link venues', 'sportspress' ),