extended base dialog for 'add edit justifications' component
This commit is contained in:
parent
2fcd899023
commit
5457fcacf5
@ -43,13 +43,13 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="dialog-actions">
|
||||
<button [disabled]="form.invalid || !changed" color="primary" mat-flat-button type="submit">
|
||||
<button [disabled]="disabled" color="primary" mat-flat-button type="submit">
|
||||
{{ 'add-edit-justification.actions.save' | translate }}
|
||||
</button>
|
||||
|
||||
<div class="all-caps-label cancel" mat-dialog-close translate="add-edit-justification.actions.cancel"></div>
|
||||
<div class="all-caps-label cancel" translate="add-edit-justification.actions.cancel" (click)="close()"></div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<iqser-circle-button class="dialog-close" icon="iqser:close" mat-dialog-close></iqser-circle-button>
|
||||
<iqser-circle-button class="dialog-close" icon="iqser:close" (action)="close()"></iqser-circle-button>
|
||||
</section>
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, Inject, Injector } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { Justification } from '@red/domain';
|
||||
import { JustificationsService } from '@services/entity-services/justifications.service';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { LoadingService } from '@iqser/common-ui';
|
||||
import { BaseDialogComponent, LoadingService } from '@iqser/common-ui';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-add-edit-justification-dialog',
|
||||
@ -12,23 +12,21 @@ import { LoadingService } from '@iqser/common-ui';
|
||||
styleUrls: ['./add-edit-justification-dialog.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class AddEditJustificationDialogComponent {
|
||||
readonly form: FormGroup = this._getForm();
|
||||
export class AddEditJustificationDialogComponent extends BaseDialogComponent {
|
||||
|
||||
constructor(
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
private readonly _justificationService: JustificationsService,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
public dialogRef: MatDialogRef<AddEditJustificationDialogComponent>,
|
||||
protected readonly _injector: Injector,
|
||||
protected readonly _dialogRef: MatDialogRef<AddEditJustificationDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public justification: Justification,
|
||||
) {}
|
||||
) {
|
||||
super(_injector, _dialogRef);
|
||||
|
||||
get changed(): boolean {
|
||||
return (
|
||||
!this.justification ||
|
||||
Object.keys(this.form.getRawValue()).reduce((prev, key) => prev || this.justification[key] !== this.form.get(key).value, false)
|
||||
);
|
||||
this.form = this._getForm();
|
||||
this.initialFormValue = this.form.getRawValue();
|
||||
}
|
||||
|
||||
async save() {
|
||||
@ -38,7 +36,7 @@ export class AddEditJustificationDialogComponent {
|
||||
await this._justificationService.createOrUpdate(this.form.getRawValue(), dossierTemplateId).toPromise();
|
||||
await this._justificationService.loadAll(dossierTemplateId).toPromise();
|
||||
this._loadingService.stop();
|
||||
this.dialogRef.close(true);
|
||||
this._dialogRef.close(true);
|
||||
}
|
||||
|
||||
private _getForm(): FormGroup {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user