scinote-web/app/assets/javascripts/projects/index.js

716 lines
25 KiB
JavaScript
Raw Normal View History

2016-02-12 23:52:43 +08:00
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
// TODO
// - error handling of assigning user to project, check XHR data.errors
// - error handling of removing user from project, check XHR data.errors
// - refresh project users tab after manage user modal is closed
// - refactor view handling using library, ex. backbone.js
/* global HelperModule dropdownSelector Sidebar Turbolinks filterDropdown InfiniteScroll AsyncDropdown GLOBAL_CONSTANTS */
/* eslint-disable no-use-before-define */
2016-02-12 23:52:43 +08:00
var ProjectsIndex = (function() {
var projectsWrapper = '#projectsWrapper';
var toolbarWrapper = '#toolbarWrapper';
var cardsWrapper = '#cardsWrapper';
var editProjectModal = '#edit-modal';
2021-01-06 22:02:26 +08:00
var moveToModal = '#move-to-modal';
var pageSize = GLOBAL_CONSTANTS.DEFAULT_ELEMENTS_PER_PAGE;
2016-02-12 23:52:43 +08:00
var exportProjectsModal = null;
var exportProjectsModalHeader = null;
var exportProjectsModalBody = null;
var exportProjectsBtn = '.export-projects-btn';
var exportProjectsSubmit = '#export-projects-modal-submit';
let projectsCurrentSort;
let projectsViewSearch;
let createdOnFromFilter;
let createdOnToFilter;
let membersFilter;
let lookInsideFolders;
let archivedOnFromFilter;
let archivedOnToFilter;
// Arrays with selected project and folder IDs shared between both views
var selectedProjects = [];
var selectedProjectFolders = [];
2021-01-06 22:02:26 +08:00
var destinationFolder;
// Init new project folder modal function
function initNewProjectFolderModal() {
2020-12-03 19:57:45 +08:00
var newProjectFolderModal = '#new-project-folder-modal';
// Modal's submit handler function
$(projectsWrapper)
.on('ajax:success', newProjectFolderModal, function(ev, data) {
$(newProjectFolderModal).modal('hide');
HelperModule.flashAlertMsg(data.message, 'success');
refreshCurrentView();
})
.on('ajax:error', newProjectFolderModal, function(e, data) {
let form = $(this).find('form#new_project_folder');
form.renderFormErrors('project_folder', data.responseJSON);
});
$(projectsWrapper)
.on('ajax:success', '.new-project-folder-btn', function(e, data) {
// Add and show modal
$(projectsWrapper).append($.parseHTML(data.html));
$(newProjectFolderModal).modal('show');
$(newProjectFolderModal).find("input[type='text']").focus();
// Remove modal when it gets closed
$(newProjectFolderModal).on('hidden.bs.modal', function() {
$(newProjectFolderModal).remove();
});
});
}
2016-02-12 23:52:43 +08:00
/**
* Initialize the JS for new project modal to work.
*/
function initNewProjectModal() {
var newProjectModal = '#new-project-modal';
2016-02-12 23:52:43 +08:00
// Modal's submit handler function
$(projectsWrapper)
.on('ajax:success', newProjectModal, function(ev, data) {
$(newProjectModal).modal('hide');
HelperModule.flashAlertMsg(data.message, 'success');
refreshCurrentView();
})
.on('ajax:error', newProjectModal, function(ev, data) {
$(this).renderFormErrors('project', data.responseJSON);
});
2016-02-12 23:52:43 +08:00
$(projectsWrapper)
.on('ajax:success', '.new-project-btn', function(ev, data) {
// Add and show modal
$(projectsWrapper).append($.parseHTML(data.html));
$(newProjectModal).modal('show');
$(newProjectModal).find("input[type='text']").focus();
// init select picker
$(newProjectModal).find('.selectpicker').selectpicker();
// Remove modal when it gets closed
$(newProjectModal).on('hidden.bs.modal', function() {
$(newProjectModal).remove();
});
});
}
2021-02-11 05:11:42 +08:00
// init delete project folders
function initDeleteFoldersToolbarButton() {
2021-02-11 05:11:42 +08:00
$(projectsWrapper)
2021-02-12 01:27:16 +08:00
.on('ajax:before', '.delete-folders-btn', function() {
2021-02-11 05:11:42 +08:00
let buttonForm = $(this);
buttonForm.find('input[name="project_folders_ids[]"]').remove();
selectedProjectFolders.forEach(function(id) {
$('<input>').attr({
type: 'hidden',
name: 'project_folders_ids[]',
value: id
}).appendTo(buttonForm);
});
})
2021-02-12 01:27:16 +08:00
.on('ajax:success', '.delete-folders-btn', function(ev, data) {
// Add and show modal
let deleteModal = $(data.html);
$(projectsWrapper).append(deleteModal);
deleteModal.modal('show');
// Remove modal when it gets closed
deleteModal.on('hidden.bs.modal', function() {
$(this).remove();
});
});
$(projectsWrapper)
2021-02-11 05:11:42 +08:00
.on('ajax:success', '.delete-folders-form', function(ev, data) {
$('.modal-project-folder-delete').modal('hide');
HelperModule.flashAlertMsg(data.message, 'success');
refreshCurrentView();
})
.on('ajax:error', '.delete-folders-form', function(ev, data) {
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
});
}
// init project toolbar archive/restore functions
function initArchiveRestoreToolbarButtons() {
$(projectsWrapper)
.on('ajax:before', '.archive-projects-form, .restore-projects-form', function() {
let buttonForm = $(this);
buttonForm.find('input[name="projects_ids[]"]').remove();
selectedProjects.forEach(function(id) {
$('<input>').attr({
type: 'hidden',
name: 'projects_ids[]',
value: id
}).appendTo(buttonForm);
});
})
.on('ajax:success', '.archive-projects-form, .restore-projects-form', function(ev, data) {
HelperModule.flashAlertMsg(data.message, 'success');
// Project saved, reload view
refreshCurrentView();
})
.on('ajax:error', '.archive-projects-form, .restore-projects-form', function(ev, data) {
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
});
2016-02-12 23:52:43 +08:00
}
// init project card archive/restore function
function initArchiveRestoreButton() {
$(projectsWrapper)
.on('ajax:success', '.project-archive-restore-form', function(ev, data) {
HelperModule.flashAlertMsg(data.message, 'success');
refreshCurrentView();
})
.on('ajax:error', '.project-archive-restore-form', function(ev, data) {
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
});
}
/**
* Initialize the JS for export projects modal to work.
*/
function initExportProjectsModal() {
$(projectsWrapper).on('click', exportProjectsBtn, function(ev) {
ev.stopPropagation();
ev.preventDefault();
2018-10-12 06:48:12 +08:00
// Load HTML to refresh users list
$.ajax({
url: $(exportProjectsBtn).data('url'),
type: 'GET',
2018-10-12 06:48:12 +08:00
dataType: 'json',
data: {
project_ids: selectedProjects,
project_folder_ids: selectedProjectFolders
2018-10-12 06:48:12 +08:00
},
success: function(data) {
// Update modal title
exportProjectsModalHeader.text(data.title);
2018-10-12 06:48:12 +08:00
// Set modal body
exportProjectsModalBody.html(data.html);
// Update modal footer (show/hide buttons)
if (data.status === 'error') {
$('#export-projects-modal-close').show();
$('#export-projects-modal-cancel').hide();
$(exportProjectsSubmit).hide();
} else {
$('#export-projects-modal-close').hide();
$('#export-projects-modal-cancel').show();
$(exportProjectsSubmit).show();
}
2018-10-12 06:48:12 +08:00
// Show the modal
exportProjectsModal.modal('show');
},
error: function(data) {
HelperModule.flashAlertMsg(data.responseJSON.flash, 'danger');
2018-10-12 06:48:12 +08:00
}
});
2018-10-12 06:48:12 +08:00
});
// Remove modal content when modal window is closed.
exportProjectsModal.on('hidden.bs.modal', function() {
exportProjectsModalHeader.html('');
exportProjectsModalBody.html('');
});
}
function initSelectAllCheckbox() {
$(projectsWrapper).on('click', '.sci-checkbox.select-all', function() {
var selectAll = this.checked;
$.each($('.folder-card-selector, .project-card-selector'), function() {
if (this.checked !== selectAll) this.click();
});
});
}
function initExportProjects() {
// Submit the export projects
$(exportProjectsSubmit).click(function() {
$.ajax({
url: $(exportProjectsSubmit).data('export-projects-submit-url'),
type: 'POST',
dataType: 'json',
data: {
project_ids: selectedProjects,
project_folder_ids: selectedProjectFolders
},
success: function(data) {
// Hide modal and show success flash
exportProjectsModal.modal('hide');
HelperModule.flashAlertMsg(data.flash, 'success');
},
error: function() {
// TODO
}
});
});
}
function updateSelectedCards() {
$('.project-card').removeClass('selected');
$.each(selectedProjects, function(index, value) {
let selectedCard = $('.project-card[data-id="' + value + '"]');
selectedCard.addClass('selected');
});
}
function checkActionPermission(permission) {
let allProjects;
let allFolders;
allProjects = selectedProjects.every(function(projectId) {
return $(`.project-card[data-id="${projectId}"]`).data(permission);
});
allFolders = selectedProjectFolders.every(function(projectFolderId) {
return $(`.folder-card[data-id="${projectFolderId}"]`).data(permission);
});
return allProjects && allFolders;
}
function updateProjectsToolbar() {
window.actionToolbarComponent.fetchActions(
{
project_ids: selectedProjects,
project_folder_ids: selectedProjectFolders
}
);
window.actionToolbarComponent.setReloadCallback(refreshCurrentView);
}
function refreshCurrentView() {
loadCardsView();
2023-04-26 16:24:50 +08:00
window.navigatorContainer.reloadCurrentLevel = true
}
function initEditButton() {
function loadEditModal(url) {
$.get(url, function(result) {
$(editProjectModal).find('.modal-content').html(result.html);
$(editProjectModal).modal('show');
$(editProjectModal).find('.selectpicker').selectpicker();
$(editProjectModal).find('form')
.on('ajax:success', function(ev, data) {
$(editProjectModal).modal('hide');
HelperModule.flashAlertMsg(data.message, 'success');
refreshCurrentView();
}).on('ajax:error', function(ev, data) {
if ($(this).hasClass('edit_project')) {
$(this).renderFormErrors('project', data.responseJSON.errors);
} else {
$(this).renderFormErrors('project_folder', data.responseJSON.errors);
}
});
});
}
$(projectsWrapper).on('click', '.edit-btn', function(ev) {
var editUrl = $(`.project-card[data-id=${selectedProjects[0]}]`).data('edit-url') ||
$(`.folder-card[data-id=${selectedProjectFolders[0]}]`).data('edit-url');
ev.stopPropagation();
ev.preventDefault();
loadEditModal(editUrl);
});
$('.projects-container').on('click', '.edit-project-btn', function(ev) {
var editUrl = $(this).attr('href');
ev.stopPropagation();
ev.preventDefault();
loadEditModal(editUrl);
});
}
2021-01-06 22:02:26 +08:00
function initMoveButton() {
2021-01-06 22:45:26 +08:00
function initializeJSTree(foldersTree) {
2021-01-06 22:02:26 +08:00
var timeOut = false;
2021-01-06 22:45:26 +08:00
foldersTree.jstree({
core: {
multiple: false,
themes: {
dots: false,
variant: 'large'
}
},
search: {
show_only_matches: true,
show_only_matches_children: true
},
plugins: ['wholerow', 'search']
});
2021-01-06 22:02:26 +08:00
2021-01-06 22:45:26 +08:00
foldersTree.on('changed.jstree', function(e, data) {
2021-01-06 22:02:26 +08:00
destinationFolder = data.instance.get_node(data.selected[0]).id.replace('folder_', '');
});
// Search timeout
2021-01-06 22:45:26 +08:00
$('#searchFolderTree').keyup(function() {
if (timeOut) { clearTimeout(timeOut); }
timeOut = setTimeout(function() {
foldersTree.jstree(true).search($('#searchFolderTree').val());
2021-01-06 22:02:26 +08:00
}, 250);
});
}
function loadMoveToModal(url) {
let items;
let projects;
let folders;
if ((selectedProjects.length) && (selectedProjectFolders.length)) {
items = 'project_and_folders';
} else if (selectedProjectFolders.length) {
items = 'folders';
} else {
items = 'projects';
}
2021-01-06 22:45:26 +08:00
projects = selectedProjects.map(e => ({ id: e, type: 'project' }));
folders = selectedProjectFolders.map(e => ({ id: e, type: 'project_folder' }));
2021-01-06 22:02:26 +08:00
let movables = projects.concat(folders);
$.get(url, { items: items, sort: projectsCurrentSort, view_mode: $('.projects-index').data('view-mode') }, function(result) {
2021-01-06 22:02:26 +08:00
$(moveToModal).find('.modal-content').html(result.html);
$(moveToModal).modal('show');
2021-01-06 22:45:26 +08:00
initializeJSTree($(moveToModal).find('#moveToFolders'));
2021-01-06 22:02:26 +08:00
$(moveToModal).find('form')
.on('ajax:before', function() {
2021-01-06 22:45:26 +08:00
$('<input>').attr({
type: 'hidden',
2021-01-06 22:02:26 +08:00
name: 'destination_folder_id',
2021-01-06 22:45:26 +08:00
value: destinationFolder
}).appendTo($(this));
2021-01-06 22:02:26 +08:00
2021-01-06 22:45:26 +08:00
$('<input>').attr({
type: 'hidden',
2021-01-06 22:02:26 +08:00
name: 'movables',
2021-01-06 22:45:26 +08:00
value: JSON.stringify(movables)
}).appendTo($(this));
2021-01-06 22:02:26 +08:00
})
.on('ajax:success', function(ev, data) {
$(moveToModal).modal('hide');
HelperModule.flashAlertMsg(data.flash, 'success');
refreshCurrentView();
2021-01-06 22:45:26 +08:00
})
.on('ajax:error', function(ev, data) {
2021-01-06 22:02:26 +08:00
$(moveToModal).modal('hide');
HelperModule.flashAlertMsg(data.responseJSON.flash, 'danger');
});
});
}
$(projectsWrapper).on('click', '.move-projects-btn', function(e) {
2021-01-06 22:02:26 +08:00
e.preventDefault();
loadMoveToModal($(this).data('url'));
});
}
function loadPlaceHolder() {
let palceholder = '';
$.each(Array(pageSize), function() {
palceholder += $('#projectPlaceholder').html();
});
$(palceholder).insertAfter($(cardsWrapper).find('.table-header'));
}
function loadCardsView() {
var requestParams = {
view_mode: $('.projects-index').data('view-mode'),
sort: projectsCurrentSort,
search: projectsViewSearch,
members: membersFilter,
created_on_from: createdOnFromFilter,
created_on_to: createdOnToFilter,
folders_search: lookInsideFolders,
archived_on_from: archivedOnFromFilter,
archived_on_to: archivedOnToFilter
};
var viewContainer = $(cardsWrapper);
var cardsUrl = viewContainer.data('projects-cards-url');
loadPlaceHolder();
$.ajax({
url: cardsUrl,
type: 'GET',
dataType: 'json',
data: { ...requestParams, ...{ page: 1 } },
success: function(data) {
$('#breadcrumbsWrapper').html(data.breadcrumbs_html);
$(projectsWrapper).find('.projects-title').html(data.title_html);
$(toolbarWrapper).html(data.toolbar_html);
initProjectsViewModeSwitch();
viewContainer.data('projects-cards-url', data.projects_cards_url);
viewContainer.removeClass('no-results');
viewContainer.find('.card, .projects-group, .no-results-container').remove();
viewContainer.append(data.cards_html);
if (viewContainer.find('.no-results-container').length) {
viewContainer.addClass('no-results');
}
selectedProjects.length = 0;
selectedProjectFolders.length = 0;
updateProjectsToolbar();
if (data.filtered) {
InfiniteScroll.removeScroll(cardsWrapper);
} else {
InfiniteScroll.init(cardsWrapper, {
url: cardsUrl,
eventTarget: window,
placeholderTemplate: '#projectPlaceholder',
endOfListTemplate: '#projectEndOfList',
pageSize: pageSize,
2022-09-07 16:01:00 +08:00
lastPage: !data.next_page,
customResponse: (response) => {
$(response.cards_html).appendTo(cardsWrapper);
},
customParams: (params) => {
return { ...params, ...requestParams };
}
});
}
},
error: function() {
viewContainer.html('Error loading project list');
},
complete: function() {
updateSelectAllCheckbox();
}
});
}
function initProjectsViewModeSwitch() {
2020-12-10 18:39:45 +08:00
let projectsPageSelector = '.projects-index';
$('.view-switch-btn-name').text($('.button-to.selected').text());
$('.button-to.selected').removeClass('btn-light');
$('.button-to.selected').addClass('form-dropdown-state-item');
$('.button-to.selected .view-switch-list-span').css('color', 'white');
$('.button-to.selected').removeClass('selected');
$(projectsPageSelector)
.on('ajax:success', '.change-projects-view-type-form', function(ev, data) {
$('.view-switch-btn-name').text($(ev.target).find('.button-to').text());
2022-12-02 19:53:22 +08:00
$(cardsWrapper).removeClass('list cards').addClass(data.cards_view_type_class);
$(projectsPageSelector).find('.cards-switch .button-to').removeClass('form-dropdown-state-item');
$(projectsPageSelector).find('.cards-switch .button-to').addClass('btn-light');
$(projectsPageSelector).find('.cards-switch .button-to .view-switch-list-span').css('color', 'black');
$(ev.target).find('.button-to').removeClass('btn-light');
$(ev.target).find('.button-to').addClass('form-dropdown-state-item');
$(ev.target).find('.button-to .view-switch-list-span').css('color', 'white');
$(ev.target).parents('.dropdown.view-switch').removeClass('open');
InfiniteScroll.loadMore(cardsWrapper);
})
.on('ajax:error', '.change-projects-view-type-form', function(ev, data) {
HelperModule.flashAlertMsg(data.responseJSON.flash, 'danger');
});
// Active/Archived switch
// We have different sorting, filters for active/archived views.
// With turbolinks visit all those elements are updated.
2020-12-10 18:39:45 +08:00
$(projectsPageSelector).on('click', '.archive-switch', function() {
$(projectsPageSelector).find('.projects-container').remove();
Turbolinks.visit($(this).data('url'));
});
}
function initSorting() {
2020-12-18 18:07:59 +08:00
$('#sortMenuDropdown a').click(function() {
if (projectsCurrentSort !== $(this).data('sort')) {
2020-12-18 18:07:59 +08:00
$('#sortMenuDropdown a').removeClass('selected');
projectsCurrentSort = $(this).data('sort');
2023-04-26 16:24:50 +08:00
loadCardsView();
2020-12-18 18:07:59 +08:00
$(this).addClass('selected');
$('#sortMenu').dropdown('toggle');
}
});
}
function selectDate($field) {
var datePicker = $field.data('DateTimePicker');
if (datePicker && datePicker.date()) {
return datePicker.date()._d.toUTCString();
}
return null;
}
function initProjectsFilters() {
var $filterDropdown = filterDropdown.init(filtersEnabled);
let $projectsFilter = $('.projects-index .projects-filters');
2020-11-26 19:17:59 +08:00
let $membersFilter = $('.members-filter', $projectsFilter);
let $foldersCB = $('#folder_search', $projectsFilter);
let $createdOnFromFilter = $('.created-on-filter .from-date', $projectsFilter);
let $createdOnToFilter = $('.created-on-filter .to-date', $projectsFilter);
let $archivedOnFromFilter = $('.archived-on-filter .from-date', $projectsFilter);
let $archivedOnToFilter = $('.archived-on-filter .to-date', $projectsFilter);
let $textFilter = $('#textSearchFilterInput', $projectsFilter);
function getFilterValues() {
createdOnFromFilter = selectDate($createdOnFromFilter);
createdOnToFilter = selectDate($createdOnToFilter);
membersFilter = dropdownSelector.getValues($('.members-filter'));
lookInsideFolders = $foldersCB.prop('checked') ? 'true' : '';
archivedOnFromFilter = selectDate($archivedOnFromFilter);
archivedOnToFilter = selectDate($archivedOnToFilter);
projectsViewSearch = $textFilter.val();
}
function filtersEnabled() {
getFilterValues();
return projectsViewSearch
|| createdOnFromFilter
|| createdOnToFilter
|| (membersFilter && membersFilter.length !== 0)
|| lookInsideFolders
|| archivedOnFromFilter
|| archivedOnToFilter;
}
function appliedFiltersMark() {
filterDropdown.toggleFilterMark($filterDropdown, filtersEnabled());
}
dropdownSelector.init($membersFilter, {
optionClass: 'checkbox-icon users-dropdown-list',
optionLabel: (data) => {
2020-11-26 19:17:59 +08:00
return `<img class="item-avatar" src="${data.params.avatar_url}"/> ${data.label}`;
},
tagLabel: (data) => {
2020-11-26 19:17:59 +08:00
return `<img class="item-avatar" src="${data.params.avatar_url}"/> ${data.label}`;
},
labelHTML: true,
tagClass: 'users-dropdown-list'
});
$projectsFilter.on('click', '#folderSearchInfoBtn', function(e) {
e.stopPropagation();
$('#folderSearchInfo').toggle();
});
2021-02-23 20:16:39 +08:00
$projectsFilter.on('click', '#folder_search', function(e) {
e.stopPropagation();
});
$filterDropdown.on('filter:apply', function() {
appliedFiltersMark();
2023-04-26 16:24:50 +08:00
loadCardsView();
});
// Clear filters
$filterDropdown.on('filter:clear', function() {
dropdownSelector.clearData($membersFilter);
if ($createdOnFromFilter.data('DateTimePicker')) $createdOnFromFilter.data('DateTimePicker').clear();
if ($createdOnToFilter.data('DateTimePicker')) $createdOnToFilter.data('DateTimePicker').clear();
if ($archivedOnFromFilter.data('DateTimePicker')) $archivedOnFromFilter.data('DateTimePicker').clear();
if ($archivedOnToFilter.data('DateTimePicker')) $archivedOnToFilter.data('DateTimePicker').clear();
$foldersCB.prop('checked', false);
$textFilter.val('');
});
// Prevent filter window close
$filterDropdown.on('filter:clickBody', function() {
$('#textSearchFilterHistory').hide();
$textFilter.closest('.dropdown').removeClass('open');
dropdownSelector.closeDropdown($membersFilter);
$('#folderSearchInfo').hide();
});
}
function updateSelectAllCheckbox() {
const tableWrapper = $(cardsWrapper);
2023-02-17 22:47:37 +08:00
const checkboxesCount = $(
'.sci-checkbox.folder-card-selector, .sci-checkbox.project-card-selector',
tableWrapper
).length;
const selectedCheckboxesCount = selectedProjects.length + selectedProjectFolders.length;
const selectAllCheckbox = $('.sci-checkbox.select-all', tableWrapper);
selectAllCheckbox.prop('indeterminate', false);
if (selectedCheckboxesCount === 0) {
selectAllCheckbox.prop('checked', false);
} else if (selectedCheckboxesCount === checkboxesCount) {
selectAllCheckbox.prop('checked', true);
} else {
selectAllCheckbox.prop('indeterminate', true);
}
}
/**
* Initializes cards view
*/
function init() {
exportProjectsModal = $('#export-projects-modal');
exportProjectsModalHeader = exportProjectsModal.find('.modal-title');
exportProjectsModalBody = exportProjectsModal.find('.modal-body');
updateSelectedCards();
initNewProjectFolderModal();
initNewProjectModal();
initExportProjectsModal();
initExportProjects();
initDeleteFoldersToolbarButton();
initArchiveRestoreToolbarButtons();
initEditButton();
initMoveButton();
initProjectsViewModeSwitch();
initSorting();
initSelectAllCheckbox();
initProjectsFilters();
initArchiveRestoreButton();
loadCardsView();
AsyncDropdown.init($(projectsWrapper));
$(projectsWrapper).on('click', '.folder-card-selector', function() {
let folderCard = $(this).closest('.folder-card');
let folderId = folderCard.data('id');
let index = $.inArray(folderId, selectedProjectFolders);
// If checkbox is checked and row ID is not in list of selected folder IDs
if (this.checked && index === -1) {
selectedProjectFolders.push(folderId);
// Otherwise, if checkbox is not checked and ID is in list of selected IDs
} else if (!this.checked && index !== -1) {
selectedProjectFolders.splice(index, 1);
}
updateSelectAllCheckbox();
updateProjectsToolbar();
});
$(projectsWrapper).on('click', '.project-card-selector', function() {
let projectCard = $(this).closest('.project-card');
let projectId = projectCard.data('id');
// Determine whether ID is in the list of selected project IDs
let index = $.inArray(projectId, selectedProjects);
// If checkbox is checked and row ID is not in list of selected project IDs
if (this.checked && index === -1) {
$(this).closest('.project-card').addClass('selected');
selectedProjects.push(projectId);
// Otherwise, if checkbox is not checked and ID is in list of selected IDs
} else if (!this.checked && index !== -1) {
$(this).closest('.project-card').removeClass('selected');
selectedProjects.splice(index, 1);
}
updateSelectAllCheckbox();
updateProjectsToolbar();
});
}
init();
return {
loadCardsView: loadCardsView
};
}());