-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpeopletoolMod.js
More file actions
160 lines (153 loc) · 5.48 KB
/
peopletoolMod.js
File metadata and controls
160 lines (153 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
$(document).ready(function () {
//***Begin People Tool Configuration
// always use IIFE, to isolate code from global scope
(function () {
"use strict";
// only run this code on the users page
if (/^\/courses\/\d+\/users$/.test(window.location.pathname)) {
$("#role_id option[value=3]").remove();
$("#role_id option[value=10]").remove();
$("#role_id option[value=11]").remove();
$("#role_id option[value=4]").remove();
$("#role_id option[value=9]").remove();
$("#role_id option[value=7]").remove();
if (!ENV.permissions.manage_students) {
$("#role_id option[value=12]").remove();
$("#role_id option[value=5]").remove();
$("#role_id option[value=26]").remove();
$("#role_id option[value=32]").remove();
$("#role_id option[value=35]").remove();
$("#role_id option[value=6]").remove();
}
const addPeopleModal = function (mtx, obs) {
let watchResults = document.querySelector(
'span > span > span > span > div[role="presentation"] > ul[role="listbox"]'
);
// the result list is available
if (watchResults) {
//Remove roles from "Add People" screen within a course
//student
$("#3").remove();
//shopper
$("#10").remove();
//auditor
$("#11").remove();
//teacher
$("#4").remove();
//instructor
$("#9").remove();
//observer
$("#7").remove();
if (!ENV.permissions.manage_students) {
//guest instructor
$("#12").remove();
//ta
$("#5").remove();
//grader
$("#26").remove();
//ula
$("#32").remove();
//accessibility support
$("#35").remove();
//designer
$("#6").remove();
}
}
};
// wait for the modal to be open
const watchForModal = function () {
const uiDialog = function (mtx, obs) {
let pplMdl = document.getElementById("add_people_modal");
// the modal is found
if (pplMdl) {
const defaultRole = document.getElementById(
"peoplesearch_select_role"
);
if (
defaultRole.value === "Student" ||
defaultRole.value === "Teacher"
) {
defaultRole.value = "";
}
if (
$("#add_people_modal").length == 1 &&
$("#addPeople-yaleDirLink").length == 0
) {
//Change "Login Id" to "NetID" on "Add People" screen within a course
$('[for="peoplesearch_radio_unique_id"] span:nth-child(2)').text(
"NetID or LoginID"
);
//Hide "SIS ID" on "Add People" screen within a course
$('[for="peoplesearch_radio_sis_user_id"]').hide();
//Add Yale Directory Link on "Add People" screen within a course
$(
".addpeople__peoplesearch fieldset:nth-child(2) div:first"
).append(
"<div id='addPeople-yaleDirLink' style='float: right;'><a href='https://directory.yale.edu' target='_blank'>Yale Directory</a></div>"
);
$("#peoplesearch_select_role").css({
border: "2px solid red",
"border-radius": "4px",
});
var roleWarning =
"<h6 id='addPeople-yaleRoleWarning'>Please select a role to continue</h6>";
$(
'[for="peoplesearch_select_role"] span:first span:first'
).append(roleWarning);
}
if (
$("#peoplesearch_select_role").val() === "" ||
$(
".addpeople__peoplesearch fieldset:nth-child(2) textarea"
).val() === ""
) {
$("#addpeople_next").hide();
} else {
$("#addpeople_next").show();
}
//hide/show next button based on role select
if (
$("#peoplesearch_select_role").val() === "" ||
$(
".addpeople__peoplesearch fieldset:nth-child(2) textarea"
).val() === ""
) {
$("#addpeople_next").hide();
} else {
$("#addpeople_next").show();
}
if ($("#peoplesearch_select_role").val() === "") {
$("#peoplesearch_select_role").css({
border: "2px solid red",
"border-radius": "4px",
});
$("#addPeople-yaleRoleWarning").show();
} else {
$("#peoplesearch_select_role").css({
border: "",
"border-radius": "",
});
$("#addPeople-yaleRoleWarning").hide();
}
// watch the add people modal instead
const observer = new MutationObserver(addPeopleModal);
observer.observe(document.body, {
childList: true,
subtree: true,
});
}
};
// watch document.body for modal
const observer = new MutationObserver(uiDialog);
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
});
};
// start when the user clicks the compose button
watchForModal();
}
})();
//***End People Tool Configuration
});