diff --git a/qgis-app/models/templatetags/resources_utils.py b/qgis-app/models/templatetags/resources_utils.py index 0782f3f..68a88e0 100755 --- a/qgis-app/models/templatetags/resources_utils.py +++ b/qgis-app/models/templatetags/resources_utils.py @@ -95,4 +95,13 @@ def get_sustaining_members_section(): else: return "Section not found" except requests.RequestException as e: - return f"Error: {e}" \ No newline at end of file + return f"Error: {e}" + +@register.filter +def get_string_tags(tags): + """ + Get the string representation of tags + """ + if not tags: + return '' + return ', '.join([tag.name for tag in tags]) \ No newline at end of file diff --git a/qgis-app/static/js/resource_upload.js b/qgis-app/static/js/resource_upload.js index 3872646..7ca5985 100644 --- a/qgis-app/static/js/resource_upload.js +++ b/qgis-app/static/js/resource_upload.js @@ -5,13 +5,13 @@ let disableSubmit = () =>{ $("#licenseAgreed").prop('disabled', true); $("#licenseAgreed").removeClass() - $("#licenseAgreed").addClass("btn") + $("#licenseAgreed").addClass("button") } let enableSubmit = () => { $("#licenseAgreed").prop('disabled', false); $("#licenseAgreed").removeClass() - $("#licenseAgreed").addClass("btn btn-primary") + $("#licenseAgreed").addClass("button is-success") } // Disable submit button diff --git a/qgis-app/static/style/scss/style.scss b/qgis-app/static/style/scss/style.scss index c7df222..f0e6015 100644 --- a/qgis-app/static/style/scss/style.scss +++ b/qgis-app/static/style/scss/style.scss @@ -328,3 +328,11 @@ a.is-active > span { height: 16px; display:block; } + +#tag-suggestions { + position: absolute; + width: 100%; + z-index: 1; + max-height: 250px; + overflow: auto; +} diff --git a/qgis-app/templates/base/form_snippet.html b/qgis-app/templates/base/form_snippet.html index 313f989..84dda0f 100644 --- a/qgis-app/templates/base/form_snippet.html +++ b/qgis-app/templates/base/form_snippet.html @@ -1,156 +1,217 @@ {% load i18n resources_custom_tags resources_utils %} -
- {% for field in form %} -
- {% if field.field.widget|klass == 'CheckboxInput' %} +
+ {% for field in form %} +
+ {% if field.field.widget|klass == 'CheckboxInput' %} +
+ + {% if field.errors %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} + {% endif %} +
+ {% elif field.field.widget|klass == 'ClearableFileInput' %} +
+ +
+ {% if field.errors %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} + {% endif %} + {% elif field.field.widget|klass == 'Textarea' %} +
+
- - {% if field.errors %} - {% for error in field.errors %} -

{{ error }}

- {% endfor %} - {% endif %} +
- {% elif field.field.widget|klass == 'ClearableFileInput' %} -
- + {% if field.errors %} +

{{ field.errors }}

+ {% endif %} +
+ {% elif field.field.widget|klass == 'TextInput' or field.field.widget|klass == 'URLInput' %} +
+ +
+
{% if field.errors %} - {% for error in field.errors %} + {% for error in field.errors %}

{{ error }}

{% endfor %} - {% endif %} - {% elif field.field.widget|klass == 'Textarea' %} -
- -
- -
- {% if field.errors %} -

{{ field.errors }}

- {% endif %} -
- {% elif field.field.widget|klass == 'TextInput' or field.field.widget|klass == 'URLInput' %} -
- -
- -
- {% if field.errors %} - {% for error in field.errors %} -

{{ error }}

+ {% endif %} +
+ {% elif field.field.widget|klass == 'EmailInput' %} +
+ +
+ + + + +
+ {% if field.errors %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} + {% endif %} +
+ {% elif field.field.widget|klass == 'Select' %} +
+ +
+
+
- {% elif field.field.widget|klass == 'EmailInput' %} -
- -
- - - - -
- {% if field.errors %} - {% for error in field.errors %} -

{{ error }}

- {% endfor %} - {% endif %}
- {% elif field.field.widget|klass == 'Select' %} -
- -
-
- -
-
- {% if field.errors %} - {% for error in field.errors %} -

{{ error }}

- {% endfor %} - {% endif %} + {% if field.errors %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} + {% endif %} +
+ {% elif field.field.widget|klass == 'TagWidget' %} +
+ +
+
+ +
- {% else %} -
- -
- {{ field }} -
- {% if field.errors %} - {% for error in field.errors %} -

{{ error }}

- {% endfor %} - {% endif %} +
+ +
+
+ {% else %} +
+ +
+ {{ field }}
+ {% if field.errors %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} {% endif %} -
{{ field.help_text | safe }}
- {% endfor %} -
- - + + fileInput.on("change", function () { + if (fileInput[0].files.length > 0) { + fileName.text(fileInput[0].files[0].name); + } else { + fileName.text("Choose a file…"); + } + }); + + tagInput.on('input', function () { + const query = tagInput.val(); + + if (query.length > 1) { + $.ajax({ + url: `/taggit_autosuggest/list/?q=${query}`, + method: 'GET', + success: function (suggestions) { + // Clear previous suggestions + suggestionBox.empty(); + + // Display new suggestions + suggestions.forEach(tag => { + const tagElement = $('').addClass('dropdown-item').text(tag.name); + tagElement.on('click', function () { + addTag(tag.name); + }); + suggestionBox.append(tagElement); + }); + + // Add option to add new tag if no suggestions match + if (suggestions.length === 0) { + const addNewTagElement = $('').addClass('dropdown-item').text(`Add "${query}"`); + addNewTagElement.on('click', function () { + addTag(query); + }); + suggestionBox.append(addNewTagElement); + } + + suggestionBox.removeClass('is-hidden'); + } + }); + } else { + suggestionBox.addClass('is-hidden'); + } + }); + + function addTag(tagName) { + // Check if tag already exists + if (selectedTags.children().toArray().some(tag => $(tag).text().trim() === tagName)) return; + + // Add tag to selected tags + const tagEl = $('').addClass('tag is-info m-1').text(tagName); + + const deleteBtn = $('').addClass('delete is-small'); + deleteBtn.on('click', function () { + tagEl.remove(); + updateHiddenInput(); + }); + + tagEl.append(deleteBtn); + selectedTags.append(tagEl); + + // Clear suggestions and input + suggestionBox.addClass('is-hidden'); + tagInput.val(''); + + // Update hidden input + updateHiddenInput(); + } + + function updateHiddenInput() { + const tags = selectedTags.children().toArray().map(tag => $(tag).text().trim()); + hiddenInput.val(tags.join(',')); + } + }); + diff --git a/qgis-app/templates/base/update_form.html b/qgis-app/templates/base/update_form.html index 8861056..ba23179 100644 --- a/qgis-app/templates/base/update_form.html +++ b/qgis-app/templates/base/update_form.html @@ -1,49 +1,5 @@ {% extends "base/base.html" %}{% load i18n static%} -{% block extrajs %} -{{ block.super }} - - - - -{% endblock %} - {% block extracss %} {{ block.super }} @@ -83,11 +39,11 @@

{% trans "Update" %} {{ resource_name }}: {{ object.name

{% endif %} -
+ {% csrf_token %} {% include "base/form_snippet.html" %} -
-
{% endif %} - + {% csrf_token %} {% include "base/form_snippet.html" %} - -
+
+
+
- +
+
+ +
+