1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-06-05 22:09:38 +02:00

fix: Fix Material web pre15 BC

This commit is contained in:
Maicol Battistini
2023-08-17 15:36:30 +02:00
parent 446011eecb
commit 13a6dba0ed
16 changed files with 132 additions and 100 deletions

View File

@@ -31,6 +31,7 @@ export default abstract class AddEditRecordDialog<M extends Model<any, any>> ext
// Recommended: <= 3
protected numberOfColumns: number = 3;
protected record!: M;
protected formId?: string;
oninit(vnode: Vnode<RecordDialogAttributes<M>, this>) {
super.oninit(vnode);
@@ -57,16 +58,19 @@ export default abstract class AddEditRecordDialog<M extends Model<any, any>> ext
contents(): Children {
return (
<>
<h2 slot="headline">{this.record.isNew() ? __('Nuovo record') : __('Modifica record')}</h2>
{this.form()}
{this.afterForm().toArray()}
</>
);
}
headline() {
return <span slot="headline">{this.record.isNew() ? __('Nuovo record') : __('Modifica record')}</span>;
}
form(): Children {
this.formId ??= `form-${Date.now()}`;
return (
<Form state={this.formState} onsubmit={this.onFormSubmit.bind(this)}>
<Form id={this.formId} state={this.formState} onsubmit={this.onFormSubmit.bind(this)}>
{this.formContents()}
</Form>
);
@@ -95,24 +99,24 @@ export default abstract class AddEditRecordDialog<M extends Model<any, any>> ext
abstract fields(): Collection<Children>;
onCancelButtonClicked(): void {
this.close('cancel');
void this.close('cancel');
}
async onFormSubmit() {
if (isFormValid(this.formElement!) && await this.save()) {
this.close();
void this.close();
}
}
afterForm(): VnodeCollection {
actions(): VnodeCollection {
return collect<VnodeCollectionItem>({
cancelButton: (
<md-text-button slot="footer" onclick={this.onCancelButtonClicked.bind(this)}>
<md-text-button onclick={this.onCancelButtonClicked.bind(this)}>
{__('Annulla')}
</md-text-button>
),
saveButton: (
<md-text-button type="submit" slot="footer" onclick={this.onSaveButtonClicked.bind(this)}>
<md-text-button type="submit" form={this.formId}>
{__('Salva')}
<MdIcon icon={mdiFloppy} slot="icon"/>
</md-text-button>
@@ -120,10 +124,6 @@ export default abstract class AddEditRecordDialog<M extends Model<any, any>> ext
});
}
onSaveButtonClicked(): void {
this.formElement?.requestSubmit();
}
async save(): Promise<boolean> {
this.record.setAttributes(this.modelAttributesFromFormState);
try {
@@ -136,9 +136,7 @@ export default abstract class AddEditRecordDialog<M extends Model<any, any>> ext
}
}
// @ts-expect-error - Temporary
afterSave(response: SaveResponse<M>): void {
// @ts-expect-error - Temporary
const responseModel = response.getModel() as M;
if (responseModel !== undefined) {
this.record = responseModel;