Skip to content

Commit

Permalink
refact(modal-result): refact form result property
Browse files Browse the repository at this point in the history
  • Loading branch information
William Aguera committed Jul 1, 2019
1 parent e9fd2c1 commit b14e866
Showing 1 changed file with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,51 @@
import {
Input, OnInit, Directive, HostListener, ContentChild,
} from '@angular/core';
import { ModalResult } from '../../core/enums/modal-result';
import { ModalService } from '../services/modal.service';
import { TlButton } from '../../button/button';
import {ModalResult} from '../../core/enums/modal-result';
import {ModalService} from '../services/modal.service';
import {TlButton} from '../../button/button';

@Directive( {
@Directive({
selector: '[mdResult]'
} )
})
export class ModalResultDirective implements OnInit {

@Input( 'mdResult' ) mdResult: ModalResult;
@Input('mdResult') mdResult: ModalResult;

@Input( 'formResult' ) formResult;
set formResultValue(value) {
this.formResult = value;
@Input('formResult')
set formResult(value) {
this._formResult = value;
}

@ContentChild( TlButton, {static: true} ) button: TlButton;
get formResult() {
return this._formResult;
}

@ContentChild(TlButton, {static: true}) button: TlButton;

private modalId: string;

@HostListener( 'click' )
private _formResult;

@HostListener('click')
onClick() {
if (!this.button.disabled) {
this.emitCallback();
setTimeout(() => {
this.emitCallback();
}, 1);
}
}

@HostListener( 'keydown.enter' )
@HostListener('keydown.enter')
onKeyDown() {
if (!this.button.disabled) {
this.emitCallback();
}
setTimeout(() => {
if (!this.button.disabled) {
this.emitCallback();
}
}, 1);
}

constructor( private modalService: ModalService ) {
constructor(private modalService: ModalService) {
}

ngOnInit() {
Expand All @@ -65,22 +75,22 @@ export class ModalResultDirective implements OnInit {
}

emitCallback(): Promise<any> {
return new Promise( ( resolve ) => {
if ( !this.mdResult ) {
return new Promise(() => {
if (!this.mdResult || this.button.disabled) {
return;
}
this.modalService.execCallBack( this.getResult(), this.modalId );
} );
this.modalService.execCallBack(this.getResult(), this.modalId);
});
}

getResult() {
if ( this.formResult ) {
return {
mdResult: ModalResult[ this.mdResult ],
mdResult: ModalResult[this.mdResult],
formResult: this.formResult
};
}
return { mdResult: ModalResult[ this.mdResult ] };
return {mdResult: ModalResult[this.mdResult]};
}

}

0 comments on commit b14e866

Please sign in to comment.