Further javascript improvements

This commit is contained in:
Patrick Jentsch 2023-10-05 16:08:04 +02:00
parent 7cae84ffdc
commit d3f2d5648e
7 changed files with 30 additions and 22 deletions

View File

@ -1,8 +1,8 @@
class CreateContributionForm extends Form {
Forms.CreateContributionForm = class CreateContributionForm extends Forms.BaseForm {
static autoInit() {
let createContributionFormElements = document.querySelectorAll('.create-contribution-form');
for (let createContributionFormElement of createContributionFormElements) {
new CreateContributionForm(createContributionFormElement);
new Forms.CreateContributionForm(createContributionFormElement);
}
}
@ -15,4 +15,4 @@ class CreateContributionForm extends Form {
}
});
}
}
};

View File

@ -1,8 +1,8 @@
class CreateCorpusFileForm extends Form {
Forms.CreateCorpusFileForm = class CreateCorpusFileForm extends Forms.BaseForm {
static autoInit() {
let createCorpusFileFormElements = document.querySelectorAll('.create-corpus-file-form');
for (let createCorpusFileFormElement of createCorpusFileFormElements) {
new CreateCorpusFileForm(createCorpusFileFormElement);
new Forms.CreateCorpusFileForm(createCorpusFileFormElement);
}
}
@ -15,4 +15,4 @@ class CreateCorpusFileForm extends Form {
}
});
}
}
};

View File

@ -1,8 +1,8 @@
class CreateJobForm extends Form {
Forms.CreateJobForm = class CreateJobForm extends Forms.BaseForm {
static autoInit() {
let createJobFormElements = document.querySelectorAll('.create-job-form');
for (let createJobFormElement of createJobFormElements) {
new CreateJobForm(createJobFormElement);
new Forms.CreateJobForm(createJobFormElement);
}
}
@ -22,4 +22,4 @@ class CreateJobForm extends Form {
}
});
}
}
};

View File

@ -1,9 +1,17 @@
class Form {
static autoInit() {
CreateContributionForm.autoInit();
CreateCorpusFileForm.autoInit();
CreateJobForm.autoInit();
var Forms = {};
Forms.autoInit = () => {
for (let propertyName in Forms) {
let property = Forms[propertyName];
// Call the autoInit method of all properties that are subclasses of Forms.BaseForm
if (property.prototype instanceof Forms.BaseForm) {
property.autoInit();
}
}
};
Forms.BaseForm = class BaseForm {
static autoInit() {throw 'Not implemented';}
constructor(formElement) {
this.formElement = formElement;
@ -139,4 +147,4 @@ class Form {
}
}
}
}
};

View File

@ -102,4 +102,4 @@ ResourceDisplays.CorpusDisplay = class CorpusDisplay extends ResourceDisplays.Ba
new Date(creationDate).toLocaleString("en-US")
);
}
}
};

View File

@ -123,4 +123,4 @@ ResourceDisplays.JobDisplay = class JobDisplay extends ResourceDisplays.BaseDisp
setServiceVersion(serviceVersion) {
this.setElements(this.displayElement.querySelectorAll('.job-service-version'), serviceVersion);
}
}
};

View File

@ -35,10 +35,10 @@
{%- assets
filters='rjsmin',
output='gen/Forms.%(version)s.js',
'js/Forms/Form.js',
'js/Forms/CreateCorpusFileForm.js',
'js/Forms/CreateJobForm.js',
'js/Forms/CreateContributionForm.js'
'js/forms/index.js',
'js/forms/create-contribution-form.js',
'js/forms/create-corpus-file-form.js',
'js/forms/create-job-form.js'
%}
<script src="{{ ASSET_URL }}"></script>
{%- endassets %}
@ -141,7 +141,7 @@
{alignment: 'right', constrainWidth: false, coverTrigger: false}
);
ResourceList.autoInit();
Form.autoInit();
Forms.autoInit();
// Display flashed messages
for (let [category, message] of {{ get_flashed_messages(with_categories=True)|tojson }}) {