Permalink
Browse files

Update movie search by ID (#393)

  • Loading branch information...
Charlie Merland
Charlie Merland committed Dec 6, 2017
1 parent 316a1eb commit 5169894efc5d5caa466e539ce3a1edab7e5ac15b
Showing with 27 additions and 23 deletions.
  1. +3 −3 admin/class-wpmoly-api-wrapper.php
  2. +24 −20 assets/js/admin/wpmoly-editor-meta.js
@@ -112,10 +112,10 @@ public static function search_movie_callback() {
if ( '' == $data || '' == $type )
return false;
if ( 'title' == $type )
if ( false !== strpos( $data, 'id:' ) )
$response = self::get_movie_by_id( str_replace( 'id:', '', $data ), $lang, $_id );
else
$response = self::get_movie_by_title( $data, $lang, $_id );
else if ( 'id' == $type )
$response = self::get_movie_by_id( $data, $lang, $_id );
wpmoly_ajax_response( $response );
}
@@ -135,28 +135,32 @@ wpmoly = wpmoly || {};
data: ( wpmoly_edit_meta.type == 'title' ? wpmoly_edit_meta.title : wpmoly_edit_meta.tmdb_id ),
lang: wpmoly_edit_meta.lang
},
error: function( response ) {
wpmoly_state.clear();
$.each( response.responseJSON.errors, function() {
wpmoly_state.set( this, 'error' );
});
},
success: function( response ) {
if ( 'movie' == response.data.result ) {
wpmoly_edit_meta.set( response.data.movies[ 0 ] );
if ( wpmoly_edit_meta.poster_featured )
wpmoly_posters.set_featured( response.data.movies[ 0 ].poster_path );
}
else if ( 'movies' == response.data.result ) {
wpmoly_edit_meta.select( response.data.movies, response.data.message );
}
else if ( 'empty' == response.data.result ) {
wpmoly_state.set( response.data.message, 'error' );
complete: function( response, b, c ) {
console.log( response, b, c );
if ( undefined !== response.responseJSON.errors ) {
wpmoly_state.clear();
$.each( response.responseJSON.errors, function() {
wpmoly_state.set( this, 'error' );
});
} else if ( undefined !== response.responseJSON.data ) {
var data = response.responseJSON.data,
result = data.result || data._result;
if ( 'movie' == result ) {
wpmoly_edit_meta.set( data );
if ( wpmoly_edit_meta.poster_featured )
wpmoly_posters.set_featured( data.poster_path );
}
else if ( 'movies' == result ) {
wpmoly_edit_meta.select( data.movies, data.message );
}
else if ( 'empty' == result ) {
wpmoly_state.set( data.message, 'error' );
}
}
},
complete: function( r ) {
wpmoly.editor.$spinner.hide();
wpmoly.update_nonce( 'search-movies', r.responseJSON.nonce );
wpmoly.update_nonce( 'search-movies', response.responseJSON.nonce );
}
});
};

0 comments on commit 5169894

Please sign in to comment.