Commit a4da143c by cahrens

Delete unused student_profile code (WIP profile).

parent 0b42c772
......@@ -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'
......
......@@ -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',
......
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("<div id=\"profile-tpl\">" + profileFixture + "</div>");
appendSetFixtures("<div id=\"languages-tpl\">" + languageFixture + "</div>");
// 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");
});
});
}
);
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);
<%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>
<%block name="js_extra">
<script type="text/javascript" src="${static.url('js/vendor/underscore-min.js')}"></script>
<script type="text/javascript" src="${static.url('js/vendor/backbone-min.js')}"></script>
<%static:js group='student_profile'/>
</%block>
<%block name="header_extras">
% for template_name in ["profile", "languages"]:
<script type="text/template" id="${template_name}-tpl">
<%static:include path="student_profile/${template_name}.underscore" />
</script>
% endfor
</%block>
<h1>Student Profile</h1>
<p>This is a placeholder for the student's profile page.</p>
<div id="profile-container"></div>
% if third_party_auth.is_enabled():
<%include file="third_party_auth.html" />
% endif
<% _.each( languageInfo.languages, function( language ){ %>
<% if ( language.name === languageInfo.preferredLanguage.name ){ %>
<option value=<%= language.code %> selected="selected"><%= language.name %></option>
<% } else { %>
<option value=<%= language.code %>><%= language.name %></option>
<% } %>
<% }); %>
<form id="profile-form">
<label for="profile-name"><%- gettext("Full Name") %></label>
<input id="profile-name" type="text" name="profile-name" value="" placeholder="Xsy" />
<div id="profile-name-status" />
<label for="preference-language"><%- gettext('Preferred Language') %></label>
<select id="preference-language" name="preference-language"></select>
<div id="preference-language-status" />
<div class="profile-submit">
<input type="submit" id="submit-button" value="<%- gettext('Update Profile') %>">
</div>
<div id="submit-status" />
</form>
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