From c94f043c2b6ea1585d1415350a7f7513bb0abb44 Mon Sep 17 00:00:00 2001 From: Ahsan Ulhaq Date: Mon, 6 Jul 2015 16:17:15 +0500 Subject: [PATCH] Credit Payment - Dashboard States ECOM-1578 --- common/djangoapps/student/views.py | 2 + lms/static/js/dashboard/credit.js | 49 +++++++++++++++++ lms/static/sass/multicourse/_dashboard.scss | 5 +- .../dashboard/_dashboard_credit_info.html | 53 +++++++++++++------ 4 files changed, 93 insertions(+), 16 deletions(-) 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"]:
- % if credit_status["error"]: -

+

- % elif not credit_status["purchased"]: + % if not credit_status["purchased"] and not credit_status["error"] :

% if credit_status["deadline"] < datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=30): ${_("The opportunity to purchase credit for this course expires on {deadline}. You've worked hard - don't miss out!").format(deadline=get_default_time_display(credit_status["deadline"]))} @@ -27,19 +26,34 @@

## TODO: set the URL for the link to the provider selection page on the E-Commerce service - ${_("Purchase Course Credit")} + ${_("Purchase Course Credit")}
- % elif credit_status["request_status"] in [None, "pending"]: -

- ${_("Thanks for your payment! We are currently processing your course credit. You'll see a message here when the transaction is complete. For more information, see {provider_link}.").format( - provider_link=u'{provider_name}'.format( - provider_url=credit_status["provider_status_url"], - provider_name=credit_status["provider_name"], + % elif credit_status["request_status"] in [None, "pending"] and not credit_status["error"] : + % if credit_status["request_status"] == "pending": +

+ ${_("Thanks for your payment! We are currently processing your course credit. You'll see a message here when the transaction is complete. For more information, see {provider_link}.").format( + provider_link=u'{provider_name}'.format( + provider_url=credit_status["provider_status_url"], + provider_name=credit_status["provider_name"], + ) ) - ) - } -

- % elif credit_status["request_status"] == "approved": + } +

+ % elif credit_status["request_status"] is None: +

+ ${_("Thank you for your payment! To receive your course credit, go to the {provider_link} website. You may have to complete some additional steps depending on the institution").format( + provider_link=u'{provider_name}'.format( + provider_url=credit_status["provider_status_url"], + provider_name=credit_status["provider_name"], + ) + ) + } +

+ % endif + + +
+ % elif credit_status["request_status"] == "approved" and not credit_status["error"] :

${_("Congratulations - you have received credit for this course! For more information, see {provider_link}.").format( provider_link=u'{provider_name}'.format( @@ -49,7 +63,8 @@ ) }

- % elif credit_status["request_status"] == "rejected": + ${_("Access credit")} + % elif credit_status["request_status"] == "rejected" and not credit_status["error"] :

${_("{provider_name} has declined your request for course credit. For more information, contact {provider_link}.").format( provider_name=credit_status["provider_name"], @@ -60,6 +75,14 @@ ) }

+ + ${_("Contact {provider_link}").format(provider_link=u'{provider_name}'.format( + provider_url=credit_status["provider_status_url"], + provider_name=credit_status["provider_name"], + ) + ) + } + % endif
% endif