diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js
index a6b9ce0a..ca7c70b1 100644
--- a/assets/js/admin/sportspress-admin.js
+++ b/assets/js/admin/sportspress-admin.js
@@ -620,4 +620,83 @@ jQuery(document).ready(function($){
$(".sp-select-sport").change(function() {
$(".sp-configure-sport").hide();
});
+
+ // Ajax checklist
+ $(".sp-ajax-checklist").siblings(".sp-tab-select").find("select").change(function() {
+ $(this).closest(".sp-tab-select").siblings(".sp-ajax-checklist").find("ul").html("
" + localized_strings.loading + "");
+ $.post( ajaxurl, {
+ action: "sp-get-players",
+ team: $(this).val(),
+ league: ('yes' == localized_strings.option_filter_by_league) ? $("select[name=\"tax_input[sp_league][]\"]").val() : null,
+ season: ('yes' == localized_strings.option_filter_by_season) ? $("select[name=\"tax_input[sp_season][]\"]").val() : null,
+ index: $(this).closest(".sp-instance").index(),
+ nonce: $("#sp-get-players-nonce").val()
+ }).done(function( response ) {
+ index = response.data.index;
+ $target = $(".sp-instance").eq(index).find(".sp-ajax-checklist ul");
+ if ( response.success ) {
+ $target.html("");
+ if(response.data.players.length) {
+ $target.eq(0).append("");
+ $(response.data.players).each(function( key, value ) {
+ $target.eq(0).append("");
+ });
+ $target.eq(0).append("" + localized_strings.show_all + "");
+ } else {
+ $target.eq(0).html("" + localized_strings.no_results_found + " " + localized_strings.show_all + "");
+ }
+ if(response.data.staff.length) {
+ $target.eq(1).append("");
+ $(response.data.staff).each(function( key, value ) {
+ $target.eq(1).append("");
+ });
+ $target.eq(1).append("" + localized_strings.show_all + "");
+ } else {
+ $target.eq(1).html("" + localized_strings.no_results_found + " " + localized_strings.show_all + "");
+ }
+ } else {
+ $target.html("" + localized_strings.no_results_found + "");
+ }
+ });
+ });
+
+ // Activate Ajax trigger
+ $(".sp-ajax-trigger").change(function() {
+ $(".sp-ajax-checklist").siblings(".sp-tab-select").find("select").change();
+ });
+
+ // Ajax show all filter
+ $(".sp-tab-panel").on("click", ".sp-ajax-show-all", function() {
+ index = $(this).closest(".sp-instance").index();
+ $(this).parent().html(localized_strings.loading);
+ $.post( ajaxurl, {
+ action: "sp-get-players",
+ index: index,
+ nonce: $("#sp-get-players-nonce").val()
+ }).done(function( response ) {
+ index = response.data.index;
+ console.log(index);
+ $target = $(".sp-instance").eq(index).find(".sp-ajax-checklist ul");
+ $target.find(".sp-ajax-show-all-container").hide();
+ if ( response.success ) {
+ if(response.data.players.length) {
+ $(response.data.players).each(function( key, value ) {
+ if($target.find("input[value=" + value.ID + "]").length) return true;
+ $target.eq(0).append("");
+ });
+ } else {
+ $target.eq(0).html("" + localized_strings.no_results_found + "");
+ }
+ if(response.data.staff.length) {
+ $(response.data.staff).each(function( key, value ) {
+ $target.eq(1).append("");
+ });
+ } else {
+ $target.eq(1).html("" + localized_strings.no_results_found + "");
+ }
+ } else {
+ $target.html("" + localized_strings.no_results_found + "");
+ }
+ });
+ });
});
\ No newline at end of file
diff --git a/includes/class-sp-modules.php b/includes/class-sp-modules.php
index e39411db..a370f702 100644
--- a/includes/class-sp-modules.php
+++ b/includes/class-sp-modules.php
@@ -113,13 +113,6 @@ class SP_Modules {
'link' => 'http://tboy.co/pro',
'desc' => __( 'Clone anything with just one click. Great for creating multiple events.', 'sportspress' ),
),
- 'lazy_loading' => array(
- 'label' => __( 'Lazy Loading', 'sportspress' ),
- 'class' => 'SportsPress_Lazy_Loading',
- 'icon' => 'sp-icon-moon',
- 'link' => 'http://tboy.co/pro',
- 'desc' => __( 'Load players using Ajax to speed up the event edit screen.', 'sportspress' ),
- ),
),
'other' => array(
'twitter' => array(
diff --git a/modules/sportspress-lazy-loading.php b/modules/sportspress-lazy-loading.php
new file mode 100644
index 00000000..5bc6f2be
--- /dev/null
+++ b/modules/sportspress-lazy-loading.php
@@ -0,0 +1,213 @@
+ 'menu_order',
+ );
+
+ if ( $team ) {
+ $args['meta_query'] = array(
+ array(
+ 'key' => 'sp_current_team',
+ 'value' => sp_array_value( $_POST, 'team' ),
+ ),
+ );
+ }
+
+ if ( $league || $season ) {
+ $args['tax_query'] = array( 'relation' => 'AND' );
+
+ if ( $league ) {
+ $args['tax_query'][] = array(
+ 'taxonomy' => 'sp_league',
+ 'field' => 'id',
+ 'terms' => $league,
+ );
+ }
+
+ if ( $season ) {
+ $args['tax_query'][] = array(
+ 'taxonomy' => 'sp_season',
+ 'field' => 'id',
+ 'terms' => $season,
+ );
+ }
+ }
+
+ $player_args = $args;
+ $player_args['meta_key'] = 'sp_number';
+ $player_args['orderby'] = 'meta_value_num';
+ $player_args['order'] = 'ASC';
+
+ $players = sp_get_posts( 'sp_player', $player_args );
+ $staff = sp_get_posts( 'sp_staff', $args );
+ $data = array( 'index' => $index );
+
+ foreach ( $players as $key => $value ) {
+ $players[ $key ]->post_title = sp_get_player_name_with_number( $value->ID );
+ }
+
+ $data['players'] = $players;
+ $data['staff'] = $staff;
+ wp_send_json_success( $data );
+ }
+
+ /**
+ * Ajax checklist.
+ */
+ public function checklist( $post_id = null, $post_type = 'post', $display = 'block', $team = null, $index = null, $slug = null ) {
+ if ( ! isset( $slug ) ):
+ $slug = $post_type;
+ endif;
+
+ $selected = (array)get_post_meta( $post_id, $slug, false );
+ if ( sizeof( $selected ) ) {
+ $selected = sp_array_between( $selected, 0, $index );
+ } else {
+ $selected = sp_array_between( (array)get_post_meta( $post_id, $post_type, false ), 0, $index );
+ }
+
+ $leagues = get_the_terms( $post_id, 'sp_league' );
+ $seasons = get_the_terms( $post_id, 'sp_season' );
+
+ $args = array(
+ 'orderby' => 'menu_order',
+ );
+
+ if ( 'sp_player' == $post_type ):
+ $args['meta_key'] = 'sp_number';
+ $args['orderby'] = 'meta_value_num';
+ $args['order'] = 'ASC';
+ endif;
+
+ $args['meta_query'] = array(
+ array(
+ 'key' => 'sp_current_team',
+ 'value' => $team,
+ ),
+ );
+
+ if ( $leagues || $seasons ) {
+ $args['tax_query'] = array( 'relation' => 'AND' );
+
+ if ( $leagues ) {
+ $args['tax_query'][] = array(
+ 'taxonomy' => 'sp_league',
+ 'field' => 'id',
+ 'terms' => wp_list_pluck( $leagues, 'term_id' ),
+ );
+ }
+
+ if ( $seasons ) {
+ $args['tax_query'][] = array(
+ 'taxonomy' => 'sp_season',
+ 'field' => 'id',
+ 'terms' => wp_list_pluck( $seasons, 'term_id' ),
+ );
+ }
+ }
+
+ $posts = sp_get_posts( $post_type, $args );
+ $post_ids = wp_list_pluck( $posts, 'ID' );
+ $diff = array_diff( $post_ids, $selected );
+ $selected = array_flip( $selected );
+ ?>
+
+ __( 'No results found.', 'sportspress' ),
+ 'select_all' => __( 'Select All', 'sportspress' ),
+ 'show_all' => __( 'Show all', 'sportspress' ),
+ 'loading' => __( 'Loading…', 'sportspress' ),
+ 'option_filter_by_league' => get_option( 'sportspress_event_filter_teams_by_league', 'no' ),
+ 'option_filter_by_season' => get_option( 'sportspress_event_filter_teams_by_season', 'no' ),
+ ) ) ;
+ return $strings;
+ }
+}
+
+endif;
+
+new SportsPress_Lazy_Loading();
\ No newline at end of file