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

View File

@ -81,12 +81,13 @@ if (!class_exists('Soundmap')){
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-email', __("Uploader Mail", 'soundmap'), array($this,'soundmap_email_meta_box'), 'marker', 'side', 'low');
add_meta_box('soundmap-sound-info', __("Info", 'soundmap'), array($this,'info_meta_box'), 'marker', 'side', 'high');
add_meta_box('soundmap-sound-attachments', __("Media files attached.", 'soundmap'), array($this, 'attachments_meta_box'), 'marker', 'side', 'high');
add_meta_box('soundmap-media-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');
// Ya no es necesario
//add_meta_box('soundmap-email', __("Uploader Mail", 'soundmap'), array($this, 'email_meta_box'), 'marker', 'side', 'low');
} //metaboxes_register_callback
function soundmap_email_meta_box(){
function email_meta_box(){
global $post;
$mail = get_post_meta($post->ID, 'EMAIL', TRUE);
echo "<p>" . $mail . "</p>";
@ -106,23 +107,19 @@ if (!class_exists('Soundmap')){
global $post;
$files = get_post_meta($post->ID, 'soundmap_attachments_id', FALSE);
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 id="soundmap-attachments">';
echo '<div class="add_button_container"><input type="button" id="add_files" class="button button-primary button-large" value="Add Files"></div>';
$out = '';
if ($files){
foreach($files as $file){
echo $file;
$data = wp_prepare_attachment_for_js( $file );
echo $data;
$out .= "<div class='soundmap-attach-item'>
<div class='att-icon'><img src='{$data['icon']}'/></div>
<div class='att-info'>
<a href='{$data['url']}'><strong>{$data['title']}</strong></a><br/>
<span class='att-length'>{$data['fileLength']}</span><br/>
<a href='#' class='delete-att-item'>Borrar</a>
</div>
<div class='clear'></div>
<input type='hidden' name='soundmap-att-ids[]' value='{$file}' /></div>";
$data = wp_prepare_attachment_for_js( $file );
$out .= "<div class='soundmap-attach-item'>
<!-- <div class='att-icon'><img src='{$data['icon']}'/></div> -->
<div class='att-info'><a href='{$data['url']}'><strong>{$data['title']}</strong></a><br/>
<audio controls>
<source src='{$data['url']} type='{$data['mime']}'>
</audio><br/>
<a href='#' class='delete-att-item'>Borrar</a></div><div class='clear'></div><input type='hidden' name='soundmap-att-ids[]' value='{$file}' /></div>";
}
}
echo '<div id="soundmap-attachments-list">' . $out . '</div>';
@ -357,21 +354,17 @@ if (!class_exists('Soundmap')){
wp_localize_script( 'soundmap', 'WP_Soundmap', $params);
}
function register_hooks(){
function register_hooks(){
add_action('init', array($this, 'init'));
add_action('admin_menu', array($this, 'admin_menu'));
add_action('save_post', array($this,'save_post'));
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('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_nopriv_soundmap_JSON_load_markers',array($this, 'JSON_load_markers'));
add_action('wp_ajax_nopriv_soundmap_load_infowindow', array($this, 'load_infowindow'));
@ -379,42 +372,34 @@ if (!class_exists('Soundmap')){
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_soundmap-get-content',array($this, 'soundmap_get_content'));
/* REST API Options */
add_action('rest_api_init', function() {
register_rest_field('marker','georeference',
array(
'get_callback' => 'marker_get_georeference',
'schema' => null
)
);
});
add_action('rest_api_init',function() {
register_rest_field('marker','media',
array(
'get_callback' => 'marker_get_media',
'schema' => null
)
);
});
/* REST API Options */
add_action('rest_api_init','soinumapa_create_marker_georeference');
function soinumapa_create_marker_georeference() {
register_rest_field('marker','georeference',
array(
'get_callback' => 'marker_get_georeference',
'schema' => null
)
);
}
add_action('rest_api_init','soinumapa_create_marker_media');
function soinumapa_create_marker_media() {
register_rest_field('marker','media',
array(
'get_callback' => 'marker_get_media',
'schema' => null
)
);
}
add_action('rest_api_init','soinumapa_create_marker_author');
function soinumapa_create_marker_author() {
register_rest_field('marker','author',
array(
'get_callback' => 'marker_get_author',
'schema' => null
)
);
}
add_action('rest_api_init', function() {
register_rest_field('marker','author',
array(
'get_callback' => 'marker_get_author',
'schema' => null
)
);
});
function marker_get_georeference ($object, $field_name, $request){
//return $object['id'];