From e677bfe8a1e1d906a7a0fe9550b234f223ae4dde Mon Sep 17 00:00:00 2001 From: ndiggity Date: Tue, 10 Mar 2015 00:45:17 -0500 Subject: [PATCH 1/2] Added code to support abandoned file processing The Upload URL and Crop URL processing files are perfect for processing uploaded and cropped files as required. However, there is no support for files which are abandoned by a user in either the uploaded or cropped stages. These can of course be removed manually or by a CRON job... but why not add functionality here to deal with them before they pile up and to eliminate the possibility of manual removal or a CRON job from interfering with a user. I added such functionality to the croppic.js and made a sample processing file. I modeled the code on the existing code to facilitate additions if needed. --- croppic.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/croppic.js b/croppic.js index a9edeca..d802900 100644 --- a/croppic.js +++ b/croppic.js @@ -20,6 +20,7 @@ cropUrl:'', cropData:{}, outputUrlId:'', + deleteUrl:'', //styles imgEyecandy:true, imgEyecandyOpacity:0.2, @@ -155,6 +156,7 @@ that.croppedImg.remove(); $(this).hide(); + that.delete(that.cropUrl); if (typeof (that.options.onAfterRemoveCroppedImg) === typeof(Function)) { that.options.onAfterRemoveCroppedImg.call(that); @@ -412,7 +414,10 @@ that.cropControlCrop.on('click',function(){ that.crop(); }); that.cropControlReset = that.cropControlsCrop.find('.cropControlReset'); - that.cropControlReset.on('click',function(){ that.reset(); }); + that.cropControlReset.on('click',function(){ + that.delete(that.imgUrl); + that.reset(); + }); }, initDrag:function(){ @@ -621,6 +626,7 @@ that.imgEyecandy.hide(); that.destroy(); + that.cropUrl=response.url; that.obj.append(''); if(that.options.outputUrlId !== ''){ $('#'+that.options.outputUrlId).val(response.url); } @@ -675,6 +681,51 @@ if( !$.isEmptyObject( that.loader ) ){ that.loader.remove(); } if( !$.isEmptyObject( that.form ) ){ that.form.remove(); } that.obj.html(''); - } + }, + + delete: function (myURL) { + var that = this; + + var deleteData = { + deleteUrl:myURL + }; + + var formData = new FormData(); + + for (var key in deleteData) { + if( deleteData.hasOwnProperty(key) ) { + formData.append( key , deleteData[key] ); + } + } + + $.ajax({ + url: that.options.deleteUrl, + data: formData, + context: document.body, + cache: false, + contentType: false, + processData: false, + type: 'POST' + }).always(function(data) { + response = typeof data == 'object' ? data : jQuery.parseJSON(data); + + if (response.status == 'success') { + + //add code if desired + + } + + if (response.status == 'error') { + if (that.options.onError) + that.options.onError.call(that, response.message); + that.hideLoader(); + setTimeout(function() { + that.reset(); + }, 2000) + } + + }); + + } }; -})(window, document); \ No newline at end of file +})(window, document); From 5471e6d51e601e0075490434cee84d73f274ec50 Mon Sep 17 00:00:00 2001 From: ndiggity Date: Tue, 10 Mar 2015 00:51:06 -0500 Subject: [PATCH 2/2] example delete processing file --- img_delete_file.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 img_delete_file.php diff --git a/img_delete_file.php b/img_delete_file.php new file mode 100644 index 0000000..4fc3ae3 --- /dev/null +++ b/img_delete_file.php @@ -0,0 +1,19 @@ + 'success', + ); +} else { + $response = Array( + "status" => 'error', + ); +} +print json_encode($response);