|
|
|
@ -23,9 +23,10 @@ function reload(fileSpan) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addFile(inputEl, file, eagerUpload) {
|
|
|
|
|
function addFile_board(inputEl, file, eagerUpload, id) {
|
|
|
|
|
|
|
|
|
|
if ($('#attachments_fields').children().length < 30) {
|
|
|
|
|
var attachments_frame = '#attachments_fields' + id;
|
|
|
|
|
if ($(attachments_frame).children().length < 30) {
|
|
|
|
|
deleteallfiles = $(inputEl).data('deleteAllFiles');
|
|
|
|
|
var attachmentId = addFile.nextAttachmentId++;
|
|
|
|
|
|
|
|
|
@ -48,7 +49,7 @@ function addFile(inputEl, file, eagerUpload) {
|
|
|
|
|
|
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
|
$('<div>', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} )
|
|
|
|
|
).appendTo('#attachments_fields');
|
|
|
|
|
).appendTo(attachments_frame);
|
|
|
|
|
|
|
|
|
|
if(eagerUpload) {
|
|
|
|
|
ajaxUpload(file, attachmentId, fileSpan, inputEl);
|
|
|
|
@ -58,7 +59,42 @@ function addFile(inputEl, file, eagerUpload) {
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
function addFile(inputEl, file, eagerUpload) {
|
|
|
|
|
|
|
|
|
|
var attachments_frame = '#attachments_fields';
|
|
|
|
|
if ($(attachments_frame).children().length < 30) {
|
|
|
|
|
deleteallfiles = $(inputEl).data('deleteAllFiles');
|
|
|
|
|
var attachmentId = addFile.nextAttachmentId++;
|
|
|
|
|
|
|
|
|
|
var fileSpan = $('<span>', { 'id': 'attachments_' + attachmentId, 'class':'attachment' });
|
|
|
|
|
|
|
|
|
|
fileSpan.append(
|
|
|
|
|
$('<input>', { 'type': 'text', 'class': 'filename readonly', 'name': 'attachments[' + attachmentId + '][filename]', 'readonly': 'readonly'} ).val(file.name),
|
|
|
|
|
$('<input>', { 'type': 'text', 'class': 'description', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 254, 'placeholder': $(inputEl).data('descriptionPlaceholder') } ).toggle(!eagerUpload),
|
|
|
|
|
$('<span >'+$(inputEl).data('fieldIsPublic')+':</span>').attr({ 'class': 'ispublic-label' }) ,
|
|
|
|
|
$('<input>', { 'type': 'checkbox', 'class': 'is_public_checkbox','value':1, 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', checked:'checked' } ).toggle(!eagerUpload),
|
|
|
|
|
$('<a> </a>').attr({ 'href': "#", 'class': 'remove-upload' }).click(function(){
|
|
|
|
|
if(confirm($(inputEl).data('areYouSure'))){
|
|
|
|
|
removeFile();
|
|
|
|
|
if(!eagerUpload){
|
|
|
|
|
(function(e){
|
|
|
|
|
reload(e);
|
|
|
|
|
})(fileSpan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).toggle(!eagerUpload),
|
|
|
|
|
$('<div>', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} )
|
|
|
|
|
).appendTo('#attachments_fields');
|
|
|
|
|
|
|
|
|
|
if(eagerUpload) {
|
|
|
|
|
ajaxUpload(file, attachmentId, fileSpan, inputEl);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return attachmentId;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
addFile.nextAttachmentId = 1;
|
|
|
|
|
|
|
|
|
|
function ajaxUpload(file, attachmentId, fileSpan, inputEl) {
|
|
|
|
@ -202,7 +238,26 @@ function addInputFiles(inputEl) {
|
|
|
|
|
|
|
|
|
|
//clearedFileInput.insertAfter('#attachments_fields');
|
|
|
|
|
}
|
|
|
|
|
function addInputFiles_board(inputEl, id) {
|
|
|
|
|
// var clearedFileInput = $(inputEl).clone().val('');
|
|
|
|
|
|
|
|
|
|
if (inputEl.files) {
|
|
|
|
|
// upload files using ajax
|
|
|
|
|
uploadAndAttachFiles_board(inputEl.files, inputEl, id);
|
|
|
|
|
// $(inputEl).remove();
|
|
|
|
|
} else {
|
|
|
|
|
// browser not supporting the file API, upload on form submission
|
|
|
|
|
var attachmentId;
|
|
|
|
|
var aFilename = inputEl.value.split(/\/|\\/);
|
|
|
|
|
attachmentId = addFile_board(inputEl, { name: aFilename[ aFilename.length - 1 ] }, false, id);
|
|
|
|
|
if (attachmentId) {
|
|
|
|
|
$(inputEl).attr({ name: 'attachments[' + attachmentId + '][file]'}).hide();
|
|
|
|
|
$('#upload_file_count').html("<span id=\"count\">"+count+"</span>"+$(inputEl).data('fileCount'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//clearedFileInput.insertAfter('#attachments_fields');
|
|
|
|
|
}
|
|
|
|
|
function uploadAndAttachFiles(files, inputEl) {
|
|
|
|
|
|
|
|
|
|
var maxFileSize = $(inputEl).data('max-file-size');
|
|
|
|
@ -218,7 +273,21 @@ function uploadAndAttachFiles(files, inputEl) {
|
|
|
|
|
$.each(files, function() {addFile(inputEl, this, true);});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function uploadAndAttachFiles_board(files, inputEl, id) {
|
|
|
|
|
|
|
|
|
|
var maxFileSize = $(inputEl).data('max-file-size');
|
|
|
|
|
var maxFileSizeExceeded = $(inputEl).data('max-file-size-message');
|
|
|
|
|
|
|
|
|
|
var sizeExceeded = false;
|
|
|
|
|
$.each(files, function() {
|
|
|
|
|
if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {sizeExceeded=true;}
|
|
|
|
|
});
|
|
|
|
|
if (sizeExceeded) {
|
|
|
|
|
window.alert(maxFileSizeExceeded);
|
|
|
|
|
} else {
|
|
|
|
|
$.each(files, function() {addFile_board(inputEl, this, true, id);});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function handleFileDropEvent(e) {
|
|
|
|
|
|
|
|
|
|
$(this).removeClass('fileover');
|
|
|
|
|