Commit 1096ba34 by Clinton Blackburn

Merge pull request #283 from edx/clintonb/credit-cleanup

Credit Cleanup
parents f1e16b16 141293a6
...@@ -52,7 +52,7 @@ class Checkout(TemplateView): ...@@ -52,7 +52,7 @@ class Checkout(TemplateView):
'payment_processors': processors_dict, 'payment_processors': processors_dict,
'credit_seats': credit_seats, 'credit_seats': credit_seats,
'lms_url_root': settings.LMS_URL_ROOT, 'lms_url_root': settings.LMS_URL_ROOT,
'providers_ids': provider_ids, 'provider_ids': provider_ids,
'analytics_data': json.dumps({ 'analytics_data': json.dumps({
'course': { 'course': {
'courseId': course.id 'courseId': course.id
......
define([ define([
'backbone', 'backbone',
'underscore.string',
'models/credit_eligibility_model' 'models/credit_eligibility_model'
], ],
function (Backbone, function (Backbone,
_s,
CreditEligibility) { CreditEligibility) {
'use strict'; 'use strict';
return Backbone.Collection.extend({ return Backbone.Collection.extend({
model: CreditEligibility, model: CreditEligibility,
/*jshint undef: false */ /**
url: lmsRootUrl + '/api/credit/v1/eligibility/', * Initializes the collection.
/*jshint undef: true */ *
setUrl: function (username, courseKey) { * @param {Object} options This Object MUST contain lmsRootUrl, username, and courseKey keys.
this.url += '?username=' + username + '&course_key=' + courseKey; */
initialize: function (options) {
this.lmsRootUrl = options.lmsRootUrl;
this.username = options.username;
this.courseKey = options.courseKey;
},
/**
* Returns the URL where eligibility data should be retrieved.
* @returns {String}
*/
url: function () {
var data = {
root: this.lmsRootUrl,
username: encodeURIComponent(this.username),
courseKey: encodeURIComponent(this.courseKey)
};
return _s.sprintf(
'%(root)s/api/credit/v1/eligibility/?username=%(username)s&course_key=%(courseKey)s',
data
);
} }
} }
); );
} }
); );
define([
'backbone',
'underscore.string',
'models/credit_provider_model'
],
function (Backbone,
_s,
CreditProvider) {
'use strict';
return Backbone.Collection.extend({
model: CreditProvider,
/**
* Initializes the collection.
*
* @param {Object} options This Object MUST contain lmsRootUrl and providerIds keys.
*/
initialize: function (options) {
this.lmsRootUrl = options.lmsRootUrl;
this.providerIds = options.providerIds;
},
/**
* Returns the URL where provider data should be retrieved.
* @returns {String}
*/
url: function () {
var data = {
root: this.lmsRootUrl,
providerIds: this.providerIds
};
return _s.sprintf('%(root)s/api/credit/v1/providers/?provider_ids=%(providerIds)s', data);
}
}
);
}
);
define([
'backbone',
'js/models/provider_model'
],
function (Backbone, ProviderModel) {
'use strict';
return Backbone.Collection.extend({
model: ProviderModel,
/*jshint undef: false */
url: lmsRootUrl + '/api/credit/v1/providers/',
/*jshint undef: true */
setUrl: function (providerIds) {
this.url += '?provider_ids=' + providerIds;
}
}
);
}
);
...@@ -4,10 +4,6 @@ define([ ...@@ -4,10 +4,6 @@ define([
function (Backbone) { function (Backbone) {
'use strict'; 'use strict';
// Stores our provider information
return Backbone.Model.extend({}); return Backbone.Model.extend({});
} }
); );
...@@ -4,13 +4,13 @@ require([ ...@@ -4,13 +4,13 @@ require([
'models/user_model', 'models/user_model',
'models/tracking_model', 'models/tracking_model',
'models/course_model', 'models/course_model',
'collections/provider_collection', 'collections/credit_provider_collection',
'collections/credit_eligibility_collection', 'collections/credit_eligibility_collection',
'views/clickable_view', 'views/clickable_view',
'views/analytics_view', 'views/analytics_view',
'views/payment_button_view', 'views/payment_button_view',
'utils/utils', 'utils/utils',
'views/provider_view', 'views/credit_provider_view',
'views/credit_eligibility_view' 'views/credit_eligibility_view'
], ],
function ($, function ($,
...@@ -18,27 +18,39 @@ require([ ...@@ -18,27 +18,39 @@ require([
UserModel, UserModel,
TrackingModel, TrackingModel,
CourseModel, CourseModel,
ProviderCollection, CreditProviderCollection,
CreditEligibilityCollection, CreditEligibilityCollection,
ClickableView, ClickableView,
AnalyticsView, AnalyticsView,
PaymentButtonView, PaymentButtonView,
Utils, Utils,
ProviderView, CreditProviderView,
CreditEligibilityView) { CreditEligibilityView) {
'use strict'; 'use strict';
var $container = $('.credit-checkout'),
$courseDetails = $container.find('#course-name'),
$providerDetails = $container.find('.provider-details'),
lmsRootUrl = $container.data('lms-root-url');
new PaymentButtonView({ new PaymentButtonView({
el: $('#payment-buttons') el: $('#payment-buttons')
}); });
new ProviderView({ new CreditProviderView({
el: $('.provider-details'), el: $providerDetails,
collection: new ProviderCollection() collection: new CreditProviderCollection({
lmsRootUrl: lmsRootUrl,
providerIds: $providerDetails.data('provider-ids')
})
}); });
new CreditEligibilityView({ new CreditEligibilityView({
collection: new CreditEligibilityCollection() collection: new CreditEligibilityCollection({
lmsRootUrl: lmsRootUrl,
username: $courseDetails.data('username'),
courseKey: $courseDetails.data('course_key')
})
}); });
var courseModel = new CourseModel(), var courseModel = new CourseModel(),
......
define([
'collections/credit_eligibility_collection'
],
function (CreditEligibilityCollection) {
'use strict';
var collection,
lmsRootUrl = 'http://lms.local',
username = 'testuser',
courseKey = 'course-v1:LinuxFoundationX+LFS101x.2+1T2015';
beforeEach(function () {
collection = new CreditEligibilityCollection({
lmsRootUrl: lmsRootUrl,
username: username,
courseKey: courseKey
});
});
describe('CreditEligibilityCollection', function () {
describe('initialize', function () {
it('stores lmsRootUrl', function () {
expect(collection.lmsRootUrl).toEqual(lmsRootUrl);
});
it('stores username', function () {
expect(collection.username).toEqual(username);
});
it('stores courseKey', function () {
expect(collection.courseKey).toEqual(courseKey);
});
});
describe('url', function () {
it('returns a Credit API URL', function () {
var expected = lmsRootUrl + '/api/credit/v1/eligibility/?username=' +
username + '&course_key=' + encodeURIComponent(courseKey);
expect(collection.url()).toEqual(expected);
});
});
});
}
);
define([
'collections/credit_provider_collection'
],
function (CreditProviderCollection) {
'use strict';
var collection,
lmsRootUrl = 'http://lms.local',
providerIds = 'ASU,MIT';
beforeEach(function () {
collection = new CreditProviderCollection({lmsRootUrl: lmsRootUrl, providerIds: providerIds});
});
describe('CreditProviderCollection', function () {
describe('initialize', function () {
it('stores lmsRootUrl', function () {
expect(collection.lmsRootUrl).toEqual(lmsRootUrl);
});
it('stores providerIds', function () {
expect(collection.providerIds).toEqual(providerIds);
});
});
describe('url', function () {
it('returns a Credit API URL', function () {
var expected = lmsRootUrl + '/api/credit/v1/providers/?provider_ids=' + providerIds;
expect(collection.url()).toEqual(expected);
});
});
});
}
);
define([ define([
'jquery', 'jquery',
'underscore', 'underscore',
'backbone' 'backbone',
'moment'
], ],
function ($, _, Backbone) { function ($,
_,
Backbone,
moment) {
'use strict'; 'use strict';
return Backbone.View.extend({ return Backbone.View.extend({
initialize: function () { initialize: function () {
this.checkEligibility(); this.listenTo(this.collection, 'sync', this.render);
this.collection.fetch();
}, },
checkEligibility: function () { render: function () {
var $courseDetails = $('#course-name'), var deadline;
username = $courseDetails.data('username'),
courseKey = $courseDetails.data('course_key'),
self = this;
this.collection.setUrl(username, courseKey); if (this.collection.length) {
this.collection.fetch({ deadline = moment.utc(this.collection.at(0).get('deadline'));
success: function (collection) { $('.eligibility-details').find('.deadline-date').text(deadline.format('LL'));
self.renderEligibilityDate(collection);
},
error: function () {
self.toggleProviderContent(false);
}
}
);
},
renderEligibilityDate: function (collection) {
// For getting full month name, default lang is set to 'en-us',
// It will be translated in django template
var eligibilityData = collection.toJSON(),
deadline, formattedDate;
if (eligibilityData.length) {
deadline = new Date(eligibilityData[0].deadline);
// TODO Use moment.format(). See http://momentjs.com/docs/#/displaying/.
formattedDate = deadline.toLocaleString('en-us', {month: 'long'}) + ' ' + deadline.getDay() + ',' +
deadline.getFullYear();
$('.eligibility-details').find('.deadline-date').text(formattedDate);
this.toggleProviderContent(true); this.toggleProviderContent(true);
} else { } else {
this.toggleProviderContent(false); this.toggleProviderContent(false);
......
...@@ -2,41 +2,31 @@ define([ ...@@ -2,41 +2,31 @@ define([
'jquery', 'jquery',
'underscore', 'underscore',
'backbone', 'backbone',
'text!templates/provider_details.html' 'text!templates/credit_provider_details.html'
], ],
function ($, _, Backbone, providerTemplate) { function ($,
_,
Backbone,
creditProviderTemplate) {
'use strict'; 'use strict';
return Backbone.View.extend({ return Backbone.View.extend({
template: _.template(creditProviderTemplate),
initialize: function () { initialize: function () {
this.getProviders(); this.listenTo(this.collection, 'sync', this.render);
this.collection.fetch();
}, },
getProviders: function () { render: function () {
var self = this; var provider;
this.collection.setUrl(this.$el[0].dataset.providersIds); if (this.collection.length) {
this.collection.fetch({
success: function (collection) {
self.renderProviderDetail(collection);
},
error: function () {
self.toggleProviderContent(false);
}
}
);
},
renderProviderDetail: function (collection) {
var providerData = collection.toJSON(),
template;
if (providerData.length) {
// Currently we are assuming that we are having only one provider // Currently we are assuming that we are having only one provider
template = _.template(providerTemplate); provider = this.collection.at(0);
$('.title').find('.provider-name').text(providerData[0].display_name); // TODO Get rid of this!
this.$el.html(template(providerData[0])); $('.title').find('.provider-name').text(provider.get('display_name'));
this.$el.html(this.template(provider.attributes));
this.toggleProviderContent(true); this.toggleProviderContent(true);
} else { } else {
this.toggleProviderContent(false); this.toggleProviderContent(false);
......
...@@ -5,3 +5,10 @@ ...@@ -5,3 +5,10 @@
// Disable Bootstrap default dotted outline // Disable Bootstrap default dotted outline
outline:inherit; outline:inherit;
} }
// Use the Pattern Library's decoration (border-bottom)
.btn-link {
&:focus, &:hover {
text-decoration: none;
}
}
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
.show-instructions { .show-instructions {
padding-left: initial; padding-left: initial;
margin-bottom: 5px;
} }
} }
......
...@@ -2,13 +2,12 @@ ...@@ -2,13 +2,12 @@
<img alt="<%= display_name %>" class="img-responsive provider-image" src="<%= thumbnail_url %>"> <img alt="<%= display_name %>" class="img-responsive provider-image" src="<%= thumbnail_url %>">
</div> </div>
<div class="col-sm-10"> <div class="col-sm-10">
<h3 class="title"><%= gettext('About Credit at ') %> <%= id %> </h3> <h3 class="title"><%= interpolate(gettext('About Credit at %(provider)s'), {provider:id}, true) %></h3>
<p><%= gettext( description ) %></p> <p><%= gettext( description ) %></p>
<button class="btn btn-link show-instructions" data-toggle="collapse" data-target="#fulfillment-instructions"><%= <button class="btn-link show-instructions" data-toggle="collapse" data-target="#fulfillment-instructions">
gettext( "How does credit works?" ) %> <%= gettext( "How does credit work?" ) %>
</button> </button>
<div class="collapse" id="fulfillment-instructions"> <div class="collapse" id="fulfillment-instructions">
<h4 class="text-uppercase"><%= gettext('credit with ') %><%= display_name %> </h4>
<%= fulfillment_instructions %> <%= fulfillment_instructions %>
</div> </div>
</div> </div>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{% block title %}{% trans "Credit Checkout" %}{% endblock title %} {% block title %}{% trans "Credit Checkout" %}{% endblock title %}
{% block content %} {% block content %}
<div class="container credit-checkout"> <div class="container credit-checkout" data-lms-root-url="{{ lms_url_root }}">
<div class="row center-block course-details"> <div class="row center-block course-details">
<div class="col-sm-11"> <div class="col-sm-11">
<h3 class="title"> <h3 class="title">
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
{% trans "Something went wrong! Please try again later." %} {% trans "Something went wrong! Please try again later." %}
</div> </div>
<div class="provider-panel hide"> <div class="provider-panel hide">
<div data-providers-ids="{{ providers_ids }}" class="row center-block provider-details"> <div data-provider-ids="{{ provider_ids }}" class="row center-block provider-details">
{# data will be loaded with underscore template #} {# data will be loaded with underscore template #}
</div> </div>
...@@ -117,12 +117,7 @@ ...@@ -117,12 +117,7 @@
</div> </div>
</div> </div>
<form id="payment-processor-form"> <form id="payment-processor-form"></form>
</form>
<script>
var lmsRootUrl = "{{ lms_url_root }}";
</script>
{% if analytics_data %} {% if analytics_data %}
<script type="text/javascript"> <script type="text/javascript">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment