media handling fixes from andy. see #5911

git-svn-id: http://svn.automattic.com/wordpress/trunk@7256 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-03-11 23:15:17 +00:00
parent 349fc66bd1
commit 2c535c4ca7
2 changed files with 44 additions and 13 deletions

View File

@ -55,20 +55,11 @@ function prepareMediaItem(fileObj, serverData) {
// Bind AJAX to the new Delete button // Bind AJAX to the new Delete button
jQuery('#media-item-' + fileObj.id + ' a.delete').bind('click',function(){ jQuery('#media-item-' + fileObj.id + ' a.delete').bind('click',function(){
// Tell the server to delete it. TODO: handle exceptions // Tell the server to delete it. TODO: handle exceptions
jQuery.ajax({url:'admin-ajax.php',type:'post',data:{ jQuery.ajax({url:'admin-ajax.php',type:'post',success:deleteSuccess,error:deleteError,id:fileObj.id,data:{
id : this.id.replace(/[^0-9]/g,''), id : this.id.replace(/[^0-9]/g,''),
action : 'delete-post', action : 'delete-post',
_ajax_nonce : this.href.replace(/^.*wpnonce=/,'')} _ajax_nonce : this.href.replace(/^.*wpnonce=/,'')}
}); });
// Decrement the counters.
if ( type = jQuery('#type-of-' + this.id.replace(/[^0-9]/g,'')).val() )
jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-1);
if ( jQuery(this).parents('.media-item').eq(0).hasClass('child-of-'+post_id) )
jQuery('#attachments-count').text(jQuery('#attachments-count').text()-1);
// Vanish it.
jQuery(this).parents(".media-item").eq(0).slideToggle(300,function(){jQuery(this).remove();if(jQuery('.media-item').length==0)jQuery('.insert-gallery').hide();updateMediaForm();});
return false; return false;
}); });
@ -79,6 +70,45 @@ function prepareMediaItem(fileObj, serverData) {
.parent().eq(0).children('.toggle').toggle(); .parent().eq(0).children('.toggle').toggle();
} }
function itemAjaxError(id, html) {
var error = jQuery('#media-item-error' + id);
error.html('<div class="file-error"><button type="button" id="dismiss-'+id+'" class="button dismiss">'+swfuploadL10n.dismiss+'</button>'+html+'</div>');
jQuery('#dismiss-'+id).click(function(){jQuery(this).parents('.file-error').slideUp(200, function(){jQuery(this).empty();})});
}
function deleteSuccess(data, textStatus) {
if ( data == '-1' )
return itemAjaxError(this.id, 'You do not have permission. Has your session expired?');
if ( data == '0' )
return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?');
var item = jQuery('#media-item-' + this.id);
// Decrement the counters.
if ( type = jQuery('#type-of-' + this.id).val() )
jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-1);
if ( item.hasClass('child-of-'+post_id) )
jQuery('#attachments-count').text(jQuery('#attachments-count').text()-1);
if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) {
jQuery('.toggle').toggle();
jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
}
jQuery('#media-item-' + this.id + ' .filename:empty').remove();
jQuery('#media-item-' + this.id + ' .filename').append(' <span class="file-error">'+swfuploadL10n.deleted+'</span>').siblings('a.toggle').remove();
jQuery('#media-item-' + this.id + ' .describe').slideUp(500, function(){jQuery(this).parents('.media-item').slideUp(1500,function(){jQuery(this).remove();updateMediaForm();})}).end.remove();
return;
// Vanish it.
item.slideToggle(300,function(){jQuery(this).remove();if(jQuery('.media-item').length==0)jQuery('.insert-gallery').hide();updateMediaForm();});
}
function deleteError(X, textStatus, errorThrown) {
// TODO
}
function updateMediaForm() { function updateMediaForm() {
// Just one file, no need for collapsible part // Just one file, no need for collapsible part
if ( jQuery('.type-form #media-items>*').length == 1 ) { if ( jQuery('.type-form #media-items>*').length == 1 ) {
@ -130,8 +160,8 @@ function wpQueueError(message) {
// file-specific message // file-specific message
function wpFileError(fileObj, message) { function wpFileError(fileObj, message) {
jQuery('#media-item-' + fileObj.id + ' .filename').after('<div class="file-error"><button type="button" class="button dismiss">'+swfuploadL10n.dismiss+'</button>'+message+'</div>').siblings('.progress').remove(); jQuery('#media-item-' + fileObj.id + ' .filename').after('<div class="file-error"><button type="button" id="dismiss-' + fileObj.id + '" class="button dismiss">'+swfuploadL10n.dismiss+'</button>'+message+'</div>').siblings('.toggle').remove();
jQuery('.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})}); jQuery('#dismiss-' + fileObj.id).click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})});
} }
function fileQueueError(fileObj, error_code, message) { function fileQueueError(fileObj, error_code, message) {

View File

@ -84,7 +84,7 @@ class WP_Scripts {
$this->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2'); $this->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2');
$this->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2'); $this->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2');
$this->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2'); $this->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2');
$this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080228'); $this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080301');
// these error messages came from the sample swfupload js, they might need changing. // these error messages came from the sample swfupload js, they might need changing.
$this->localize( 'swfupload-handlers', 'swfuploadL10n', array( $this->localize( 'swfupload-handlers', 'swfuploadL10n', array(
'queue_limit_exceeded' => __('You have attempted to queue too many files.'), 'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
@ -102,6 +102,7 @@ class WP_Scripts {
'upload_stopped' => __('Upload stopped.'), 'upload_stopped' => __('Upload stopped.'),
'dismiss' => __('Dismiss'), 'dismiss' => __('Dismiss'),
'crunching' => __('Crunching&hellip;'), 'crunching' => __('Crunching&hellip;'),
'deleted' => __('Deleted'),
) ); ) );
$this->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery'), '3' ); $this->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery'), '3' );