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', '.task-selector', function() {
|
|
|
|
let taskId = $(this).closest('.task-selector-container').data('task-id');
|
|
|
|
let index = $.inArray(taskId, selectedTasks);
|
2023-06-28 21:39:03 +08:00
|
|
|
|
|
|
|
window.actionToolbarComponent.fetchActions({ my_module_ids: selectedTasks });
|
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);
|
|
|
|
} else if (!this.checked && index !== -1) {
|
|
|
|
selectedTasks.splice(index, 1);
|
|
|
|
}
|
|
|
|
});
|
2023-05-03 17:15:17 +08:00
|
|
|
|
2023-06-28 21:39:03 +08:00
|
|
|
function restoreMyModules(url, ids) {
|
|
|
|
$.post(url, { my_modules_ids: ids, view: 'cards' });
|
|
|
|
}
|
|
|
|
|
|
|
|
function initRestoreMyModules() {
|
|
|
|
$('#module-archive').on('click', '#restoreTask', (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
restoreMyModules(e.currentTarget.dataset.url, selectedTasks);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-03 17:15:17 +08:00
|
|
|
function initMoveButton() {
|
2023-06-28 21:39:03 +08:00
|
|
|
$('#module-archive').on('click', '#moveTask', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2023-05-03 17:15:17 +08:00
|
|
|
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();
|
2023-08-09 16:33:58 +08:00
|
|
|
}).fail((data) => {
|
2023-05-03 17:15:17 +08:00
|
|
|
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
|
|
|
|
});
|
|
|
|
$('#modal-move-modules').modal('hide');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#modal-move-modules').modal('show');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-28 21:39:03 +08:00
|
|
|
window.initActionToolbar();
|
|
|
|
initRestoreMyModules();
|
2023-05-03 17:15:17 +08:00
|
|
|
initMoveButton();
|
2020-12-11 18:52:24 +08:00
|
|
|
}());
|