Skip to content

Commit

Permalink
Merge pull request #48 from kraftner/issue/36
Browse files Browse the repository at this point in the history
PR: Multi Uploader breaks when Upload fails
  • Loading branch information
franz-josef-kaiser authored Nov 18, 2016
2 parents 9f66ff8 + 510c75c commit 4182c2c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 35 deletions.
61 changes: 38 additions & 23 deletions assets/src/logo/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@
task : 'fetch'
} )
)
.then(
// success
function( response ) {
//console.log( 'RESPONSE', self.attributes );
},
// error
function( reason ) {
//console.log( 'Model:fetch Error',reason );
}
);
.done( function( response ) {
self.set( {
thumb : response.data.thumb,
name : response.data.name,
width : response.data.width,
height : response.data.height,
link : response.data.link
} );
} )
.fail( function( reason ) {
//console.log( 'Model:fetch Error',reason );
} );

/*wp.ajax.post( plugin.action, {
_ajax_nonce : plugin._ajax_nonce,
Expand All @@ -69,7 +71,9 @@

// Triggered by: views.Delete
destroy : function( att_id ) {

var self = this;

$.when(
$.post( this.urlRoot, {
action : plugin.action,
Expand All @@ -78,16 +82,13 @@
task : 'destroy'
} )
)
.then(
// success
function( response ) {
//console.log( 'Model:destroy Success', response );
},
// error
function( reason ) {
//console.log( 'Model:destroy Error', reason );
}
);
.done( function( response ) {
// console.log( 'Model:destroy Success', response );
} )
.fail( function( reason ) {
// console.log( 'Model:destroy Error', reason );
} );

return {};
}
} );
Expand Down Expand Up @@ -260,9 +261,23 @@
// Bind event handler to file upload / drag&drop
uploader.bind( 'FileUploaded', function( up, file, response ) {

if ( 200 !== response.status ) {
return;
}
if ( 200 !== response.status ) {
return;
}

// Start C&P from handlers.js
// https://github.com/WordPress/WordPress/blob/32be6f7bb73b5c8e4bdd90179aa85b275606d982/wp-includes/js/plupload/handlers.js#L83-L87

var serverData = response.response;

// on success serverData should be numeric, fix bug in html4 runtime returning the serverData wrapped in a <pre> tag
serverData = serverData.replace(/^<pre>(\d+)<\/pre>$/, '$1');

// if async-upload returned an error message, place it in the media item div and return
if ( serverData.match(/media-upload-error|error-div/) ) {
return;
}
// End C&P from handlers.js

// Triggers Model:fetch( att_id ) & event listeners in the views
logo.set( { 'att_id' : response.response } );
Expand Down
2 changes: 1 addition & 1 deletion assets/src/logo/all.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions assets/src/logo/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,23 @@
// Bind event handler to file upload / drag&drop
uploader.bind( 'FileUploaded', function( up, file, response ) {

if ( 200 !== response.status ) {
return;
}
if ( 200 !== response.status ) {
return;
}

// Start C&P from handlers.js
// https://github.com/WordPress/WordPress/blob/32be6f7bb73b5c8e4bdd90179aa85b275606d982/wp-includes/js/plupload/handlers.js#L83-L87

var serverData = response.response;

// on success serverData should be numeric, fix bug in html4 runtime returning the serverData wrapped in a <pre> tag
serverData = serverData.replace(/^<pre>(\d+)<\/pre>$/, '$1');

// if async-upload returned an error message, place it in the media item div and return
if ( serverData.match(/media-upload-error|error-div/) ) {
return;
}
// End C&P from handlers.js

// Triggers Model:fetch( att_id ) & event listeners in the views
logo.set( { 'att_id' : response.response } );
Expand Down
2 changes: 1 addition & 1 deletion assets/src/logo/controller.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/src/logo/models.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/src/logo/views.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4182c2c

Please sign in to comment.