Skip to content
Snippets Groups Projects
Select Git revision
  • b71683de7bc2f44b8a7e937733ca479acdfced85
  • master default protected
  • dev-moodle-4
  • hsh_v4.1.2
  • hsh_v4.1.1
  • hsh_v4.1.0
6 results

jmodule.js

Blame
  • jmodule.js 6.02 KiB
    define(['jquery'], function ($) {
        function getRootWebSitePath() {
            var _location = document.location.toString();
            var applicationNameIndex = _location.indexOf('/', _location.indexOf('://') + 3);
            var applicationName = _location.substring(0, applicationNameIndex) + '/';
            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,
                    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;