AnsweredAssumed Answered

Enroll user via theme edit

Question asked by Henry Acevedo on Apr 27, 2020
Latest reply on Apr 29, 2020 by Robert Carroll

Hello,

 

Not a web developer so I have only basic knowledge of CSS and JS. I am trying to put some buttons in the course settings that instructors can click on to add people to their course. These buttons are for our student assistants and it speeds up the process of them being added to a course to help troubleshoot remotely.

 

I got a version of this working, but it isn't working consistently. Right now the latest version of Firefox isn't doing it while previous versions are working. Chrome is working on my machine.

 

Is there any way I can modify this to make it more consistent? It is adding them as a custom role, and when it works it works well. Any help is appreciated. This code is part of the .js in the theme.

if (ENV['current_user_roles'].includes('teacher')) {
    var undel = window.location.href;
    var course_id = undel.match(/\d{2,}/);
    var api_url = "/api/v1/courses/REPLACE_THIS/enrollments";
    api_url = api_url.replace("REPLACE_THIS",course_id);
    undel = undel.slice(0, -9);
    undel = undel + "/undelete";
    
    $("div#right-side-wrapper.ic-app-main-content__secondary aside#right-side > div > a.Button.Button--link.Button--link--has-divider.Button--course-settings.validator_link").after("<a class='Button Button--link Button--link--has-divider Button--course-settings' href='" + undel + "'><i class='icon-trash'></i> Undelete Content</a>");
    
    $("div#right-side-wrapper.ic-app-main-content__secondary aside#right-side > div > a.Button.Button--link.Button--link--has-divider.Button--course-settings.validator_link").after("<a class='Button Button--link Button--link--has-divider Button--course-settings' href='.' id='addLMS3'><i class='icon-user'></i> LMS Support #3</a>");
    
    $("div#right-side-wrapper.ic-app-main-content__secondary aside#right-side > div > a.Button.Button--link.Button--link--has-divider.Button--course-settings.validator_link").after("<a class='Button Button--link Button--link--has-divider Button--course-settings' href='.' id='addLMS2'><i class='icon-user'></i> LMS Support #2</a>");
    
    $("div#right-side-wrapper.ic-app-main-content__secondary aside#right-side > div > a.Button.Button--link.Button--link--has-divider.Button--course-settings.validator_link").after("<a class='Button Button--link Button--link--has-divider Button--course-settings' href='.' id='addLMS1'><i class='icon-user'></i> LMS Support #1</a>");


    document.getElementById("addLMS1").onclick = function() {addLMSPerson1()};
    document.getElementById("addLMS2").onclick = function() {addLMSPerson2()};
    document.getElementById("addLMS3").onclick = function() {addLMSPerson3()};

    function addLMSPerson1() {
        $.post(api_url, { 'enrollment': {'user_id': xxxxx, 'type': 'TaEnrollment', 'role_id': 23} });
    }
    
    function addLMSPerson2() {
        $.post(api_url, { 'enrollment': {'user_id': xxxxx, 'type': 'TaEnrollment', 'role_id': 23} });
    }
    
    function addLMSPerson3() {
        $.post(api_url, { 'enrollment': {'user_id': xxxxx, 'type': 'TaEnrollment', 'role_id': 23} });
    }
}

Thank you,

Henry

Outcomes