Merge branch 'MDL-68688-310' of git://github.com/aanabit/moodle into MOODLE_310_STABLE
authorSara Arjona <sara@moodle.com>
Wed, 16 Sep 2020 15:03:27 +0000 (17:03 +0200)
committerSara Arjona <sara@moodle.com>
Thu, 17 Sep 2020 07:16:52 +0000 (09:16 +0200)
contentbank/amd/build/sort.min.js
contentbank/amd/build/sort.min.js.map
contentbank/amd/src/sort.js
contentbank/templates/bankcontent.mustache
lang/en/contentbank.php

index 2fd3317..4660de4 100644 (file)
Binary files a/contentbank/amd/build/sort.min.js and b/contentbank/amd/build/sort.min.js differ
index a1b8557..06c091c 100644 (file)
Binary files a/contentbank/amd/build/sort.min.js.map and b/contentbank/amd/build/sort.min.js.map differ
index 34c282b..ed67de5 100644 (file)
@@ -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;
+        }
     });
 };
 
index a62beff..f5c800e 100644 (file)
@@ -95,87 +95,96 @@ data-region="contentbank">
                 <div class="cb-navbar-totalsearch d-none">
                 </div>
             </div>
-            <div class="cb-content-wrapper d-flex px-2" data-region="filearea">
-                <div class="cb-heading bg-white">
-                    <div class="cb-file cb-column d-flex">
-                        <div class="title">{{#str}} contentname, contentbank {{/str}}</div>
-                        <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="contentname" data-action="sortname"
-                            title="{{#str}} sortbyx, core, {{#str}} contentname, contentbank {{/str}} {{/str}}">
-                            <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
-                            <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
-                            <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
-                        </button>
-                    </div>
-                    <div class="cb-date cb-column d-flex">
-                        <div class="title">{{#str}} lastmodified, contentbank {{/str}}</div>
-                        <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="lastmodified" data-action="sortdate"
-                        title="{{#str}} sortbyx, core, {{#str}} lastmodified, contentbank {{/str}} {{/str}}">
-                            <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
-                            <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
-                            <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
-                        </button>
-                    </div>
-                    <div class="cb-size cb-column d-flex">
-                        <div class="title">{{#str}} size, contentbank {{/str}}</div>
-                        <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="size" data-action="sortsize"
-                        title="{{#str}} sortbyx, core, {{#str}} size, contentbank {{/str}} {{/str}}">
-                            <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
-                            <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
-                            <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
-                        </button>
-                    </div>
-                    <div class="cb-type cb-column d-flex">
-                        <div class="title">{{#str}} type, contentbank {{/str}}</div>
-                        <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="type" data-action="sorttype"
-                        title="{{#str}} sortbyx, core, {{#str}} type, contentbank {{/str}} {{/str}}">
-                            <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
-                            <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
-                            <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
-                        </button>
-                    </div>
-                    <div class="cb-author cb-column d-flex last">
-                        <div class="title">{{#str}} author, contentbank {{/str}}</div>
-                        <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="author" data-action="sortauthor"
-                        title="{{#str}} sortbyx, core, {{#str}} author, contentbank {{/str}} {{/str}}">
-                            <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
-                            <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
-                            <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
-                        </button>
-                    </div>
-                </div>
-            {{#contents}}
-                <div class="cb-listitem"
-                    data-file="{{{ title }}}"
-                    data-name="{{{ name }}}"
-                    data-bytes="{{ bytes }}"
-                    data-timemodified="{{ timemodified }}"
-                    data-type="{{{ type }}}"
-                    data-author="{{{ author }}}">
-                    <div class="cb-file cb-column position-relative">
-                        <div class="cb-thumbnail" role="img" aria-label="{{{ name }}}"
-                        style="background-image: url('{{{ icon }}}');">
+            {{#contents.0}}
+                <div class="cb-content-wrapper d-flex px-2" data-region="filearea">
+                    <div class="cb-heading bg-white">
+                        <div class="cb-file cb-column d-flex">
+                            <div class="title">{{#str}} contentname, contentbank {{/str}}</div>
+                            <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="contentname" data-action="sortname"
+                                title="{{#str}} sortbyx, core, {{#str}} contentname, contentbank {{/str}} {{/str}}">
+                                <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
+                                <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
+                                <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
+                            </button>
+                        </div>
+                        <div class="cb-date cb-column d-flex">
+                            <div class="title">{{#str}} lastmodified, contentbank {{/str}}</div>
+                            <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="lastmodified" data-action="sortdate"
+                            title="{{#str}} sortbyx, core, {{#str}} lastmodified, contentbank {{/str}} {{/str}}">
+                                <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
+                                <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
+                                <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
+                            </button>
+                        </div>
+                        <div class="cb-size cb-column d-flex">
+                            <div class="title">{{#str}} size, contentbank {{/str}}</div>
+                            <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="size" data-action="sortsize"
+                            title="{{#str}} sortbyx, core, {{#str}} size, contentbank {{/str}} {{/str}}">
+                                <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
+                                <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
+                                <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
+                            </button>
+                        </div>
+                        <div class="cb-type cb-column d-flex">
+                            <div class="title">{{#str}} type, contentbank {{/str}}</div>
+                            <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="type" data-action="sorttype"
+                            title="{{#str}} sortbyx, core, {{#str}} type, contentbank {{/str}} {{/str}}">
+                                <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
+                                <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
+                                <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
+                            </button>
+                        </div>
+                        <div class="cb-author cb-column d-flex last">
+                            <div class="title">{{#str}} author, contentbank {{/str}}</div>
+                            <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="author" data-action="sortauthor"
+                            title="{{#str}} sortbyx, core, {{#str}} author, contentbank {{/str}} {{/str}}">
+                                <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
+                                <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
+                                <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
+                            </button>
                         </div>
-                        <a href="{{{ link }}}" class="cb-link stretched-link" title="{{{ name }}}">
-                            <span class="cb-name word-break-all clamp-2" data-region="cb-content-name">
-                                {{{ name }}}
-                            </span>
-                        </a>
-                    </div>
-                    <div class="cb-date cb-column small">
-                        {{#userdate}} {{ timemodified }}, {{#str}} strftimedatetimeshort, core_langconfig {{/str}} {{/userdate}}
-                    </div>
-                    <div class="cb-size cb-column small">
-                        {{ size }}
                     </div>
-                    <div class="cb-type cb-column small">
-                        {{{ type }}}
+                {{#contents}}
+                    <div class="cb-listitem"
+                        data-file="{{{ title }}}"
+                        data-name="{{{ name }}}"
+                        data-bytes="{{ bytes }}"
+                        data-timemodified="{{ timemodified }}"
+                        data-type="{{{ type }}}"
+                        data-author="{{{ author }}}">
+                        <div class="cb-file cb-column position-relative">
+                            <div class="cb-thumbnail" role="img" aria-label="{{{ name }}}"
+                            style="background-image: url('{{{ icon }}}');">
+                            </div>
+                            <a href="{{{ link }}}" class="cb-link stretched-link" title="{{{ name }}}">
+                                <span class="cb-name word-break-all clamp-2" data-region="cb-content-name">
+                                    {{{ name }}}
+                                </span>
+                            </a>
+                        </div>
+                        <div class="cb-date cb-column small">
+                            {{#userdate}} {{ timemodified }}, {{#str}} strftimedatetimeshort, core_langconfig {{/str}} {{/userdate}}
+                        </div>
+                        <div class="cb-size cb-column small">
+                            {{ size }}
+                        </div>
+                        <div class="cb-type cb-column small">
+                            {{{ type }}}
+                        </div>
+                        <div class="cb-type cb-column last small">
+                            {{{ author }}}
+                        </div>
                     </div>
-                    <div class="cb-type cb-column last small">
-                        {{{ author }}}
+                {{/contents}}
+                </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}}
-            </div>
+            {{/contents.0}}
         </div>
     </div>
 </div>
index 6535c93..4e073a6 100644 (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['lastmodified'] = 'Last modified';
 $string['name'] = 'Content';
+$string['nocontentavailable'] = 'No content available';
 $string['nocontenttypes'] = 'No content types available';
 $string['nopermissiontodelete'] = 'You do not have permission to delete content.';
 $string['nopermissiontomanage'] = 'You do not have permission to manage content.';