From a4da143ca6d7feb6cb0c69c8b43ffa865c999809 Mon Sep 17 00:00:00 2001 From: cahrens Date: Sun, 28 Jun 2015 16:16:48 -0400 Subject: [PATCH] Delete unused student_profile code (WIP profile). --- lms/envs/common.py | 6 - lms/static/js/spec/main.js | 6 - .../js/spec/student_profile/profile_spec.js | 178 --------------- lms/static/js/student_profile/profile.js | 205 ------------------ lms/templates/student_profile/index.html | 32 --- .../student_profile/languages.underscore | 7 - .../student_profile/profile.underscore | 14 -- 7 files changed, 448 deletions(-) delete mode 100644 lms/static/js/spec/student_profile/profile_spec.js delete mode 100644 lms/static/js/student_profile/profile.js delete mode 100644 lms/templates/student_profile/index.html delete mode 100644 lms/templates/student_profile/languages.underscore delete mode 100644 lms/templates/student_profile/profile.underscore diff --git a/lms/envs/common.py b/lms/envs/common.py index 03193858c5..63cb891399 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1279,8 +1279,6 @@ student_account_js = [ 'js/student_account/accessApp.js', ] -student_profile_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/student_profile/**/*.js')) - verify_student_js = [ 'js/form.ext.js', 'js/my_courses_dropdown.js', @@ -1550,10 +1548,6 @@ PIPELINE_JS = { 'source_filenames': student_account_js, 'output_filename': 'js/student_account.js' }, - 'student_profile': { - 'source_filenames': student_profile_js, - 'output_filename': 'js/student_profile.js' - }, 'verify_student': { 'source_filenames': verify_student_js, 'output_filename': 'js/verify_student.js' diff --git a/lms/static/js/spec/main.js b/lms/static/js/spec/main.js index 2640cd23d5..b90b713f38 100644 --- a/lms/static/js/spec/main.js +++ b/lms/static/js/spec/main.js @@ -91,7 +91,6 @@ 'js/student_account/views/RegisterView': 'js/student_account/views/RegisterView', 'js/student_account/views/AccessView': 'js/student_account/views/AccessView', 'js/student_account/views/HintedLoginView': 'js/student_account/views/HintedLoginView', - 'js/student_profile/profile': 'js/student_profile/profile', 'js/student_profile/views/learner_profile_fields': 'js/student_profile/views/learner_profile_fields', 'js/student_profile/views/learner_profile_factory': 'js/student_profile/views/learner_profile_factory', 'js/student_profile/views/learner_profile_view': 'js/student_profile/views/learner_profile_view', @@ -281,10 +280,6 @@ exports: 'js/student_account/account', deps: ['jquery', 'underscore', 'backbone', 'gettext', 'jquery.cookie'] }, - 'js/student_profile/profile': { - exports: 'js/student_profile/profile', - deps: ['jquery', 'underscore', 'backbone', 'gettext', 'jquery.cookie'] - }, 'js/staff_debug_actions': { exports: 'js/staff_debug_actions', deps: ['gettext'] @@ -643,7 +638,6 @@ 'lms/include/js/spec/student_account/account_settings_factory_spec.js', 'lms/include/js/spec/student_account/account_settings_fields_spec.js', 'lms/include/js/spec/student_account/account_settings_view_spec.js', - 'lms/include/js/spec/student_profile/profile_spec.js', 'lms/include/js/spec/views/fields_spec.js', 'lms/include/js/spec/student_profile/learner_profile_factory_spec.js', 'lms/include/js/spec/student_profile/learner_profile_view_spec.js', diff --git a/lms/static/js/spec/student_profile/profile_spec.js b/lms/static/js/spec/student_profile/profile_spec.js deleted file mode 100644 index 82f354582f..0000000000 --- a/lms/static/js/spec/student_profile/profile_spec.js +++ /dev/null @@ -1,178 +0,0 @@ -define(['js/student_profile/profile'], - function() { - describe("edx.student.profile.ProfileModel", function() { - 'use strict'; - - var profile = null; - - beforeEach(function() { - profile = new edx.student.profile.ProfileModel(); - }); - - it("validates the full name field", function() { - // Full name cannot be blank - profile.set("fullName", ""); - var errors = profile.validate(profile.attributes); - expect(errors).toEqual({ - fullName: "Full name cannot be blank" - }); - - // Fill in the name and expect that the model is valid - profile.set("fullName", "Bob"); - errors = profile.validate(profile.attributes); - expect(errors).toBe(undefined); - }); - }); - - describe("edx.student.profile.PreferencesModel", function() { - var preferences = null; - - beforeEach(function() { - preferences = new edx.student.profile.PreferencesModel(); - }); - - it("validates the language field", function() { - // Language cannot be blank - preferences.set("language", ""); - var errors = preferences.validate(preferences.attributes); - expect(errors).toEqual({ - language: "Language cannot be blank" - }); - - // Fill in the language and expect that the model is valid - preferences.set("language", "eo"); - errors = preferences.validate(preferences.attributes); - expect(errors).toBe(undefined); - }); - }); - - describe("edx.student.profile.ProfileView", function() { - var view = null, - ajaxSuccess = true; - - var updateProfile = function(fields) { - view.profileModel.set(fields); - view.clearStatus(); - view.profileModel.save(); - }; - - var updatePreferences = function(fields) { - view.preferencesModel.set(fields); - view.clearStatus(); - view.preferencesModel.save(); - }; - - var assertAjax = function(url, method, data) { - expect($.ajax).toHaveBeenCalled(); - var ajaxArgs = $.ajax.mostRecentCall.args[0]; - expect(ajaxArgs.url).toEqual(url); - expect(ajaxArgs.type).toEqual(method); - expect(ajaxArgs.data).toEqual(data) - expect(ajaxArgs.headers.hasOwnProperty("X-CSRFToken")).toBe(true); - }; - - var assertSubmitStatus = function(success, expectedStatus) { - if (!success) { - expect(view.$submitStatus).toHaveClass("error"); - } else { - expect(view.$submitStatus).not.toHaveClass("error"); - } - expect(view.$submitStatus.text()).toEqual(expectedStatus); - }; - - var assertValidationError = function(expectedError, selection) { - if (expectedError === null) { - expect(selection).not.toHaveClass("validation-error"); - expect(selection.text()).toEqual(""); - } else { - expect(selection).toHaveClass("validation-error"); - expect(selection.text()).toEqual(expectedError); - } - }; - - beforeEach(function() { - var profileFixture = readFixtures("templates/student_profile/profile.underscore"), - languageFixture = readFixtures("templates/student_profile/languages.underscore"); - - setFixtures("
" + profileFixture + "
"); - appendSetFixtures("
" + languageFixture + "
"); - - // Stub AJAX calls to return success / failure - spyOn($, "ajax").andCallFake(function() { - return $.Deferred(function(defer) { - if (ajaxSuccess) { - defer.resolve(); - } else { - defer.reject(); - } - }).promise(); - }); - - var json = { - preferredLanguage: {code: 'eo', name: 'Dummy language'}, - languages: [{code: 'eo', name: 'Dummy language'}] - }; - spyOn($, "getJSON").andCallFake(function() { - return $.Deferred(function(defer) { - if (ajaxSuccess) { - defer.resolveWith(this, [json]); - } else { - defer.reject(); - } - }).promise(); - }); - - // Stub location.reload() to prevent test suite from reloading repeatedly - spyOn(edx.student.profile, "reloadPage").andCallFake(function() { - return true; - }); - - view = new edx.student.profile.ProfileView().render(); - }); - - it("updates the student profile", function() { - updateProfile({fullName: "John Smith"}); - assertAjax("", "PUT", {fullName: "John Smith"}); - assertSubmitStatus(true, "Saved"); - }); - - it("updates the student preferences", function() { - updatePreferences({language: "eo"}); - assertAjax("preferences", "PUT", {language: "eo"}); - assertSubmitStatus(true, "Saved"); - }); - - it("displays full name validation errors", function() { - // Blank name should display a validation error - updateProfile({fullName: ""}); - assertValidationError("Full name cannot be blank", view.$nameStatus); - - // If we fix the problem and resubmit, the error should go away - updateProfile({fullName: "John Smith"}); - assertValidationError(null, view.$nameStatus); - }); - - it("displays language validation errors", function() { - // Blank language should display a validation error - updatePreferences({language: ""}); - assertValidationError("Language cannot be blank", view.$languageStatus); - - // If we fix the problem and resubmit, the error should go away - updatePreferences({language: "eo"}); - assertValidationError(null, view.$languageStatus); - }); - - it("displays an error if the sync fails", function() { - // If we get an error status on the AJAX request, display an error - ajaxSuccess = false; - updateProfile({fullName: "John Smith"}); - assertSubmitStatus(false, "The data could not be saved."); - - // If we try again and succeed, the error should go away - ajaxSuccess = true; - updateProfile({fullName: "John Smith"}); - assertSubmitStatus(true, "Saved"); - }); - }); - } -); diff --git a/lms/static/js/student_profile/profile.js b/lms/static/js/student_profile/profile.js deleted file mode 100644 index 77bc8ae7a2..0000000000 --- a/lms/static/js/student_profile/profile.js +++ /dev/null @@ -1,205 +0,0 @@ -var edx = edx || {}; - -(function($, _, Backbone, gettext) { - 'use strict'; - - edx.student = edx.student || {}; - edx.student.profile = edx.student.profile || {}; - - var syncErrorMessage = gettext("The data could not be saved."); - - edx.student.profile.reloadPage = function() { - location.reload(); - }; - - edx.student.profile.ProfileModel = Backbone.Model.extend({ - defaults: { - fullName: '' - }, - - urlRoot: '', - - sync: function(method, model) { - var headers = { - 'X-CSRFToken': $.cookie('csrftoken') - }; - - $.ajax({ - url: model.urlRoot, - type: 'PUT', - data: model.attributes, - headers: headers - }) - .done(function() { - model.trigger('sync'); - }) - .fail(function() { - model.trigger('error', syncErrorMessage); - }); - }, - - validate: function(attrs) { - var errors = {}; - if (attrs.fullName.length < 1) { - errors.fullName = gettext("Full name cannot be blank"); - } - - if (!$.isEmptyObject(errors)) { - return errors; - } - } - }); - - edx.student.profile.PreferencesModel = Backbone.Model.extend({ - defaults: { - language: 'en' - }, - - urlRoot: 'preferences', - - sync: function(method, model) { - var headers = { - 'X-CSRFToken': $.cookie('csrftoken') - }; - - $.ajax({ - url: model.urlRoot, - type: 'PUT', - data: model.attributes, - headers: headers - }) - .done(function() { - model.trigger('sync'); - edx.student.profile.reloadPage(); - }) - .fail(function() { - model.trigger('error', syncErrorMessage); - }); - }, - - validate: function(attrs) { - var errors = {}; - if (attrs.language.length < 1) { - errors.language = gettext("Language cannot be blank"); - } - - if (!$.isEmptyObject(errors)) { - return errors; - } - } - }); - - edx.student.profile.ProfileView = Backbone.View.extend({ - - events: { - 'submit': 'submit', - 'change': 'change' - }, - - initialize: function() { - _.bindAll(this, 'render', 'change', 'submit', 'invalidProfile', 'invalidPreference', 'error', 'sync', 'clearStatus'); - - this.profileModel = new edx.student.profile.ProfileModel(); - this.profileModel.on('invalid', this.invalidProfile); - this.profileModel.on('error', this.error); - this.profileModel.on('sync', this.sync); - - this.preferencesModel = new edx.student.profile.PreferencesModel(); - this.preferencesModel.on('invalid', this.invalidPreference); - this.preferencesModel.on('error', this.error); - this.preferencesModel.on('sync', this.sync); - }, - - render: function() { - this.$el.html(_.template($('#profile-tpl').html())); - - this.$nameField = $('#profile-name', this.$el); - this.$nameStatus = $('#profile-name-status', this.$el); - - this.$languageChoices = $('#preference-language', this.$el); - this.$languageStatus = $('#preference-language-status', this.$el); - - this.$submitStatus = $('#submit-status', this.$el); - - var self = this; - $.getJSON('preferences/languages') - .done(function(json) { - /** Asynchronously populate the language choices. */ - self.$languageChoices.html(_.template($('#languages-tpl').html(), {languageInfo: json})); - }) - .fail(function() { - self.$languageStatus - .addClass('language-list-error') - .text(gettext("We couldn't populate the list of language choices.")); - }); - - return this; - }, - - change: function() { - this.profileModel.set({ - fullName: this.$nameField.val() - }); - - this.preferencesModel.set({ - language: this.$languageChoices.val() - }); - }, - - submit: function(event) { - event.preventDefault(); - this.clearStatus(); - this.profileModel.save(); - this.preferencesModel.save(); - }, - - invalidProfile: function(model) { - var errors = model.validationError; - if (errors.hasOwnProperty('fullName')) { - this.$nameStatus - .addClass('validation-error') - .text(errors.fullName); - } - }, - - invalidPreference: function(model) { - var errors = model.validationError; - if (errors.hasOwnProperty('language')) { - this.$languageStatus - .addClass('validation-error') - .text(errors.language); - } - }, - - error: function(error) { - this.$submitStatus - .addClass('error') - .text(error); - }, - - sync: function() { - this.$submitStatus - .addClass('success') - .text(gettext("Saved")); - }, - - clearStatus: function() { - this.$nameStatus - .removeClass('validation-error') - .text(""); - - this.$languageStatus - .removeClass('validation-error') - .text(""); - - this.$submitStatus - .removeClass('error') - .text(""); - } - }); - - return new edx.student.profile.ProfileView({ - el: $('#profile-container') - }).render(); - -})(jQuery, _, Backbone, gettext); diff --git a/lms/templates/student_profile/index.html b/lms/templates/student_profile/index.html deleted file mode 100644 index 2982add373..0000000000 --- a/lms/templates/student_profile/index.html +++ /dev/null @@ -1,32 +0,0 @@ -<%namespace name='static' file='/static_content.html'/> -<%inherit file="../main.html" /> -<%! -from django.utils.translation import ugettext as _ -import third_party_auth -%> - -<%block name="pagetitle">${_("Student Profile")} - -<%block name="js_extra"> - - - <%static:js group='student_profile'/> - - -<%block name="header_extras"> -% for template_name in ["profile", "languages"]: - -% endfor - - -

Student Profile

- -

This is a placeholder for the student's profile page.

- -
- -% if third_party_auth.is_enabled(): - <%include file="third_party_auth.html" /> -% endif diff --git a/lms/templates/student_profile/languages.underscore b/lms/templates/student_profile/languages.underscore deleted file mode 100644 index 5b11aff4f2..0000000000 --- a/lms/templates/student_profile/languages.underscore +++ /dev/null @@ -1,7 +0,0 @@ -<% _.each( languageInfo.languages, function( language ){ %> - <% if ( language.name === languageInfo.preferredLanguage.name ){ %> - - <% } else { %> - - <% } %> -<% }); %> diff --git a/lms/templates/student_profile/profile.underscore b/lms/templates/student_profile/profile.underscore deleted file mode 100644 index 76bafbc247..0000000000 --- a/lms/templates/student_profile/profile.underscore +++ /dev/null @@ -1,14 +0,0 @@ -
- - -
- - - -
- -
- -
-
-