From 35fa7c17b78bff2cdfd3292e5ee1c6ad7a3473d4 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 9 Apr 2024 14:07:08 +0200
Subject: [PATCH] refactor reports form, add recommendation preview

---
 .../scipost/static/scipost/report-preview.js  |  2 +-
 scipost_django/submissions/forms/__init__.py  | 94 +++++++++----------
 .../submissions/_report_preview.html          |  6 ++
 3 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/scipost_django/scipost/static/scipost/report-preview.js b/scipost_django/scipost/static/scipost/report-preview.js
index 3f8bb230a..2926bb568 100644
--- a/scipost_django/scipost/static/scipost/report-preview.js
+++ b/scipost_django/scipost/static/scipost/report-preview.js
@@ -40,7 +40,7 @@ $(function () {
         })
         .trigger("keyup");
 
-    $('#id_validity, #id_originality, #id_significance, #id_clarity, #id_formatting, #id_grammar').on('change', function(){
+    $('#id_validity, #id_originality, #id_significance, #id_clarity, #id_formatting, #id_grammar, #id_recommendation').on('change', function(){
         set_preview_select(this);
     }).trigger('change');
 
diff --git a/scipost_django/submissions/forms/__init__.py b/scipost_django/submissions/forms/__init__.py
index d42b7dcc1..e40e4c42e 100644
--- a/scipost_django/submissions/forms/__init__.py
+++ b/scipost_django/submissions/forms/__init__.py
@@ -2802,6 +2802,7 @@ class ReportPDFForm(forms.ModelForm):
 class ReportForm(forms.ModelForm):
     """Write Report form."""
 
+    required_css_class = "required-asterisk"
     report_type = REPORT_NORMAL
 
     class Meta:
@@ -2824,6 +2825,45 @@ class ReportForm(forms.ModelForm):
             "anonymous",
         ]
 
+        widgets = {
+            "strengths": forms.Textarea(
+                attrs={
+                    "placeholder": (
+                        "Give a point-by-point "
+                        "(numbered 1-, 2-, ...) list of the paper's strengths"
+                    ),
+                    "rows": 10,
+                    "cols": 100,
+                }
+            ),
+            "weaknesses": forms.Textarea(
+                attrs={
+                    "placeholder": (
+                        "Give a point-by-point "
+                        "(numbered 1-, 2-, ...) list of the paper's weaknesses"
+                    ),
+                    "rows": 10,
+                    "cols": 100,
+                }
+            ),
+            "report": forms.Textarea(
+                attrs={
+                    "placeholder": (
+                        "Your general remarks. Are this Journal's acceptance criteria met? "
+                        "Would you recommend publication in another Journal instead?"
+                    ),
+                    "rows": 10,
+                    "cols": 100,
+                }
+            ),
+            "requested_changes": forms.Textarea(
+                attrs={
+                    "placeholder": "Give a numbered (1-, 2-, ...) list of specifically requested changes",
+                    "cols": 100,
+                }
+            ),
+        }
+
     def __init__(self, *args, **kwargs):
         if kwargs.get("instance"):
             if kwargs["instance"].is_followup_report:
@@ -2841,57 +2881,13 @@ class ReportForm(forms.ModelForm):
         self.submission = kwargs.pop("submission")
 
         super().__init__(*args, **kwargs)
-        self.fields["strengths"].widget.attrs.update(
-            {
-                "placeholder": (
-                    "Give a point-by-point "
-                    "(numbered 1-, 2-, ...) list of the paper's strengths"
-                ),
-                "rows": 10,
-                "cols": 100,
-            }
-        )
-        self.fields["weaknesses"].widget.attrs.update(
-            {
-                "placeholder": (
-                    "Give a point-by-point "
-                    "(numbered 1-, 2-, ...) list of the paper's weaknesses"
-                ),
-                "rows": 10,
-                "cols": 100,
-            }
-        )
-        self.fields["report"].widget.attrs.update(
-            {
-                "placeholder": "Your general remarks. Are this Journal's acceptance criteria met? Would you recommend publication in another Journal instead?",
-                "rows": 10,
-                "cols": 100,
-            }
-        )
-        self.fields["requested_changes"].widget.attrs.update(
-            {
-                "placeholder": "Give a numbered (1-, 2-, ...) list of specifically requested changes",
-                "cols": 100,
-            }
-        )
-
-        self.fields["file_attachment"].label = (
-            "File attachment (2MB limit; for a figure or similar - please avoid annotated pdfs)"
-        )
 
         # Required fields on submission; optional on save as draft
-        if "save_submit" in self.data:
-            required_fields = ["report", "recommendation"]
-        else:
-            required_fields = []
-        required_fields_label = ["report", "recommendation"]
-
-        for field in required_fields:
-            self.fields[field].required = True
-
-        # Let user know the field is required!
-        for field in required_fields_label:
-            self.fields[field].label += " *"
+        self.fields["report"].required = True
+        self.fields["recommendation"].required = True
+        if "save_draft" in self.data:
+            self.fields["report"].required = False
+            self.fields["recommendation"].required = False
 
         if self.submission.eicrecommendations.active().exists():
             # An active EICRecommendation is already formulated. This Report will be flagged.
diff --git a/scipost_django/submissions/templates/submissions/_report_preview.html b/scipost_django/submissions/templates/submissions/_report_preview.html
index 43953c94a..1d6b762ab 100644
--- a/scipost_django/submissions/templates/submissions/_report_preview.html
+++ b/scipost_django/submissions/templates/submissions/_report_preview.html
@@ -29,6 +29,12 @@
       <div class="ps-md-4"><p style="white-space: pre-wrap;" data-receive="report-requested_changes"></p></div>
     </div>
   </div>
+  <div class="row" id="previewRecommendation">
+    <div class="col">
+      <h3 class="highlight tight">Recommendation</h3>
+      <div class="ps-md-4"><p style="white-space: pre-wrap;" data-receive="report-recommendation"></p></div>
+    </div>
+  </div>
 
   <div class="ratings" id="previewRatings">
     <ul>
-- 
GitLab