Код: Выделить всё
entitlementForm: FormGroup;
teams = TEAMS;
isSaving = false;
constructor(
private fb: FormBuilder,
private dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA) public data: EntitlementDialogData
) {
this.entitlementForm = this.fb.group({
displayName: [data.entitlement?.displayName || '', [Validators.required]],
name: [data.entitlement?.name || '', [
Validators.required,
Validators.pattern(/^[a-z0-9-]+$/)
]],
description: [data.entitlement?.description || '', [Validators.required]],
team: [data.entitlement?.team || '', [Validators.required]],
isActive: [data.entitlement?.isActive ?? true]
});
// Auto-generate system name from display name
this.entitlementForm.get('displayName')?.valueChanges.subscribe(displayName => {
if (!this.data.isEdit && displayName) {
const systemName = 'app-pme-' + displayName
.toLowerCase()
.replace(/[^a-z0-9\s]/g, '')
.replace(/\s+/g, '-');
this.entitlementForm.get('name')?.setValue(systemName);
}
});
}
save(): void {
if (this.entitlementForm.valid) {
this.isSaving = true;
const formValue = this.entitlementForm.value;
// Simulate save delay
setTimeout(() => {
this.dialogRef.close(formValue);
}, 1000);
}
}< /code>
.dialog-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px 24px 0;
h2 {
display: flex;
align-items: center;
gap: 8px;
margin: 0;
font-size: 1.25rem;
font-weight: 600;
color: #1e293b;
mat-icon {
color: #6366f1;
font-size: 20px;
width: 20px;
height: 20px;
}
}
button {
color: #64748b;
&:hover {
color: #374151;
background: #f1f5f9;
}
}
}
.entitlement-form {
width: 100%;
min-width: 500px;
padding: 20px 0;
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
margin-bottom: 16px;
&:has(.status-field) {
align-items: center;
}
@media (max-width: 768px) {
grid-template-columns: 1fr;
}
}
.status-field {
display: flex;
flex-direction: column;
gap: 4px;
.checkbox-hint {
color: #64748b;
font-size: 0.75rem;
margin-left: 32px;
}
}
.mat-mdc-form-field {
.mat-mdc-text-field-wrapper {
background: #ffffff;
border-radius: 6px;
}
&.mat-focused .mdc-notched-outline__leading,
&.mat-focused .mdc-notched-outline__notch,
&.mat-focused .mdc-notched-outline__trailing {
border-color: #6366f1;
}
}
}
.mat-mdc-dialog-content {
padding: 0 24px;
margin: 0;
max-height: 70vh;
overflow-y: auto;
}
.mat-mdc-dialog-actions {
padding: 16px 24px;
gap: 8px;
button {
min-width: 100px;
height: 40px;
font-weight: 600;
border-radius: 6px;
text-transform: none;
font-size: 0.8125rem;
mat-icon {
margin-right: 6px;
font-size: 16px;
width: 16px;
height: 16px;
}
}
}< /code>
{{ data.isEdit ? 'edit' : 'add' }}
{{ data.isEdit ? 'Edit' : 'Create New' }} Entitlement
close
Display Name
Display name is required
System Name
Use lowercase with dashes (e.g., app-pme-payments-viewer)
System name is required
Use lowercase letters, numbers, and dashes only
Description
Description is required
Team
{{ team }}
Team is required
Active Entitlement
Only active entitlements can be assigned to groups
Cancel
save
{{ isSaving ? 'Saving...' : (data.isEdit ? 'Update' : 'Create') }}
Подробнее здесь: https://stackoverflow.com/questions/797 ... cript-file