-
Notifications
You must be signed in to change notification settings - Fork 0
/
boxes.tmpl
263 lines (256 loc) · 10.3 KB
/
boxes.tmpl
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!--djlint:on-->
{{template "header" . }}
<style>
.word-wrap {
word-wrap: break-word;
/* Break words if needed */
word-break: break-word;
/* For even more aggressive word breaking */
white-space: normal;
/* Ensure text breaks naturally */
}
</style>
<div class="p-5 text-center bg-body-tertiary">
<h1 class="mb-3">What's in the Box</h1>
<h4 class="mb-3">Keep track of your storage box contents</h4>
<span class="badge rounded-pill badge-primary">{{ .version }}</span>
</div>
<br />
<div class="container-md">
<div class="ms-3 me-auto">
<li class="list-group-item d-flex justify-content-between align-items-center">
<h2>Boxes</h2>
<div class="row">
<div class="col">
<button type="button"
class="btn btn-success new-box"
data-mdb-ripple-init
data-mdb-modal-init
data-mdb-target="#exampleModal">
<i class="fa-solid fa-plus"></i>
</button>
<button type="button"
class="btn btn-primary new-box"
data-mdb-ripple-init
data-mdb-modal-init
data-mdb-target="#searchModal">
<i class="fa-solid fa-magnifying-glass"></i>
</button>
</div>
</div>
</li>
</div>
<hr />
<ul class="list-group list-group-light">
{{range $box := .boxes}}
<!-- <div class="text-muted">Created at: {{ $box.CreatedAt | formatAsDate }}</div> -->
<li class="list-group-item d-flex justify-content-between align-items-center border-0">
<a href="/box/{{ $box.ID }}"
class="list-group-item list-group-item-action px-3 border-0">
<div>
<div class="fw-bold word-wrap">{{ $box.Name }}</div>
<span class="badge rounded-pill badge-primary word-wrap">{{ $box.Label.String }}</span>
</div>
</a>
<button type="button"
class="btn btn-warning edit-box"
value="{{ $box.ID }}"
data-mdb-ripple-init
data-mdb-modal-init
data-mdb-target="#exampleModal"
data-name="{{ $box.Name }}"
data-id="{{ $box.ID }}"
data-label="{{ $box.Label.String }}">
<i class="fa-solid fa-pencil"></i>
</button>
<button type="button"
class="btn btn-danger rm-box"
value="{{ $box.ID }}"
data-mdb-ripple-init>
<i class="fa-solid fa-xmark"></i>
</button>
</li>
{{ end }}
</ul>
</div>
<!-- Modal -->
<div class="modal fade"
id="exampleModal"
tabindex="-1"
aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Create new box</h5>
<button type="button"
class="btn-close"
data-mdb-ripple-init
data-mdb-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="/box/create"
id="update-form"
method="post"
data-bitwarden-watching="1"
enctype="multipart/form-data">
<fieldset>
<div class="form-group">
<label for="name" class="form-label mt-4">Box name:</label>
<input type="text"
class="form-control"
name="item_name"
id="item_name"
placeholder="Box Name"
value=""
required>
</div>
<div class="form-group">
<label for="label" class="form-label mt-4">Label:</label>
<input type="text"
class="form-control"
name="item_label"
id="item_label"
placeholder="Box Label"
value=""
required>
</div>
<br />
<button type="submit" class="btn btn-primary">
<i class="fa-solid fa-check"></i> Save
</button>
</fieldset>
</form>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade"
id="searchModal"
tabindex="-1"
aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Find boxes</h5>
<button type="button"
class="btn-close"
data-mdb-ripple-init
data-mdb-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
<fieldset>
<div class="form-group">
<label for="name" class="form-label mt-4">Search by name or label:</label>
<input type="text"
class="form-control"
id="searchInput"
placeholder="Name or Label"
value=""
autofocus>
</div>
</fieldset>
<br />
<ul id="results" class="list-group list-group-light">
<li class="list-group-item d-flex justify-content-between align-items-center border-0"></li>
</ul>
</div>
</div>
</div>
</div>
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
<li class="page-item">
{{ if gt .CurrentPage 1 }}
<a class="page-link" href="?page={{ sub .CurrentPage 1 }}">Previous</a>
{{ end }}
</li>
{{ range $i := seq 1 .TotalPages }}
{{ if eq $i $.CurrentPage }}
<li class="page-item active">
<a class="page-link" href="?page={{$i}}">{{$i}}</a>
</li>
{{ end }}
{{ end }}
{{ if lt .CurrentPage .TotalPages }}
<li class="page-item">
<a class="page-link" href="?page={{ add .CurrentPage 1 }}">Next</a>
</li>
{{ end }}
</ul>
</nav>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Event listener for keystrokes in the search input
$('#searchInput').on('keyup', function() {
var query = $(this).val(); // Get the current value of the input
// Check if the input is not empty before making the request
if (query.length > 0) {
$.ajax({
url: '/api/v0/box', // Replace with your API endpoint
type: 'GET',
data: {
search: query
}, // Send the query as a parameter (e.g., "q")
success: function(response) {
console.log(response.result)
// Update the results div with the returned JSON
var resultsHtml = '';
if (response && response.result && response.result.length) {
response.result.forEach(function(item) {
resultsHtml += '<a href="/box/' + item.id + '"> <li class="list-group-item d-flex justify-content-between align-items-center border-0">' + item.name + '<span class="badge rounded-pill badge-primary">' + item.label + '</span></li></a>'; // Customize how you display each item
});
} else {
resultsHtml = 'No results found.';
}
$('#results').html(resultsHtml); // Update the results
},
error: function() {
$('#results').html('Error retrieving data.');
}
});
} else {
$('#results').html(''); // Clear results if input is empty
}
});
$('.rm-box').click(function() {
data = $(this).attr("value")
$.ajax({
url: '/box/delete',
type: 'DELETE',
contentType: "application/json",
data: JSON.stringify({
id: data
}),
success: function(result) {
location.reload();
},
error: function(result) {
alert("Error" + result.responseText);
}
});
});
});
$(document).on("click", ".edit-box", function() {
var name = $(this).data('name');
var label = $(this).data('label');
var id = $(this).data('id');
$("#update-form").attr("action", "/box/" + id + "/edit");
$("#item_name").val(name);
$("#item_label").val(label);
$("#exampleModalLabel").text("Edit Box");
});
$(document).on("click", ".new-box", function() {
$("#update-form").attr("action", "/box/create?page={{ .CurrentPage}}");
$("#item_name").val("");
$("#item_label").val("");
$("#exampleModalLabel").text("Create new box");
});
</script>
{{template "footer"}}