Skip to content

Commit

Permalink
[K6.3] Fix for set all private button (#9791)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinkeltje authored Dec 26, 2024
1 parent c337535 commit 7ca6246
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/media/kunena/core/js/upload.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,74 @@ jQuery(function ($) {

// Remove any alert messages
$('#alert_max_file').remove();
});
$('#set-secure-all').on('click', function (e) {
e.preventDefault();

const child = $('#kattach-list').find('input');
const filesidtosetprivate = [];
const $this = $(this);

child.each(function (i, el) {
const elem = $(el);

if (!elem.attr('id').match("[a-z]{8}")) {
const fileid = elem.attr('id').match("[0-9]{1,8}");
filesidtosetprivate.push(fileid);
}
});

if (filesidtosetprivate.length !== 0) {
$.ajax({
url: Joomla.getOptions('com_kunena.kunena_upload_files_set_private') + '&files_id=' + JSON.stringify(filesidtosetprivate),
type: 'POST'
})
.done(function (data) {
// Update all individual private buttons
$('#files button').each(function() {
const $btn = $(this);
if ($btn.html().includes(Joomla.Text._('COM_KUNENA_EDITOR_INSERT_PRIVATE_ATTACHMENT'))) {
$btn.removeClass('btn-primary')
.addClass('btn-success')
.prop('disabled', true)
.html(Joomla.getOptions('com_kunena.icons.secure') + ' ' +
Joomla.Text._('COM_KUNENA_EDITOR_ATTACHMENT_IS_SECURED'));

// Hide the corresponding insert button in the same container
$btn.siblings('button').each(function() {
const $siblingBtn = $(this);
if ($siblingBtn.html().includes(Joomla.Text._('COM_KUNENA_EDITOR_INSERT')) ||
$siblingBtn.html().includes(Joomla.Text._('COM_KUNENA_EDITOR_IN_MESSAGE'))) {
$siblingBtn.hide();
}
});
}
});

// Update the set-secure-all button
$this.removeClass('btn-primary')
.addClass('btn-success')
.prop('disabled', true)
.html(Joomla.getOptions('com_kunena.icons.secure') + ' ' +
Joomla.Text._('COM_KUNENA_EDITOR_ATTACHMENTS_ARE_SECURED'));

// Hide both insert and insert-all buttons
$('button').each(function() {
const $btn = $(this);
if ($btn.html().includes(Joomla.Text._('COM_KUNENA_EDITOR_INSERT')) ||
$btn.html().includes(Joomla.Text._('COM_KUNENA_EDITOR_IN_MESSAGE')) ||
$btn.attr('id') === 'insert-all') {
$btn.hide();
}
});

// Explicitly hide the insert-all button
$('#insert-all').hide();
})
.fail(function () {
//TODO: handle the error of ajax request
});
}
});
$('#insert-all').on('click', function (e) {
e.preventDefault();
Expand Down

0 comments on commit 7ca6246

Please sign in to comment.