2016-01-25 17:14:42 +01:00
// REFACTOR: Move to ActiveRecord object
Session . set ( "defaultSignInMessage" , "Improve your clinical practice with checklists." ) ;
//==================================================================================================
// ROUTER
Router . route ( '/entrySignIn' , {
template : 'entrySignIn' ,
name : 'entrySignIn'
} ) ;
Router . route ( '/sign-in' , {
template : 'entrySignIn' ,
name : 'signInRoute'
} ) ;
//==================================================================================================
// COMPONENT OUTPUTS
Template . entrySignIn . helpers ( {
getSignInMessageColor : function ( ) {
if ( ActiveEntry . errorMessages . get ( 'signInError' ) ) {
return "color: #a94442; background-color: #f2dede; border-color: #ebccd1;"
} else {
return "color: black;"
}
} ,
getSignInMessage : function ( ) {
if ( ActiveEntry . errorMessages . get ( 'signInError' ) ) {
return ActiveEntry . errorMessages . get ( 'signInError' ) ;
} else {
return Session . get ( 'defaultSignInMessage' ) ;
}
} ,
getButtonText : function ( ) {
return "Sign In" ;
// if (ActiveEntry.errorMessages.get('signInError')){
// return ActiveEntry.errorMessages.get('signInError');
// } else {
// return "Sign In";
// }
} ,
getEmailValidationStyling : function ( ) {
if ( ActiveEntry . errorMessages . equals ( 'email' , "Email is required" ) ) {
return "border: 1px solid #a94442" ;
} else if ( ActiveEntry . errorMessages . equals ( 'email' , "Email is poorly formatted" ) ) {
return "border: 1px solid #f2dede" ;
} else if ( ActiveEntry . errorMessages . equals ( 'email' , "Email present" ) ) {
return "border: 1px solid green" ;
} else {
return "border: 1px solid gray" ;
}
} ,
getPasswordValidationStyling : function ( ) {
if ( ActiveEntry . errorMessages . equals ( 'password' , "Password is required" ) ) {
return "border: 1px solid #a94442" ;
2016-02-02 21:31:01 +01:00
} else if ( ActiveEntry . errorMessages . equals ( 'password' , "Password must have at least 8 characters. It must contain at least 1 uppercase, 1 lowercase, 1 number and 1 special character." ) ) {
2016-01-25 17:14:42 +01:00
return "border: 1px solid #f2dede" ;
} else if ( ActiveEntry . errorMessages . equals ( 'password' , "Password present" ) ) {
return "border: 1px solid green" ;
} else {
return "border: 1px solid gray" ;
}
}
} ) ;
//==================================================================================================
// COMPONENT OUTPUTS
Template . entrySignIn . events ( {
'click #logoutButton' : function ( ) {
Meteor . logout ( ) ;
} ,
'click #forgotPasswordButton' : function ( event ) {
event . preventDefault ( ) ;
2016-02-02 21:31:01 +01:00
ActiveEntry . reset ( ) ;
2016-01-25 17:14:42 +01:00
Router . go ( '/forgotPassword' ) ;
} ,
"click #needAnAccountButton" : function ( event ) {
event . preventDefault ( ) ;
2016-02-02 21:31:01 +01:00
ActiveEntry . reset ( ) ;
2016-01-25 17:14:42 +01:00
Router . go ( '/entrySignUp' ) ;
} ,
'keyup input[name="email"]' : function ( event , template ) {
var email = $ ( 'input[name="email"]' ) . val ( ) ;
ActiveEntry . verifyEmail ( email ) ;
ActiveEntry . errorMessages . set ( 'signInError' , null ) ;
} ,
'change input[name="email"]' : function ( event , template ) {
var email = $ ( 'input[name="email"]' ) . val ( ) ;
ActiveEntry . verifyEmail ( email ) ;
ActiveEntry . errorMessages . set ( 'signInError' , null ) ;
} ,
'keyup #signInPagePasswordInput' : function ( event , template ) {
var password = $ ( 'input[name="password"]' ) . val ( ) ;
ActiveEntry . verifyPassword ( password ) ;
ActiveEntry . errorMessages . set ( 'signInError' , null ) ;
} ,
'change #signInPagePasswordInput' : function ( event , template ) {
var password = $ ( 'input[name="password"]' ) . val ( ) ;
ActiveEntry . verifyPassword ( password ) ;
ActiveEntry . errorMessages . set ( 'signInError' , null ) ;
} ,
// 'submit': function (event, template) {
// event.preventDefault();
// var emailValue = template.$('[name=email]').val();
// var passwordValue = template.$('[name=password]').val();
//
// ActiveEntry.signIn(emailValue, passwordValue);
// },
'click #signInToAppButton' : function ( event , template ) {
console . log ( 'click #signInToAppButton' ) ;
2016-02-02 21:31:01 +01:00
ActiveEntry . reset ( ) ;
2016-01-25 17:14:42 +01:00
// var emailValue = template.$('[name=email]').val();
// var passwordValue = template.$('[name=password]').val();
var emailValue = template . $ ( '#signInPageEmailInput' ) . val ( ) ;
var passwordValue = template . $ ( '#signInPagePasswordInput' ) . val ( ) ;
ActiveEntry . signIn ( emailValue , passwordValue ) ;
event . preventDefault ( ) ;
}
} ) ;
//==================================================================================================