Files
edx-platform/lms/static/js/instructor_dashboard/certificates.js
Zia Fazal 611d16b25a ziafazal/SOL-980: Generate certificates from instructor dashboard
* added generate certificates task and bok choy tests
* added unit tests
* changes based feedback and improved acceptance test
* Change header text
* changes based on feedback on 24/6
* added task_id to api output
* fixed broken test
* Remove "Instructor" from strings, per Docs team
* Fixed flaky entrance exam test
2015-07-02 14:32:36 -04:00

93 lines
3.0 KiB
JavaScript

var edx = edx || {};
(function($, gettext, _) {
'use strict';
edx.instructor_dashboard = edx.instructor_dashboard || {};
edx.instructor_dashboard.certificates = {};
$(function() {
/**
* Show a confirmation message before letting staff members
* enable/disable self-generated certificates for a course.
*/
$('#enable-certificates-form').on('submit', function( event ) {
var isEnabled = $('#certificates-enabled').val() === 'true',
confirmMessage = '';
if ( isEnabled ) {
confirmMessage = gettext('Allow students to generate certificates for this course?');
} else {
confirmMessage = gettext('Prevent students from generating certificates in this course?');
}
if ( !confirm( confirmMessage ) ) {
event.preventDefault();
}
});
/**
* Refresh the status for example certificate generation
* by reloading the instructor dashboard.
*/
$('#refresh-example-certificate-status').on('click', function() {
window.location.reload();
});
/**
* Start generating certificates for all students.
*/
var $section = $("section#certificates");
$section.on('click', '#btn-start-generating-certificates', function(event) {
if ( !confirm( gettext('Start generating certificates for all students in this course?') ) ) {
event.preventDefault();
return;
}
var $btn_generating_certs = $(this),$certificate_generation_status = $('.certificate-generation-status');
var url = $btn_generating_certs.data('endpoint');
$.ajax({
type: "POST",
url: url,
success: function (data) {
$btn_generating_certs.attr('disabled','disabled');
$certificate_generation_status.text(data.message);
},
error: function(jqXHR, textStatus, errorThrown) {
$certificate_generation_status.text(gettext('Error while generating certificates. Please try again.'));
}
});
});
});
var Certificates = (function() {
function Certificates($section) {
$section.data('wrapper', this);
this.instructor_tasks = new window.InstructorDashboard.util.PendingInstructorTasks($section);
}
Certificates.prototype.onClickTitle = function() {
return this.instructor_tasks.task_poller.start();
};
Certificates.prototype.onExit = function() {
return this.instructor_tasks.task_poller.stop();
};
return Certificates;
})();
_.defaults(window, {
InstructorDashboard: {}
});
_.defaults(window.InstructorDashboard, {
sections: {}
});
_.defaults(window.InstructorDashboard.sections, {
Certificates: Certificates
});
})($, gettext, _);