Skip to content

Instantly share code, notes, and snippets.

@avatsaev
Last active February 10, 2017 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avatsaev/708c94f1cd31f2e95c8060233671d53d to your computer and use it in GitHub Desktop.
Save avatsaev/708c94f1cd31f2e95c8060233671d53d to your computer and use it in GitHub Desktop.
import {Component, OnInit, Input, EventEmitter} from '@angular/core';
import {MaterializeAction} from "angular2-materialize";
@Component({
selector: 'app-auth-dialog',
templateUrl: './auth-dialog.component.html',
styleUrls: ['./auth-dialog.component.sass']
})
export class AuthDialogComponent implements OnInit {
@Input('auth-mode') authMode: 'login' | 'register' = 'login';
modalActions = new EventEmitter<string|MaterializeAction>();
constructor() {
}
onLoginFormResult(e){
if(e.signedIn)
this.closeDialog();
else{
alert(e.err.json().errors[0])
}
}
onRegisterFormResult(e){
if(e.signedUp)
this.closeDialog();
else{
alert(e.err.json().errors.full_messages[0])
}
}
openDialog(mode: 'login' | 'register' = 'login'){
this.authMode = mode;
this.modalActions.emit({action:"modal", params:['open']});
}
closeDialog(){
this.modalActions.emit({action:"modal", params:['close']});
}
ngOnInit() {
}
isLoginMode(){return this.authMode == 'login'}
isRegisterMode(){return this.authMode == 'register'}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment