|
16 | 16 | <tbody> |
17 | 17 | {% for item in items %} |
18 | 18 | <tr class="{% if item.strikes %}row-flagged{% endif %}{% if item.protected %} row-protected{% endif %}" |
19 | | - x-data="{ protecting: false }"> |
| 19 | + x-data="queueRow({{ item | tojson }})"> |
20 | 20 | <td> |
21 | 21 | <span class="badge" data-arr-type="{{ item.arr_type }}">{{ item.arr_name }}</span> |
22 | 22 | </td> |
|
57 | 57 | </td> |
58 | 58 | <td> |
59 | 59 | {% if not item.protected %} |
60 | | - <button class="outline small-btn" |
61 | | - :aria-busy="protecting" |
62 | | - @click="protecting = true; fetch('/api/protected/' + {{ item.download_id | tojson }}, { |
63 | | - method: 'POST', |
64 | | - headers: {'Content-Type': 'application/json'}, |
65 | | - body: JSON.stringify({title: {{ item.title | tojson }}, arr_name: {{ item.arr_name | tojson }}}) |
66 | | - }).then(() => { htmx.trigger('#queue-container', 'refresh'); protecting = false; })"> |
| 60 | + <button class="outline small-btn" :aria-busy="protecting" @click="protect()"> |
67 | 61 | Protect |
68 | 62 | </button> |
69 | 63 | {% else %} |
70 | | - <button class="outline secondary small-btn" |
71 | | - @click="fetch('/api/protected/' + {{ item.download_id | tojson }}, { method: 'DELETE' }) |
72 | | - .then(() => htmx.trigger('#queue-container', 'refresh'))"> |
| 64 | + <button class="outline secondary small-btn" @click="unprotect()"> |
73 | 65 | Unprotect |
74 | 66 | </button> |
75 | 67 | {% endif %} |
|
80 | 72 | </table> |
81 | 73 | </figure> |
82 | 74 | <p><small>{{ total }} items in queue</small></p> |
| 75 | + |
| 76 | +<script> |
| 77 | +function queueRow(item) { |
| 78 | + return { |
| 79 | + protecting: false, |
| 80 | + protect() { |
| 81 | + this.protecting = true; |
| 82 | + fetch('/api/protected/' + encodeURIComponent(item.download_id), { |
| 83 | + method: 'POST', |
| 84 | + headers: {'Content-Type': 'application/json'}, |
| 85 | + body: JSON.stringify({title: item.title, arr_name: item.arr_name}) |
| 86 | + }).then(() => { |
| 87 | + htmx.trigger('#queue-container', 'refresh'); |
| 88 | + this.protecting = false; |
| 89 | + }); |
| 90 | + }, |
| 91 | + unprotect() { |
| 92 | + fetch('/api/protected/' + encodeURIComponent(item.download_id), { |
| 93 | + method: 'DELETE' |
| 94 | + }).then(() => htmx.trigger('#queue-container', 'refresh')); |
| 95 | + } |
| 96 | + } |
| 97 | +} |
| 98 | +</script> |
83 | 99 | {% else %} |
84 | 100 | <p>Queue is empty</p> |
85 | 101 | {% endif %} |
0 commit comments