aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cockpit/js/cockpit.js4
-rw-r--r--js/utils-mock.js25
-rw-r--r--js/utils-prod.js6
-rw-r--r--mass-graducation/src/main.js1
4 files changed, 23 insertions, 13 deletions
diff --git a/cockpit/js/cockpit.js b/cockpit/js/cockpit.js
index f8ee8e9..7503f32 100644
--- a/cockpit/js/cockpit.js
+++ b/cockpit/js/cockpit.js
@@ -13,7 +13,7 @@ import {
import { fetchStudent, fetchStudents } from "../../js/student-ENV.js";
import {
isTeacher as getIsTeacher,
- getCurrentName,
+ getFirstAndLastname,
getUserId,
} from "../../js/utils-ENV.js";
import { initSelection } from "../../js/selection.js";
@@ -293,6 +293,6 @@ async function initCockpit() {
window.onload = function() {
isTeacher = getIsTeacher();
DEFAULT_STUDENT_ICON = document.getElementById("student-info-icon").src;
- [firstname, lastname] = getCurrentName();
+ [firstname, lastname] = getFirstAndLastname();
initCockpit();
}
diff --git a/js/utils-mock.js b/js/utils-mock.js
index 7859a1e..c4a9a73 100644
--- a/js/utils-mock.js
+++ b/js/utils-mock.js
@@ -4,17 +4,10 @@ export function isTeacher() {
return !(new URLSearchParams(document.location.search)).has("student");
}
-export function getCurrentName() {
+export function getFirstAndLastname() {
let firstname = "";
let lastname = "";
- const autoNameDiv = document.getElementById("auto-name");
- if (autoNameDiv) {
- firstname = autoNameDiv.children[0].innerHTML;
- lastname = autoNameDiv.children[1].innerHTML;
- autoNameDiv.remove();
- }
-
const params = new URLSearchParams(document.location.search);
if (params.has("firstname"))
firstname = params.get("firstname")
@@ -24,8 +17,20 @@ export function getCurrentName() {
return [firstname, lastname];
}
+export function getName() {
+ let name = "";
+
+ const params = new URLSearchParams(document.location.search);
+ if (params.has("firstname"))
+ name = params.get("firstname")
+ if (params.has("lastname"))
+ name += params.get("lastname")
+
+ return name;
+}
+
export function getUserId() {
- const [firstname, lastname] = getCurrentName();
+ const name = getName();
- return fetchStudent(null, firstname + " " + lastname).id;
+ return fetchStudent(null, name).id;
}
diff --git a/js/utils-prod.js b/js/utils-prod.js
index 119870c..ab8e311 100644
--- a/js/utils-prod.js
+++ b/js/utils-prod.js
@@ -3,7 +3,7 @@ export function isTeacher() {
|| document.body.classList.contains('editing');
}
-export function getCurrentName() {
+export function getFirstAndLastname() {
let firstname = "";
let lastname = "";
@@ -15,6 +15,10 @@ export function getCurrentName() {
return [firstname, lastname];
}
+export function getName() {
+ return document.querySelector("div.user-name").textContent;
+}
+
export function getUserId() {
// M is exported by Moodle
return M.cfg.userid;
diff --git a/mass-graducation/src/main.js b/mass-graducation/src/main.js
index 86d2165..0f0de07 100644
--- a/mass-graducation/src/main.js
+++ b/mass-graducation/src/main.js
@@ -144,4 +144,5 @@ window.onload = function() {
(group) => `${group.name}`,
loadGroup,
);
+ name = getName();
}