1 |
efrain |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Manage the quiz views.
|
|
|
18 |
*
|
|
|
19 |
* @module quizaccess_seb/view
|
|
|
20 |
* @author Andrew Madden <andrewmadden@catalyst-au.net>
|
|
|
21 |
* @copyright 2021 Catalyst IT
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
import Notification from "core/notification";
|
|
|
26 |
import * as Templates from "core/templates";
|
|
|
27 |
import * as Str from "core/str";
|
|
|
28 |
import ModalAlert from "core/local/modal/alert";
|
|
|
29 |
|
|
|
30 |
/** @var SELECTOR List of CSS selectors. */
|
|
|
31 |
const SELECTOR = {
|
|
|
32 |
MAIN: '#region-main',
|
|
|
33 |
LOADING: '.seb-loading',
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
/** @var Template List of mustache templates. */
|
|
|
37 |
const TEMPLATE = {
|
|
|
38 |
LOADING: 'quizaccess_seb/loading',
|
|
|
39 |
};
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Manages view when access has been granted.
|
|
|
43 |
*/
|
|
|
44 |
export const allowAccess = () => {
|
|
|
45 |
window.location.reload();
|
|
|
46 |
};
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Add an alert to page to inform that Safe Exam Browser access is being checked.
|
|
|
50 |
*
|
|
|
51 |
* @return {Promise}
|
|
|
52 |
*/
|
|
|
53 |
export const addLoadingAlert = () => {
|
|
|
54 |
return Templates.render(TEMPLATE.LOADING, {}).then((html, js) => {
|
|
|
55 |
const alertRegion = window.document.querySelector(SELECTOR.MAIN);
|
|
|
56 |
return Templates.prependNodeContents(alertRegion, html, js);
|
|
|
57 |
}).catch(Notification.exception);
|
|
|
58 |
};
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Remove the Safe Exam Browser access check alert from the page.
|
|
|
62 |
*/
|
|
|
63 |
export const clearLoadingAlert = () => {
|
|
|
64 |
const alert = window.document.querySelector(SELECTOR.LOADING);
|
|
|
65 |
if (alert) {
|
|
|
66 |
Templates.replaceNode(alert, '', '');
|
|
|
67 |
}
|
|
|
68 |
};
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Display validation failed modal.
|
|
|
72 |
*/
|
|
|
73 |
export const showValidationFailedModal = () => {
|
|
|
74 |
ModalAlert.create({
|
|
|
75 |
title: Str.get_string('sebkeysvalidationfailed', 'quizaccess_seb'),
|
|
|
76 |
body: Str.get_string('invalidkeys', 'quizaccess_seb'),
|
|
|
77 |
large: false,
|
|
|
78 |
show: true,
|
|
|
79 |
}).catch(Notification.exception);
|
|
|
80 |
};
|