summaryrefslogtreecommitdiff
path: root/ishtar_common/templates/ishtar/forms/search_query.html
blob: ff51d483dd22671f22a2b0bba9a021dfc88d673d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{% load i18n inline_formset table_form %}
<div class="modal-dialog modal-sm" id="save-search-div">
    <div class="modal-content">
        <div class="modal-header">
            <h5>{% trans "Bookmark search" %}</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <form enctype="multipart/form-data"
              action="{% url 'save-search-query' app_label model %}"
              method="post"
              id="save-search-form">
            <div class="modal-body form-row-modal">
              {% csrf_token %}

              <div class='form'>

                {% if form.non_field_errors %}
                <div class="alert alert-danger" role="alert">
                    {{form.non_field_errors}}
                </div>
                {% endif %}

                {% for hidden in form.hidden_fields %}
                {{hidden}}
                {% if hidden.errors %}<div class="invalid-feedback">
                    {{ hidden.errors }}
                </div>{% endif %}
                {% endfor %}

                {% if form.search_query %}
                <div class="form-row">
                    <input type="radio" name="create_or_update" value="create"
                           id="create-choice" checked >
                    &nbsp;<label for="create-choice">{% trans "New" %}</label>
                </div>
                {% else %}
                <input type="hidden" name="create_or_update" value="create">
                {% endif %}
                <div id="new-search-query">
                    <div class="form-row">
                        {% with form.label as field %}
                        {% include "blocks/bs_field_snippet.html" %}
                        {% endwith %}
                    </div>
                    <div class="form-row">
                        <div class="form-group col-lg-12">
                            <span>
                                {{form.is_alert}}
                                <label for="{{form.is_alert.auto_id}}">{{form.is_alert.label}}</label>
                            </span>
                        </div>
                    </div>
                </div>
                {% if form.search_query %}
                <div class="form-row">
                    <input type="radio" name="create_or_update" value="update"
                           id="update-choice">
                    &nbsp;<label for="update-choice">{% trans "Update" %}</label>
                </div>
                <div id="update-search-query">
                    <div class="form-row">
                        {% with form.search_query as field %}
                        {% include "blocks/bs_field_snippet.html" %}
                        {% endwith %}
                    </div>
                </div>
                {% endif %}
              </div>
            </div>
            <div class="modal-footer">
                <div class="col-sm">
                    <button type="button" id="search-save-submit"
                            name='validate'
                            value="validate" class="btn btn-success">
                        {% trans "Validate" %}
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

<script type='text/javascript'>

var update_form_display = function(){
    if ($("#create-choice:checked").length){
        $("#update-search-query").hide();
        $("#new-search-query").show();
    } else {
        $("#new-search-query").hide();
        $("#update-search-query").show();
    }
}

$(document).ready(function(){
    $("#id_query").val($(".search-vector").val());
    $("#search-save-submit").click(
        function(){
            $.ajax({
                type: "POST",
                url: "{% url 'save-search-query' app_label model %}",
                data: $("#save-search-form").serialize(),
                success: function(data){
                    $("#save-search-div").parent().html(data);
                },
                dataType: 'html'
            });
            return false;
        }
    );
    $("#create-choice").click(update_form_display);
    $("#update-choice").click(update_form_display);
    update_form_display();
});

</script>