Newer
Older
define(['jquery'], function ($) {
function getRootWebSitePath() {
var _location = document.location.toString();
var applicationNameIndex = _location.indexOf('/', _location.indexOf('://') + 3);
var applicationName = _location.substring(0, applicationNameIndex) + '/';
return applicationName;
//var webFolderIndex = _location.indexOf('/', _location.indexOf(applicationName) + applicationName.length);
//var webFolderFullPath = _location.substring(0, webFolderIndex);
//return webFolderFullPath;
}
function search(searchstring, reloadBool, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester) {
if (reloadBool) {
$("#hshcourseprogress").show();
$.ajax({
type: 'GET',
url: getRootWebSitePath() + '/blocks/hshcourselist/hshcourselist.php',
data: 'course=' + searchstring + '&instanceid=' + instanceid
+ '&sesskey=' + sesskey + '&contextid=' + contextid
+ '&idSearching=' + idSearching + '&orderbysemester=' + orderbysemester,
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
dataType: "json",
success: function (response) {
var plainJSON = JSON.stringify(response);
var courses = JSON.parse(plainJSON);
var list = $("<ul class='list-group' id='hshcourselistul'></ul>");
if (courses.length > 0) {
$.each(courses, function (index, course) {
switch (displaymode) {
case '0':
displaystr = course.shortname;
break;
case '1':
displaystr = course.fullname;
break;
case '2':
displaystr = course.shortname + ': ' + course.fullname;
break;
default:
displaystr = course.fullname;
break;
}
$('<li class="list-group-item hshcoursesearchlistitem " value="' + course.id + '">'
+ '<a href="' + getRootWebSitePath() + '/course/view.php?id=' + course.id + '">' + displaystr + '</a> </li>')
.appendTo(list);
});
}
$("#hshcourselistul").replaceWith(list);
$("#hshcourseprogress").hide();
},
error: function () {
console.error("error");
if (o.statusText !== 'abort') {
$("#hshcourseprogress").hide();
if (o.statusText !== undefined) {
console.error("ABORT + STATUS : " + o.statusText);
}
}
}
});
} else {
}
}
return {
init: function (jsdataobject) {
var jsdataobject = jsdataobject;
var instanceid = jsdataobject.instanceid;
var sesskey = jsdataobject.sesskey;
var displaymode = jsdataobject.displaymode;
var contextid = jsdataobject.contextid;
var reloadList = false;
var idSearching = false;
var searchstring;
var orderbysemester = jsdataobject.orderbysemester;
var displaystr;
$("#hshcourseprogress").hide();
$(".idSarchingLabel").hide();
$('#orderbysemestercheckbox_id').on('change', function () {
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
orderbysemester = document.getElementById('orderbysemestercheckbox_id').checked;
reloadList = true;
searchstring = document.getElementById('hshcourselistsearch').value;
if (searchstring.slice(0, 1) === '#') {
$(".idSarchingLabel").show();
idSearching = true;
searchstring = searchstring.slice(1);
} else {
$(".idSarchingLabel").hide();
idSearching = false;
}
search(searchstring, reloadList, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester);
});
$('#hshcourselistsearch').on('keyup', function (e) {
var key = e.keyCode;
orderbysemester = document.getElementById('orderbysemestercheckbox_id').checked;
if (key !== 40 && key !== 38 && key !== 13) {
reloadList = true;
searchstring = document.getElementById('hshcourselistsearch').value;
if (searchstring.slice(0, 1) === '#') {
$(".idSarchingLabel").show();
idSearching = true;
searchstring = searchstring.slice(1);
} else {
$(".idSarchingLabel").hide();
idSearching = false;
}
search(searchstring, reloadList, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester);
}
});
$('#hshcourseform').on('submit', function (e) {
e.preventDefault;
reloadList = true;
idSearching = false;
orderbysemester = document.getElementById('orderbysemestercheckbox_id').checked;
searchstring = document.getElementById('hshcourselistsearch').value;
if (searchstring.slice(0, 1) === '#') {
idSearching = true;
searchstring = searchstring.slice(1);
} else {
idSearching = false;
}
search(searchstring, reloadList, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester);
});
},
}
});