Merge branch 'MDL-68688-310' of git://github.com/aanabit/moodle into MOODLE_310_STABLE

This commit is contained in:
Sara Arjona 2020-09-16 17:03:27 +02:00
commit bf127517b3
5 changed files with 152 additions and 127 deletions

View file

@ -1,2 +1,2 @@
define ("core_contentbank/sort",["exports","./selectors","core/str","core/prefetch","core/ajax","core/notification"],function(a,b,c,d,e,f){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=g(b);d=g(d);e=g(e);f=g(f);function g(a){return a&&a.__esModule?a:{default:a}}var h=function(){var a=document.querySelector(b.default.regions.contentbank);d.default.prefetchStrings("contentbank",["contentname","lastmodified","size","type","author"]);d.default.prefetchStrings("moodle",["sortbyx","sortbyxreverse"]);i(a)};a.init=h;var i=function(a){var c=document.querySelector(b.default.regions.filearea),d=c.querySelectorAll(b.default.elements.listitem),e=a.querySelector(b.default.actions.viewgrid),f=a.querySelector(b.default.actions.viewlist);e.addEventListener("click",function(){a.classList.remove("view-list");a.classList.add("view-grid");e.classList.add("active");f.classList.remove("active");j(!1)});f.addEventListener("click",function(){a.classList.remove("view-grid");a.classList.add("view-list");f.classList.add("active");e.classList.remove("active");j(!0)});var g=a.querySelector(b.default.actions.sortname);g.addEventListener("click",function(){var b=k(a,g);m(c,d,"data-file",b)});var h=a.querySelector(b.default.actions.sortdate);h.addEventListener("click",function(){var b=k(a,h);m(c,d,"data-timemodified",b)});var i=a.querySelector(b.default.actions.sortsize);i.addEventListener("click",function(){var b=k(a,i);m(c,d,"data-bytes",b)});var l=a.querySelector(b.default.actions.sorttype);l.addEventListener("click",function(){var b=k(a,l);m(c,d,"data-type",b)});var n=a.querySelector(b.default.actions.sortauthor);n.addEventListener("click",function(){var b=k(a,n);m(c,d,"data-author",b)})},j=function(a){if(!1===a){a=null}var b={methodname:"core_user_update_user_preferences",args:{preferences:[{type:"core_contentbank_view_list",value:a}]}};return e.default.call([b])[0].catch(f.default.exception)},k=function(a,c){var d=a.querySelectorAll(b.default.elements.sortbutton);d.forEach(function(a){if(a!==c){a.classList.remove("dir-asc");a.classList.remove("dir-desc");a.classList.add("dir-none");l(a,!1)}});var e=!0;if(c.classList.contains("dir-none")){c.classList.remove("dir-none");c.classList.add("dir-asc")}else if(c.classList.contains("dir-asc")){c.classList.remove("dir-asc");c.classList.add("dir-desc");e=!1}else if(c.classList.contains("dir-desc")){c.classList.remove("dir-desc");c.classList.add("dir-asc")}l(c,e);return e},l=function(a,b){var d=b?"sortbyxreverse":"sortbyx";return(0,c.get_string)(a.dataset.string,"contentbank").then(function(a){return(0,c.get_string)(d,"core",a)}).then(function(b){a.setAttribute("title",b);return b}).catch()},m=function(a,b,c,d){var e=[].slice.call(b).sort(function(e,a){var b=e.getAttribute(c),f=a.getAttribute(c);if(!isNaN(b)){b=parseInt(b);f=parseInt(f)}if(d){return b>f?1:-1}else{return b<f?1:-1}});e.forEach(function(b){return a.appendChild(b)})}}); define ("core_contentbank/sort",["exports","./selectors","core/str","core/prefetch","core/ajax","core/notification"],function(a,b,c,d,e,f){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=g(b);d=g(d);e=g(e);f=g(f);function g(a){return a&&a.__esModule?a:{default:a}}var h=function(){var a=document.querySelector(b.default.regions.contentbank);d.default.prefetchStrings("contentbank",["contentname","lastmodified","size","type","author"]);d.default.prefetchStrings("moodle",["sortbyx","sortbyxreverse"]);i(a)};a.init=h;var i=function(a){a.addEventListener("click",function(c){var d=a.querySelector(b.default.actions.viewlist),e=a.querySelector(b.default.actions.viewgrid);if(c.target.closest(b.default.actions.viewgrid)){a.classList.remove("view-list");a.classList.add("view-grid");e.classList.add("active");d.classList.remove("active");j(!1);return}if(c.target.closest(b.default.actions.viewlist)){a.classList.remove("view-grid");a.classList.add("view-list");d.classList.add("active");e.classList.remove("active");j(!0);return}var f=document.querySelector(b.default.regions.filearea),g=f.querySelectorAll(b.default.elements.listitem);if(f&&g){var h=c.target.closest(b.default.actions.sortname);if(h){var i=k(a,h);m(f,g,"data-file",i);return}var l=c.target.closest(b.default.actions.sortdate);if(l){var n=k(a,l);m(f,g,"data-timemodified",n);return}var o=c.target.closest(b.default.actions.sortsize);if(o){var p=k(a,o);m(f,g,"data-bytes",p);return}var q=c.target.closest(b.default.actions.sorttype);if(q){var r=k(a,q);m(f,g,"data-type",r);return}var s=c.target.closest(b.default.actions.sortauthor);if(s){var t=k(a,s);m(f,g,"data-author",t)}}})},j=function(a){if(!1===a){a=null}var b={methodname:"core_user_update_user_preferences",args:{preferences:[{type:"core_contentbank_view_list",value:a}]}};return e.default.call([b])[0].catch(f.default.exception)},k=function(a,c){var d=a.querySelectorAll(b.default.elements.sortbutton);d.forEach(function(a){if(a!==c){a.classList.remove("dir-asc");a.classList.remove("dir-desc");a.classList.add("dir-none");l(a,!1)}});var e=!0;if(c.classList.contains("dir-none")){c.classList.remove("dir-none");c.classList.add("dir-asc")}else if(c.classList.contains("dir-asc")){c.classList.remove("dir-asc");c.classList.add("dir-desc");e=!1}else if(c.classList.contains("dir-desc")){c.classList.remove("dir-desc");c.classList.add("dir-asc")}l(c,e);return e},l=function(a,b){var d=b?"sortbyxreverse":"sortbyx";return(0,c.get_string)(a.dataset.string,"contentbank").then(function(a){return(0,c.get_string)(d,"core",a)}).then(function(b){a.setAttribute("title",b);return b}).catch()},m=function(a,b,c,d){var e=[].slice.call(b).sort(function(e,a){var b=e.getAttribute(c),f=a.getAttribute(c);if(!isNaN(b)){b=parseInt(b);f=parseInt(f)}if(d){return b>f?1:-1}else{return b<f?1:-1}});e.forEach(function(b){return a.appendChild(b)})}});
//# sourceMappingURL=sort.min.js.map //# sourceMappingURL=sort.min.js.map

