MDL-66845 mod_forum: Hook up save button
authorAndrew Nicols <andrew@nicols.co.uk>
Sat, 5 Oct 2019 08:08:45 +0000 (16:08 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Wed, 30 Oct 2019 02:23:41 +0000 (10:23 +0800)
Part of MDL-66074

13 files changed:
mod/forum/amd/build/grades/grader.min.js
mod/forum/amd/build/grades/grader.min.js.map
mod/forum/amd/build/local/grades/grader.min.js
mod/forum/amd/build/local/grades/grader.min.js.map
mod/forum/amd/build/local/grades/local/grader/selectors.min.js
mod/forum/amd/build/local/grades/local/grader/selectors.min.js.map
mod/forum/amd/build/local/grades/local/grader/user_picker.min.js
mod/forum/amd/build/local/grades/local/grader/user_picker.min.js.map
mod/forum/amd/src/grades/grader.js
mod/forum/amd/src/local/grades/grader.js
mod/forum/amd/src/local/grades/local/grader/selectors.js
mod/forum/amd/src/local/grades/local/grader/user_picker.js
mod/forum/templates/local/grades/local/grader/navigation.mustache

index 6169ac5..2bb04a8 100644 (file)
Binary files a/mod/forum/amd/build/grades/grader.min.js and b/mod/forum/amd/build/grades/grader.min.js differ
index 5b80040..2769244 100644 (file)
Binary files a/mod/forum/amd/build/grades/grader.min.js.map and b/mod/forum/amd/build/grades/grader.min.js.map differ
index 8db2e6c..d4e333c 100644 (file)
Binary files a/mod/forum/amd/build/local/grades/grader.min.js and b/mod/forum/amd/build/local/grades/grader.min.js differ
index 6940597..640f8e8 100644 (file)
Binary files a/mod/forum/amd/build/local/grades/grader.min.js.map and b/mod/forum/amd/build/local/grades/grader.min.js.map differ
index 2c1440d..f63728b 100644 (file)
Binary files a/mod/forum/amd/build/local/grades/local/grader/selectors.min.js and b/mod/forum/amd/build/local/grades/local/grader/selectors.min.js differ
index d3dfc8f..79f26b4 100644 (file)
Binary files a/mod/forum/amd/build/local/grades/local/grader/selectors.min.js.map and b/mod/forum/amd/build/local/grades/local/grader/selectors.min.js.map differ
index 9cb271e..4fb0c82 100644 (file)
Binary files a/mod/forum/amd/build/local/grades/local/grader/user_picker.min.js and b/mod/forum/amd/build/local/grades/local/grader/user_picker.min.js differ
index 67fb8a6..a2afa80 100644 (file)
Binary files a/mod/forum/amd/build/local/grades/local/grader/user_picker.min.js.map and b/mod/forum/amd/build/local/grades/local/grader/user_picker.min.js.map differ
index a44979a..2ff4512 100644 (file)
@@ -94,11 +94,40 @@ const discussionPostMapper = discussion => {
     };
 };
 
