2023-05-03 17:15:17 +08:00
|
|
|
/* global HelperModule */
|
|
|
|
|
2020-12-11 18:52:24 +08:00
|
|
|
(function() {
|
|
|
|
let selectedTasks = [];
|
|
|
|
|
|
|
|
$('#module-archive').on('click', '.restore-button-container', function(e) {
|
|
|
|
e.preventDefault();
|
2020-12-29 00:44:47 +08:00
|
|
|
let restoreForm = $('.restore-button-container').find('form');
|
|
|
|
|
|
|
|
selectedTasks.forEach(function(id) {
|
|
|
|
$('<input>').attr({
|
|
|
|
type: 'hidden',
|
|
|
|
name: 'my_modules_ids[]',
|
|
|
|
value: id
|
|
|
|
}).appendTo(restoreForm);
|
|
|
|
});
|
|
|
|
restoreForm.submit();
|
2020-12-11 18:52:24 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#module-archive').on('click', '.task-selector', function() {
|
|
|
|
let taskId = $(this).closest('.task-selector-container').data('task-id');
|
|
|
|
let index = $.inArray(taskId, selectedTasks);
|
2023-05-03 17:15:17 +08:00
|
|
|
const restoreTasksButton = $('.restore-button-container');
|
|
|
|
const moveTasksButton = $('.move-button-container');
|
2020-12-11 18:52:24 +08:00
|
|
|
|
|
|
|
// If checkbox is checked and row ID is not in list of selected folder IDs
|
|
|
|
if (this.checked && index === -1) {
|
|
|
|
selectedTasks.push(taskId);
|
2023-05-03 17:15:17 +08:00
|
|
|
restoreTasksButton.collapse('show');
|
|
|
|
moveTasksButton.collapse('show');
|
2020-12-11 18:52:24 +08:00
|
|
|
// Otherwise, if checkbox is not checked and ID is in list of selected IDs
|
|
|
|
} else if (!this.checked && index !== -1) {
|
|
|
|
selectedTasks.splice(index, 1);
|
|
|
|
}
|
|
|
|
// Hide button
|
2023-05-03 17:15:17 +08:00
|
|
|
if (selectedTasks.length === 0) {
|
|
|
|
restoreTasksButton.collapse('hide');
|
|
|
|
moveTasksButton.collapse('hide');
|
|
|
|
}
|
2020-12-11 18:52:24 +08:00
|
|
|
});
|
2023-05-03 17:15:17 +08:00
|
|
|
|
|
|
|
function initMoveButton() {
|
|
|
|
$('.move-button-container').on('click', 'button', function() {
|
|
|
|
const cardsContainer = $('#cards-container');
|
|
|
|
$.get(cardsContainer.data('move-modules-modal-url'), (modalData) => {
|
|
|
|
if ($('#modal-move-modules').length > 0) {
|
|
|
|
$('#modal-move-modules').replaceWith(modalData.html);
|
|
|
|
} else {
|
|
|
|
$('#module-archive').append(modalData.html);
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#modal-move-modules').on('shown.bs.modal', function() {
|
|
|
|
$(this).find('.selectpicker').selectpicker().focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#modal-move-modules').on('click', 'button[data-action="confirm"]', () => {
|
|
|
|
const moveParams = {
|
|
|
|
to_experiment_id: $('#modal-move-modules').find('.selectpicker').val(),
|
|
|
|
my_module_ids: selectedTasks
|
|
|
|
};
|
|
|
|
$.post(cardsContainer.data('move-modules-url'), moveParams, (data) => {
|
|
|
|
HelperModule.flashAlertMsg(data.message, 'success');
|
|
|
|
window.location.reload();
|
|
|
|
}).error((data) => {
|
|
|
|
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
|
|
|
|
});
|
|
|
|
$('#modal-move-modules').modal('hide');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#modal-move-modules').modal('show');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initMoveButton();
|
2020-12-11 18:52:24 +08:00
|
|
|
}());
|