From d69067a00185afa26099cdf690a9b782e9e741b1 Mon Sep 17 00:00:00 2001 From: silvadealmeida Date: Tue, 6 Aug 2024 15:15:44 +0200 Subject: [PATCH 1/6] . --- geonode/base/models.py | 2 +- .../datasets/dataset_metadata_advanced.html | 29 ++-- geonode/layers/views.py | 34 ++++- .../static/geonode/js/utils/formsetsInTabs.js | 136 +++++++++++++----- geonode/static/geonode/js/utils/fundings_.js | 120 ++++++++++++++++ 5 files changed, 268 insertions(+), 53 deletions(-) create mode 100644 geonode/static/geonode/js/utils/fundings_.js diff --git a/geonode/base/models.py b/geonode/base/models.py index 858e25bbf29..b703a7c62de 100644 --- a/geonode/base/models.py +++ b/geonode/base/models.py @@ -700,7 +700,7 @@ def __str__(self): class Funder(models.Model): - funding_reference = models.ForeignKey(FundingReference, null=False, blank=False, on_delete=models.CASCADE) + funding_reference = models.ForeignKey(FundingReference, null=True, blank=True, on_delete=models.CASCADE) award_number = models.CharField( max_length=255, help_text=_("The code assigned by the funder to a sponsored award (grant). (e.g. 282625)") ) diff --git a/geonode/layers/templates/datasets/dataset_metadata_advanced.html b/geonode/layers/templates/datasets/dataset_metadata_advanced.html index d1c4b202bce..569585c7162 100644 --- a/geonode/layers/templates/datasets/dataset_metadata_advanced.html +++ b/geonode/layers/templates/datasets/dataset_metadata_advanced.html @@ -129,11 +129,9 @@

{% trans "Edit Metadata" %}

{% block funder_form %} +
{{funder_form.management_form }}
- - -
@@ -144,25 +142,25 @@

{% trans "Edit Metadata" %}

