Skip to content

Commit

Permalink
Merge branch 'maintenance/clean-up-js-files' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
frjo committed Jan 9, 2025
2 parents 9156fca + 1182ad3 commit 395d36f
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ <h2>{{ value }}</h2>
{% endblock %}

{% block extra_js %}
{{ form.media.js }}
{{ field_blocks_ids|json_script:"block-ids" }}
<script src="{% static 'js/determination-template.js' %}"></script>
{% endblock %}
3 changes: 1 addition & 2 deletions hypha/apply/funds/templates/funds/application_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h3>{% blocktrans %}Sorry this {{ page|verbose_name }} is not accepting applicat
{% endif %}
{% endfor %}

{# Hidden fields needed e.g. for django-file-form. See `StreamBaseForm.hidden_fields` #}
{# Hidden fields needed e.g. for django-file-form. See `StreamBaseForm.hidden_fields` #}
{% for hidden_field in form.hidden_fields %}
{{ hidden_field }}
{% endfor %}
Expand All @@ -85,7 +85,6 @@ <h3>{% blocktrans %}Sorry this {{ page|verbose_name }} is not accepting applicat
{% endblock %}

{% block extra_js %}
{{ form.media.js }}
<script src="{% static 'js/application-form.js' %}"></script>
<script src="{% static 'js/tinymce-word-count.js' %}"></script>
<script src="{% static 'js/submission-form-copy.js' %}"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% endif %}
{% endfor %}

{# Hidden fields needed e.g. for django-file-form. See `StreamBaseForm.hidden_fields` #}
{# Hidden fields needed e.g. for django-file-form. See `StreamBaseForm.hidden_fields` #}
{% for hidden_field in form.hidden_fields %}
{{ hidden_field }}
{% endfor %}
Expand All @@ -44,7 +44,6 @@
{% endblock %}

{% block extra_js %}
{{ form.media.js }}
<script src="{% static 'js/application-form.js' %}"></script>
<script src="{% static 'js/tinymce-word-count.js' %}"></script>
<script src="{% static 'js/multi-input-fields.js' %}"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
{% if action %}action="{{ action }}"{% endif %}
>
{% csrf_token %}
{{ form.media.js }}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
enctype="multipart/form-data"
>
{% csrf_token %}
{{ form.media.js }}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
hx-post="{{ request.path }}"
>
{% csrf_token %}
{{ form.media.js }}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
hx-post="{{ request.path }}"
>
{% csrf_token %}
{{ form.media.js }}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,3 @@
</div>
</div>
{% endblock %}

{% block extra_js %}
{{ form.media.js }}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
enctype="multipart/form-data"
>
{% csrf_token %}
{{ form.media.js }}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{% endif %}
{% endfor %}

{# Hidden fields needed e.g. for django-file-form. See `StreamBaseForm.hidden_fields` #}
{# Hidden fields needed e.g. for django-file-form. See `StreamBaseForm.hidden_fields` #}
{% for hidden_field in pf_form.hidden_fields %}
{{ hidden_field }}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@
</div>
</div>
{% endblock %}

{% block extra_js %}
{{ form.media.js }}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,5 @@
{% endblock %}

{% block extra_js %}
{{ form.media.js }}
<script src="{% static 'js/multi-input-fields.js' %}"></script>
{% endblock %}
1 change: 0 additions & 1 deletion hypha/apply/review/templates/review/review_edit_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,5 @@ <h2>{{ value }}</h2>
{% endblock %}

{% block extra_js %}
{{ form.media.js }}
<script src="{% static 'js/review-form-actions.js' %}"></script>
{% endblock %}
1 change: 0 additions & 1 deletion hypha/apply/review/templates/review/review_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@ <h2>{{ value }}</h2>
{% endblock %}

{% block extra_js %}
{{ form.media.js }}
<script src="{% static 'js/review-form-actions.js' %}"></script>
{% endblock %}
2 changes: 1 addition & 1 deletion hypha/apply/stream_forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def media(self):
]
},
js=[
static("file_form/file_form.js"),
static("file_form/file_form.min.js"),
static("js/file-uploads.js"),
],
)
Expand Down
30 changes: 17 additions & 13 deletions hypha/static_src/javascript/file-uploads.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
jQuery(function ($) {
// We use htmx.onLoad() so it will initilise file uploads in htmx dialogs.
htmx.onLoad(function () {
// Initialize django-file-form
$("form")
.get()
.forEach(function (form) {
// Prevent initialising it multiple times and run it for forms
// that have a `form_id` field added by django-file-form.
if (!form.initUploadFieldsDone && form.querySelector("[name=form_id]")) {
init(form);
form.initUploadFieldsDone = true;
}
});
document.querySelectorAll("form").forEach(function (form) {
// Prevent initializing it multiple times and run it for forms
// that have a `form_id` field added by django-file-form.
if (!form.initUploadFieldsDone && form.querySelector("[name=form_id]")) {
init(form);
form.initUploadFieldsDone = true;
}
});

/**
* Initialize django-file-form for a form.
* @param {object} form The form to initialize.
*/
function init(form) {
if ($(".form__group--file").length) {
if (document.querySelectorAll(".form__group--file").length) {
window.initUploadFields(form);

// Hide wrapper elements for hidden inputs added by django-file-form
$("input[type=hidden]").closest(".form__group").hide();
document.querySelectorAll("input[type=hidden]").forEach(function (input) {
const closestFormGroup = input.closest(".form__group");
if (closestFormGroup) {
closestFormGroup.style.display = "none";
}
});
}
}
});
6 changes: 4 additions & 2 deletions hypha/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<link rel="stylesheet" href="{% static 'css/tailwind-output.css' %}">
<link rel="stylesheet" href="{% static 'css/main.css' %}">
<!-- Load any form css -->
<!-- Needed for most forms so load it here once. -->
{{ form.media.css }}
{% block extra_css %}{% endblock %}
<link rel="stylesheet" href="{% static 'css/print.css' %}" media="print">
Expand Down Expand Up @@ -123,14 +123,16 @@
</script>
<!-- htmx end -->

<!-- Placeholder for the htmx modal & toast-->
<!-- Placeholder for the htmx modal & toast -->
{% include "includes/_modal-placeholder.html" %}
{% include "includes/_toast-placeholder.html" %}

<!-- We still need jQuery for select2, daterangepicker and a few custom scripts. -->
<!-- Please do not add new features that require jQuery! -->
<script src="{% static 'js/vendor/jquery.min.js' %}"></script>

<!-- Needed for most forms so load it here once. -->
{{ form.media.js }}
{% block extra_js %}{% endblock %}

{% block sentry_sdk %}
Expand Down

0 comments on commit 395d36f

Please sign in to comment.