From d3f2d5648ed1fdb172c5ca843964021f2acd45b0 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Thu, 5 Oct 2023 16:08:04 +0200
Subject: [PATCH] Further javascript improvements
---
.../create-contribution-form.js} | 6 +++---
.../create-corpus-file-form.js} | 6 +++---
.../create-job-form.js} | 6 +++---
.../js/{Forms/Form.js => forms/index.js} | 20 +++++++++++++------
.../js/resource-displays/corpus-display.js | 2 +-
.../js/resource-displays/job-display.js | 2 +-
app/templates/_scripts.html.j2 | 10 +++++-----
7 files changed, 30 insertions(+), 22 deletions(-)
rename app/static/js/{Forms/CreateContributionForm.js => forms/create-contribution-form.js} (74%)
rename app/static/js/{Forms/CreateCorpusFileForm.js => forms/create-corpus-file-form.js} (74%)
rename app/static/js/{Forms/CreateJobForm.js => forms/create-job-form.js} (85%)
rename app/static/js/{Forms/Form.js => forms/index.js} (92%)
diff --git a/app/static/js/Forms/CreateContributionForm.js b/app/static/js/forms/create-contribution-form.js
similarity index 74%
rename from app/static/js/Forms/CreateContributionForm.js
rename to app/static/js/forms/create-contribution-form.js
index e7651ab0..68003796 100644
--- a/app/static/js/Forms/CreateContributionForm.js
+++ b/app/static/js/forms/create-contribution-form.js
@@ -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 {
}
});
}
-}
+};
diff --git a/app/static/js/Forms/CreateCorpusFileForm.js b/app/static/js/forms/create-corpus-file-form.js
similarity index 74%
rename from app/static/js/Forms/CreateCorpusFileForm.js
rename to app/static/js/forms/create-corpus-file-form.js
index ae8dba3b..6cbc8a3a 100644
--- a/app/static/js/Forms/CreateCorpusFileForm.js
+++ b/app/static/js/forms/create-corpus-file-form.js
@@ -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 {
}
});
}
-}
+};
diff --git a/app/static/js/Forms/CreateJobForm.js b/app/static/js/forms/create-job-form.js
similarity index 85%
rename from app/static/js/Forms/CreateJobForm.js
rename to app/static/js/forms/create-job-form.js
index 6aa2d1b6..0ee64e3a 100644
--- a/app/static/js/Forms/CreateJobForm.js
+++ b/app/static/js/forms/create-job-form.js
@@ -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 {
}
});
}
-}
+};
diff --git a/app/static/js/Forms/Form.js b/app/static/js/forms/index.js
similarity index 92%
rename from app/static/js/Forms/Form.js
rename to app/static/js/forms/index.js
index c3496e18..b3bd9224 100644
--- a/app/static/js/Forms/Form.js
+++ b/app/static/js/forms/index.js
@@ -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 {
}
}
}
-}
+};
diff --git a/app/static/js/resource-displays/corpus-display.js b/app/static/js/resource-displays/corpus-display.js
index 6bfa1676..4381ec88 100644
--- a/app/static/js/resource-displays/corpus-display.js
+++ b/app/static/js/resource-displays/corpus-display.js
@@ -102,4 +102,4 @@ ResourceDisplays.CorpusDisplay = class CorpusDisplay extends ResourceDisplays.Ba
new Date(creationDate).toLocaleString("en-US")
);
}
-}
+};
diff --git a/app/static/js/resource-displays/job-display.js b/app/static/js/resource-displays/job-display.js
index 2d107716..d52f0b0e 100644
--- a/app/static/js/resource-displays/job-display.js
+++ b/app/static/js/resource-displays/job-display.js
@@ -123,4 +123,4 @@ ResourceDisplays.JobDisplay = class JobDisplay extends ResourceDisplays.BaseDisp
setServiceVersion(serviceVersion) {
this.setElements(this.displayElement.querySelectorAll('.job-service-version'), serviceVersion);
}
-}
+};
diff --git a/app/templates/_scripts.html.j2 b/app/templates/_scripts.html.j2
index b2ca56a4..de457973 100644
--- a/app/templates/_scripts.html.j2
+++ b/app/templates/_scripts.html.j2
@@ -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'
%}
{%- 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 }}) {