diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 6a827fcd99..e98ce9473b 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -880,6 +880,7 @@ def _credit_statuses(user, course_enrollments): "purchased": course_key in credit_enrollments, "provider_name": None, "provider_status_url": None, + "provider_id": None, "request_status": request_status_by_course.get(course_key), "error": False, } @@ -903,6 +904,7 @@ def _credit_statuses(user, course_enrollments): provider_info = provider_info_by_id.get(provider_id, {}) status["provider_name"] = provider_info.get("display_name") status["provider_status_url"] = provider_info.get("status_url") + status["provider_id"] = provider_id statuses[course_key] = status diff --git a/lms/static/js/dashboard/credit.js b/lms/static/js/dashboard/credit.js index b40af18030..2173ffc792 100644 --- a/lms/static/js/dashboard/credit.js +++ b/lms/static/js/dashboard/credit.js @@ -2,6 +2,13 @@ 'use strict'; $(document).ready(function() { + var errorContainer = $(".credit-error-msg"), + creditStatusError = errorContainer.data("credit-error"); + + if (creditStatusError == "True"){ + errorContainer.toggleClass("is-hidden"); + } + // Fire analytics events when the "purchase credit" button is clicked $(".purchase-credit-btn").on("click", function(event) { var courseKey = $(event.target).data("course-key"); @@ -13,5 +20,47 @@ } ); }); + // This event invokes credit request endpoint. It will initiate + // a credit request for the credit course for the provided user. + $(".pending-credit-btn").on("click", function(event){ + var courseKey = $(event.target).data("course-key"), + username = $(event.target).data("user"), + provider_id = $(event.target).data("provider"), + postData = { + 'course_key': courseKey, + 'username': username + }; + $.ajax({ + url: 'api/credit/v1/provider/' + provider_id + '/request/', + type: 'POST', + headers: { + 'X-CSRFToken': $.cookie('csrftoken') + }, + data: JSON.stringify(postData) , + context: this, + success: function(requestData){ + var form = $('#credit-pending-form'); + + $('input', form).remove(); + + form.attr( 'action', requestData.url ); + form.attr( 'method', 'POST' ); + + _.each( requestData.parameters, function( value, key ) { + $('').attr({ + type: 'hidden', + name: key, + value: value + }).appendTo(form); + }); + form.submit(); + }, + error: function(xhr){ + $(".credit-request-pending-msg").hide("is-hidden"); + $(".pending-credit-btn").hide(); + errorContainer.toggleClass("is-hidden"); + } + }); + }); }); })(jQuery, window.analytics); diff --git a/lms/static/sass/multicourse/_dashboard.scss b/lms/static/sass/multicourse/_dashboard.scss index f51f697da7..13875c1519 100644 --- a/lms/static/sass/multicourse/_dashboard.scss +++ b/lms/static/sass/multicourse/_dashboard.scss @@ -540,8 +540,11 @@ @include float(right); } - .purchase-credit-btn { + .credit-btn { @extend %btn-pl-yellow-base; + background-image: none ; + text-shadow: none; + box-shadow: none; } .message { diff --git a/lms/templates/dashboard/_dashboard_credit_info.html b/lms/templates/dashboard/_dashboard_credit_info.html index edfb11ff35..371efd1596 100644 --- a/lms/templates/dashboard/_dashboard_credit_info.html +++ b/lms/templates/dashboard/_dashboard_credit_info.html @@ -9,15 +9,14 @@ % if credit_status["eligible"]:
% endif