Browse Source

feat(theme-basic): change modal

pull/1556/head
TheDiaval 7 years ago
parent
commit
2e0dc813bd
  1. 38
      npm/ng-packs/packages/theme-basic/src/lib/components/change-password/change-password.component.html
  2. 45
      npm/ng-packs/packages/theme-basic/src/lib/components/change-password/change-password.component.ts

38
npm/ng-packs/packages/theme-basic/src/lib/components/change-password/change-password.component.html

@ -1,12 +1,9 @@
<ng-template #modalContent let-modal> <abp-modal *ngIf="visible" [(visible)]="visible">
<div class="modal-header"> <ng-template #abpHeader>
<h4 class="modal-title" id="modal-basic-title">{{ 'AbpIdentity::ChangePassword' | abpLocalization }}</h4> <h4>{{ 'AbpIdentity::ChangePassword' | abpLocalization }}</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss()"> </ng-template>
<span aria-hidden="true">&times;</span> <ng-template #abpBody>
</button> <form [formGroup]="form" novalidate>
</div>
<form [formGroup]="form" (ngSubmit)="onSubmit()" novalidate>
<div class="modal-body">
<div class="form-group"> <div class="form-group">
<label for="current-password">{{ 'AbpIdentity::DisplayName:CurrentPassword' | abpLocalization }}</label <label for="current-password">{{ 'AbpIdentity::DisplayName:CurrentPassword' | abpLocalization }}</label
><span> * </span><input type="password" id="current-password" class="form-control" formControlName="password" /> ><span> * </span><input type="password" id="current-password" class="form-control" formControlName="password" />
@ -23,15 +20,14 @@
{{ 'AbpIdentity::Identity.PasswordConfirmationFailed' | abpLocalization }} {{ 'AbpIdentity::Identity.PasswordConfirmationFailed' | abpLocalization }}
</div> </div>
</div> </div>
</div> </form>
</ng-template>
<div class="modal-footer"> <ng-template #abpFooter>
<button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="modal.close()"> <button type="button" class="btn btn-secondary" #abpClose>
{{ 'AbpIdentity::Cancel' | abpLocalization }} {{ 'AbpIdentity::Cancel' | abpLocalization }}
</button> </button>
<button type="submit" class="btn btn-primary"> <button type="button" class="btn btn-primary" (click)="onSubmit()">
<i class="fa fa-check mr-1"></i> <span>{{ 'AbpIdentity::Save' | abpLocalization }}</span> <i class="fa fa-check mr-1"></i> <span>{{ 'AbpIdentity::Save' | abpLocalization }}</span>
</button> </button>
</div> </ng-template>
</form> </abp-modal>
</ng-template>

45
npm/ng-packs/packages/theme-basic/src/lib/components/change-password/change-password.component.ts

@ -11,11 +11,8 @@ import {
ViewChild, ViewChild,
} from '@angular/core'; } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { comparePasswords, validatePassword } from '@ngx-validate/core'; import { comparePasswords, validatePassword } from '@ngx-validate/core';
import { Store } from '@ngxs/store'; import { Store } from '@ngxs/store';
import { from } from 'rxjs';
import { take } from 'rxjs/operators';
const { minLength, required } = Validators; const { minLength, required } = Validators;
@ -24,8 +21,17 @@ const { minLength, required } = Validators;
templateUrl: './change-password.component.html', templateUrl: './change-password.component.html',
}) })
export class ChangePasswordComponent implements OnInit, OnChanges { export class ChangePasswordComponent implements OnInit, OnChanges {
protected _visible;
@Input() @Input()
visible: boolean; get visible(): boolean {
return this._visible;
}
set visible(value: boolean) {
this._visible = value;
this.visibleChange.emit(value);
}
@Output() @Output()
visibleChange = new EventEmitter<boolean>(); visibleChange = new EventEmitter<boolean>();
@ -35,9 +41,7 @@ export class ChangePasswordComponent implements OnInit, OnChanges {
form: FormGroup; form: FormGroup;
modalRef: NgbModalRef; constructor(private fb: FormBuilder, private store: Store) {}
constructor(private fb: FormBuilder, private modalService: NgbModal, private store: Store) {}
ngOnInit(): void { ngOnInit(): void {
this.form = this.fb.group( this.form = this.fb.group(
@ -62,28 +66,13 @@ export class ChangePasswordComponent implements OnInit, OnChanges {
newPassword: this.form.get('newPassword').value, newPassword: this.form.get('newPassword').value,
}), }),
) )
.subscribe(() => this.modalRef.close()); .subscribe(() => {
this.visible = false;
});
} }
openModal() { openModal() {
this.modalRef = this.modalService.open(this.modalContent); this.visible = true;
this.visibleChange.emit(true);
from(this.modalRef.result)
.pipe(take(1))
.subscribe(
data => {
this.setVisible(false);
},
reason => {
this.setVisible(false);
},
);
}
setVisible(value: boolean) {
this.visible = value;
this.visibleChange.emit(value);
} }
ngOnChanges({ visible }: SimpleChanges): void { ngOnChanges({ visible }: SimpleChanges): void {
@ -91,8 +80,8 @@ export class ChangePasswordComponent implements OnInit, OnChanges {
if (visible.currentValue) { if (visible.currentValue) {
this.openModal(); this.openModal();
} else if (visible.currentValue === false && this.modalService.hasOpenModals()) { } else if (visible.currentValue === false && this.visible) {
this.modalRef.close(); this.visible = false;
} }
} }
} }

Loading…
Cancel
Save