510 lines
21 KiB
HTML
510 lines
21 KiB
HTML
{% extends "base.html" %}
|
|
{% load static i18n %}
|
|
{% load widget_tweaks %}
|
|
|
|
{% block title %}{{ title }} - {{ block.super }}{% endblock %}
|
|
|
|
{% block customCSS %}
|
|
<style>
|
|
/* UI Variables for the KAAT-S Theme */
|
|
:root {
|
|
--kaauh-teal: #00636e;
|
|
--kaauh-teal-dark: #004a53;
|
|
--kaauh-border: #eaeff3;
|
|
--kaauh-gray-light: #f8f9fa;
|
|
}
|
|
|
|
/* Form Container Styling */
|
|
.form-container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
/* Card Styling */
|
|
.card {
|
|
border: 1px solid var(--kaauh-border);
|
|
border-radius: 0.75rem;
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
|
|
}
|
|
|
|
/* Main Action Button Style */
|
|
.btn-main-action {
|
|
background-color: var(--kaauh-teal);
|
|
border-color: var(--kaauh-teal);
|
|
color: white;
|
|
font-weight: 600;
|
|
transition: all 0.2s ease;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
padding: 0.5rem 1.5rem;
|
|
}
|
|
|
|
.btn-main-action:hover {
|
|
background-color: var(--kaauh-teal-dark);
|
|
border-color: var(--kaauh-teal-dark);
|
|
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
|
|
}
|
|
|
|
/* Secondary Button Style */
|
|
.btn-outline-secondary {
|
|
color: var(--kaauh-teal-dark);
|
|
border-color: var(--kaauh-teal);
|
|
}
|
|
.btn-outline-secondary:hover {
|
|
background-color: var(--kaauh-teal-dark);
|
|
color: white;
|
|
border-color: var(--kaauh-teal-dark);
|
|
}
|
|
|
|
/* Form Field Styling */
|
|
.form-control:focus {
|
|
border-color: var(--kaauh-teal);
|
|
box-shadow: 0 0 0 0.2rem rgba(0, 99, 110, 0.25);
|
|
}
|
|
|
|
.form-select:focus {
|
|
border-color: var(--kaauh-teal);
|
|
box-shadow: 0 0 0 0.2rem rgba(0, 99, 110, 0.25);
|
|
}
|
|
|
|
/* Breadcrumb Styling */
|
|
.breadcrumb {
|
|
background-color: transparent;
|
|
padding: 0;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.breadcrumb-item + .breadcrumb-item::before {
|
|
content: ">";
|
|
color: var(--kaauh-teal);
|
|
}
|
|
|
|
/* Alert Styling */
|
|
.alert {
|
|
border-radius: 0.5rem;
|
|
border: none;
|
|
}
|
|
|
|
/* Loading State */
|
|
.btn.loading {
|
|
position: relative;
|
|
pointer-events: none;
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.btn.loading::after {
|
|
content: "";
|
|
position: absolute;
|
|
width: 16px;
|
|
height: 16px;
|
|
margin: auto;
|
|
border: 2px solid transparent;
|
|
border-top-color: #ffffff;
|
|
border-radius: 50%;
|
|
animation: spin 1s linear infinite;
|
|
top: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
/* Current Profile Section */
|
|
.current-profile {
|
|
background-color: var(--kaauh-gray-light);
|
|
border-radius: 0.5rem;
|
|
padding: 1rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.current-profile h6 {
|
|
color: var(--kaauh-teal-dark);
|
|
font-weight: 600;
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
|
|
.current-image {
|
|
width: 100px;
|
|
height: 100px;
|
|
object-fit: cover;
|
|
border-radius: 50%;
|
|
border: 2px solid var(--kaauh-teal);
|
|
margin-right: 1rem;
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="container-fluid py-4">
|
|
<div class="form-container">
|
|
<!-- Breadcrumb Navigation -->
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item">
|
|
<a href="{% url 'source_list' %}" class="text-decoration-none text-secondary">
|
|
<i class="fas fa-plug me-1"></i> {% trans "Sources" %}
|
|
</a>
|
|
</li>
|
|
{% if source %}
|
|
<li class="breadcrumb-item">
|
|
<a href="{% url 'source_detail' source.pk %}" class="text-decoration-none text-secondary">
|
|
{{ source.name }}
|
|
</a>
|
|
</li>
|
|
<li class="breadcrumb-item active" aria-current="page"
|
|
style="
|
|
color: #F43B5E; /* Rosy Accent Color */
|
|
font-weight: 600;">{% trans "Update" %}</li>
|
|
{% else %}
|
|
<li class="breadcrumb-item active" aria-current="page"
|
|
style="
|
|
color: #F43B5E; /* Rosy Accent Color */
|
|
font-weight: 600;">{% trans "Create" %}</li>
|
|
{% endif %}
|
|
</ol>
|
|
</nav>
|
|
|
|
<!-- Header -->
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h4 style="color: var(--kaauh-teal-dark); font-weight: 700;">
|
|
<i class="fas fa-plug me-2"></i> {{ title }}
|
|
</h4>
|
|
<div class="d-flex gap-2">
|
|
{% if source %}
|
|
<a href="{% url 'source_detail' source.pk %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-eye me-1"></i> {% trans "View Details" %}
|
|
</a>
|
|
<a href="{% url 'source_delete' source.pk %}" class="btn btn-danger">
|
|
<i class="fas fa-trash me-1"></i> {% trans "Delete" %}
|
|
</a>
|
|
{% endif %}
|
|
<a href="{% url 'source_list' %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-arrow-left me-1"></i> {% trans "Back to List" %}
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
{% if source %}
|
|
<!-- Current Source Info -->
|
|
<div class="card shadow-sm mb-4">
|
|
<div class="card-body">
|
|
<div class="current-profile">
|
|
<h6><i class="fas fa-info-circle me-2"></i>{% trans "Currently Editing" %}</h6>
|
|
<div class="d-flex align-items-center">
|
|
<div class="current-image d-flex align-items-center justify-content-center bg-light">
|
|
<i class="fas fa-plug text-muted"></i>
|
|
</div>
|
|
<div>
|
|
<h5 class="mb-1">{{ source.name }}</h5>
|
|
{% if source.source_type %}
|
|
<p class="text-muted mb-0">{% trans "Type" %}: {{ source.get_source_type_display }}</p>
|
|
{% endif %}
|
|
{% if source.ip_address %}
|
|
<p class="text-muted mb-0">{% trans "IP Address" %}: {{ source.ip_address }}</p>
|
|
{% endif %}
|
|
<small class="text-muted">
|
|
{% trans "Created" %}: {{ source.created_at|date:"d M Y" }} •
|
|
{% trans "Last Updated" %}: {{ source.updated_at|date:"d M Y" }}
|
|
</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Form Card -->
|
|
<div class="card shadow-sm">
|
|
<div class="card-body p-4">
|
|
{% if form.non_field_errors %}
|
|
<div class="alert alert-danger" role="alert">
|
|
<h5 class="alert-heading">
|
|
<i class="fas fa-exclamation-triangle me-2"></i>{% trans "Error" %}
|
|
</h5>
|
|
{% for error in form.non_field_errors %}
|
|
<p class="mb-0">{{ error }}</p>
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if messages %}
|
|
{% for message in messages %}
|
|
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
|
|
{{ message }}
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{% trans 'Close' %}"></button>
|
|
</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
|
|
<form method="post" novalidate id="source-form">
|
|
{% csrf_token %}
|
|
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label for="{{ form.name.id_for_label }}" class="form-label">
|
|
{{ form.name.label }} <span class="text-danger">*</span>
|
|
</label>
|
|
{{ form.name|add_class:"form-control" }}
|
|
{% if form.name.errors %}
|
|
<div class="invalid-feedback d-block">
|
|
{% for error in form.name.errors %}
|
|
{{ error }}
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
<div class="form-text">{{ form.name.help_text }}</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label for="{{ form.source_type.id_for_label }}" class="form-label">
|
|
{{ form.source_type.label }} <span class="text-danger">*</span>
|
|
</label>
|
|
{{ form.source_type|add_class:"form-control" }}
|
|
{% if form.source_type.errors %}
|
|
<div class="invalid-feedback d-block">
|
|
{% for error in form.source_type.errors %}
|
|
{{ error }}
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
<div class="form-text">{{ form.source_type.help_text }}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label for="{{ form.ip_address.id_for_label }}" class="form-label">
|
|
{{ form.ip_address.label }} <span class="text-danger">*</span>
|
|
</label>
|
|
{{ form.ip_address|add_class:"form-control" }}
|
|
{% if form.ip_address.errors %}
|
|
<div class="invalid-feedback d-block">
|
|
{% for error in form.ip_address.errors %}
|
|
{{ error }}
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
<div class="form-text">{{ form.ip_address.help_text }}</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label for="{{ form.trusted_ips.id_for_label }}" class="form-label">
|
|
{{ form.trusted_ips.label }}
|
|
</label>
|
|
{{ form.trusted_ips|add_class:"form-control" }}
|
|
{% if form.trusted_ips.errors %}
|
|
<div class="invalid-feedback d-block">
|
|
{% for error in form.trusted_ips.errors %}
|
|
{{ error }}
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
<div class="form-text">{{ form.trusted_ips.help_text }}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="{{ form.description.id_for_label }}" class="form-label">
|
|
{{ form.description.label }}
|
|
</label>
|
|
{{ form.description|add_class:"form-control" }}
|
|
{% if form.description.errors %}
|
|
<div class="invalid-feedback d-block">
|
|
{% for error in form.description.errors %}
|
|
{{ error }}
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
<div class="form-text">{{ form.description.help_text }}</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<div class="form-check">
|
|
{{ form.is_active|add_class:"form-check-input" }}
|
|
<label for="{{ form.is_active.id_for_label }}" class="form-check-label">
|
|
{{ form.is_active.label }}
|
|
</label>
|
|
</div>
|
|
{% if form.is_active.errors %}
|
|
<div class="invalid-feedback d-block">
|
|
{% for error in form.is_active.errors %}
|
|
{{ error }}
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
<div class="form-text">{{ form.is_active.help_text }}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- API Credentials Section -->
|
|
{% if source %}
|
|
<div class="card bg-light mb-4">
|
|
<div class="card-header">
|
|
<h6 class="mb-0">{% trans "API Credentials" %}</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label class="form-label">{% trans "API Key" %}</label>
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" value="{{ source.api_key }}" readonly>
|
|
<button type="button" class="btn btn-outline-secondary"
|
|
hx-post="{% url 'copy_to_clipboard' %}"
|
|
hx-vals='{"text": "{{ source.api_key }}"}'
|
|
title="{% trans 'Copy to clipboard' %}">
|
|
<i class="fas fa-copy"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label class="form-label">{% trans "API Secret" %}</label>
|
|
<div class="input-group">
|
|
<input type="password" class="form-control" value="{{ source.api_secret }}" readonly id="api-secret">
|
|
<button type="button" class="btn btn-outline-secondary" onclick="toggleSecretVisibility()">
|
|
<i class="fas fa-eye" id="secret-toggle-icon"></i>
|
|
</button>
|
|
<button type="button" class="btn btn-outline-secondary"
|
|
hx-post="{% url 'copy_to_clipboard' %}"
|
|
hx-vals='{"text": "{{ source.api_secret }}"}'
|
|
title="{% trans 'Copy to clipboard' %}">
|
|
<i class="fas fa-copy"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="text-end">
|
|
<a href="{% url 'generate_api_keys' source.pk %}" class="btn btn-warning">
|
|
<i class="fas fa-key"></i> {% trans "Generate New Keys" %}
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div class="d-flex gap-2">
|
|
<button form="source-form" type="submit" class="btn btn-main-action">
|
|
<i class="fas fa-save me-1"></i> {% trans "Save" %}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Form Validation
|
|
const form = document.getElementById('source-form');
|
|
if (form) {
|
|
form.addEventListener('submit', function(e) {
|
|
const submitBtn = form.querySelector('button[type="submit"]');
|
|
submitBtn.classList.add('loading');
|
|
submitBtn.disabled = true;
|
|
|
|
// Basic validation
|
|
const name = document.getElementById('id_name');
|
|
if (name && !name.value.trim()) {
|
|
e.preventDefault();
|
|
submitBtn.classList.remove('loading');
|
|
submitBtn.disabled = false;
|
|
alert('{% trans "Source name is required." %}');
|
|
return;
|
|
}
|
|
|
|
const ipAddress = document.getElementById('id_ip_address');
|
|
if (ipAddress && ipAddress.value.trim() && !isValidIP(ipAddress.value.trim())) {
|
|
e.preventDefault();
|
|
submitBtn.classList.remove('loading');
|
|
submitBtn.disabled = false;
|
|
alert('{% trans "Please enter a valid IP address." %}');
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
|
|
// IP validation helper
|
|
function isValidIP(ip) {
|
|
const ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
return ipRegex.test(ip);
|
|
}
|
|
|
|
// Warn before leaving if changes are made
|
|
let formChanged = false;
|
|
const formInputs = form ? form.querySelectorAll('input, select, textarea') : [];
|
|
|
|
formInputs.forEach(input => {
|
|
input.addEventListener('change', function() {
|
|
formChanged = true;
|
|
});
|
|
});
|
|
|
|
window.addEventListener('beforeunload', function(e) {
|
|
if (formChanged) {
|
|
e.preventDefault();
|
|
e.returnValue = '{% trans "You have unsaved changes. Are you sure you want to leave?" %}';
|
|
return e.returnValue;
|
|
}
|
|
});
|
|
|
|
if (form) {
|
|
form.addEventListener('submit', function() {
|
|
formChanged = false;
|
|
});
|
|
}
|
|
});
|
|
|
|
function toggleSecretVisibility() {
|
|
const secretInput = document.getElementById('api-secret');
|
|
const toggleIcon = document.getElementById('secret-toggle-icon');
|
|
|
|
if (secretInput.type === 'password') {
|
|
secretInput.type = 'text';
|
|
toggleIcon.classList.remove('fa-eye');
|
|
toggleIcon.classList.add('fa-eye-slash');
|
|
} else {
|
|
secretInput.type = 'password';
|
|
toggleIcon.classList.remove('fa-eye-slash');
|
|
toggleIcon.classList.add('fa-eye');
|
|
}
|
|
}
|
|
|
|
// Handle HTMX copy to clipboard feedback
|
|
document.body.addEventListener('htmx:afterRequest', function(evt) {
|
|
if (evt.detail.successful && evt.detail.target.matches('[hx-post*="copy_to_clipboard"]')) {
|
|
const button = evt.detail.target;
|
|
const originalIcon = button.innerHTML;
|
|
button.innerHTML = '<i class="fas fa-check"></i>';
|
|
button.classList.remove('btn-outline-secondary');
|
|
button.classList.add('btn-success');
|
|
|
|
setTimeout(() => {
|
|
button.innerHTML = originalIcon;
|
|
button.classList.remove('btn-success');
|
|
button.classList.add('btn-outline-secondary');
|
|
}, 2000);
|
|
}
|
|
});
|
|
</script>
|
|
{% endblock %}
|