Skip to content

Commit

Permalink
[Fixes: #7034] Metadata UI freezes on empty mandatory fields (#7036)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi authored Mar 9, 2021
1 parent 1179181 commit f2add03
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
19 changes: 19 additions & 0 deletions geonode/layers/templates/layers/layer_metadata_advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,25 @@ <h2>{% trans "Metadata Provider" %}</h2>
</form>
</div>
</div>

<div class="modal fade" style="width: 100%; height: 100%;" id="error_mandatoryDialog" data-backdrop="static" data-keyboard="false" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content panel-warning">
<div class="modal-header panel-heading">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "ERROR" %}</h4>
</div>
<div class="modal-body general_errors">
{% trans "Following items are required:" %}
<p id="general_errors"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
</div>
</div>
</div>
</div>

{% endblock %}

{% block extra_script %}
Expand Down
3 changes: 3 additions & 0 deletions geonode/locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6276,6 +6276,9 @@ msgstr "stato dell'elemento sconosciuto: %s"
msgid "error during import: %s"
msgstr "errore durante l'importazione: %s"

msgid "Following items are required:"
msgstr "I seguenti elementi sono obbligatori:"

msgid "Could not find any valid Time Regex for the Mosaic files."
msgstr "Impossibile trovare file kml all'interno del kmz caricato."

Expand Down
19 changes: 19 additions & 0 deletions geonode/templates/metadata_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,25 @@ <h4 class="modal-title">{% trans "ERROR" %}</h4>
</div>
</div>
</div>

<div class="modal fade" style="width: 100%; height: 100%;" id="error_mandatoryDialog" data-backdrop="static" data-keyboard="false" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content panel-warning">
<div class="modal-header panel-heading">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "ERROR" %}</h4>
</div>
<div class="modal-body general_errors">
{% trans "Following items are required:" %}
<p id="general_errors"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
</div>
</div>
</div>
</div>

{% block body %}{% endblock body %}
{% block sidebar %}{% endblock sidebar %}
{% endblock body_outer %}
Expand Down
25 changes: 23 additions & 2 deletions geonode/templates/metadata_form_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@
$('#id_resource-group').change(onInputChange).change();
document.querySelector('select[name="resource-keywords"]').onchange=onInputChange

$( ':input[id*="id_tkeywords"][required]:visible').each( function () {
$('#' + this.id).change(onInputChange).change();
});

$('#id_resource-regions').change(onInputChange).change();
$('#id_resource-temporal_extent_end').on('blur', function() {$(this).change(onInputChange).change();})
$('#id_resource-temporal_extent_start').on('blur', function() {$(this).change(onInputChange).change();})
Expand Down Expand Up @@ -469,7 +473,7 @@
) {
$('#group_mandatoryDialog').modal();
} else {
$('#preview_pleaseWaitDialog').modal();
validateRequiredInput()
}
});

Expand All @@ -491,10 +495,27 @@
) {
$('#group_mandatoryDialog').modal();
} else {
$('#preview_pleaseWaitDialog').modal();
validateRequiredInput()
}
});

function validateRequiredInput() {
const required_inputs = $(':input[required]:visible')
var errors = []
$( ':input[required]:visible').each( function () {
if ( this.value.trim() == '' ) {
errors.push(this.id)
}
});
if (errors.length > 0) {
console.error("Following items are required: " + errors)
$(".general_errors").find("p").html(errors.join('<br>'));
$('#error_mandatoryDialog').modal();
} else {
$('#preview_pleaseWaitDialog').modal();
}
}

$('#btn_upd_md_done').click(function(){
if
( is_category_mandatory &&
Expand Down

0 comments on commit f2add03

Please sign in to comment.