This repository was archived by the owner on Aug 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmodule.js
executable file
·69 lines (63 loc) · 2.75 KB
/
module.js
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
M.block_quickcourselist = {
sesskey: null,
init: function(Y, instanceid, sesskey, displaymode, contextid) {
this.Y = Y;
this.sesskey = sesskey;
this.instanceid = instanceid;
this.displaymode = displaymode;
this.contextid = contextid;
this.progress = Y.one('#quickcourseprogress');
this.xhr = null;
Y.one('#quickcourselistsearch').on('keyup', function(e) {
var searchstring = e.target.get('value');
this.search(searchstring);
}, this);
Y.one('#quickcourseform').on('submit', function(e) {
e.preventDefault();
var searchstring = e.target.getById('quickcourselistsearch').get('value');
this.search(searchstring);
}, this);
},
search: function(string) {
var Y = this.Y;
uri = M.cfg.wwwroot+'/blocks/quickcourselist/quickcourse.php';
if (this.xhr != null) {
this.xhr.abort();
}
this.progress.setStyle('visibility', 'visible');
var displaymode = this.displaymode;
this.xhr = Y.io(uri, {
data: 'course='+string+'&instanceid='+this.instanceid+'&sesskey='+this.sesskey+'&contextid='+this.contextid,
context: this,
on: {
success: function(id, o) {
var courses = Y.JSON.parse(o.responseText);
list = Y.Node.create('<ul />');
if (courses.length > 0) {
Y.Array.each(courses, function(course) {
switch (displaymode) {
case '1': displaystr = course.shortname; break;
case '2': displaystr = course.fullname; break;
case '3': displaystr = course.shortname+': '+course.fullname; break;
}
Y.Node.create('<li><a href="'+M.cfg.wwwroot+'/course/view.php?id='+course.id+'">'+displaystr+'</a></li>').appendTo(list);
});
}
Y.one('#quickcourselist').replace(list);
list.setAttribute('id', 'quickcourselist');
this.progress.setStyle('visibility', 'hidden');
},
failure: function(id, o) {
if (o.statusText != 'abort') {
this.progress.setStyle('visibility', 'hidden');
if (o.statusText !== undefined) {
var list = Y.Node.create('<p>'+o.statusText+'</p>');
Y.one('#quickcourselist').replace(list);
list.set('id', 'quickcourselist');
}
}
}
}
});
}
}