diff --git a/lms/envs/common.py b/lms/envs/common.py index e49b889451..510b97eb26 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1275,9 +1275,6 @@ student_account_js = [ 'js/src/accessibility_tools.js', 'js/src/ie_shim.js', 'js/src/string_utils.js', - 'js/student_account/enrollment.js', - 'js/student_account/emailoptin.js', - 'js/student_account/shoppingcart.js', 'js/student_account/models/LoginModel.js', 'js/student_account/models/RegisterModel.js', 'js/student_account/models/PasswordResetModel.js', diff --git a/lms/static/js/spec/main.js b/lms/static/js/spec/main.js index 0be6cc19e1..ec511a15ed 100644 --- a/lms/static/js/spec/main.js +++ b/lms/static/js/spec/main.js @@ -373,18 +373,6 @@ 'js/models/notification', 'jquery.fileupload' ] }, - 'js/student_account/enrollment': { - exports: 'edx.student.account.EnrollmentInterface', - deps: ['jquery', 'jquery.cookie'] - }, - 'js/student_account/emailoptin': { - exports: 'edx.student.account.EmailOptInInterface', - deps: ['jquery', 'jquery.cookie'] - }, - 'js/student_account/shoppingcart': { - exports: 'edx.student.account.ShoppingCartInterface', - deps: ['jquery', 'jquery.cookie', 'underscore'] - }, // Student account registration/login // Loaded explicitly until these are converted to RequireJS 'js/student_account/views/FormView': { diff --git a/lms/static/js/spec/student_account/emailoptin_spec.js b/lms/static/js/spec/student_account/emailoptin_spec.js index 3354a20295..480199cecc 100644 --- a/lms/static/js/spec/student_account/emailoptin_spec.js +++ b/lms/static/js/spec/student_account/emailoptin_spec.js @@ -2,7 +2,7 @@ define(['common/js/spec_helpers/ajax_helpers', 'js/student_account/emailoptin'], function( AjaxHelpers, EmailOptInInterface ) { 'use strict'; - describe( 'edx.student.account.EmailOptInInterface', function() { + describe( 'EmailOptInInterface', function() { var COURSE_KEY = 'edX/DemoX/Fall', EMAIL_OPT_IN = 'True', diff --git a/lms/static/js/spec/student_account/enrollment_spec.js b/lms/static/js/spec/student_account/enrollment_spec.js index b4e23bf124..27cfdc9106 100644 --- a/lms/static/js/spec/student_account/enrollment_spec.js +++ b/lms/static/js/spec/student_account/enrollment_spec.js @@ -2,7 +2,7 @@ define(['common/js/spec_helpers/ajax_helpers', 'js/student_account/enrollment'], function( AjaxHelpers, EnrollmentInterface ) { 'use strict'; - describe( 'edx.student.account.EnrollmentInterface', function() { + describe( 'EnrollmentInterface', function() { var COURSE_KEY = 'edX/DemoX/Fall', ENROLL_URL = '/api/commerce/v0/baskets/', diff --git a/lms/static/js/spec/student_account/shoppingcart_spec.js b/lms/static/js/spec/student_account/shoppingcart_spec.js index 1c8907b13e..9048951dd2 100644 --- a/lms/static/js/spec/student_account/shoppingcart_spec.js +++ b/lms/static/js/spec/student_account/shoppingcart_spec.js @@ -2,7 +2,7 @@ define(['common/js/spec_helpers/ajax_helpers', 'js/student_account/shoppingcart' function(AjaxHelpers, ShoppingCartInterface) { 'use strict'; - describe( 'edx.student.account.ShoppingCartInterface', function() { + describe( 'ShoppingCartInterface', function() { var COURSE_KEY = "edX/DemoX/Fall", ADD_COURSE_URL = "/shoppingcart/add/course/edX/DemoX/Fall/", diff --git a/lms/static/js/student_account/emailoptin.js b/lms/static/js/student_account/emailoptin.js index b06eef6f62..20b6d9b306 100644 --- a/lms/static/js/student_account/emailoptin.js +++ b/lms/static/js/student_account/emailoptin.js @@ -1,34 +1,33 @@ -var edx = edx || {}; - -(function($) { +;(function (define) { 'use strict'; + define(['jquery', 'jquery.cookie'], function($) { - edx.student = edx.student || {}; - edx.student.account = edx.student.account || {}; + var EmailOptInInterface = { - edx.student.account.EmailOptInInterface = { + urls: { + emailOptInUrl: '/user_api/v1/preferences/email_opt_in/' + }, - urls: { - emailOptInUrl: '/user_api/v1/preferences/email_opt_in/' - }, + headers: { + 'X-CSRFToken': $.cookie('csrftoken') + }, - headers: { - 'X-CSRFToken': $.cookie('csrftoken') - }, + /** + * Set the email opt in setting for the organization associated + * with this course. + * @param {string} courseKey Slash-separated course key. + * @param {string} emailOptIn The preference to opt in or out of organization emails. + */ + setPreference: function( courseKey, emailOptIn ) { + return $.ajax({ + url: this.urls.emailOptInUrl, + type: 'POST', + data: {course_id: courseKey, email_opt_in: emailOptIn}, + headers: this.headers + }); + } + }; - /** - * Set the email opt in setting for the organization associated - * with this course. - * @param {string} courseKey Slash-separated course key. - * @param {string} emailOptIn The preference to opt in or out of organization emails. - */ - setPreference: function( courseKey, emailOptIn ) { - return $.ajax({ - url: this.urls.emailOptInUrl, - type: 'POST', - data: {course_id: courseKey, email_opt_in: emailOptIn}, - headers: this.headers - }); - } - }; -})(jQuery); + return EmailOptInInterface; + }); +}).call(this, define || RequireJS.define); diff --git a/lms/static/js/student_account/enrollment.js b/lms/static/js/student_account/enrollment.js index 4053d98b6d..ecd668f1ae 100644 --- a/lms/static/js/student_account/enrollment.js +++ b/lms/static/js/student_account/enrollment.js @@ -1,68 +1,65 @@ -var edx = edx || {}; - -(function($) { +;(function (define) { 'use strict'; + define(['jquery', 'jquery.cookie'], function($) { - edx.student = edx.student || {}; - edx.student.account = edx.student.account || {}; + var EnrollmentInterface = { - edx.student.account.EnrollmentInterface = { + urls: { + baskets: '/api/commerce/v0/baskets/', + }, - urls: { - baskets: '/api/commerce/v0/baskets/', - }, + headers: { + 'X-CSRFToken': $.cookie('csrftoken') + }, - headers: { - 'X-CSRFToken': $.cookie('csrftoken') - }, + /** + * Enroll a user in a course, then redirect the user. + * @param {string} courseKey Slash-separated course key. + * @param {string} redirectUrl The URL to redirect to once enrollment completes. + */ + enroll: function( courseKey, redirectUrl ) { + var data_obj = {course_id: courseKey}, + data = JSON.stringify(data_obj); - /** - * Enroll a user in a course, then redirect the user. - * @param {string} courseKey Slash-separated course key. - * @param {string} redirectUrl The URL to redirect to once enrollment completes. - */ - enroll: function( courseKey, redirectUrl ) { - var data_obj = {course_id: courseKey}, - data = JSON.stringify(data_obj); - - $.ajax({ - url: this.urls.baskets, - type: 'POST', - contentType: 'application/json; charset=utf-8', - data: data, - headers: this.headers, - context: this - }) - .fail(function( jqXHR ) { - var responseData = JSON.parse(jqXHR.responseText); - if ( jqXHR.status === 403 && responseData.user_message_url ) { - // Check if we've been blocked from the course - // because of country access rules. - // If so, redirect to a page explaining to the user - // why they were blocked. - this.redirect( responseData.user_message_url ); - } else { - // Otherwise, redirect the user to the next page. + $.ajax({ + url: this.urls.baskets, + type: 'POST', + contentType: 'application/json; charset=utf-8', + data: data, + headers: this.headers, + context: this + }).fail(function( jqXHR ) { + var responseData = JSON.parse(jqXHR.responseText); + if ( jqXHR.status === 403 && responseData.user_message_url ) { + // Check if we've been blocked from the course + // because of country access rules. + // If so, redirect to a page explaining to the user + // why they were blocked. + this.redirect( responseData.user_message_url ); + } else { + // Otherwise, redirect the user to the next page. + if ( redirectUrl ) { + this.redirect( redirectUrl ); + } + } + }).done(function() { + // If we successfully enrolled, redirect the user + // to the next page (usually the student dashboard or payment flow) if ( redirectUrl ) { this.redirect( redirectUrl ); } - } - }) - .done(function() { - // If we successfully enrolled, redirect the user - // to the next page (usually the student dashboard or payment flow) - if ( redirectUrl ) { - this.redirect( redirectUrl ); - } - }); - }, + }); + }, - /** - * Redirect to a URL. Mainly useful for mocking out in tests. - * @param {string} url The URL to redirect to. - */ - redirect: function(url) { - window.location.href = url; - } - }; -})(jQuery); + /** + * Redirect to a URL. Mainly useful for mocking out in tests. + * @param {string} url The URL to redirect to. + */ + redirect: function(url) { + window.location.href = url; + } + }; + + return EnrollmentInterface; + }); +}).call(this, define || RequireJS.define); diff --git a/lms/static/js/student_account/shoppingcart.js b/lms/static/js/student_account/shoppingcart.js index 18ec197914..36af44f3ee 100644 --- a/lms/static/js/student_account/shoppingcart.js +++ b/lms/static/js/student_account/shoppingcart.js @@ -1,49 +1,45 @@ /** -* Use the shopping cart to purchase courses. -*/ - -var edx = edx || {}; - -(function($) { + * Use the shopping cart to purchase courses. + */ +;(function (define) { 'use strict'; + define(['jquery', 'jquery.cookie'], function($) { - edx.student = edx.student || {}; - edx.student.account = edx.student.account || {}; + var ShoppingCartInterface = { + urls: { + viewCart: "/shoppingcart/", + addCourse: "/shoppingcart/add/course/" + }, - edx.student.account.ShoppingCartInterface = { + headers: { + 'X-CSRFToken': $.cookie('csrftoken') + }, - urls: { - viewCart: "/shoppingcart/", - addCourse: "/shoppingcart/add/course/" - }, + /** + * Add a course to a cart, then redirect to the view cart page. + * @param {string} courseId The slash-separated course ID to add to the cart. + */ + addCourseToCart: function( courseId ) { + $.ajax({ + url: this.urls.addCourse + courseId + "/", + type: 'POST', + data: {}, + headers: this.headers, + context: this + }).always(function() { + this.redirect( this.urls.viewCart ); + }); + }, - headers: { - 'X-CSRFToken': $.cookie('csrftoken') - }, + /** + * Redirect to a URL. Mainly useful for mocking out in tests. + * @param {string} url The URL to redirect to. + */ + redirect: function( url ) { + window.location.href = url; + } + }; - /** - * Add a course to a cart, then redirect to the view cart page. - * @param {string} courseId The slash-separated course ID to add to the cart. - */ - addCourseToCart: function( courseId ) { - $.ajax({ - url: this.urls.addCourse + courseId + "/", - type: 'POST', - data: {}, - headers: this.headers, - context: this - }).always(function() { - this.redirect( this.urls.viewCart ); - }); - }, - - /** - * Redirect to a URL. Mainly useful for mocking out in tests. - * @param {string} url The URL to redirect to. - */ - redirect: function( url ) { - window.location.href = url; - } - }; - -})(jQuery); + return ShoppingCartInterface; + }); +}).call(this, define || RequireJS.define); diff --git a/lms/static/js/student_account/views/FinishAuthView.js b/lms/static/js/student_account/views/FinishAuthView.js index 49cb7055a4..72d66bf298 100644 --- a/lms/static/js/student_account/views/FinishAuthView.js +++ b/lms/static/js/student_account/views/FinishAuthView.js @@ -26,18 +26,14 @@ ;(function (define, undefined) { 'use strict'; define([ + 'jquery', 'underscore', 'backbone', 'gettext', 'js/student_account/emailoptin', 'js/student_account/enrollment', 'js/student_account/shoppingcart' - ], function (_, Backbone, gettext, emailOptInInterface, enrollmentInterface, shoppingCartInterface) { - // These are not yet converted to requireJS: - var edx = window.edx || {}; - emailOptInInterface = emailOptInInterface || edx.student.account.EmailOptInInterface; - enrollmentInterface = enrollmentInterface || edx.student.account.EnrollmentInterface; - shoppingCartInterface = shoppingCartInterface || edx.student.account.ShoppingCartInterface; + ], function ($, _, Backbone, gettext, emailOptInInterface, enrollmentInterface, shoppingCartInterface) { var FinishAuthView = Backbone.View.extend({ el: '#finish-auth-status', diff --git a/lms/static/js/student_account/views/finish_auth_factory.js b/lms/static/js/student_account/views/finish_auth_factory.js new file mode 100644 index 0000000000..aa4ffbff9a --- /dev/null +++ b/lms/static/js/student_account/views/finish_auth_factory.js @@ -0,0 +1,12 @@ +(function (define) { + 'use strict'; + define("js/student_account/views/finish_auth_factory", + ['jquery', 'underscore', 'backbone', 'js/student_account/views/FinishAuthView', 'utility'], + function ($, _, Backbone, FinishAuthView) { + return function() { + var view = new FinishAuthView({}); + view.render(); + }; + } + ); +}).call(this, define || RequireJS.define); diff --git a/lms/static/lms/js/build.js b/lms/static/lms/js/build.js index 7d33a88420..6f6b088c6f 100644 --- a/lms/static/lms/js/build.js +++ b/lms/static/lms/js/build.js @@ -18,9 +18,10 @@ * done. */ modules: getModulesList([ - 'teams/js/teams_tab_factory', + 'js/student_account/views/account_settings_factory', + 'js/student_account/views/finish_auth_factory', 'js/student_profile/views/learner_profile_factory', - 'js/student_account/views/account_settings_factory' + 'teams/js/teams_tab_factory' ]), /** diff --git a/lms/templates/student_account/finish_auth.html b/lms/templates/student_account/finish_auth.html index e868289bcf..1fa5cd077e 100644 --- a/lms/templates/student_account/finish_auth.html +++ b/lms/templates/student_account/finish_auth.html @@ -5,32 +5,9 @@ <%block name="pagetitle">${_("Please Wait")} <%block name="headextra"> - - - +<%static:require_module module_name="js/student_account/views/finish_auth_factory" class_name="FinishAuthFactory"> + FinishAuthFactory(); +