From b57bed3b7dc7e589e5e480922723b9144a3317c9 Mon Sep 17 00:00:00 2001 From: Astrid van Eerd Date: Tue, 5 Nov 2024 08:41:51 +0100 Subject: [PATCH 01/11] Update upload.main.js Stripping linebreaks when removing attachment. --- src/media/kunena/core/js/upload.main.js | 44 ++++++++++++++----------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/media/kunena/core/js/upload.main.js b/src/media/kunena/core/js/upload.main.js index ae140a8f9b7..9e9270cc2f8 100644 --- a/src/media/kunena/core/js/upload.main.js +++ b/src/media/kunena/core/js/upload.main.js @@ -345,7 +345,7 @@ jQuery(function ($) { }); }); - const removeButton = $('').insertBefore($('#files')); - - $('#form_submit_button').prop('disabled', false); - - return false; - } else { - fileCount = Object.keys(data['files']).length + fileCount; - } - }) - .bind('fileuploadchange', function (e, data) { - $('#form_submit_button').prop('disabled', true); - - $('#remove-all').show(); - $('#insert-all').show(); - - if (Joomla.getOptions('com_kunena.privateMessage') == 1) { - $('#set-secure-all').show(); - } - - const filecoutntmp = Object.keys(data['files']).length + fileCount; - - if (filecoutntmp > Joomla.getOptions('com_kunena.kunena_upload_files_maxfiles')) { - $('').insertBefore($('#files')); + $('#kattach_form').show(); - $('#form_submit_button').prop('disabled', false); + const fileCountTotal = Object.keys(data['files']).length + fileCount; - return false; - } else { - fileCount = Object.keys(data['files']).length + fileCount; - } - }) - .on('fileuploadadd', function (e, data) { - $('#progress-bar').css( - 'width', - '0%' - ); - - $('#progress').show(); - - data.context = $('
').appendTo('#files'); - - $.each(data.files, function (index, file) { - const node = $('

') - .append($('').text(file.name)); - if (!index) { - node - .append('
'); - } + if (fileCountTotal > Joomla.getOptions('com_kunena.kunena_upload_files_maxfiles')) { + $('

') + .insertBefore($('#files')); + + $('#form_submit_button').prop('disabled', false); + return false; + } + + fileCount = fileCountTotal; +}) +.bind('fileuploadchange', function (e, data) { + $('#form_submit_button').prop('disabled', true); + $('#remove-all').show(); + $('#insert-all').show(); + + if (Joomla.getOptions('com_kunena.privateMessage') == 1) { + $('#set-secure-all').show(); + } - node.appendTo(data.context); - }); - }).on('fileuploadprocessalways', function (e, data) { - const index = data.index, - file = data.files[index], - node = $(data.context.children()[index]); - if (file.preview) { - node - .prepend('
') - .prepend(file.preview); - } + const fileCountTotal = Object.keys(data['files']).length + fileCount; - if (file.error) { - node - .append('
') - .append($('').text(file.error)); + if (fileCountTotal > Joomla.getOptions('com_kunena.kunena_upload_files_maxfiles')) { + $('') + .insertBefore($('#files')); + + $('#form_submit_button').prop('disabled', false); + return false; + } + + fileCount = fileCountTotal; +}) +.on('fileuploadadd', function (e, data) { + $('#progress-bar').css('width', '0%'); + $('#progress').show(); + + data.context = $('
').appendTo('#files'); + + $.each(data.files, function (index, file) { + const node = $('

').append($('').text(file.name)); + if (!index) { + node.append('
'); } + node.appendTo(data.context); + }); +}) +.on('fileuploadprocessalways', function (e, data) { + const index = data.index, + file = data.files[index], + node = $(data.context.children()[index]); + + if (file.preview) { + node.prepend('
').prepend(file.preview); + } - if (index + 1 === data.files.length) { - data.context.find('button.btn-primary') - .text(Joomla.Text._('COM_KUNENA_UPLOADED_LABEL_UPLOAD_BUTTON')) - .prop('disabled', !!data.files.error); - } - }).on('fileuploaddone', function (e, data) { - // $.each(data.result.data, function (index, file) - const progress = parseInt(data.loaded / data.total * 100, 10); + if (file.error) { + node.append('
') + .append($('').text(file.error)); + } - $('.progress-bar').css( - 'width', - progress + '%' + if (index + 1 === data.files.length) { + data.context.find('button.btn-primary') + .text(Joomla.Text._('COM_KUNENA_UPLOADED_LABEL_UPLOAD_BUTTON')) + .prop('disabled', !!data.files.error); + } +}) +.on('fileuploaddone', function (e, data) { + const progress = parseInt(data.loaded / data.total * 100, 10); + $('.progress-bar').css('width', progress + '%') + .prop('aria-valuenow', progress); + + const link = $('').attr('target', '_blank') + .prop('href', data.result.location); + + data.context.find('span').wrap(link); + + if (data.result.success === true) { + $('#form_submit_button').prop('disabled', false); + + // Add hidden inputs for attachments + $('#kattach-list').append( + '' + + '' ); - $('.progress-bar').prop('aria-valuenow', progress); - - const link = $('') - .attr('target', '_blank') - .prop('href', data.result.location); - - data.context.find('span') - .wrap(link); - - if (data.result.success === true) { - $('#form_submit_button').prop('disabled', false); - - // The attachment has been right uploaded, so now we need to put into input hidden to added to message - $('#kattach-list').append(''); - $('#kattach-list').append(''); - - data.uploaded = true; - - data.context.append(insertButton.clone(true).data(data)); - if (data.context.find('button').hasClass('btn-danger')) { - data.context.find('button.btn-danger').remove(); - } - - if (Joomla.getOptions('com_kunena.privateMessage') == 1) { - data.context.append(setPrivateButton.clone(true).data(data)); - } - - data.context.append(removeButton.clone(true).data(data)); - } else if (data.result.message) { - $('#form_submit_button').prop('disabled', false); - - data.uploaded = false; - data.context.append(removeButton.clone(true).data(data)); + data.uploaded = true; - var error = null; - - if (data.result.message.length > 0) { - error = $('