1441 |
ariadna |
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 |
import UserSearch from 'core_user/comboboxsearch/user';
|
|
|
17 |
import * as Repository from 'mod_assign/repository';
|
|
|
18 |
|
|
|
19 |
// Define our standard lookups.
|
|
|
20 |
const selectors = {
|
|
|
21 |
component: '.user-search',
|
|
|
22 |
groupid: '[data-region="groupid"]',
|
|
|
23 |
instance: '[data-region="instance"]',
|
|
|
24 |
currentvalue: '[data-region="currentvalue"]',
|
|
|
25 |
};
|
|
|
26 |
const component = document.querySelector(selectors.component);
|
|
|
27 |
const groupID = parseInt(component.querySelector(selectors.groupid).dataset.groupid, 10);
|
|
|
28 |
const assignID = parseInt(component.querySelector(selectors.instance).dataset.instance, 10);
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Allow the user to search for users in the action bar.
|
|
|
32 |
*
|
|
|
33 |
* @module mod_assign/user
|
|
|
34 |
* @copyright 2024 Ilya Tregubov <ilyatregubov@proton.me>
|
|
|
35 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
36 |
*/
|
|
|
37 |
export default class User extends UserSearch {
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Construct the class.
|
|
|
41 |
*
|
|
|
42 |
* @param {string} baseUrl The base URL for the page.
|
|
|
43 |
*/
|
|
|
44 |
constructor(baseUrl) {
|
|
|
45 |
super();
|
|
|
46 |
this.baseUrl = baseUrl;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Allow the class to be invoked via PHP.
|
|
|
51 |
*
|
|
|
52 |
* @param {string} baseUrl The base URL for the page.
|
|
|
53 |
* @returns {User}
|
|
|
54 |
*/
|
|
|
55 |
static init(baseUrl) {
|
|
|
56 |
return new User(baseUrl);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Build up the view all link.
|
|
|
61 |
*
|
|
|
62 |
* @returns {string|*}
|
|
|
63 |
*/
|
|
|
64 |
selectAllResultsLink() {
|
|
|
65 |
const url = new URL(this.baseUrl);
|
|
|
66 |
url.searchParams.set('search', this.getSearchTerm());
|
|
|
67 |
|
|
|
68 |
return url.toString();
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Get the data we will be searching against in this component.
|
|
|
73 |
*
|
|
|
74 |
* @returns {Promise<*>}
|
|
|
75 |
*/
|
|
|
76 |
fetchDataset() {
|
|
|
77 |
return Repository.userFetch(assignID, groupID).then((r) => r);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Build up the link that is dedicated to a particular result.
|
|
|
82 |
*
|
|
|
83 |
* @param {Number} userID The ID of the user selected.
|
|
|
84 |
* @returns {string|*}
|
|
|
85 |
*/
|
|
|
86 |
selectOneLink(userID) {
|
|
|
87 |
const url = new URL(this.baseUrl);
|
|
|
88 |
url.searchParams.set('search', this.getSearchTerm());
|
|
|
89 |
url.searchParams.set('userid', userID.toString());
|
|
|
90 |
|
|
|
91 |
return url.toString();
|
|
|
92 |
}
|
|
|
93 |
}
|