added a warning if keep indefinitely is checked and a password is not input

This commit is contained in:
Rostislav Raykov
2024-12-02 13:49:33 +02:00
parent 63ed6d4675
commit 98636bace5
2 changed files with 28 additions and 50 deletions

View File

@@ -69,6 +69,21 @@ function isPasswordProtected() {
return passwordField && passwordField.value.trim() !== "";
}
function validateKeepIndefinitely() {
const keepIndefinitely = document.getElementById("keepIndefinitely").checked;
const password = document.getElementById("password").value;
if (keepIndefinitely && !password) {
return confirm(
"You have selected 'Keep indefinitely' but haven't set a password. " +
"This means the file will only be deletable by an admin. " +
"Do you want to proceed?"
);
}
return true; // Allow form submission if conditions are not met
}
function validateFileSize() {
const maxFileSize = document.getElementsByClassName('maxFileSize')[0].innerText;
const file = document.getElementById('file').files[0];

View File

@@ -85,23 +85,17 @@
id="uploadForm"
method="post"
th:action="@{/file/upload}"
onsubmit="return validateKeepIndefinitely()"
>
<!-- CSRF Token -->
<input th:name="${_csrf.parameterName}"
th:value="${_csrf.token}"
type="hidden"/>
<input th:name="${_csrf.parameterName}" th:value="${_csrf.token}" type="hidden"/>
<!-- UUID -->
<input name="uuid"
th:value="${uuid}"
type="hidden"/>
<input name="uuid" th:value="${uuid}" type="hidden"/>
<!-- File Input -->
<div class="mb-3">
<label class="form-label"
for="file">Select
a
file:</label>
<label class="form-label" for="file">Select a file:</label>
<input
class="form-control"
id="file"
@@ -113,61 +107,30 @@
</div>
<!-- File Size Alert -->
<div class="alert alert-danger"
id="fileSizeAlert"
role="alert"
style="display: none;">
File
size
exceeds
the
<span th:text="${maxFileSize}">1GB</span>
limit.
<div class="alert alert-danger" id="fileSizeAlert" role="alert" style="display: none;">
File size exceeds the <span th:text="${maxFileSize}">1GB</span> limit.
</div>
<!-- Description Input -->
<div class="mb-3">
<label class="form-label"
for="description">Description:</label>
<input
class="form-control"
id="description"
name="description"
type="text"
/>
<label class="form-label" for="description">Description:</label>
<input class="form-control" id="description" name="description" type="text"/>
</div>
<!-- Keep Indefinitely Checkbox -->
<div class="form-check mb-3">
<input
class="form-check-input"
id="keepIndefinitely"
name="keepIndefinitely"
type="checkbox"
/>
<label class="form-check-label"
for="keepIndefinitely">
Keep
indefinitely
</label>
<input class="form-check-input" id="keepIndefinitely" name="keepIndefinitely" type="checkbox"/>
<label class="form-check-label" for="keepIndefinitely">Keep indefinitely</label>
</div>
<!-- Password Input -->
<div class="mb-3">
<label class="form-label"
for="password">Password
(Optional):</label>
<input
class="form-control"
id="password"
name="password"
type="password"
/>
<label class="form-label" for="password">Password (Optional):</label>
<input class="form-control" id="password" name="password" type="password"/>
</div>
<!-- Submit Button -->
<button class="btn btn-primary w-100"
type="submit">
<button class="btn btn-primary w-100" type="submit">
Upload
</button>
</form>