Skip to content

Commit

Permalink
Move css inside a html to external file shinneider#22
Browse files Browse the repository at this point in the history
  • Loading branch information
gabbyprecious committed Mar 1, 2020
1 parent ca6bb32 commit 2119164
Showing 1 changed file with 76 additions and 61 deletions.
137 changes: 76 additions & 61 deletions django_admin_search/templates/admin/custom_search_form.html
Original file line number Diff line number Diff line change
@@ -1,87 +1,102 @@
{% load i18n static %}


<!-- Stylesheet connection -->
{% block stylesheet %} {% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}"> {% endblock %} {% block modal %}
{% block stylesheet %}

<form id="advanced_admin_search" class="modal" style="display: none;">
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
{% endblock %}

<div class="advanced_search_form_body">
{% block form_fields %} {% include "admin/custom_fieldset.html" %} {% endblock %}
</div>

{% if show_result_count %}
<span class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }}

{% block modal %}

<form id="advanced_admin_search" class="modal" style="display: none;">

<div class="advanced_search_form_body">
{% block form_fields %}
{% include "admin/custom_fieldset.html" %}
{% endblock %}
</div>

{% if show_result_count %}
<span class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }}
results{% endblocktrans %} (<a href="?{% if cl.is_popup %}_popup=1{% endif %}">
{% if cl.show_full_result_count %}{% blocktrans with full_result_count=cl.full_result_count %}
{{ full_result_count }} total{% endblocktrans %}{% else %}{% trans "Show all" %}{% endif %}</a>)
</span> {% endif %} {% for pair in cl.params.items %} {% if pair.0 != search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}" />{% endif %} {% endfor %} {% block modal_search_button %}
<button id="submit_form" type="submit" class="form_submit_button">
</span>
{% endif %}
{% for pair in cl.params.items %}
{% if pair.0 != search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endif %}
{% endfor %}

{% block modal_search_button %}
<button id="submit_form" type="submit" class="form_submit_button">
{% block modal_search_button_text %}
{% trans 'filter'|title %}
{% endblock %}
</button> {% endblock %}
</button>
{% endblock %}

</form>
</form>

{% endblock %} {% block search_admin_button %}
<div class="search_button">
<!-- Link to open the modal -->
<a href="#advanced_admin_search" rel="modal:open" class="search_button">
<img src="{% static " admin/img/search.svg " %}" alt="Search" height="15" />
<span>
{% endblock %}

{% block search_admin_button %}
<div class="search_button">
<!-- Link to open the modal -->
<a href="#advanced_admin_search" rel="modal:open" class="search_button">
<img src="{% static "admin/img/search.svg" %}" alt="Search" height="15"/>
<span>
{% block search_admin_button_text %}
{% trans 'advanced search'|title %}
{% endblock %}
</span>
</a>
</div>
</a>
</div>
{% endblock %}


<!-- Scripts -->
{% block scripts %}
<!-- jQuery -->
<script src="{% static 'jquery/jquery.min.js' %}"></script>

<!-- JQuery Mask-->
<script src="{% static 'jquery_mask/jquerymask.js' %}"></script>

<!-- jQuery Modal -->
<script src="{% static 'jquery_modal/jquery.modal.min.js' %}"></script>
<link rel="stylesheet" href="{% static 'jquery_modal/jquery.modal.min.css' %}" />

<!-- Submit Button (Get parameters)-->
<script>
let searchParams = new URLSearchParams(window.location.search)

page = searchParams.get('p')
page = page == null ? 0 : ($.isNumeric(page) ? parseInt(page) : 0);

$("#advanced_admin_search").submit(function() {
$('#advanced_admin_search input').each(function(k, v) {
v.disabled = v.value === '';
});

params = $('#advanced_admin_search').serialize()

/*
<!-- jQuery -->
<script src="{% static 'jquery/jquery.min.js' %}"></script>

<!-- JQuery Mask-->
<script src="{% static 'jquery_mask/jquerymask.js' %}"></script>

<!-- jQuery Modal -->
<script src="{% static 'jquery_modal/jquery.modal.min.js' %}"></script>
<link rel="stylesheet" href="{% static 'jquery_modal/jquery.modal.min.css' %}" />

<!-- Submit Button (Get parameters)-->
<script>
let searchParams = new URLSearchParams(window.location.search)

page = searchParams.get('p')
page = page == null ? 0 : ( $.isNumeric(page) ? parseInt(page) : 0 );

$( "#advanced_admin_search" ).submit(function() {
$('#advanced_admin_search input').each(function(k, v) {
v.disabled = v.value === '';
});

after apply filter is more common to leave user to the first page
because a data length is changed, current page may no longer exist
(Ex, filter return empty queryset, nos has second page).
but if your need to keep a page, uncomment this
if (page != 0) { // this main current page
// params = 'p=' + page + '&' + params;
}
*/

href = window.location.pathname
window.location.href = href + '?' + params;
return false;
});
</script>
params = $('#advanced_admin_search').serialize()

/*
after apply filter is more common to leave user to the first page
because a data length is changed, current page may no longer exist
(Ex, filter return empty queryset, nos has second page).
but if your need to keep a page, uncomment this
if (page != 0) { // this main current page
// params = 'p=' + page + '&' + params;
}
*/

href = window.location.pathname
window.location.href = href + '?' + params;
return false;
});
</script>

{% endblock %}

0 comments on commit 2119164

Please sign in to comment.