Sunday, 25 August 2013

fineuploader custom delete to reset fileLimit

fineuploader custom delete to reset fileLimit

i had set the validation with itemLimit 10
validation: {
allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
itemLimit: 10
},
and after upload complete, i use jquery to append the thumbnails and
delete button for the image
.on('complete', function(event, id, fileName, responseJSON) {
if (responseJSON.success) {
$('.writestatus').css('border-bottom', 'none');
$('#image-list').show();
$('.qq-upload-list').hide();
$('#image-list-content').append('<div class="image-list-img"
id="preview_image_' + id + '"><a href="/images/' +
responseJSON.uploadName + '" data-lightbox="upload-preview"><img
class="uploader-preview" src="/images/' + responseJSON.uploadName
+ '"><a href="#" class="deleteImg"><span class="preview_image_' +
id + '">Delete</span></a></a><input type="hidden" value="' +
responseJSON.uploadName + '" name="image_' + id + '" /></div>');
}
});
and once the delete button clicked, this function execute
$(function() {
//===== Delete img setup =====//
$('.deleteImg').live('click', function(e){
e.preventDefault();
var src = $(this).parent().find('img').attr('src');
var container = $(this).find('span').attr('class');
delete_image(src, container);
});
function delete_image(src, container){
$.ajax({
type: "POST",
url: "/ajax/status/delete.php?do=deleteImg",
data: "target=" + src,
dataType: "json",
beforeSend: function(){
},
success: function(msg){
var status = msg.status;
var message = msg.message;
if(status == 'identity-fail'){
//Identity fail, logout
window.location.href = '/logout';
}
if(status == 'error'){
//jGrowl show error message
$.jGrowl("close");
setTimeout(function(){
$.jGrowl(message, { header:'<font
color="red">ERROR</font>', life: 10000 });
}, 800);
}
if(status == 'successful'){
$('#' + container).remove();
alert(netItems);
var left =
$('#image-list-content').find('.image-list-img').length;
if(left == '0')
{
$('.writestatus').css('border-bottom', '1px solid
rgb(215,215,215)');
$('#image-list').hide();
}
}
},
error: function(){
//Set the form to available submit
alert('–¢'möŒëC¿—ü—ŠÇ—ˆõ');
}
});
//make sure the form doesn't post
return false;
};
});
everything work fine, upload and delete can be done, but when i upload 10
image, and delete 1 and re-upload 1, it got error alert that "Too many
items(11) would be uploaded, item limit is 10", i know this error is due
to the itemLimit in validation, how can i set the fineuploader itemlimit
+1 or -1 fineuploader the current uploaded image var at the delete_image()
function?
appreciate for help

No comments:

Post a Comment