Fix: Failed Remove Media Item

This commit is contained in:
Luca 2022-12-13 22:59:00 +01:00
parent 79122e6086
commit 66cfd8dff4
2 changed files with 51 additions and 65 deletions

View File

@ -63,7 +63,7 @@
initEvents: function(){ initEvents: function(){
$('#add_files').bind('click', this.openMediaManager); $('#add_files').bind('click', this.openMediaManager);
wp.media.frames.file_frame.on('select',this.mediaSelected, this); wp.media.frames.file_frame.on('select',this.mediaSelected, this);
$('.delete-att-item').live('click', this.removeMedia); $('.att-info').on('click','.delete-att-item', this.removeMedia);
setTimeout(() => { this.map.invalidateSize(); }, 0); setTimeout(() => { this.map.invalidateSize(); }, 0);
}, },
@ -90,6 +90,7 @@
id: attachment.id id: attachment.id
}); });
$('#soundmap-attachments-list').append(_o); $('#soundmap-attachments-list').append(_o);
$('.att-info').on('click','.delete-att-item', this.removeMedia);
}, },
@ -115,7 +116,7 @@
$(document).ready(function(){ $(document).ready(function(){
console.log($('#map_canvas').width()); //console.log($('#map_canvas').width());
// Add Timeout for wait load metabox // Add Timeout for wait load metabox
setTimeout(function() { setTimeout(function() {
soundmap.initMap(); soundmap.initMap();

View File

@ -81,12 +81,13 @@ if (!class_exists('Soundmap')){
function metaboxes_register_callback(){ function metaboxes_register_callback(){
add_meta_box('soundmap-map', __("Place the Marker", 'soundmap'), array($this, 'map_meta_box'), 'marker', 'normal', 'high'); add_meta_box('soundmap-map', __("Place the Marker", 'soundmap'), array($this, 'map_meta_box'), 'marker', 'normal', 'high');
add_meta_box('soundmap-email', __("Uploader Mail", 'soundmap'), array($this,'soundmap_email_meta_box'), 'marker', 'side', 'low'); add_meta_box('soundmap-media-info', __("Info", 'soundmap'), array($this,'info_meta_box'), 'marker', 'side', 'high');
add_meta_box('soundmap-sound-info', __("Info", 'soundmap'), array($this,'info_meta_box'), 'marker', 'side', 'high'); add_meta_box('soundmap-media-attachments', __("Media files attached.", 'soundmap'), array($this, 'attachments_meta_box'), 'marker', 'side', 'high');
add_meta_box('soundmap-sound-attachments', __("Media files attached.", 'soundmap'), array($this, 'attachments_meta_box'), 'marker', 'side', 'high'); // Ya no es necesario
//add_meta_box('soundmap-email', __("Uploader Mail", 'soundmap'), array($this, 'email_meta_box'), 'marker', 'side', 'low');
} //metaboxes_register_callback } //metaboxes_register_callback
function soundmap_email_meta_box(){ function email_meta_box(){
global $post; global $post;
$mail = get_post_meta($post->ID, 'EMAIL', TRUE); $mail = get_post_meta($post->ID, 'EMAIL', TRUE);
echo "<p>" . $mail . "</p>"; echo "<p>" . $mail . "</p>";
@ -107,22 +108,18 @@ if (!class_exists('Soundmap')){
$files = get_post_meta($post->ID, 'soundmap_attachments_id', FALSE); $files = get_post_meta($post->ID, 'soundmap_attachments_id', FALSE);
echo '<div id="soundmap-attachments">'; echo '<div id="soundmap-attachments">';
echo '<div><input type="button" id="add_files" class="button button-primary button-large" value="Add Files"></div>'; echo '<div class="add_button_container"><input type="button" id="add_files" class="button button-primary button-large" value="Add Files"></div>';
$out = ''; $out = '';
if ($files){ if ($files){
foreach($files as $file){ foreach($files as $file){
echo $file;
$data = wp_prepare_attachment_for_js( $file ); $data = wp_prepare_attachment_for_js( $file );
echo $data;
$out .= "<div class='soundmap-attach-item'> $out .= "<div class='soundmap-attach-item'>
<div class='att-icon'><img src='{$data['icon']}'/></div> <!-- <div class='att-icon'><img src='{$data['icon']}'/></div> -->
<div class='att-info'> <div class='att-info'><a href='{$data['url']}'><strong>{$data['title']}</strong></a><br/>
<a href='{$data['url']}'><strong>{$data['title']}</strong></a><br/> <audio controls>
<span class='att-length'>{$data['fileLength']}</span><br/> <source src='{$data['url']} type='{$data['mime']}'>
<a href='#' class='delete-att-item'>Borrar</a> </audio><br/>
</div> <a href='#' class='delete-att-item'>Borrar</a></div><div class='clear'></div><input type='hidden' name='soundmap-att-ids[]' value='{$file}' /></div>";
<div class='clear'></div>
<input type='hidden' name='soundmap-att-ids[]' value='{$file}' /></div>";
} }
} }
echo '<div id="soundmap-attachments-list">' . $out . '</div>'; echo '<div id="soundmap-attachments-list">' . $out . '</div>';
@ -358,19 +355,15 @@ if (!class_exists('Soundmap')){
} }
function register_hooks(){ function register_hooks(){
add_action('init', array($this, 'init')); add_action('init', array($this, 'init'));
add_action('admin_menu', array($this, 'admin_menu')); add_action('admin_menu', array($this, 'admin_menu'));
add_action('save_post', array($this,'save_post')); add_action('save_post', array($this,'save_post'));
add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts')); add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'));
//add_action('wp_print_footer_scripts', array($this, 'wp_print_footer_scripts'),1);
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('init', array($this, 'add_feed')); add_action('init', array($this, 'add_feed'));
/*add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('admin_init', array($this, 'register_admin_scripts'));*/
//AJAX ACTIONS //AJAX ACTIONS
add_action('wp_ajax_soundmap_JSON_load_markers',array($this, 'JSON_load_markers')); add_action('wp_ajax_soundmap_JSON_load_markers',array($this, 'JSON_load_markers'));
add_action('wp_ajax_nopriv_soundmap_JSON_load_markers',array($this, 'JSON_load_markers')); add_action('wp_ajax_nopriv_soundmap_JSON_load_markers',array($this, 'JSON_load_markers'));
@ -379,42 +372,34 @@ if (!class_exists('Soundmap')){
add_action('wp_ajax_soundmap-get-markers',array($this, 'soundmap_get_markers')); add_action('wp_ajax_soundmap-get-markers',array($this, 'soundmap_get_markers'));
add_action('wp_ajax_nopriv_soundmap-get-markers',array($this,'soundmap_get_markers')); add_action('wp_ajax_nopriv_soundmap-get-markers',array($this,'soundmap_get_markers'));
//add_action('wp_ajax_nopriv_soundmap-get-markers',array($this, 'soundmap_get_markers'));
add_action('wp_ajax_soundmap-get-content',array($this, 'soundmap_get_content')); add_action('wp_ajax_soundmap-get-content',array($this, 'soundmap_get_content'));
/* REST API Options */ /* REST API Options */
add_action('rest_api_init', function() {
add_action('rest_api_init','soinumapa_create_marker_georeference');
function soinumapa_create_marker_georeference() {
register_rest_field('marker','georeference', register_rest_field('marker','georeference',
array( array(
'get_callback' => 'marker_get_georeference', 'get_callback' => 'marker_get_georeference',
'schema' => null 'schema' => null
) )
); );
} });
add_action('rest_api_init',function() {
add_action('rest_api_init','soinumapa_create_marker_media');
function soinumapa_create_marker_media() {
register_rest_field('marker','media', register_rest_field('marker','media',
array( array(
'get_callback' => 'marker_get_media', 'get_callback' => 'marker_get_media',
'schema' => null 'schema' => null
) )
); );
} });
add_action('rest_api_init','soinumapa_create_marker_author'); add_action('rest_api_init', function() {
function soinumapa_create_marker_author() {
register_rest_field('marker','author', register_rest_field('marker','author',
array( array(
'get_callback' => 'marker_get_author', 'get_callback' => 'marker_get_author',
'schema' => null 'schema' => null
) )
); );
} });
function marker_get_georeference ($object, $field_name, $request){ function marker_get_georeference ($object, $field_name, $request){
//return $object['id']; //return $object['id'];