Skip to content

Commit

Permalink
MDL-68688 core_contentbank: Empty content bank notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaia Anabitarte committed Sep 10, 2020
1 parent d4d798e commit 22da620
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 132 deletions.
2 changes: 1 addition & 1 deletion contentbank/amd/build/sort.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contentbank/amd/build/sort.min.js.map

Large diffs are not rendered by default.

123 changes: 69 additions & 54 deletions contentbank/amd/src/sort.js
Expand Up @@ -48,63 +48,78 @@ export const init = () => {
*/
const registerListenerEvents = (contentBank) => {

// The search.
const fileArea = document.querySelector(selectors.regions.filearea);
const shownItems = fileArea.querySelectorAll(selectors.elements.listitem);

// The view buttons.
const viewGrid = contentBank.querySelector(selectors.actions.viewgrid);
const viewList = contentBank.querySelector(selectors.actions.viewlist);

viewGrid.addEventListener('click', () => {
contentBank.classList.remove('view-list');
contentBank.classList.add('view-grid');
viewGrid.classList.add('active');
viewList.classList.remove('active');
setViewListPreference(false);
});

viewList.addEventListener('click', () => {
contentBank.classList.remove('view-grid');
contentBank.classList.add('view-list');
viewList.classList.add('active');
viewGrid.classList.remove('active');
setViewListPreference(true);
});

// Sort by file name alphabetical
const sortByName = contentBank.querySelector(selectors.actions.sortname);
sortByName.addEventListener('click', () => {
const ascending = updateSortButtons(contentBank, sortByName);
updateSortOrder(fileArea, shownItems, 'data-file', ascending);
});

// Sort by date.
const sortByDate = contentBank.querySelector(selectors.actions.sortdate);
sortByDate.addEventListener('click', () => {
const ascending = updateSortButtons(contentBank, sortByDate);
updateSortOrder(fileArea, shownItems, 'data-timemodified', ascending);
});
contentBank.addEventListener('click', e => {
const viewList = contentBank.querySelector(selectors.actions.viewlist);
const viewGrid = contentBank.querySelector(selectors.actions.viewgrid);

// View as Grid button.
if (e.target.closest(selectors.actions.viewgrid)) {
contentBank.classList.remove('view-list');
contentBank.classList.add('view-grid');
viewGrid.classList.add('active');
viewList.classList.remove('active');
setViewListPreference(false);

return;
}

// Sort by size.
const sortBySize = contentBank.querySelector(selectors.actions.sortsize);
sortBySize.addEventListener('click', () => {
const ascending = updateSortButtons(contentBank, sortBySize);
updateSortOrder(fileArea, shownItems, 'data-bytes', ascending);
});
// View as List button.
if (e.target.closest(selectors.actions.viewlist)) {
contentBank.classList.remove('view-grid');
contentBank.classList.add('view-list');
viewList.classList.add('active');
viewGrid.classList.remove('active');
setViewListPreference(true);

// Sort by type.
const sortByType = contentBank.querySelector(selectors.actions.sorttype);
sortByType.addEventListener('click', () => {
const ascending = updateSortButtons(contentBank, sortByType);
updateSortOrder(fileArea, shownItems, 'data-type', ascending);
});
return;
}

// Sort by author.
const sortByAuthor = contentBank.querySelector(selectors.actions.sortauthor);
sortByAuthor.addEventListener('click', () => {
const ascending = updateSortButtons(contentBank, sortByAuthor);
updateSortOrder(fileArea, shownItems, 'data-author', ascending);
// TODO: This should _not_ use `document`. Every query should be constrained to the content bank container.
const fileArea = document.querySelector(selectors.regions.filearea);
const shownItems = fileArea.querySelectorAll(selectors.elements.listitem);

if (fileArea && shownItems) {

// Sort by file name alphabetical
const sortByName = e.target.closest(selectors.actions.sortname);
if (sortByName) {
const ascending = updateSortButtons(contentBank, sortByName);
updateSortOrder(fileArea, shownItems, 'data-file', ascending);
return;
}

// Sort by date.
const sortByDate = e.target.closest(selectors.actions.sortdate);
if (sortByDate) {
const ascending = updateSortButtons(contentBank, sortByDate);
updateSortOrder(fileArea, shownItems, 'data-timemodified', ascending);
return;
}

// Sort by size.
const sortBySize = e.target.closest(selectors.actions.sortsize);
if (sortBySize) {
const ascending = updateSortButtons(contentBank, sortBySize);
updateSortOrder(fileArea, shownItems, 'data-bytes', ascending);
return;
}

// Sort by type.
const sortByType = e.target.closest(selectors.actions.sorttype);
if (sortByType) {
const ascending = updateSortButtons(contentBank, sortByType);
updateSortOrder(fileArea, shownItems, 'data-type', ascending);
return;
}

// Sort by author.
const sortByAuthor = e.target.closest(selectors.actions.sortauthor);
if (sortByAuthor) {
const ascending = updateSortButtons(contentBank, sortByAuthor);
updateSortOrder(fileArea, shownItems, 'data-author', ascending);
}
return;
}
});
};

Expand Down

0 comments on commit 22da620

Please sign in to comment.