};
};
+/**
+ * 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);
// 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');
}
* @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';
};
};
-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);
}
});
};
};
};
-// 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
} = {}) => {
const saveGradeFunction = getSaveUserGradeFunction(graderContainer, setGradeForUser);
Templates.replaceNodeContents(graderContainer, graderHTML, '');
- registerEventListeners(graderLayout);
const updateUserContent = getUpdateUserContentFunction(graderContainer, getContentForUser, getGradeForUser);
// Fetch the userpicker for display.
saveGradeFunction
);
+ // Register all event listeners.
+ registerEventListeners(graderLayout, userPicker, saveGradeFunction);
+
// Display the newly created user picker.
displayUserPicker(graderContainer, userPicker.rootNode);
};
buttons: {
toggleFullscreen: getDataSelector('action', 'togglefullscreen'),
closeGrader: getDataSelector('action', 'closegrader'),
+ saveGrade: getDataSelector('action', 'savegrade'),
},
regions: {
moduleReplace: getDataSelector('region', 'module_content'),
* 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);
}
});
}
<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>