final stage of the app
This commit is contained in:
454
app/templates/edit_links.html
Normal file
454
app/templates/edit_links.html
Normal file
@@ -0,0 +1,454 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Edit {{ page.title }}</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.2em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 30px;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
background: #f8f9fa;
|
||||
padding: 25px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.form-section h2 {
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.form-group textarea {
|
||||
height: 80px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 12px 25px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #dc3545 0%, #fd7e14 100%);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: linear-gradient(135deg, #6c757d 0%, #adb5bd 100%);
|
||||
}
|
||||
|
||||
.links-section h2 {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.link-item {
|
||||
background: white;
|
||||
border: 1px solid #e9ecef;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.link-item.editing {
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.link-display {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.link-edit {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.link-item.editing .link-display {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.link-item.editing .link-edit {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.link-title {
|
||||
font-size: 1.2em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.link-description {
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.link-url {
|
||||
color: #667eea;
|
||||
font-size: 0.9em;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.link-actions {
|
||||
margin-top: 15px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn-small {
|
||||
padding: 8px 15px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
color: #666;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.empty-state .icon {
|
||||
font-size: 3em;
|
||||
margin-bottom: 15px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.page-actions {
|
||||
background: #f8f9fa;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
border-top: 1px solid #e9ecef;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 12px 20px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background: #d4edda;
|
||||
border: 1px solid #c3e6cb;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
background: #f8d7da;
|
||||
border: 1px solid #f5c6cb;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.main-content {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.page-actions {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>✏️ Edit Links</h1>
|
||||
<p>Manage your link collection: {{ page.title }}</p>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-success" id="success-alert">
|
||||
Operation completed successfully!
|
||||
</div>
|
||||
|
||||
<div class="alert alert-error" id="error-alert">
|
||||
An error occurred. Please try again.
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="form-section">
|
||||
<h2>Add New Link</h2>
|
||||
<form id="add-link-form">
|
||||
<div class="form-group">
|
||||
<label for="link-title">Title *</label>
|
||||
<input type="text" id="link-title" placeholder="Link title" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="link-url">URL *</label>
|
||||
<input type="url" id="link-url" placeholder="https://example.com" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="link-description">Description</label>
|
||||
<textarea id="link-description" placeholder="Optional description"></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success">Add Link</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="links-section">
|
||||
<h2>Current Links ({{ page.links|length }})</h2>
|
||||
<div id="links-container">
|
||||
{% if page.links %}
|
||||
{% for link in page.links %}
|
||||
<div class="link-item" data-link-id="{{ link.id }}">
|
||||
<div class="link-display">
|
||||
<div class="link-title">{{ link.title }}</div>
|
||||
{% if link.description %}
|
||||
<div class="link-description">{{ link.description }}</div>
|
||||
{% endif %}
|
||||
<div class="link-url">{{ link.url }}</div>
|
||||
<div class="link-actions">
|
||||
<button class="btn btn-small btn-secondary" onclick="editLink('{{ link.id }}')">Edit</button>
|
||||
<button class="btn btn-small btn-danger" onclick="deleteLink('{{ link.id }}')">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="link-edit">
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
<input type="text" class="edit-title" value="{{ link.title }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>URL</label>
|
||||
<input type="url" class="edit-url" value="{{ link.url }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<textarea class="edit-description">{{ link.description or '' }}</textarea>
|
||||
</div>
|
||||
<div class="link-actions">
|
||||
<button class="btn btn-small btn-success" onclick="saveLink('{{ link.id }}')">Save</button>
|
||||
<button class="btn btn-small btn-secondary" onclick="cancelEdit('{{ link.id }}')">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="icon">📝</div>
|
||||
<h3>No links yet</h3>
|
||||
<p>Add your first link using the form on the left.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-actions">
|
||||
<a href="/links/{{ page.id }}" target="_blank" class="btn">👁️ View Public Page</a>
|
||||
<a href="/" class="btn btn-secondary">🏠 Back to Dashboard</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const pageId = '{{ page.id }}';
|
||||
|
||||
// Add new link
|
||||
document.getElementById('add-link-form').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const title = document.getElementById('link-title').value;
|
||||
const url = document.getElementById('link-url').value;
|
||||
const description = document.getElementById('link-description').value;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/link_pages/${pageId}/links`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ title, url, description })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('Link added successfully!', 'success');
|
||||
setTimeout(() => location.reload(), 1000);
|
||||
} else {
|
||||
showAlert(result.error || 'Failed to add link', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showAlert('Network error occurred', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// Edit link
|
||||
function editLink(linkId) {
|
||||
const linkItem = document.querySelector(`[data-link-id="${linkId}"]`);
|
||||
linkItem.classList.add('editing');
|
||||
}
|
||||
|
||||
// Cancel edit
|
||||
function cancelEdit(linkId) {
|
||||
const linkItem = document.querySelector(`[data-link-id="${linkId}"]`);
|
||||
linkItem.classList.remove('editing');
|
||||
}
|
||||
|
||||
// Save link
|
||||
async function saveLink(linkId) {
|
||||
const linkItem = document.querySelector(`[data-link-id="${linkId}"]`);
|
||||
const title = linkItem.querySelector('.edit-title').value;
|
||||
const url = linkItem.querySelector('.edit-url').value;
|
||||
const description = linkItem.querySelector('.edit-description').value;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/link_pages/${pageId}/links/${linkId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ title, url, description })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('Link updated successfully!', 'success');
|
||||
setTimeout(() => location.reload(), 1000);
|
||||
} else {
|
||||
showAlert(result.error || 'Failed to update link', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showAlert('Network error occurred', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Delete link
|
||||
async function deleteLink(linkId) {
|
||||
if (!confirm('Are you sure you want to delete this link?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/link_pages/${pageId}/links/${linkId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('Link deleted successfully!', 'success');
|
||||
setTimeout(() => location.reload(), 1000);
|
||||
} else {
|
||||
showAlert(result.error || 'Failed to delete link', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showAlert('Network error occurred', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Show alert
|
||||
function showAlert(message, type) {
|
||||
const alert = document.getElementById(`${type}-alert`);
|
||||
alert.textContent = message;
|
||||
alert.style.display = 'block';
|
||||
|
||||
setTimeout(() => {
|
||||
alert.style.display = 'none';
|
||||
}, 3000);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user