summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-01 18:07:55 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-01 18:40:01 +0100
commitcd612c54926ea3b0d2400a3ca9e4e9e8babcfaff (patch)
treecf87537c48f785e10211ba74c2677c7ef4a0fb2e /js
parent56762ca8cc862a4873b3c3edf491b07daffd5626 (diff)
change_password: do not use alerts in normal operation
Diffstat (limited to 'js')
-rw-r--r--js/codeq/change_password.js50
1 files changed, 28 insertions, 22 deletions
diff --git a/js/codeq/change_password.js b/js/codeq/change_password.js
index 6311764..8091a6d 100644
--- a/js/codeq/change_password.js
+++ b/js/codeq/change_password.js
@@ -1,5 +1,5 @@
/* CodeQ: an online programming tutor.
- Copyright (C) 2015 UL FRI
+ Copyright (C) 2015,2016 UL FRI
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License as published by the Free
@@ -14,44 +14,47 @@ details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-/**
- * Created by robert on 10/14/15.
- *
- */
-(function(){
+(function () {
"use strict";
var jqScreen = $('#screen-change-password'),
jqChangePassForm = $('#change-password-form'),
jqNew = $('#change-password-new'),
jqVerify = $('#change-password-verify'),
jqCancelBtn = $('#change-password-cancel'),
- jqErrorMismatch = jqChangePassForm.find('.error.mismatch');
+ jqMessages = jqChangePassForm.find('.error,.success'),
+ redirectTimeout = null;
- codeq.globalStateMachine.register('changePassword',{
+ codeq.globalStateMachine.register('changePassword', {
'jqScreen': jqScreen,
'isModal': true,
- 'enter': function() {
- jqErrorMismatch.hide();
+ 'enter': function () {
+ jqChangePassForm.find('button,input').prop('disabled', false);
+ jqMessages.hide();
jqCancelBtn.on('click',function(){
history.back();//forces a transition to the previous state
});
jqChangePassForm.on('submit', function (e) {
- jqErrorMismatch.hide();
+ jqMessages.hide();
if (jqNew.val() != jqVerify.val()) {
- jqErrorMismatch.show();
+ jqChangePassForm.find('.error.mismatch').show();
}
else {
codeq.comms.changePassword(jqNew.val())
.then(function (data) {
- if (data.code !== 0) throw new Error('Password change failed, code: ' + data.code + ', message: ' + data.message);
- alert('Password changed.');
- history.back();//force to return to previous state
+ switch (data.code) {
+ case 0:
+ jqChangePassForm.find('button,input').prop('disabled', true);
+ jqChangePassForm.find('.success').show();
+ redirectTimeout = setTimeout(function () {
+ history.back();
+ }, 2000);
+ break;
+ default:
+ jqChangePassForm.find('.error.failed').show();
+ }
})
.fail(function (reason) {
- codeq.log.error('Password change failed: ' + reason, reason);
alert('Password change failed: ' + reason);
})
.done();
@@ -59,12 +62,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
e.preventDefault(); // Prevent the form from submitting via the browser.
});
-
jqScreen.css('display', '');
$('#disabled').css('display', 'none');
},
- 'exit' : function(){
- jqErrorMismatch.hide();
+ 'exit': function () {
+ if (redirectTimeout !== null) {
+ clearTimeout(redirectTimeout);
+ redirectTimeout = null;
+ }
+ jqChangePassForm.find('button,input').prop('disabled', false);
+ jqMessages.hide();
jqChangePassForm.off('submit');
jqCancelBtn.off('click');
jqScreen.css('display', 'none');
@@ -72,5 +79,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqVerify.val('');
}
});
-
})();