|
5 | 5 |
|
6 | 6 | {% block tillcontent %} |
7 | 7 |
|
8 | | -<form class="mb-2" action="" method="get"> |
9 | | - {% include "form-horizontal.html" %} |
10 | | - <div class="row justify-content-center"> |
11 | | - <button class="btn btn-primary w-75" type="submit">Find</button> |
| 8 | +<form class="mb-2" action="" method="post">{% csrf_token %} |
| 9 | + <div class="row mb-3"> |
| 10 | + <label for="manufacturerInput" class="col-sm-2 col-form-label">Manufacturer</label> |
| 11 | + <div class="col-sm-10"> |
| 12 | + <input type="search" class="form-control" id="manufacturerInput" name="manufacturer"> |
| 13 | + </div> |
12 | 14 | </div> |
| 15 | + |
| 16 | + <div class="row mb-3"> |
| 17 | + <label for="nameInput" class="col-sm-2 col-form-label">Name</label> |
| 18 | + <div class="col-sm-10"> |
| 19 | + <input type="search" class="form-control" id="nameInput" name="name"> |
| 20 | + </div> |
| 21 | + </div> |
| 22 | + |
| 23 | + <div class="row mb-3"> |
| 24 | + <label for="departmentInput" class="col-sm-2 col-form-label">Department</label> |
| 25 | + <div class="col-sm-10"> |
| 26 | + <select class="col-sm-10 form-select" id="departmentInput" aria-label="Department" name="department"> |
| 27 | + <option value="" selected>Any</option> |
| 28 | + {% for d in departments %} |
| 29 | + <option value="{{d.id}}">{{d.description}}</option> |
| 30 | + {% endfor %} |
| 31 | + </select> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + |
| 35 | + <div class="row mb-3 form-check"> |
| 36 | + <div class="col-sm-10 offset-sm-2"> |
| 37 | + <input class="form-check-input" type="checkbox" value="" id="checkArchived" name="include_archived"> |
| 38 | + <label class="form-check-label" for="checkArchived"> |
| 39 | + Include archived? |
| 40 | + </label> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + |
| 44 | + {% if create_form %} |
| 45 | + <button class="btn btn-secondary mb-2" type="button" data-bs-toggle="modal" data-bs-target="#createModal"> |
| 46 | + Add new stock type |
| 47 | + </button> |
| 48 | + {% endif %} |
| 49 | + |
| 50 | + {% if candidate_stocktakes %} |
| 51 | + {% for st in candidate_stocktakes %} |
| 52 | + <button class="btn btn-secondary mb-2 candidate-stocktake-button" type="submit" name="submit_add_to_{{st.id}}" disabled> |
| 53 | + Add to scope for stock take {{st.id}} ({{st.description}}) |
| 54 | + </button> |
| 55 | + {% endfor %} |
| 56 | + <p>N.B. stock types already assigned to a stock take won't be assigned |
| 57 | + to a different one.</p> |
| 58 | + {% endif %} |
13 | 59 | </form> |
14 | 60 |
|
15 | 61 | {% if create_form %} |
16 | | -<button class="btn btn-secondary mb-2" type="button" data-bs-toggle="modal" data-bs-target="#createModal"> |
17 | | - Add new stock type |
18 | | -</button> |
19 | | - |
20 | 62 | {% modal "createModal" dialog_class="modal-lg" title="Add new stock type" %} |
21 | 63 | <form action="" method="post">{% csrf_token %} |
22 | 64 | <datalist id="manufacturers"> |
|
46 | 88 |
|
47 | 89 | {% endif %} |
48 | 90 |
|
49 | | -{% if stocktypes %} |
50 | | -{% if candidate_stocktakes %} |
51 | | -<form action="" method="post">{% csrf_token %} |
52 | | - {% for st in candidate_stocktakes %} |
53 | | - <button class="btn btn-secondary mb-2" type="submit" name="submit_add_to_{{st.id}}"> |
54 | | - Add to scope for stock take {{st.id}} ({{st.description}}) |
55 | | - </button> |
56 | | - {% endfor %} |
57 | | -</form> |
58 | | -<p>N.B. stock types already assigned to a stock take won't be assigned |
59 | | - to a different one.</p> |
60 | | -{% endif %} |
61 | 91 | <table class="table table-striped table-hover table-sm" id="stocktypelist"> |
62 | 92 | <thead class="table-light"> |
63 | 93 | <tr> |
|
71 | 101 | </tr> |
72 | 102 | </thead> |
73 | 103 | <tbody> |
74 | | -{% for t in stocktypes %} |
75 | | -<tr{% if t.archived %} class="table-danger"{% endif %}> |
76 | | -<td><a href="?manufacturer={{t.manufacturer|urlencode}}">{{t.manufacturer}}</a></td> |
77 | | -<td><a href="{{t.get_absolute_url}}">{{t.name}}</a></td> |
78 | | -<td data-sort="{{t.abv|default:0.00}}">{{t.abvstr}}</td> |
79 | | -<td><a href="{{t.department.get_absolute_url}}">{{t.department}}</a></td> |
80 | | -<td>{{t.unit.description}}</td> |
81 | | -{% if t.saleprice %}<td class="money" data-sort="{{t.saleprice}}">{{money}}{{t.pricestr}}</td> |
82 | | -{% else %}<td data-sort="0.00"></td>{% endif %} |
83 | | -<td>{% if t.stocktake %}<a href="{{t.stocktake.get_absolute_url}}">{{t.stocktake}}</a>{% endif %}</td> |
84 | | -</tr> |
85 | | -{% endfor %} |
86 | 104 | </tbody> |
87 | 105 | </table> |
| 106 | + |
88 | 107 | <script type="text/javascript"> |
89 | | -$(document).ready(function(){ |
90 | | - $("#stocktypelist").DataTable(); |
91 | | -}); |
92 | | -</script> |
| 108 | + $(document).ready(function() { |
| 109 | + let include_archived = false; |
| 110 | + let manufacturer = null; |
| 111 | + let name = null; |
| 112 | + let department = null; |
93 | 113 |
|
94 | | -{% endif %} |
| 114 | + function update_candidate_stocktakes() { |
| 115 | + const valid = (!!manufacturer || !!name || !!department); |
| 116 | + if (valid) { |
| 117 | + $(".candidate-stocktake-button").removeAttr('disabled'); |
| 118 | + } else { |
| 119 | + $(".candidate-stocktake-button").attr('disabled', 'disabled'); |
| 120 | + } |
| 121 | + } |
95 | 122 |
|
| 123 | + const stocktype_api = $("#stocktypelist").DataTable({ |
| 124 | + ajax: { |
| 125 | + url: '{% url "tillweb-datatable-stocktypes" %}', |
| 126 | + dataSrc: 'data', |
| 127 | + data: function (d) { |
| 128 | + if (manufacturer) { |
| 129 | + d.manufacturer = manufacturer; |
| 130 | + } |
| 131 | + if (name) { |
| 132 | + d.name = name; |
| 133 | + } |
| 134 | + if (department) { |
| 135 | + d.department = department; |
| 136 | + } |
| 137 | + d.include_archived = include_archived ? 'yes': 'no'; |
| 138 | + }, |
| 139 | + }, |
| 140 | + columns: [ |
| 141 | + { data: 'manufacturer', |
| 142 | + render: render_link('manufacturer_url', DataTable.render.text()), |
| 143 | + }, |
| 144 | + { data: 'name', |
| 145 | + render: render_link('stocktype_url', DataTable.render.text()), |
| 146 | + }, |
| 147 | + { data: 'abv', |
| 148 | + render: render_abv(), |
| 149 | + }, |
| 150 | + { data: 'department', |
| 151 | + render: render_link('department_url', DataTable.render.text()), |
| 152 | + }, |
| 153 | + { data: 'unit', |
| 154 | + render: render_link('unit_url', DataTable.render.text()), |
| 155 | + }, |
| 156 | + { data: 'saleprice', |
| 157 | + render: render_money(), |
| 158 | + }, |
| 159 | + { data: 'stocktake', |
| 160 | + render: render_link('stocktake_url', DataTable.render.text()), |
| 161 | + }, |
| 162 | + ], |
| 163 | + order: [[0, 'asc'], [1, 'asc']], |
| 164 | + searching: false, |
| 165 | + paging: true, |
| 166 | + serverSide: true, |
| 167 | + }); |
| 168 | + const reloadDebounce = DataTable.util.debounce(function() { |
| 169 | + stocktype_api.ajax.reload(null, true);}); |
| 170 | + |
| 171 | + $("#manufacturerInput").on("input", function() { |
| 172 | + manufacturer = this.value; |
| 173 | + reloadDebounce(); |
| 174 | + update_candidate_stocktakes(); |
| 175 | + }); |
| 176 | + $("#nameInput").on("input", function() { |
| 177 | + name = this.value; |
| 178 | + reloadDebounce(); |
| 179 | + update_candidate_stocktakes(); |
| 180 | + }); |
| 181 | + $("#departmentInput").change(function() { |
| 182 | + department = this.value; |
| 183 | + stocktype_api.ajax.reload(null, true); |
| 184 | + update_candidate_stocktakes(); |
| 185 | + }); |
| 186 | + $("#checkArchived").change(function() { |
| 187 | + include_archived = this.checked; |
| 188 | + stocktype_api.ajax.reload(null, true); |
| 189 | + }); |
| 190 | + }); |
| 191 | +</script> |
96 | 192 | {% endblock %} |
0 commit comments