From 1179181a77f9d8fc837fa6129033b569cefd0772 Mon Sep 17 00:00:00 2001 From: mattiagiupponi <51856725+mattiagiupponi@users.noreply.github.com> Date: Tue, 9 Mar 2021 09:45:29 +0100 Subject: [PATCH] [Fixes: #7033] Mandatory fields in editor (#7039) --- geonode/context_processors.py | 3 +- geonode/layers/templates/layouts/panels.html | 30 ++++++++++++++------ geonode/templates/metadata_form_js.html | 30 ++++++++++++++++++-- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/geonode/context_processors.py b/geonode/context_processors.py index add7156795f..169910e8ef4 100644 --- a/geonode/context_processors.py +++ b/geonode/context_processors.py @@ -192,6 +192,7 @@ def resource_urls(request): GEONODE_APPS_ENABLE=getattr(settings, 'GEONODE_APPS_ENABLE', False), GEONODE_APPS_NAME=getattr(settings, 'GEONODE_APPS_NAME', 'Apps'), GEONODE_APPS_NAV_MENU_ENABLE=getattr(settings, 'GEONODE_APPS_NAV_MENU_ENABLE', False), - CATALOG_METADATA_TEMPLATE=getattr(settings, "CATALOG_METADATA_TEMPLATE", "catalogue/full_metadata.xml") + CATALOG_METADATA_TEMPLATE=getattr(settings, "CATALOG_METADATA_TEMPLATE", "catalogue/full_metadata.xml"), + UI_REQUIRED_FIELDS=getattr(settings, "UI_REQUIRED_FIELDS", []) ) return defaults diff --git a/geonode/layers/templates/layouts/panels.html b/geonode/layers/templates/layouts/panels.html index 3e4cbbb6231..698f493d430 100644 --- a/geonode/layers/templates/layouts/panels.html +++ b/geonode/layers/templates/layouts/panels.html @@ -239,9 +239,19 @@
- + {% if UI_REQUIRED_FIELDS %} + + + {% else %} + + {% endif %} + {% endblock edit_progress %} {% block breadcrumbs %} @@ -253,7 +263,11 @@ {% trans "Location and Licenses" %}{% trans "Other, Optional, Metadata" %}
{% trans "* Field declared Mandatory by the Metadata Schema" %}
")); + var mandatoryWarning = "{% trans "* Field declared Mandatory by the Metadata Schema" %}
" + if (!!$(this).closest('.check-select').length) { + $(e.target).parent().parent().append(gettext(mandatoryWarning)); + } else if (!!$(this).closest('#mdinfo').length) { + $(e.target).parent().append(gettext(mandatoryWarning)); } empty++; } @@ -337,6 +360,7 @@ }; {% endblock onInputChange %} {% block trigger_onInputChange %} + {{UI_REQUIRED_FIELDS}}.forEach(element => $('#' + element).change(onInputChange).change()); $('#category_form').change(onInputChange).change(); $('#id_resource-group').change(onInputChange).change(); document.querySelector('select[name="resource-keywords"]').onchange=onInputChange