File diff suppressed because one or more lines are too long

View file

@ -48,63 +48,78 @@ export const init = () => {
*/ */
const registerListenerEvents = (contentBank) => { const registerListenerEvents = (contentBank) => {
// The search. contentBank.addEventListener('click', e => {
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); const viewList = contentBank.querySelector(selectors.actions.viewlist);
const viewGrid = contentBank.querySelector(selectors.actions.viewgrid);
viewGrid.addEventListener('click', () => { // View as Grid button.
if (e.target.closest(selectors.actions.viewgrid)) {
contentBank.classList.remove('view-list'); contentBank.classList.remove('view-list');
contentBank.classList.add('view-grid'); contentBank.classList.add('view-grid');
viewGrid.classList.add('active'); viewGrid.classList.add('active');
viewList.classList.remove('active'); viewList.classList.remove('active');
setViewListPreference(false); setViewListPreference(false);
});
viewList.addEventListener('click', () => { return;
}
// View as List button.
if (e.target.closest(selectors.actions.viewlist)) {
contentBank.classList.remove('view-grid'); contentBank.classList.remove('view-grid');
contentBank.classList.add('view-list'); contentBank.classList.add('view-list');
viewList.classList.add('active'); viewList.classList.add('active');
viewGrid.classList.remove('active'); viewGrid.classList.remove('active');
setViewListPreference(true); setViewListPreference(true);
});
return;
}
// 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 // Sort by file name alphabetical
const sortByName = contentBank.querySelector(selectors.actions.sortname); const sortByName = e.target.closest(selectors.actions.sortname);
sortByName.addEventListener('click', () => { if (sortByName) {
const ascending = updateSortButtons(contentBank, sortByName); const ascending = updateSortButtons(contentBank, sortByName);
updateSortOrder(fileArea, shownItems, 'data-file', ascending); updateSortOrder(fileArea, shownItems, 'data-file', ascending);
}); return;
}
// Sort by date. // Sort by date.
const sortByDate = contentBank.querySelector(selectors.actions.sortdate); const sortByDate = e.target.closest(selectors.actions.sortdate);
sortByDate.addEventListener('click', () => { if (sortByDate) {
const ascending = updateSortButtons(contentBank, sortByDate); const ascending = updateSortButtons(contentBank, sortByDate);
updateSortOrder(fileArea, shownItems, 'data-timemodified', ascending); updateSortOrder(fileArea, shownItems, 'data-timemodified', ascending);
}); return;
}
// Sort by size. // Sort by size.
const sortBySize = contentBank.querySelector(selectors.actions.sortsize); const sortBySize = e.target.closest(selectors.actions.sortsize);
sortBySize.addEventListener('click', () => { if (sortBySize) {
const ascending = updateSortButtons(contentBank, sortBySize); const ascending = updateSortButtons(contentBank, sortBySize);
updateSortOrder(fileArea, shownItems, 'data-bytes', ascending); updateSortOrder(fileArea, shownItems, 'data-bytes', ascending);
}); return;
}
// Sort by type. // Sort by type.
const sortByType = contentBank.querySelector(selectors.actions.sorttype); const sortByType = e.target.closest(selectors.actions.sorttype);
sortByType.addEventListener('click', () => { if (sortByType) {
const ascending = updateSortButtons(contentBank, sortByType); const ascending = updateSortButtons(contentBank, sortByType);
updateSortOrder(fileArea, shownItems, 'data-type', ascending); updateSortOrder(fileArea, shownItems, 'data-type', ascending);
}); return;
}
// Sort by author. // Sort by author.
const sortByAuthor = contentBank.querySelector(selectors.actions.sortauthor); const sortByAuthor = e.target.closest(selectors.actions.sortauthor);
sortByAuthor.addEventListener('click', () => { if (sortByAuthor) {
const ascending = updateSortButtons(contentBank, sortByAuthor); const ascending = updateSortButtons(contentBank, sortByAuthor);
updateSortOrder(fileArea, shownItems, 'data-author', ascending); updateSortOrder(fileArea, shownItems, 'data-author', ascending);
}
return;
}
}); });
}; };