{% else %}
  • {{ forloop.counter }} -
  • {% endif %} {%endfor%} @@ -234,9 +232,21 @@

    {% trans "Edit Metadata" %}

    - + + {% endblock funder_form %} + {% block related_identifier_form %} + +
    + ============ FORM ============ +
    + {% comment %} {{related_identifier_form.management_form }} + {% for form in related_identifier_form %} + {{form.as_p}} + {% endfor %} {% endcomment %} + + {% endblock related_identifier_form %} @@ -377,8 +387,9 @@ }); + {% comment %} {% endcomment %} {% endblock %} \ No newline at end of file diff --git a/geonode/layers/views.py b/geonode/layers/views.py index b5ed1a52584..b180fe70f7c 100644 --- a/geonode/layers/views.py +++ b/geonode/layers/views.py @@ -53,7 +53,7 @@ from geonode.base.auth import get_or_create_token from geonode.base.forms import CategoryForm, TKeywordForm, ThesaurusAvailableForm from geonode.base.views import batch_modify -from geonode.base.models import Thesaurus, TopicCategory, Funder +from geonode.base.models import Thesaurus, TopicCategory, Funder, RelatedIdentifier from geonode.base.enumerations import CHARSETS from geonode.decorators import check_keyword_write_perms from geonode.layers.forms import DatasetForm, DatasetTimeSerieForm, LayerAttributeForm, NewLayerUploadForm @@ -363,6 +363,14 @@ def dataset_metadata( extra=0, min_num=1, ) + + RelatedIdentifierFormset = modelformset_factory( + RelatedIdentifier, + fields=["related_identifier", "related_identifier_type", "relation_type"], + can_delete=True, + extra=0, + min_num=1, + ) current_keywords = [keyword.name for keyword in layer.keywords.all()] topic_category = layer.category @@ -419,10 +427,15 @@ def dataset_metadata( "errors": [re.sub(re.compile("<.*?>"), "", str(err)) for err in attribute_form.errors], } return HttpResponse(json.dumps(out), content_type="application/json", status=400) - funders_intial_values = Funder.objects.all().filter(resourcebase=layer) + funder_form = FunderFormset( request.POST, - prefix="funder_form", + prefix="form_funder", + ) + + related_identifier_form = RelatedIdentifierFormset( + request.POST, + prefix="related_identifier_form", ) category_form = CategoryForm( request.POST, @@ -483,7 +496,13 @@ def dataset_metadata( ) funders_intial_values = Funder.objects.all().filter(resourcebase=layer) - funder_form = FunderFormset(prefix="funder_form", queryset=funders_intial_values) + funder_form = FunderFormset(prefix="form_funder", queryset=funders_intial_values) + + related_identifier_intial_values = RelatedIdentifier.objects.all().filter(resourcebase=layer) + related_identifier_form = RelatedIdentifierFormset( + prefix="related_identifier_form", queryset=related_identifier_intial_values + ) + category_form = CategoryForm( prefix="category_choice_field", initial=topic_category.id if topic_category else None ) @@ -555,6 +574,7 @@ def dataset_metadata( and dataset_form.is_valid() and attribute_form.is_valid() and funder_form.is_valid() + # and related_identifier_form.is_valid() and category_form.is_valid() and tkeywords_form.is_valid() and timeseries_form.is_valid() @@ -581,6 +601,11 @@ def dataset_metadata( funder_form.save() instance = funder_form.save(commit=False) layer.funders.add(*instance) + + related_identifier_form.save() + instance = related_identifier_form.save(commit=False) + layer.related_identifier.add(*instance) + layer.save() new_keywords = current_keywords if request.keyword_readonly else dataset_form.cleaned_data["keywords"] @@ -694,6 +719,7 @@ def dataset_metadata( "attribute_form": attribute_form, "timeseries_form": timeseries_form, "funder_form": funder_form, + "form_related_identifier": related_identifier_form, "category_form": category_form, "tkeywords_form": tkeywords_form, "preview": getattr(settings, "GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY", "mapstore"), diff --git a/geonode/static/geonode/js/utils/formsetsInTabs.js b/geonode/static/geonode/js/utils/formsetsInTabs.js index 5b78f4ac0be..ae8bf24b378 100644 --- a/geonode/static/geonode/js/utils/formsetsInTabs.js +++ b/geonode/static/geonode/js/utils/formsetsInTabs.js @@ -1,38 +1,82 @@ +console.log('carregado') -let totalForms = $('#id_' + prefix + '-TOTAL_FORMS').val(); -let initialForms = $('#id_' + prefix + '-INITIAL_FORMS').val(); -let maxForms = $('#id_' + prefix + '-MAX_NUM_FORMS').val(); -let minForms = $('#id_' + prefix + '-MIN_NUM_FORMS').val(); -let deleteInput = $("#id_FORM-xx-DELETE") -let hiddenInput = $("#id_FORM-xx-id") -let allDelete = $('#DELETE') +for (let name of formsetsInTabs) { -let actualForms = totalForms + form = $('#' + name) + console.log(form) + console.log("acima") -let templateTab = $('.templateTab') -let templateContent = $('.templateContent') -let allTabs = $('.allTabs') -let allforms = $('.allContent') + reOrder(form) + hideDeleteCheckbox(form) +} + + +function dataForm(form) { + instance = form.attr('id') + console.log(instance) + totalForms = $('#id_' + instance + '-TOTAL_FORMS').val(); + initialForms = $('#id_' + instance + '-INITIAL_FORMS').val(); + maxForms = $('#id_' + instance + '-MAX_NUM_FORMS').val(); + minForms = $('#id_' + instance + '-MIN_NUM_FORMS').val(); + + allDelete = form.find('#DELETE') + + actualForms = totalForms + + templateTab = form.find('.templateTab') + templateContent = form.find('.templateContent') + allTabs = form.find('.allTabs') + allForms = form.find('.allContent') + + + + return { + totalForms, + initialForms, + maxForms, + minForms, + allDelete, + actualForms, + templateTab, + templateContent, + allTabs, + allForms, + } +} -reOrder() -hideDeleteCheckbox() -$("#nav-add").on("click", function () { + +// let totalForms = activeForm.totalForms +// let initialForms = activeForm.initialForms +// let maxForms = activeForm.maxForms +// let minForms = activeForm.minForms + + + + +function addNewTab(element) { + button = $("#" + element.id) + form = button.closest("div[id^=form]") + infosForm = dataForm(form) + prefix = form.attr("id") + actualForms = infosForm.actualForms label = Number(actualForms) + 1 - removeActive() - newTab = templateTab.clone(true).removeClass('hidden') + removeActive(form) + newTab = infosForm.templateTab.clone(true).removeClass('hidden') + console.log(newTab) newTab.removeClass('templateTab').removeClass('nav-empty') newTab.attr('id', '') newTab.find('a').attr('href', '#' + prefix + '-' + actualForms) newTab.attr('aria-controls', prefix + '-' + actualForms) newTab.find('.newTabTex').text(label) newTab.find('.newTabTex').addClass('tabTex').removeClass('newTabTex') - newTab.insertBefore($('.li-add')) - newTab.addClass('active') + newTab.insertBefore(form.find('.li-add')) + newTab.addClass('active') + templateContent = infosForm.templateContent newContent = templateContent.clone(true).removeClass('hidden') newContent.removeClass('templateContent').removeClass('nav-empty') newContent.attr('id', prefix + '-' + actualForms) @@ -42,17 +86,25 @@ $("#nav-add").on("click", function () { $(this).attr('name', $(this).attr('name').replace("__prefix__", actualForms)) $(this).attr('id', $(this).attr('id').replace("__prefix__", actualForms)) }) - newContent.insertBefore($('.templateContent')) + newContent.insertBefore(form.find('.templateContent')) actualForms++ $('#id_' + prefix + '-TOTAL_FORMS').attr("value", actualForms) -}); +}; -$(".nav-remove").on("click", function () { - removeActive() - number = $(this).parent('a').attr('href').split('-')[1] - tabToRemove = $(this).parent('a').parent('li') +function removeTab(element) { + + element = $(element) + form = element.closest("div[id^=form]") + console.log(form.attr("id")) + infosForm = dataForm(form) + prefix = form.attr("id") + actualForms = infosForm.actualForms + removeActive(form) + console.log(element[0]) + number = element.parent('a').attr('href').split('-')[1] + tabToRemove = element.parent('a').parent('li') tabToRemove.remove() contentToRemove = $('#' + prefix + '-' + number) @@ -61,19 +113,25 @@ $(".nav-remove").on("click", function () { toDjango = contentToRemove.children('div') toDjango.hide().insertAfter(templateContent) contentToRemove.remove() - $('.allContent').find('.tab-pane').first().addClass('active') - $('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) - reOrder() + form.find('.allContent').find('.tab-pane').first().addClass('active') + form.find('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) + reOrder(form) actualForms-- + console.log(actualForms) + console.log(prefix) + $('#id_' + prefix + '-TOTAL_FORMS').attr("value", actualForms) -}); +}; -function reOrder() { +function reOrder(form) { + console.log(form[0]) + prefix = form.attr("id") + console.log(prefix) counter = 0 - $('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) + form.find('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) - $('.allTabs').find('li a').each( + form.find('.allTabs').find('li a').each( function () { $(this).attr('href', '#' + prefix + '-' + counter) $(this).attr('aria-controls', prefix + '-' + counter) @@ -84,7 +142,7 @@ function reOrder() { ) counterCont = 0 - $('.allContent').find('.tab-pane').each( + form.find('.allContent').find('.tab-pane').each( function () { if ($(this).attr('id') != 'templateContent') { $(this).attr('id', prefix + '-' + counterCont) @@ -100,13 +158,13 @@ function reOrder() { } -function removeActive() { - $('.allTabs').find('li').each( +function removeActive(form) { + form.find('.allTabs').find('li').each( function () { $(this).removeClass('active') $(this).find('a').attr('aria-expanded', false) }) - $('.allContent').find('.tab-pane').each( + form.find('.allContent').find('.tab-pane').each( function () { $(this).removeClass('active') @@ -114,7 +172,7 @@ function removeActive() { } -function hideDeleteCheckbox() { - allforms.find('#DELETE').hide() - allforms.find('#DELETE').prev().hide() +function hideDeleteCheckbox(form) { + form.find('.allContent').find('#DELETE').hide() + form.find('.allContent').find('#DELETE').prev().hide() } diff --git a/geonode/static/geonode/js/utils/fundings_.js b/geonode/static/geonode/js/utils/fundings_.js new file mode 100644 index 00000000000..5b78f4ac0be --- /dev/null +++ b/geonode/static/geonode/js/utils/fundings_.js @@ -0,0 +1,120 @@ + + +let totalForms = $('#id_' + prefix + '-TOTAL_FORMS').val(); +let initialForms = $('#id_' + prefix + '-INITIAL_FORMS').val(); +let maxForms = $('#id_' + prefix + '-MAX_NUM_FORMS').val(); +let minForms = $('#id_' + prefix + '-MIN_NUM_FORMS').val(); +let deleteInput = $("#id_FORM-xx-DELETE") +let hiddenInput = $("#id_FORM-xx-id") + +let allDelete = $('#DELETE') + +let actualForms = totalForms + +let templateTab = $('.templateTab') +let templateContent = $('.templateContent') +let allTabs = $('.allTabs') +let allforms = $('.allContent') + +reOrder() +hideDeleteCheckbox() + +$("#nav-add").on("click", function () { + label = Number(actualForms) + 1 + removeActive() + newTab = templateTab.clone(true).removeClass('hidden') + newTab.removeClass('templateTab').removeClass('nav-empty') + newTab.attr('id', '') + newTab.find('a').attr('href', '#' + prefix + '-' + actualForms) + newTab.attr('aria-controls', prefix + '-' + actualForms) + newTab.find('.newTabTex').text(label) + newTab.find('.newTabTex').addClass('tabTex').removeClass('newTabTex') + newTab.insertBefore($('.li-add')) + newTab.addClass('active') + + + newContent = templateContent.clone(true).removeClass('hidden') + newContent.removeClass('templateContent').removeClass('nav-empty') + newContent.attr('id', prefix + '-' + actualForms) + newContent.addClass('in active') + newContent.find('select, input').each( + function () { + $(this).attr('name', $(this).attr('name').replace("__prefix__", actualForms)) + $(this).attr('id', $(this).attr('id').replace("__prefix__", actualForms)) + }) + newContent.insertBefore($('.templateContent')) + + actualForms++ + $('#id_' + prefix + '-TOTAL_FORMS').attr("value", actualForms) +}); + + +$(".nav-remove").on("click", function () { + removeActive() + number = $(this).parent('a').attr('href').split('-')[1] + tabToRemove = $(this).parent('a').parent('li') + + tabToRemove.remove() + contentToRemove = $('#' + prefix + '-' + number) + contentToRemove.find('#DELETE input').prop("checked", true) + contentToRemove.removeAttr('role') + toDjango = contentToRemove.children('div') + toDjango.hide().insertAfter(templateContent) + contentToRemove.remove() + $('.allContent').find('.tab-pane').first().addClass('active') + $('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) + reOrder() + actualForms-- + + +}); + +function reOrder() { + counter = 0 + $('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) + + $('.allTabs').find('li a').each( + function () { + $(this).attr('href', '#' + prefix + '-' + counter) + $(this).attr('aria-controls', prefix + '-' + counter) + counterLabel = counter + 1 + $(this).find('.tabTex').text(counterLabel) + counter++ + } + ) + + counterCont = 0 + $('.allContent').find('.tab-pane').each( + function () { + if ($(this).attr('id') != 'templateContent') { + $(this).attr('id', prefix + '-' + counterCont) + $(this).find('#DELETE').find('input').attr('id', 'id_' + prefix + '-' + counterCont + '-DELETE') + $(this).find('#DELETE').find('input').attr('name', prefix + '-' + counterCont + '-DELETE') + $(this).find('div div:last').find('input').attr('id', 'id_' + prefix + '-' + counterCont + '-id') + $(this).find('div div:last').find('input').attr('name', prefix + '-' + counterCont + '-id') + counterCont++ + } + + } + ) + +} + +function removeActive() { + $('.allTabs').find('li').each( + function () { + $(this).removeClass('active') + $(this).find('a').attr('aria-expanded', false) + }) + $('.allContent').find('.tab-pane').each( + function () { + + $(this).removeClass('active') + }) + +} + +function hideDeleteCheckbox() { + allforms.find('#DELETE').hide() + allforms.find('#DELETE').prev().hide() +} From 2ebc3d435b7c2865e99fbf5e4a95ff511b7681ae Mon Sep 17 00:00:00 2001 From: silvadealmeida Date: Tue, 6 Aug 2024 16:21:09 +0200 Subject: [PATCH 2/6] . --- geonode/base/models.py | 17 +++++++++++--- geonode/layers/views.py | 2 ++ .../static/geonode/js/utils/formsetsInTabs.js | 23 +++++++++++-------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/geonode/base/models.py b/geonode/base/models.py index b703a7c62de..9429a335384 100644 --- a/geonode/base/models.py +++ b/geonode/base/models.py @@ -685,15 +685,19 @@ class FundingReference(models.Model): """Funding Reference Identifiers""" funder_name = models.CharField( - max_length=255, help_text=_("Name of the funding provider. (e.g. European Commission)") + blank=True, null=True, max_length=255, help_text=_("Name of the funding provider. (e.g. European Commission)") ) funder_identifier = models.CharField( + blank=True, + null=True, max_length=255, help_text=_( "Uniquely identifies a funding entity, according to various types. (e.g. http://doi.org/10.13039/501100000780)" ), ) - funder_identifier_type = models.CharField(max_length=255, help_text=_("The type of the Identifier. (e.g. BMBF)")) + funder_identifier_type = models.CharField( + blank=True, null=True, max_length=255, help_text=_("The type of the Identifier. (e.g. BMBF)") + ) def __str__(self): return f"{self.funder_name}" @@ -702,15 +706,22 @@ def __str__(self): class Funder(models.Model): funding_reference = models.ForeignKey(FundingReference, null=True, blank=True, on_delete=models.CASCADE) award_number = models.CharField( - max_length=255, help_text=_("The code assigned by the funder to a sponsored award (grant). (e.g. 282625)") + blank=True, + null=True, + max_length=255, + help_text=_("The code assigned by the funder to a sponsored award (grant). (e.g. 282625)"), ) award_uri = models.CharField( + blank=True, + null=True, max_length=255, help_text=_( "The URI leading to a page provided by the funder for more information about the award (grant). (e.g. http://cordis.europa.eu/project/rcn/100180_en.html)" ), ) award_title = models.CharField( + blank=True, + null=True, max_length=255, help_text=_( "The human readable title of the award (grant). (e.g. MOTivational strength of ecosystem services)" diff --git a/geonode/layers/views.py b/geonode/layers/views.py index b180fe70f7c..3821e5d67dd 100644 --- a/geonode/layers/views.py +++ b/geonode/layers/views.py @@ -600,6 +600,8 @@ def dataset_metadata( layer.set_contact_roles_from_metadata_edit(dataset_form) funder_form.save() instance = funder_form.save(commit=False) + + print(funder_form.deleted_forms) layer.funders.add(*instance) related_identifier_form.save() diff --git a/geonode/static/geonode/js/utils/formsetsInTabs.js b/geonode/static/geonode/js/utils/formsetsInTabs.js index ae8bf24b378..346b6938df9 100644 --- a/geonode/static/geonode/js/utils/formsetsInTabs.js +++ b/geonode/static/geonode/js/utils/formsetsInTabs.js @@ -9,7 +9,7 @@ for (let name of formsetsInTabs) { console.log("acima") reOrder(form) - hideDeleteCheckbox(form) + // hideDeleteCheckbox(form) } @@ -107,19 +107,20 @@ function removeTab(element) { tabToRemove = element.parent('a').parent('li') tabToRemove.remove() - contentToRemove = $('#' + prefix + '-' + number) + contentToRemove = form.find('#' + prefix + '-' + number) + console.log(contentToRemove[0]) + console.log("para remover") contentToRemove.find('#DELETE input').prop("checked", true) + console.log(contentToRemove.find('#DELETE input').prop("checked")) contentToRemove.removeAttr('role') - toDjango = contentToRemove.children('div') - toDjango.hide().insertAfter(templateContent) - contentToRemove.remove() + toDjango = contentToRemove + toDjango.hide().detach().insertAfter(form.find('.templateContent')) + // contentToRemove.remove() form.find('.allContent').find('.tab-pane').first().addClass('active') form.find('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) reOrder(form) actualForms-- - console.log(actualForms) - console.log(prefix) - $('#id_' + prefix + '-TOTAL_FORMS').attr("value", actualForms) + form.find('#id_' + prefix + '-TOTAL_FORMS').attr("value", actualForms) }; @@ -129,7 +130,7 @@ function reOrder(form) { prefix = form.attr("id") console.log(prefix) counter = 0 - form.find('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) + form.find('.allTabs').find('li a').each( function () { @@ -157,6 +158,10 @@ function reOrder(form) { ) } +form.find('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) +#TODO +form.find('tab-content').find('.tab-pane').removeClassClass('active') +form.find('tab-content').find('.tab-pane:first').addClass('active') function removeActive(form) { form.find('.allTabs').find('li').each( From 41b28623bc314b4849a7fb9d95757a4eac428f40 Mon Sep 17 00:00:00 2001 From: silvadealmeida Date: Wed, 7 Aug 2024 13:00:12 +0200 Subject: [PATCH 3/6] . --- .../datasets/dataset_metadata_advanced.html | 116 +++++++++++++++-- geonode/layers/views.py | 8 +- .../static/geonode/js/utils/formsetsInTabs.js | 45 ++----- geonode/static/geonode/js/utils/fundings_.js | 120 ------------------ 4 files changed, 124 insertions(+), 165 deletions(-) delete mode 100644 geonode/static/geonode/js/utils/fundings_.js diff --git a/geonode/layers/templates/datasets/dataset_metadata_advanced.html b/geonode/layers/templates/datasets/dataset_metadata_advanced.html index 569585c7162..be512acfea4 100644 --- a/geonode/layers/templates/datasets/dataset_metadata_advanced.html +++ b/geonode/layers/templates/datasets/dataset_metadata_advanced.html @@ -238,13 +238,111 @@

    {% trans "Edit Metadata" %}

    {% block related_identifier_form %} -
    - ============ FORM ============ -
    - {% comment %} {{related_identifier_form.management_form }} - {% for form in related_identifier_form %} - {{form.as_p}} - {% endfor %} {% endcomment %} + {% endblock related_identifier_form %} @@ -387,9 +485,9 @@ }); - {% comment %} {% endcomment %} + {% comment %} {% endcomment %} {% endblock %} \ No newline at end of file diff --git a/geonode/layers/views.py b/geonode/layers/views.py index 3821e5d67dd..f11a3c0bf1c 100644 --- a/geonode/layers/views.py +++ b/geonode/layers/views.py @@ -435,7 +435,7 @@ def dataset_metadata( related_identifier_form = RelatedIdentifierFormset( request.POST, - prefix="related_identifier_form", + prefix="form_related_identifier", ) category_form = CategoryForm( request.POST, @@ -500,7 +500,7 @@ def dataset_metadata( related_identifier_intial_values = RelatedIdentifier.objects.all().filter(resourcebase=layer) related_identifier_form = RelatedIdentifierFormset( - prefix="related_identifier_form", queryset=related_identifier_intial_values + prefix="form_related_identifier", queryset=related_identifier_intial_values ) category_form = CategoryForm( @@ -574,7 +574,7 @@ def dataset_metadata( and dataset_form.is_valid() and attribute_form.is_valid() and funder_form.is_valid() - # and related_identifier_form.is_valid() + and related_identifier_form.is_valid() and category_form.is_valid() and tkeywords_form.is_valid() and timeseries_form.is_valid() @@ -721,7 +721,7 @@ def dataset_metadata( "attribute_form": attribute_form, "timeseries_form": timeseries_form, "funder_form": funder_form, - "form_related_identifier": related_identifier_form, + "related_identifier_form": related_identifier_form, "category_form": category_form, "tkeywords_form": tkeywords_form, "preview": getattr(settings, "GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY", "mapstore"), diff --git a/geonode/static/geonode/js/utils/formsetsInTabs.js b/geonode/static/geonode/js/utils/formsetsInTabs.js index 346b6938df9..d3809bd2460 100644 --- a/geonode/static/geonode/js/utils/formsetsInTabs.js +++ b/geonode/static/geonode/js/utils/formsetsInTabs.js @@ -1,21 +1,14 @@ -console.log('carregado') - - for (let name of formsetsInTabs) { form = $('#' + name) - console.log(form) - console.log("acima") - reOrder(form) - // hideDeleteCheckbox(form) + hideDeleteCheckbox(form) } function dataForm(form) { instance = form.attr('id') - console.log(instance) totalForms = $('#id_' + instance + '-TOTAL_FORMS').val(); initialForms = $('#id_' + instance + '-INITIAL_FORMS').val(); maxForms = $('#id_' + instance + '-MAX_NUM_FORMS').val(); @@ -48,14 +41,6 @@ function dataForm(form) { -// let totalForms = activeForm.totalForms -// let initialForms = activeForm.initialForms -// let maxForms = activeForm.maxForms -// let minForms = activeForm.minForms - - - - function addNewTab(element) { button = $("#" + element.id) form = button.closest("div[id^=form]") @@ -65,7 +50,6 @@ function addNewTab(element) { label = Number(actualForms) + 1 removeActive(form) newTab = infosForm.templateTab.clone(true).removeClass('hidden') - console.log(newTab) newTab.removeClass('templateTab').removeClass('nav-empty') newTab.attr('id', '') newTab.find('a').attr('href', '#' + prefix + '-' + actualForms) @@ -94,41 +78,38 @@ function addNewTab(element) { function removeTab(element) { - + removeActive(form) element = $(element) form = element.closest("div[id^=form]") - console.log(form.attr("id")) infosForm = dataForm(form) prefix = form.attr("id") actualForms = infosForm.actualForms - removeActive(form) - console.log(element[0]) + number = element.parent('a').attr('href').split('-')[1] tabToRemove = element.parent('a').parent('li') tabToRemove.remove() contentToRemove = form.find('#' + prefix + '-' + number) - console.log(contentToRemove[0]) - console.log("para remover") - contentToRemove.find('#DELETE input').prop("checked", true) - console.log(contentToRemove.find('#DELETE input').prop("checked")) + contentToRemove.find('#DELETE input') contentToRemove.removeAttr('role') - toDjango = contentToRemove - toDjango.hide().detach().insertAfter(form.find('.templateContent')) - // contentToRemove.remove() + toDjango = contentToRemove.children('div') + template = form.find('.templateContent') + toDjango.hide().insertAfter(template).find('#DELETE input').prop("checked", true) + contentToRemove.remove() + form.find('.allContent').find('.tab-pane').first().addClass('active') form.find('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) reOrder(form) actualForms-- - form.find('#id_' + prefix + '-TOTAL_FORMS').attr("value", actualForms) + return + + }; function reOrder(form) { - console.log(form[0]) prefix = form.attr("id") - console.log(prefix) counter = 0 @@ -159,7 +140,7 @@ function reOrder(form) { } form.find('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) -#TODO + form.find('tab-content').find('.tab-pane').removeClassClass('active') form.find('tab-content').find('.tab-pane:first').addClass('active') diff --git a/geonode/static/geonode/js/utils/fundings_.js b/geonode/static/geonode/js/utils/fundings_.js deleted file mode 100644 index 5b78f4ac0be..00000000000 --- a/geonode/static/geonode/js/utils/fundings_.js +++ /dev/null @@ -1,120 +0,0 @@ - - -let totalForms = $('#id_' + prefix + '-TOTAL_FORMS').val(); -let initialForms = $('#id_' + prefix + '-INITIAL_FORMS').val(); -let maxForms = $('#id_' + prefix + '-MAX_NUM_FORMS').val(); -let minForms = $('#id_' + prefix + '-MIN_NUM_FORMS').val(); -let deleteInput = $("#id_FORM-xx-DELETE") -let hiddenInput = $("#id_FORM-xx-id") - -let allDelete = $('#DELETE') - -let actualForms = totalForms - -let templateTab = $('.templateTab') -let templateContent = $('.templateContent') -let allTabs = $('.allTabs') -let allforms = $('.allContent') - -reOrder() -hideDeleteCheckbox() - -$("#nav-add").on("click", function () { - label = Number(actualForms) + 1 - removeActive() - newTab = templateTab.clone(true).removeClass('hidden') - newTab.removeClass('templateTab').removeClass('nav-empty') - newTab.attr('id', '') - newTab.find('a').attr('href', '#' + prefix + '-' + actualForms) - newTab.attr('aria-controls', prefix + '-' + actualForms) - newTab.find('.newTabTex').text(label) - newTab.find('.newTabTex').addClass('tabTex').removeClass('newTabTex') - newTab.insertBefore($('.li-add')) - newTab.addClass('active') - - - newContent = templateContent.clone(true).removeClass('hidden') - newContent.removeClass('templateContent').removeClass('nav-empty') - newContent.attr('id', prefix + '-' + actualForms) - newContent.addClass('in active') - newContent.find('select, input').each( - function () { - $(this).attr('name', $(this).attr('name').replace("__prefix__", actualForms)) - $(this).attr('id', $(this).attr('id').replace("__prefix__", actualForms)) - }) - newContent.insertBefore($('.templateContent')) - - actualForms++ - $('#id_' + prefix + '-TOTAL_FORMS').attr("value", actualForms) -}); - - -$(".nav-remove").on("click", function () { - removeActive() - number = $(this).parent('a').attr('href').split('-')[1] - tabToRemove = $(this).parent('a').parent('li') - - tabToRemove.remove() - contentToRemove = $('#' + prefix + '-' + number) - contentToRemove.find('#DELETE input').prop("checked", true) - contentToRemove.removeAttr('role') - toDjango = contentToRemove.children('div') - toDjango.hide().insertAfter(templateContent) - contentToRemove.remove() - $('.allContent').find('.tab-pane').first().addClass('active') - $('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) - reOrder() - actualForms-- - - -}); - -function reOrder() { - counter = 0 - $('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) - - $('.allTabs').find('li a').each( - function () { - $(this).attr('href', '#' + prefix + '-' + counter) - $(this).attr('aria-controls', prefix + '-' + counter) - counterLabel = counter + 1 - $(this).find('.tabTex').text(counterLabel) - counter++ - } - ) - - counterCont = 0 - $('.allContent').find('.tab-pane').each( - function () { - if ($(this).attr('id') != 'templateContent') { - $(this).attr('id', prefix + '-' + counterCont) - $(this).find('#DELETE').find('input').attr('id', 'id_' + prefix + '-' + counterCont + '-DELETE') - $(this).find('#DELETE').find('input').attr('name', prefix + '-' + counterCont + '-DELETE') - $(this).find('div div:last').find('input').attr('id', 'id_' + prefix + '-' + counterCont + '-id') - $(this).find('div div:last').find('input').attr('name', prefix + '-' + counterCont + '-id') - counterCont++ - } - - } - ) - -} - -function removeActive() { - $('.allTabs').find('li').each( - function () { - $(this).removeClass('active') - $(this).find('a').attr('aria-expanded', false) - }) - $('.allContent').find('.tab-pane').each( - function () { - - $(this).removeClass('active') - }) - -} - -function hideDeleteCheckbox() { - allforms.find('#DELETE').hide() - allforms.find('#DELETE').prev().hide() -} From b92068c9cb961e160eed48956fc9c0b7651cdc95 Mon Sep 17 00:00:00 2001 From: silvadealmeida Date: Wed, 7 Aug 2024 13:13:16 +0200 Subject: [PATCH 4/6] . --- geonode/static/geonode/js/utils/formsetsInTabs.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/geonode/static/geonode/js/utils/formsetsInTabs.js b/geonode/static/geonode/js/utils/formsetsInTabs.js index d3809bd2460..f494f2e3759 100644 --- a/geonode/static/geonode/js/utils/formsetsInTabs.js +++ b/geonode/static/geonode/js/utils/formsetsInTabs.js @@ -43,7 +43,9 @@ function dataForm(form) { function addNewTab(element) { button = $("#" + element.id) - form = button.closest("div[id^=form]") + console.log($(element)) + form = $(element).closest("div[id^='form']") + console.log(form) infosForm = dataForm(form) prefix = form.attr("id") actualForms = infosForm.actualForms @@ -141,7 +143,7 @@ function reOrder(form) { } form.find('.allTabs').find('li:first').addClass('active').find('a').attr('aria-expanded', true) -form.find('tab-content').find('.tab-pane').removeClassClass('active') +form.find('tab-content').find('.tab-pane').removeClass('active') form.find('tab-content').find('.tab-pane:first').addClass('active') function removeActive(form) { From 5d6032f0434fe4d8a9a56515bcaa7af83f9ef3ba Mon Sep 17 00:00:00 2001 From: silvadealmeida Date: Wed, 7 Aug 2024 13:27:13 +0200 Subject: [PATCH 5/6] . --- geonode/base/forms.py | 1 + geonode/base/models.py | 11 ++++++----- geonode/layers/views.py | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/geonode/base/forms.py b/geonode/base/forms.py index 62bc078506a..f9292102122 100644 --- a/geonode/base/forms.py +++ b/geonode/base/forms.py @@ -740,6 +740,7 @@ class Meta: "was_approved", "was_published", "funders", + "related_identifier", ) diff --git a/geonode/base/models.py b/geonode/base/models.py index 9429a335384..a377b951d57 100644 --- a/geonode/base/models.py +++ b/geonode/base/models.py @@ -671,9 +671,8 @@ def __str__(self): class RelatedIdentifier(models.Model): - related_identifier = models.CharField( - max_length=255, help_text=_("Identifiers of related resources. These must be globally unique identifiers.") - ) + related_identifer_help_text = _("Identifiers of related resources. These must be globally unique identifiers.") + related_identifier = models.CharField(max_length=255, help_text=related_identifer_help_text) related_identifier_type = models.ForeignKey(RelatedIdentifierType, on_delete=models.CASCADE) relation_type = models.ForeignKey(RelationType, on_delete=models.CASCADE) @@ -704,12 +703,14 @@ def __str__(self): class Funder(models.Model): + funders_help_text = _("List of funders, funded dataset creators") + funding_reference = models.ForeignKey(FundingReference, null=True, blank=True, on_delete=models.CASCADE) award_number = models.CharField( blank=True, null=True, max_length=255, - help_text=_("The code assigned by the funder to a sponsored award (grant). (e.g. 282625)"), + help_text=funders_help_text, ) award_uri = models.CharField( blank=True, @@ -1148,7 +1149,7 @@ class ResourceBase(PolymorphicModel, PermissionLevelMixin, ItemBase): Funder, verbose_name=_("Funder names"), null=True, blank=True, help_text=funders_help_text ) related_projects = models.ManyToManyField( - RelatedProject, verbose_name=_("related project"), null=True, blank=True, help_text=related_projects_help_text + RelatedProject, verbose_name=_("Related project"), null=True, blank=True, help_text=related_projects_help_text ) use_contraints = models.TextField( diff --git a/geonode/layers/views.py b/geonode/layers/views.py index f11a3c0bf1c..0a8f5c36c4e 100644 --- a/geonode/layers/views.py +++ b/geonode/layers/views.py @@ -601,7 +601,6 @@ def dataset_metadata( funder_form.save() instance = funder_form.save(commit=False) - print(funder_form.deleted_forms) layer.funders.add(*instance) related_identifier_form.save() From d132460711bf24dcc4f839e88e6a7b8ac6cc0503 Mon Sep 17 00:00:00 2001 From: silvadealmeida Date: Wed, 7 Aug 2024 13:27:58 +0200 Subject: [PATCH 6/6] . --- geonode/static/geonode/js/utils/formsetsInTabs.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/geonode/static/geonode/js/utils/formsetsInTabs.js b/geonode/static/geonode/js/utils/formsetsInTabs.js index f494f2e3759..8be8629a2c1 100644 --- a/geonode/static/geonode/js/utils/formsetsInTabs.js +++ b/geonode/static/geonode/js/utils/formsetsInTabs.js @@ -43,9 +43,7 @@ function dataForm(form) { function addNewTab(element) { button = $("#" + element.id) - console.log($(element)) form = $(element).closest("div[id^='form']") - console.log(form) infosForm = dataForm(form) prefix = form.attr("id") actualForms = infosForm.actualForms