+/**
+ * Launch the Grader.
+ *
+ * @param {HTMLElement} rootNode the root HTML element describing what is to be graded
+ */
+const launchWholeForumGrading = async rootNode => {
+    const data = rootNode.dataset;
+    const wholeForumFunctions = getWholeForumFunctions(data.cmid);
+    const gradingPanelFunctions = await Grader.getGradingPanelFunctions(
+        'mod_forum',
+        data.contextid,
+        data.gradingComponent,
+        data.gradingComponentSubtype,
+        data.gradableItemtype
+    );
+
+    await Grader.launch(
+        wholeForumFunctions.getUsers,
+        wholeForumFunctions.getContentForUserId,
+        gradingPanelFunctions.getter,
+        gradingPanelFunctions.setter,
+        {
+            groupid: data.groupid,
+            initialUserId: data.initialuserid,
+            moduleName: data.name
+        }
+    );
+};
+
 /**
  * Register listeners to launch the grading panel.
  */
 export const registerLaunchListeners = () => {
-    document.addEventListener('click', async(e) => {
+    document.addEventListener('click', async e => {
         if (e.target.matches(Selectors.launch)) {
             const rootNode = findGradableNode(e.target);
 
@@ -110,28 +139,11 @@ export const registerLaunchListeners = () => {
                 // Note: The preventDefault must be before any async function calls because the function becomes async
                 // at that point and the default action is implemented.
                 e.preventDefault();
-
-                const data = rootNode.dataset;
-                const wholeForumFunctions = getWholeForumFunctions(data.cmid);
-                const gradingPanelFunctions = await Grader.getGradingPanelFunctions(
-                    'mod_forum',
-                    data.contextid,
-                    data.gradingComponent,
-                    data.gradingComponentSubtype,
-                    data.gradableItemtype
-                );
-
-                Grader.launch(
-                    wholeForumFunctions.getUsers,
-                    wholeForumFunctions.getContentForUserId,
-                    gradingPanelFunctions.getter,
-                    gradingPanelFunctions.setter,
-                    {
-                        groupid: data.groupid,
-                        initialUserId: data.initialuserid,
-                        moduleName: data.name
-                    }
-                );
+                try {
+                    await launchWholeForumGrading(rootNode);
+                } catch (error) {
+                    Notification.exception(error);
+                }
             } else {
                 throw Error('Unable to find a valid gradable item');
             }
index 0a842c4..637820d 100644 (file)
@@ -22,7 +22,6 @@
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 import Templates from 'core/templates';
-// TODO import Notification from 'core/notification';
 import Selectors from './local/grader/selectors';
 import getUserPicker from './local/grader/user_picker';
 import {createLayout as createFullScreenWindow} from 'mod_forum/local/layout/fullscreen';
@@ -64,18 +63,28 @@ const getUpdateUserContentFunction = (root, getContentForUser, getGradeForUser)
     };
 };
 
-const registerEventListeners = (graderLayout) => {
+const registerEventListeners = (graderLayout, userPicker, saveGradeFunction) => {
     const graderContainer = graderLayout.getContainer();
     graderContainer.addEventListener('click', (e) => {
         if (e.target.closest(Selectors.buttons.toggleFullscreen)) {
             e.stopImmediatePropagation();
             e.preventDefault();
             graderLayout.toggleFullscreen();
-        } else if (e.target.closest(Selectors.buttons.closeGrader)) {
+
+            return;
+        }
+
+        if (e.target.closest(Selectors.buttons.closeGrader)) {
             e.stopImmediatePropagation();
             e.preventDefault();
 
             graderLayout.close();
+
+            return;
+        }
+
+        if (e.target.closest(Selectors.buttons.saveGrade)) {
+            saveGradeFunction(userPicker.currentUser);
         }
     });
 };
@@ -100,7 +109,14 @@ const getSaveUserGradeFunction = (root, setGradeForUser) => {
     };
 };
 
-// Make this explicit rather than object
+/**
+ * Launch the grader interface with the specified parameters.
+ *
+ * @param {Function} getListOfUsers A function to get the list of users
+ * @param {Function} getContentForUser A function to get the content for a specific user
+ * @param {Function} getGradeForUser A function get the grade details for a specific user
+ * @param {Function} setGradeForUser A function to set the grade for a specific user
+ */
 export const launch = async(getListOfUsers, getContentForUser, getGradeForUser, setGradeForUser, {
     initialUserId = 0, moduleName
 } = {}) => {
@@ -119,7 +135,6 @@ export const launch = async(getListOfUsers, getContentForUser, getGradeForUser,
     const saveGradeFunction = getSaveUserGradeFunction(graderContainer, setGradeForUser);
 
     Templates.replaceNodeContents(graderContainer, graderHTML, '');
-    registerEventListeners(graderLayout);
     const updateUserContent = getUpdateUserContentFunction(graderContainer, getContentForUser, getGradeForUser);
 
     // Fetch the userpicker for display.
@@ -130,6 +145,9 @@ export const launch = async(getListOfUsers, getContentForUser, getGradeForUser,
         saveGradeFunction
     );
 
+    // Register all event listeners.
+    registerEventListeners(graderLayout, userPicker, saveGradeFunction);
+
     // Display the newly created user picker.
     displayUserPicker(graderContainer, userPicker.rootNode);
 };
index 12fa562..8f55bba 100644 (file)
@@ -30,6 +30,7 @@ export default {
     buttons: {
         toggleFullscreen: getDataSelector('action', 'togglefullscreen'),
         closeGrader: getDataSelector('action', 'closegrader'),
+        saveGrade: getDataSelector('action', 'savegrade'),
     },
     regions: {
         moduleReplace: getDataSelector('region', 'module_content'),
index 252ecfa..9cbf1ee 100644 (file)
@@ -107,12 +107,12 @@ class UserPicker {
      * Register the event listeners for the user picker.
      */
     registerEventListeners() {
-        this.root.addEventListener('click', (e) => {
+        this.root.addEventListener('click', async e => {
             const button = e.target.closest(Selectors.actions.changeUser);
             if (button) {
-                this.preChangeUserCallback(this.currentUser);
+                await this.preChangeUserCallback(this.currentUser);
                 this.updateIndex(parseInt(button.dataset.direction));
-                this.showUser(this.currentUser);
+                await this.showUser(this.currentUser);
             }
         });
     }
index c7aaa3a..a99a025 100644 (file)
@@ -46,8 +46,7 @@
 
             <a href="#" class="btn btn-secondary float-right" aria-label="Close grade interface" data-action="closegrader">Close</a>
 
-            <!--TODO Save & close-->
-            <a href="#" role="button" class="btn btn-primary float-right" aria-label="Save and quit" data-action="saveclosegrader">Save</a>
+            <a href="#" role="button" class="btn btn-primary float-right" aria-label="Save and quit" data-action="savegrade">Save</a>
 
             <!--TODO Manipulate grader panel see also Grading panel-->
             <a href="#" role="button" class="btn fa fa-check-circle float-right" aria-label="Open or close grader panel" data-action="expandgrader"></a>