Course minutes: 197
Course rating:
require(['jquery', 'core/ajax'], function($, Ajax) {
$(document).ready(function() {
var $bar = $('#my-completion-bar');
if (!$bar.length) {
return; // no placeholder on this page
}
var courseid = $bar.data('courseid');
if (!courseid) {
$bar.text('Error: no course ID defined.');
return;
}
// Call the completion API
Ajax.call([{
methodname: 'core_completion_get_course_completion_status',
args: { courseid: courseid },
}])[0]
.done(function(response) {
// Build a Bootstrap-style progress bar
var percent = response.percentcomplete || 0;
var html = ''
+ ''
+ '
'
+ percent + '% complete'
+ '
'
+ '
';
$bar.html(html);
})
.fail(function(err) {
console.error(err);
$bar.text('Could not load completion data.');
});
});
});