View file

@ -95,6 +95,7 @@ data-region="contentbank">
<div class="cb-navbar-totalsearch d-none"> <div class="cb-navbar-totalsearch d-none">
</div> </div>
</div> </div>
{{#contents.0}}
<div class="cb-content-wrapper d-flex px-2" data-region="filearea"> <div class="cb-content-wrapper d-flex px-2" data-region="filearea">
<div class="cb-heading bg-white"> <div class="cb-heading bg-white">
<div class="cb-file cb-column d-flex"> <div class="cb-file cb-column d-flex">
@ -176,6 +177,14 @@ data-region="contentbank">
</div> </div>
{{/contents}} {{/contents}}
</div> </div>
{{/contents.0}}
{{^contents.0}}
<div class="cb-content-wrapper d-flex flex-wrap p-2" data-region="filearea">
<div class="w-100 p-3 text-center text-muted">
{{#str}} nocontentavailable, core_contentbank {{/str}}
</div>
</div>
{{/contents.0}}
</div> </div>
</div> </div>
</div> </div>

View file

@ -51,6 +51,7 @@ $string['file_help'] = 'Files may be stored in the content bank for use in cours
$string['itemsfound'] = '{$a} items found'; $string['itemsfound'] = '{$a} items found';
$string['lastmodified'] = 'Last modified'; $string['lastmodified'] = 'Last modified';
$string['name'] = 'Content'; $string['name'] = 'Content';
$string['nocontentavailable'] = 'No content available';
$string['nocontenttypes'] = 'No content types available'; $string['nocontenttypes'] = 'No content types available';
$string['nopermissiontodelete'] = 'You do not have permission to delete content.'; $string['nopermissiontodelete'] = 'You do not have permission to delete content.';
$string['nopermissiontomanage'] = 'You do not have permission to manage content.'; $string['nopermissiontomanage'] = 'You do not have permission to manage content.';