This commit is contained in:
Christopher Cookman 2024-12-21 02:36:06 -07:00
parent 023e4da2f9
commit 339166a509
3 changed files with 83 additions and 2 deletions

View file

@ -27,7 +27,6 @@ fetch('/api/v1/info')
<td>${reasonsFlagNames}</td>
<td>${ban.moderator || 'N/A'}</td>
<td>${banTimestamp}</td>
<td>${expiresTimestamp}</td>
<td style="color: ${ban.expiresTimestamp && new Date(ban.expiresTimestamp) < new Date() ? 'green' : ''};">
${expiresTimestamp}
</td>

View file

@ -54,7 +54,47 @@
<div class="mb-3">
<label for="expiresTimestamp" class="form-label">Expires (Optional)</label>
<input type="datetime-local" class="form-control" id="expiresTimestamp" name="expiresTimestamp">
<button type="button" class="btn btn-secondary mt-2" id="setNowButton">Now</button>
<script>
document.getElementById('setNowButton').addEventListener('click', function() {
const expiresTimestamp = document.getElementById('expiresTimestamp');
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const formattedNow = `${year}-${month}-${day}T${hours}:${minutes}`;
expiresTimestamp.value = formattedNow;
expiresTimestamp.disabled = false;
document.getElementById('neverExpires').checked = false;
});
</script>
<div class="form-check mt-2">
<input class="form-check-input" type="checkbox" id="neverExpires" name="neverExpires">
<label class="form-check-label" for="neverExpires">Never</label>
</div>
</div>
<script>
document.getElementById('neverExpires').addEventListener('change', function() {
const expiresTimestamp = document.getElementById('expiresTimestamp');
if (this.checked) {
expiresTimestamp.value = '';
expiresTimestamp.disabled = true;
expiresTimestamp.setAttribute('data-null', 'true');
} else {
expiresTimestamp.disabled = false;
expiresTimestamp.removeAttribute('data-null');
}
});
document.getElementById('banForm').addEventListener('submit', function(event) {
const expiresTimestamp = document.getElementById('expiresTimestamp');
if (expiresTimestamp.getAttribute('data-null') === 'true') {
expiresTimestamp.value = null;
}
});
</script>
<button type="submit" class="btn btn-primary w-100">Submit</button>
</form>

View file

@ -53,9 +53,51 @@
</div>
<div class="mb-3">
<label for="expiresTimestamp" class="form-label">Expires (Optional)</label>
<input type="datetime-local" class="form-control" id="expiresTimestamp" name="expiresTimestamp" value="<%= ban.expiresTimestamp %>">
<input type="datetime-local" class="form-control" id="expiresTimestamp" name="expiresTimestamp" value="<%= ban.expiresTimestamp %>" <%= ban.expiresTimestamp ? '' : 'disabled' %>>
<button type="button" class="btn btn-secondary mt-2" id="setNowButton">Now</button>
<script>
document.getElementById('setNowButton').addEventListener('click', function() {
const expiresTimestamp = document.getElementById('expiresTimestamp');
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const formattedNow = `${year}-${month}-${day}T${hours}:${minutes}`;
expiresTimestamp.value = formattedNow;
expiresTimestamp.disabled = false;
document.getElementById('neverExpires').checked = false;
});
</script>
<div class="form-check mt-2">
<input class="form-check-input" type="checkbox" id="neverExpires" name="neverExpires" <%= ban.expiresTimestamp ? '' : 'checked' %>>
<label class="form-check-label" for="neverExpires">Never</label>
</div>
</div>
<script>
document.getElementById('neverExpires').addEventListener('change', function() {
const expiresTimestamp = document.getElementById('expiresTimestamp');
if (this.checked) {
expiresTimestamp.value = '';
expiresTimestamp.disabled = true;
expiresTimestamp.setAttribute('data-null', 'true');
} else {
expiresTimestamp.disabled = false;
expiresTimestamp.removeAttribute('data-null');
}
});
document.getElementById('banForm').addEventListener('submit', function(event) {
const expiresTimestamp = document.getElementById('expiresTimestamp');
if (expiresTimestamp.getAttribute('data-null') === 'true') {
expiresTimestamp.value = null;
}
});
</script>
<button type="submit" class="btn btn-primary w-100">Submit</button>
</form>
</div>