Commit e7e25747 by AlasdairSwan

Merge pull request #5872 from edx/alasdair/logistration-form-errors-and-submit-methods

Moved to setting ajaxType with passed in method for models and now handl...
parents a86c80bb 04590949
...@@ -152,9 +152,24 @@ define([ ...@@ -152,9 +152,24 @@ define([
}); });
it('displays an error if a form definition could not be loaded', function() { it('displays an error if a form definition could not be loaded', function() {
/* TODO: Not yet implemeted in the access view; currently, it only // Spy on AJAX requests
* logs to the console. requests = AjaxHelpers.requests(this);
*/
// Init AccessView
view = new AccessView({
mode: 'login',
thirdPartyAuth: {
currentProvider: null,
providers: []
},
platformName: 'edX'
});
// Simulate an error from the LMS servers
AjaxHelpers.respondWithError(requests);
// Error message should be displayed
expect( $('#form-load-fail').hasClass('hidden') ).toBe(false);
}); });
}); });
} }
......
...@@ -23,7 +23,7 @@ define([ ...@@ -23,7 +23,7 @@ define([
year_of_birth: 2014, year_of_birth: 2014,
mailing_address: '141 Portland', mailing_address: '141 Portland',
goals: 'To boldly learn what no letter of the alphabet has learned before', goals: 'To boldly learn what no letter of the alphabet has learned before',
terms_of_service: true honor_code: true
}, },
THIRD_PARTY_AUTH = { THIRD_PARTY_AUTH = {
currentProvider: null, currentProvider: null,
...@@ -147,12 +147,12 @@ define([ ...@@ -147,12 +147,12 @@ define([
restrictions: {} restrictions: {}
}, },
{ {
name: 'terms_of_service', name: 'honor_code',
label: 'Terms of Service', label: 'I agree to the <a href="/honor">Terms of Service and Honor Code</a>',
defaultValue: '', defaultValue: '',
type: 'checkbox', type: 'checkbox',
required: true, required: true,
instructions: "Agree to the terms of service.", instructions: '',
restrictions: {} restrictions: {}
} }
] ]
...@@ -191,8 +191,8 @@ define([ ...@@ -191,8 +191,8 @@ define([
$('#register-mailing_address').val(USER_DATA.mailing_address); $('#register-mailing_address').val(USER_DATA.mailing_address);
$('#register-goals').val(USER_DATA.goals); $('#register-goals').val(USER_DATA.goals);
// Check the terms of service checkbox // Check the honor code checkbox
$('#register-terms_of_service').prop('checked', USER_DATA.terms_of_service); $('#register-honor_code').prop('checked', USER_DATA.honor_code);
// Create a fake click event // Create a fake click event
var clickEvent = $.Event('click'); var clickEvent = $.Event('click');
......
...@@ -14,9 +14,12 @@ var edx = edx || {}; ...@@ -14,9 +14,12 @@ var edx = edx || {};
remember: false remember: false
}, },
ajaxType: '',
urlRoot: '', urlRoot: '',
initialize: function( obj ) { initialize: function( obj ) {
this.ajaxType = obj.method;
this.urlRoot = obj.url; this.urlRoot = obj.url;
}, },
...@@ -27,15 +30,15 @@ var edx = edx || {}; ...@@ -27,15 +30,15 @@ var edx = edx || {};
$.ajax({ $.ajax({
url: model.urlRoot, url: model.urlRoot,
type: 'POST', type: model.ajaxType,
data: model.attributes, data: model.attributes,
headers: headers headers: headers,
}) success: function() {
.done(function() {
model.trigger('sync'); model.trigger('sync');
}) },
.fail( function( error ) { error: function( error ) {
model.trigger('error', error); model.trigger('error', error);
}
}); });
} }
}); });
......
...@@ -12,9 +12,12 @@ var edx = edx || {}; ...@@ -12,9 +12,12 @@ var edx = edx || {};
email: '' email: ''
}, },
ajaxType: '',
urlRoot: '', urlRoot: '',
initialize: function( obj ) { initialize: function( obj ) {
this.ajaxType = obj.method;
this.urlRoot = obj.url; this.urlRoot = obj.url;
}, },
...@@ -26,15 +29,15 @@ var edx = edx || {}; ...@@ -26,15 +29,15 @@ var edx = edx || {};
// Only expects an email address. // Only expects an email address.
$.ajax({ $.ajax({
url: model.urlRoot, url: model.urlRoot,
type: 'POST', type: model.ajaxType,
data: model.attributes, data: model.attributes,
headers: headers headers: headers,
}) success: function() {
.done(function() {
model.trigger('sync'); model.trigger('sync');
}) },
.fail( function( error ) { error: function( error ) {
model.trigger('error', error); model.trigger('error', error);
}
}); });
} }
}); });
......
...@@ -18,12 +18,15 @@ var edx = edx || {}; ...@@ -18,12 +18,15 @@ var edx = edx || {};
year_of_birth: '', year_of_birth: '',
mailing_address: '', mailing_address: '',
goals: '', goals: '',
terms_of_service: false honor_code: false
}, },
ajaxType: '',
urlRoot: '', urlRoot: '',
initialize: function( obj ) { initialize: function( obj ) {
this.ajaxType = obj.method;
this.urlRoot = obj.url; this.urlRoot = obj.url;
}, },
...@@ -34,15 +37,15 @@ var edx = edx || {}; ...@@ -34,15 +37,15 @@ var edx = edx || {};
$.ajax({ $.ajax({
url: model.urlRoot, url: model.urlRoot,
type: 'POST', type: model.ajaxType,
data: model.attributes, data: model.attributes,
headers: headers headers: headers,
}) success: function() {
.done(function() {
model.trigger('sync'); model.trigger('sync');
}) },
.fail( function( error ) { error: function( error ) {
model.trigger('error', error); model.trigger('error', error);
}
}); });
} }
}); });
......
...@@ -59,12 +59,13 @@ var edx = edx || {}; ...@@ -59,12 +59,13 @@ var edx = edx || {};
}, },
loadForm: function( type ) { loadForm: function( type ) {
this.getFormData( type, this.load[type], this ); this.getFormData( type, this );
}, },
load: { load: {
login: function( data, context ) { login: function( data, context ) {
var model = new edx.student.account.LoginModel({ var model = new edx.student.account.LoginModel({
method: data.method,
url: data.submit_url url: data.submit_url
}); });
...@@ -81,6 +82,7 @@ var edx = edx || {}; ...@@ -81,6 +82,7 @@ var edx = edx || {};
reset: function( data, context ) { reset: function( data, context ) {
var model = new edx.student.account.PasswordResetModel({ var model = new edx.student.account.PasswordResetModel({
method: data.method,
url: data.submit_url url: data.submit_url
}); });
...@@ -92,6 +94,7 @@ var edx = edx || {}; ...@@ -92,6 +94,7 @@ var edx = edx || {};
register: function( data, context ) { register: function( data, context ) {
var model = new edx.student.account.RegisterModel({ var model = new edx.student.account.RegisterModel({
method: data.method,
url: data.submit_url url: data.submit_url
}); });
...@@ -104,7 +107,7 @@ var edx = edx || {}; ...@@ -104,7 +107,7 @@ var edx = edx || {};
} }
}, },
getFormData: function( type, callback, context ) { getFormData: function( type, context ) {
var urls = { var urls = {
login: 'login_session', login: 'login_session',
register: 'registration', register: 'registration',
...@@ -114,13 +117,12 @@ var edx = edx || {}; ...@@ -114,13 +117,12 @@ var edx = edx || {};
$.ajax({ $.ajax({
url: '/user_api/v1/account/' + urls[type] + '/', url: '/user_api/v1/account/' + urls[type] + '/',
type: 'GET', type: 'GET',
dataType: 'json' dataType: 'json',
}) context: this,
.done(function( data ) { success: function( data ) {
callback( data, context ); this.load[type]( data, context );
}) },
.fail(function( jqXHR, textStatus, errorThrown ) { error: this.showFormError
console.log('fail ', errorThrown);
}); });
}, },
...@@ -134,6 +136,10 @@ var edx = edx || {}; ...@@ -134,6 +136,10 @@ var edx = edx || {};
this.loadForm('reset'); this.loadForm('reset');
}, },
showFormError: function() {
this.element.show( $('#form-load-fail') );
},
toggleForm: function( e ) { toggleForm: function( e ) {
var type = $(e.currentTarget).val(), var type = $(e.currentTarget).val(),
$form = $('#' + type + '-form'), $form = $('#' + type + '-form'),
......
...@@ -133,7 +133,6 @@ var edx = edx || {}; ...@@ -133,7 +133,6 @@ var edx = edx || {};
$label, $label,
key = '', key = '',
errors = [], errors = [],
// $status = $form.find('.status'),
test = {}; test = {};
for ( i=0; i<len; i++ ) { for ( i=0; i<len; i++ ) {
...@@ -144,7 +143,6 @@ var edx = edx || {}; ...@@ -144,7 +143,6 @@ var edx = edx || {};
if ( key ) { if ( key ) {
test = this.validate( elements[i] ); test = this.validate( elements[i] );
if ( test.isValid ) { if ( test.isValid ) {
obj[key] = $el.attr('type') === 'checkbox' ? $el.is(':checked') : $el.val(); obj[key] = $el.attr('type') === 'checkbox' ? $el.is(':checked') : $el.val();
$el.removeClass('error'); $el.removeClass('error');
......
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
<p class="tagline"><%- gettext("Log in or register to take courses from the world's best universities.") %></p> <p class="tagline"><%- gettext("Log in or register to take courses from the world's best universities.") %></p>
</header> </header>
<section id="form-load-fail" class="form-type hidden" aria-hidden="true">
<div class="status submission-error">
<p class="message-copy"><%- gettext("Apologies, we appear to be experiencing technical difficulties. Please try again later.") %></p>
</div>
</section>
<% if ( mode === 'login' ) { %> <% if ( mode === 'login' ) { %>
<section id="register-anchor" class="form-type"> <section id="register-anchor" class="form-type">
<span> <span>
......
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