diff options
Diffstat (limited to 'js/codeq')
-rw-r--r-- | js/codeq/login.js | 14 | ||||
-rw-r--r-- | js/codeq/navigation.js | 3 | ||||
-rw-r--r-- | js/codeq/profile.js | 38 | ||||
-rw-r--r-- | js/codeq/signup.js | 72 |
4 files changed, 85 insertions, 42 deletions
diff --git a/js/codeq/login.js b/js/codeq/login.js index a3158ae..53a422c 100644 --- a/js/codeq/login.js +++ b/js/codeq/login.js @@ -48,9 +48,16 @@ codeq.globalStateMachine.register('login',{ 'enter': function(){ - $('#navigation-home').off('click');//remove the click listener of this element here only - in each other state the listener should exist - $('.nav.navbar-nav.navbar-right').css('display','none'); + $('#navigation-home').off('click');//remove the click listener of this element here + $('.nav.navbar-nav.navbar-right').css('display','none');//hide settings etc. $('#signed-in-title').html(''); + + //setup the signup button + $('#signup_button').on('click', function(e){ + codeq.globalStateMachine.transition('signup'); + e.preventDefault(); + }); + $("#submit").on('click', loginFun); formInputs.on('keyup', function (ev) { if ((ev.keyCode || ev.which) == 13) { @@ -74,6 +81,9 @@ e.preventDefault(); }); $('.nav.navbar-nav.navbar-right').css('display',''); + + //remove the listener from the signup button + $('#signup_button').off('click'); } }); })(); diff --git a/js/codeq/navigation.js b/js/codeq/navigation.js index dab907a..58f0cf2 100644 --- a/js/codeq/navigation.js +++ b/js/codeq/navigation.js @@ -71,7 +71,7 @@ }, 'actualTransition': function (name) { //check if we are logged in - if we aren't we will always transition to the login state - if(!codeq.comms.getSid()){ + if(!codeq.comms.getSid() && name !== "signup"){//we can of course enter the signup state even if not logged in name = 'login';//this will cause the following code to transition to the login state instead of the original one given } @@ -85,7 +85,6 @@ }; codeq.globalStateMachine = makeGlobalStateMachine({}); - //setup all the buttons in the banner $('#navigation-home').on('click', function(e){ codeq.globalStateMachine.transition('language'); diff --git a/js/codeq/profile.js b/js/codeq/profile.js index 4723b4a..08a8883 100644 --- a/js/codeq/profile.js +++ b/js/codeq/profile.js @@ -4,44 +4,6 @@ (function(){
- $('#formSignUp').submit(function(event) {
- console.log($(this).serialize());
- var jqUsername = $("#modalSignUpUsername"),
- jqName = $("#modalSignUpName"),
- jqEmail = $("#modalSignUpEmail"),
- jqPassword = $("#modalSignUpPassword"),
- jqVerify = $("#modalSignUpVerify");
-
- if (jqPassword.val() != jqVerify.val()) {
- alert('Passwords do not match.');
- }
- else {
- codeq.comms.signup(jqUsername.val(), jqName.val(), jqEmail.val(), jqPassword.val())
- .then(function (data) {
- if (data.code !== 0) throw new Error('Signup failed, code: ' + data.code + ', message: ' + data.message);
-
- //back to login
- $('#modalSignUp').modal('hide');
- alert('Welcome '+ jqUsername.val() +'. Thanks for signing up.');
- $('#modalLogIn').modal('show');
- //assume user wants to sign-in with signed username
- $("#username").val(jqUsername.val());
- //clear
- jqUsername.val('');
- jqName.val('');
- jqEmail.val('');
- jqPassword.val('');
- jqVerify.val('');
- })
- .fail(function (reason) {
- codeq.log.error('Signup failed: ' + reason, reason);
- alert('Signup failed: ' + reason);
- })
- .done();
- }
- event.preventDefault(); // Prevent the form from submitting via the browser.
- });
-
$('#formChangePassword').submit(function(event) {
var jqNew = $("#modalChangePasswordNew"),
jqVerify = $("#modalChangePasswordVerify");
diff --git a/js/codeq/signup.js b/js/codeq/signup.js new file mode 100644 index 0000000..aab831f --- /dev/null +++ b/js/codeq/signup.js @@ -0,0 +1,72 @@ +/** + * Created by robert on 10/14/15. + */ +(function(){ + + var jqUsername = $("#modalSignUpUsername"), + jqName = $("#modalSignUpName"), + jqEmail = $("#modalSignUpEmail"), + jqPassword = $("#modalSignUpPassword"), + jqVerify = $("#modalSignUpVerify"); + + codeq.globalStateMachine.register('signup',{ + 'enter': function(){ + $('#navigation-home').off('click');//remove the click listener of this element here + $('.nav.navbar-nav.navbar-right').css('display','none');//hide settings etc. + $('#signed-in-title').html(''); + $("#screen_signup").css('display', ''); + $('#disabled').css('display', 'none'); + $('#exit_signup_btn').on('click',function(){ + codeq.globalStateMachine.transition('login'); + }); + + //prepare listener for successfull signup + $('#formSignUp').on('submit',function(event) { + console.log($(this).serialize()); + if (jqPassword.val() != jqVerify.val()) { + alert('Passwords do not match.'); + } + else { + codeq.comms.signup(jqUsername.val(), jqName.val(), jqEmail.val(), jqPassword.val()) + .then(function (data) { + if (data.code !== 0) throw new Error('Signup failed, code: ' + data.code + ', message: ' + data.message); + + var newUsername = jqUsername.val();//saving before transition (which will reset the value of the field) + //back to login + codeq.globalStateMachine.transition('login'); + alert('Welcome '+ newUsername +'. Thanks for signing up.'); + //assume user wants to sign-in with signed username + $("#username").val(newUsername); + + }) + .fail(function (reason) { + codeq.log.error('Signup failed: ' + reason, reason); + alert('Signup failed: ' + reason); + }) + .done(); + } + event.preventDefault(); // Prevent the form from submitting via the browser. + }); + }, + 'exit' : function(){ + $("#screen_signup").css('display', 'none'); + //re-enable the click listener + $('#navigation-home').on('click', function(e){ + codeq.globalStateMachine.transition('language'); + e.preventDefault(); + }); + //disable listeners on stuff from this page only + $('#exit_signup_btn').off('click'); + $('#formSignUp').off('submit'); + //show the menu buttons + $('.nav.navbar-nav.navbar-right').css('display',''); + + jqUsername.val(''); + jqName.val(''); + jqEmail.val(''); + jqPassword.val(''); + jqVerify.val(''); + } + }); + +})(); |