Last active
February 10, 2017 10:01
-
-
Save avatsaev/708c94f1cd31f2e95c8060233671d53d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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