✨ New Features: - Complete backup lifecycle management (create, list, download, delete, cleanup) - Web-based backup interface with real-time status updates - Individual backup deletion and bulk cleanup for old backups - Docker-aware backup operations with volume persistence - Automated backup scheduling and retention policies 📁 Added Files: - backup.py - Core backup script for creating timestamped archives - docker_backup.sh - Docker-compatible backup wrapper script - app/templates/backup.html - Web interface for backup management - BACKUP_SYSTEM.md - Comprehensive backup system documentation - BACKUP_GUIDE.md - Quick reference guide for backup operations 🔧 Enhanced Files: - Dockerfile - Added backup.py copy for container availability - docker-compose.yml - Added backup volume mount for persistence - app/routes/api.py - Added backup API endpoints (create, list, delete, cleanup) - app/routes/main.py - Added backup management route - app/templates/index.html - Added backup management navigation - README.md - Updated with backup system overview and quick start 🎯 Key Improvements: - Fixed backup creation errors in Docker environment - Added Docker-aware path detection for container operations - Implemented proper error handling and user confirmation dialogs - Added real-time backup status updates via JavaScript - Enhanced data persistence with volume mounting 💡 Use Cases: - Data protection and disaster recovery - Environment migration and cloning - Development data management - Automated maintenance workflows
1020 lines
37 KiB
HTML
Executable File
1020 lines
37 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>QR Code Manager</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: 1200px;
|
|
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.5em;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.header p {
|
|
font-size: 1.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 select,
|
|
.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 select:focus,
|
|
.form-group textarea:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.form-group textarea {
|
|
height: 100px;
|
|
resize: vertical;
|
|
}
|
|
|
|
.color-inputs {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 15px;
|
|
}
|
|
|
|
.color-input-group {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.color-input-group input[type="color"] {
|
|
width: 50px;
|
|
height: 40px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.style-selector {
|
|
display: grid;
|
|
grid-template-columns: repeat(3, 1fr);
|
|
gap: 10px;
|
|
}
|
|
|
|
.style-option {
|
|
padding: 10px;
|
|
border: 2px solid #e9ecef;
|
|
border-radius: 8px;
|
|
text-align: center;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
background: white;
|
|
}
|
|
|
|
.style-option:hover {
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.style-option.active {
|
|
border-color: #667eea;
|
|
background: #667eea;
|
|
color: white;
|
|
}
|
|
|
|
.wifi-fields,
|
|
.link-page-fields,
|
|
.email-fields,
|
|
.sms-fields,
|
|
.vcard-fields,
|
|
.url-shortener-fields {
|
|
display: none;
|
|
}
|
|
|
|
.wifi-fields.active,
|
|
.link-page-fields.active,
|
|
.email-fields.active,
|
|
.sms-fields.active,
|
|
.vcard-fields.active,
|
|
.url-shortener-fields.active {
|
|
display: block;
|
|
}
|
|
|
|
.btn {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 12px 30px;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
transition: transform 0.2s;
|
|
width: 100%;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.btn:hover {
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.btn:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.result-section {
|
|
text-align: center;
|
|
}
|
|
|
|
.qr-preview {
|
|
background: white;
|
|
border: 2px dashed #ddd;
|
|
border-radius: 10px;
|
|
padding: 30px;
|
|
margin-bottom: 20px;
|
|
min-height: 300px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.qr-preview img {
|
|
max-width: 100%;
|
|
max-height: 250px;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
.qr-preview .placeholder {
|
|
color: #999;
|
|
font-size: 1.1em;
|
|
}
|
|
|
|
.download-section {
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: #6c757d;
|
|
flex: 1;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: #28a745;
|
|
flex: 1;
|
|
}
|
|
|
|
.btn-success {
|
|
background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
|
|
flex: 1;
|
|
}
|
|
|
|
.btn-success:hover {
|
|
background: linear-gradient(135deg, #20c997 0%, #17a2b8 100%);
|
|
}
|
|
|
|
.qr-history {
|
|
margin-top: 30px;
|
|
padding: 25px;
|
|
background: #f8f9fa;
|
|
border-radius: 10px;
|
|
border: 1px solid #e9ecef;
|
|
}
|
|
|
|
.qr-history h3 {
|
|
margin-bottom: 20px;
|
|
color: #333;
|
|
}
|
|
|
|
.qr-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 15px;
|
|
padding: 15px;
|
|
background: white;
|
|
border-radius: 8px;
|
|
margin-bottom: 10px;
|
|
border: 1px solid #e9ecef;
|
|
}
|
|
|
|
.qr-item img {
|
|
width: 50px;
|
|
height: 50px;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
.qr-item-info {
|
|
flex: 1;
|
|
}
|
|
|
|
.qr-item-info h4 {
|
|
color: #333;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.qr-item-info p {
|
|
color: #666;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.qr-item-actions {
|
|
display: flex;
|
|
gap: 10px;
|
|
}
|
|
|
|
.btn-small {
|
|
padding: 5px 15px;
|
|
font-size: 12px;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
body {
|
|
padding: 10px;
|
|
}
|
|
|
|
.container {
|
|
border-radius: 10px;
|
|
}
|
|
|
|
.header {
|
|
padding: 20px 15px;
|
|
position: relative;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 2em;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.header p {
|
|
font-size: 1em;
|
|
}
|
|
|
|
.header div {
|
|
position: static !important;
|
|
text-align: center;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.main-content {
|
|
grid-template-columns: 1fr;
|
|
gap: 20px;
|
|
padding: 20px 15px;
|
|
}
|
|
|
|
.form-section {
|
|
padding: 20px 15px;
|
|
}
|
|
|
|
.form-section h2 {
|
|
font-size: 1.3em;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.color-inputs {
|
|
grid-template-columns: 1fr;
|
|
gap: 10px;
|
|
}
|
|
|
|
.style-selector {
|
|
grid-template-columns: 1fr;
|
|
gap: 8px;
|
|
}
|
|
|
|
.qr-preview {
|
|
padding: 20px 10px;
|
|
min-height: 250px;
|
|
}
|
|
|
|
.qr-preview img {
|
|
max-height: 200px;
|
|
}
|
|
|
|
.download-section {
|
|
gap: 8px;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.download-section .btn {
|
|
margin: 0;
|
|
padding: 12px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
/* QR History Mobile Optimization */
|
|
.qr-history {
|
|
margin-top: 20px;
|
|
padding: 15px;
|
|
}
|
|
|
|
.qr-history h3 {
|
|
font-size: 1.2em;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.qr-item {
|
|
flex-direction: column;
|
|
align-items: stretch;
|
|
gap: 12px;
|
|
padding: 15px;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.qr-item-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
|
|
.qr-item img {
|
|
width: 60px;
|
|
height: 60px;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.qr-item-info {
|
|
flex: 1;
|
|
margin: 0;
|
|
}
|
|
|
|
.qr-item-info h4 {
|
|
font-size: 1em;
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.qr-item-info p {
|
|
font-size: 0.85em;
|
|
margin: 0;
|
|
}
|
|
|
|
.qr-item-actions {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 8px;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.qr-item-actions.full-width {
|
|
grid-template-columns: 1fr 1fr 1fr;
|
|
}
|
|
|
|
.btn-small {
|
|
padding: 8px 12px;
|
|
font-size: 11px;
|
|
text-align: center;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
min-height: 32px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
/* Special handling for link_page items with more buttons */
|
|
.qr-item[data-type="link_page"] .qr-item-actions {
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 6px;
|
|
}
|
|
|
|
.qr-item[data-type="link_page"] .btn-small {
|
|
font-size: 10px;
|
|
padding: 6px 8px;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 480px) {
|
|
.header h1 {
|
|
font-size: 1.8em;
|
|
}
|
|
|
|
.form-section {
|
|
padding: 15px 10px;
|
|
}
|
|
|
|
.main-content {
|
|
padding: 15px 10px;
|
|
}
|
|
|
|
.qr-history {
|
|
padding: 10px;
|
|
}
|
|
|
|
.qr-item {
|
|
padding: 12px;
|
|
}
|
|
|
|
.qr-item img {
|
|
width: 50px;
|
|
height: 50px;
|
|
}
|
|
|
|
.qr-item-actions {
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 6px;
|
|
}
|
|
|
|
.btn-small {
|
|
font-size: 10px;
|
|
padding: 6px 8px;
|
|
min-height: 30px;
|
|
}
|
|
|
|
/* Stack action buttons for very small screens */
|
|
.qr-item[data-type="link_page"] .qr-item-actions {
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 5px;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>🎯 QR Code Manager</h1>
|
|
<p>Create, customize, and manage your QR codes with ease</p>
|
|
<div style="position: absolute; top: 20px; right: 20px; display: flex; gap: 10px;">
|
|
<a href="/backup" style="color: white; text-decoration: none; background: rgba(255,255,255,0.2); padding: 8px 15px; border-radius: 20px; font-size: 0.9em;">
|
|
🛡️ Backup
|
|
</a>
|
|
<a href="/logout" style="color: white; text-decoration: none; background: rgba(255,255,255,0.2); padding: 8px 15px; border-radius: 20px; font-size: 0.9em;">
|
|
👤 Logout
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<div class="form-section">
|
|
<h2>Generate QR Code</h2>
|
|
|
|
<div class="form-group">
|
|
<label for="qr-type">QR Code Type</label>
|
|
<select id="qr-type" onchange="toggleFields()">
|
|
<option value="text">Text</option>
|
|
<option value="url">URL/Website</option>
|
|
<option value="link_page">Dynamic Link Page</option>
|
|
<option value="url_shortener">URL Shortener</option>
|
|
<option value="wifi">WiFi</option>
|
|
<option value="email">Email</option>
|
|
<option value="phone">Phone</option>
|
|
<option value="sms">SMS</option>
|
|
<option value="vcard">Contact Card</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Text/URL content -->
|
|
<div class="form-group" id="text-field">
|
|
<label for="content">Content</label>
|
|
<textarea id="content" placeholder="Enter your text or URL..."></textarea>
|
|
</div>
|
|
|
|
<!-- WiFi fields -->
|
|
<div class="wifi-fields" id="wifi-fields">
|
|
<div class="form-group">
|
|
<label for="wifi-ssid">Network Name (SSID)</label>
|
|
<input type="text" id="wifi-ssid" placeholder="My WiFi Network">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="wifi-password">Password</label>
|
|
<input type="password" id="wifi-password" placeholder="WiFi Password">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="wifi-security">Security Type</label>
|
|
<select id="wifi-security">
|
|
<option value="WPA">WPA/WPA2</option>
|
|
<option value="WEP">WEP</option>
|
|
<option value="nopass">No Password</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Link Page fields -->
|
|
<div class="link-page-fields" id="link-page-fields">
|
|
<div class="form-group">
|
|
<label for="page-title">Page Title</label>
|
|
<input type="text" id="page-title" placeholder="My Link Collection" value="My Links">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="page-description">Description</label>
|
|
<textarea id="page-description" placeholder="A collection of useful links">Collection of useful links</textarea>
|
|
</div>
|
|
<div class="form-group">
|
|
<p style="background: #e3f2fd; padding: 15px; border-radius: 8px; color: #1565c0; font-size: 0.9em;">
|
|
<strong>💡 Dynamic Link Page with Short URL:</strong> This creates a QR code with a short URL that points to a web page where you can add, edit, and manage links. The QR code stays the same, but you can update the links anytime!
|
|
<br><br>✨ <strong>Auto Short URL:</strong> Your link page will automatically get a short URL like <code>qr.moto-adv.com/s/abc123</code> making the QR code simpler and easier to scan!
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- URL Shortener fields -->
|
|
<div class="url-shortener-fields" id="url-shortener-fields">
|
|
<div class="form-group">
|
|
<label for="shortener-url">URL to Shorten</label>
|
|
<input type="url" id="shortener-url" placeholder="https://example.com/very/long/url">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="shortener-title">Title (optional)</label>
|
|
<input type="text" id="shortener-title" placeholder="My Website">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="shortener-custom-code">Custom Short Code (optional)</label>
|
|
<input type="text" id="shortener-custom-code" placeholder="mylink" maxlength="20">
|
|
<small style="color: #666; font-size: 0.8em;">
|
|
Leave empty for random code. Only letters and numbers allowed.
|
|
</small>
|
|
</div>
|
|
<div class="form-group">
|
|
<p style="background: #e3f2fd; padding: 15px; border-radius: 8px; color: #1565c0; font-size: 0.9em;">
|
|
<strong>🔗 URL Shortener:</strong> Creates a short URL that redirects to your original URL. The QR code will contain the short URL. Perfect for long URLs or tracking clicks!
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Email fields -->
|
|
<div class="email-fields" id="email-fields">
|
|
<div class="form-group">
|
|
<label for="email-address">Email Address</label>
|
|
<input type="email" id="email-address" placeholder="contact@example.com">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email-subject">Subject</label>
|
|
<input type="text" id="email-subject" placeholder="Email subject">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email-body">Message</label>
|
|
<textarea id="email-body" placeholder="Email message..."></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- SMS fields -->
|
|
<div class="sms-fields" id="sms-fields">
|
|
<div class="form-group">
|
|
<label for="sms-phone">Phone Number</label>
|
|
<input type="tel" id="sms-phone" placeholder="+1234567890">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="sms-message">Message</label>
|
|
<textarea id="sms-message" placeholder="SMS message..."></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- vCard fields -->
|
|
<div class="vcard-fields" id="vcard-fields">
|
|
<div class="form-group">
|
|
<label for="vcard-name">Full Name</label>
|
|
<input type="text" id="vcard-name" placeholder="John Doe">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="vcard-organization">Organization</label>
|
|
<input type="text" id="vcard-organization" placeholder="Company Name">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="vcard-phone">Phone</label>
|
|
<input type="tel" id="vcard-phone" placeholder="+1234567890">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="vcard-email">Email</label>
|
|
<input type="email" id="vcard-email" placeholder="john@example.com">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="vcard-website">Website</label>
|
|
<input type="url" id="vcard-website" placeholder="https://example.com">
|
|
</div>
|
|
</div>
|
|
|
|
<h3 style="margin: 25px 0 15px 0; color: #333;">Customization</h3>
|
|
|
|
<div class="form-group">
|
|
<label>Colors</label>
|
|
<div class="color-inputs">
|
|
<div class="color-input-group">
|
|
<input type="color" id="foreground-color" value="#000000">
|
|
<span>Foreground</span>
|
|
</div>
|
|
<div class="color-input-group">
|
|
<input type="color" id="background-color" value="#FFFFFF">
|
|
<span>Background</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>Style</label>
|
|
<div class="style-selector">
|
|
<div class="style-option active" data-style="square">
|
|
<div>⬛</div>
|
|
<div>Square</div>
|
|
</div>
|
|
<div class="style-option" data-style="rounded">
|
|
<div>⬜</div>
|
|
<div>Rounded</div>
|
|
</div>
|
|
<div class="style-option" data-style="circle">
|
|
<div>⚫</div>
|
|
<div>Circle</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="size">Size</label>
|
|
<input type="range" id="size" min="5" max="15" value="10" oninput="updateSizeLabel()">
|
|
<small id="size-label">10px per module</small>
|
|
</div>
|
|
|
|
<button class="btn" onclick="generateQR()">Generate QR Code</button>
|
|
</div>
|
|
|
|
<div class="result-section">
|
|
<h2>Preview</h2>
|
|
<div class="qr-preview" id="qr-preview">
|
|
<div class="placeholder">
|
|
<div style="font-size: 3em; margin-bottom: 10px;">📱</div>
|
|
<div>Your QR code will appear here</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="download-section" id="download-section">
|
|
<button class="btn btn-primary" onclick="downloadQR('png')">📥 Download PNG</button>
|
|
<button class="btn btn-success" onclick="downloadQR('svg')">🎨 Download SVG</button>
|
|
<button class="btn btn-secondary" onclick="copyToClipboard()">📋 Copy Image</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="qr-history">
|
|
<h3>Recent QR Codes</h3>
|
|
<div id="qr-history-list">
|
|
<p style="color: #666; text-align: center;">No QR codes generated yet</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let currentQRId = null;
|
|
let currentQRData = null;
|
|
|
|
function toggleFields() {
|
|
const type = document.getElementById('qr-type').value;
|
|
|
|
// Hide all specific fields
|
|
document.getElementById('text-field').style.display = 'none';
|
|
document.querySelectorAll('.wifi-fields, .link-page-fields, .email-fields, .sms-fields, .vcard-fields, .url-shortener-fields').forEach(el => {
|
|
el.classList.remove('active');
|
|
});
|
|
|
|
// Show relevant fields
|
|
if (type === 'text' || type === 'url' || type === 'phone') {
|
|
document.getElementById('text-field').style.display = 'block';
|
|
const contentField = document.getElementById('content');
|
|
if (type === 'url') {
|
|
contentField.placeholder = 'https://example.com';
|
|
} else if (type === 'phone') {
|
|
contentField.placeholder = '+1234567890';
|
|
} else {
|
|
contentField.placeholder = 'Enter your text...';
|
|
}
|
|
} else {
|
|
document.getElementById(`${type.replace('_', '-')}-fields`).classList.add('active');
|
|
}
|
|
}
|
|
|
|
function updateSizeLabel() {
|
|
const size = document.getElementById('size').value;
|
|
document.getElementById('size-label').textContent = `${size}px per module`;
|
|
}
|
|
|
|
// Style selector
|
|
document.querySelectorAll('.style-option').forEach(option => {
|
|
option.addEventListener('click', function() {
|
|
document.querySelectorAll('.style-option').forEach(opt => opt.classList.remove('active'));
|
|
this.classList.add('active');
|
|
});
|
|
});
|
|
|
|
async function generateQR() {
|
|
const type = document.getElementById('qr-type').value;
|
|
let content = '';
|
|
let additionalData = {};
|
|
|
|
// Get content based on type
|
|
if (type === 'text' || type === 'url' || type === 'phone') {
|
|
content = document.getElementById('content').value;
|
|
} else if (type === 'link_page') {
|
|
additionalData.title = document.getElementById('page-title').value;
|
|
additionalData.description = document.getElementById('page-description').value;
|
|
} else if (type === 'wifi') {
|
|
additionalData.wifi = {
|
|
ssid: document.getElementById('wifi-ssid').value,
|
|
password: document.getElementById('wifi-password').value,
|
|
security: document.getElementById('wifi-security').value
|
|
};
|
|
} else if (type === 'email') {
|
|
additionalData.email = {
|
|
email: document.getElementById('email-address').value,
|
|
subject: document.getElementById('email-subject').value,
|
|
body: document.getElementById('email-body').value
|
|
};
|
|
} else if (type === 'sms') {
|
|
additionalData.sms = {
|
|
phone: document.getElementById('sms-phone').value,
|
|
message: document.getElementById('sms-message').value
|
|
};
|
|
} else if (type === 'vcard') {
|
|
additionalData.vcard = {
|
|
name: document.getElementById('vcard-name').value,
|
|
organization: document.getElementById('vcard-organization').value,
|
|
phone: document.getElementById('vcard-phone').value,
|
|
email: document.getElementById('vcard-email').value,
|
|
website: document.getElementById('vcard-website').value
|
|
};
|
|
} else if (type === 'url_shortener') {
|
|
additionalData.shortener = {
|
|
url: document.getElementById('shortener-url').value,
|
|
title: document.getElementById('shortener-title').value,
|
|
custom_code: document.getElementById('shortener-custom-code').value
|
|
};
|
|
}
|
|
|
|
const requestData = {
|
|
type: type,
|
|
content: content,
|
|
...additionalData,
|
|
size: parseInt(document.getElementById('size').value),
|
|
foreground_color: document.getElementById('foreground-color').value,
|
|
background_color: document.getElementById('background-color').value,
|
|
style: document.querySelector('.style-option.active').dataset.style
|
|
};
|
|
|
|
try {
|
|
let endpoint = '/api/generate';
|
|
if (type === 'link_page') {
|
|
endpoint = '/api/create_link_page';
|
|
} else if (type === 'url_shortener') {
|
|
endpoint = '/api/generate_shortened_qr';
|
|
}
|
|
|
|
const response = await fetch(endpoint, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(requestData)
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
currentQRId = result.qr_id;
|
|
currentQRData = result.image_data;
|
|
|
|
// Show QR code
|
|
const preview = document.getElementById('qr-preview');
|
|
let previewHTML = `<img src="${result.image_data}" alt="Generated QR Code">`;
|
|
|
|
// Add special info for link pages
|
|
if (type === 'link_page') {
|
|
previewHTML += `
|
|
<div style="margin-top: 15px; padding: 15px; background: #e3f2fd; border-radius: 8px; text-align: left;">
|
|
<h4 style="margin-bottom: 10px; color: #1565c0;">🎉 Dynamic Link Page Created with Short URL!</h4>
|
|
<p style="margin-bottom: 10px; font-size: 0.9em;"><strong>🔗 Short URL:</strong> <a href="${result.page_url}" target="_blank">${result.page_url}</a>
|
|
<button onclick="copyToClipboard('${result.page_url}')" style="margin-left: 10px; padding: 4px 8px; background: #1565c0; color: white; border: none; border-radius: 3px; cursor: pointer; font-size: 0.8em;">Copy</button></p>
|
|
<p style="margin-bottom: 10px; font-size: 0.9em;"><strong>📝 Edit URL:</strong> <a href="${result.edit_url}" target="_blank">${result.edit_url}</a></p>
|
|
${result.original_url ? `<p style="margin-bottom: 10px; font-size: 0.8em; color: #666;"><strong>Original URL:</strong> ${result.original_url}</p>` : ''}
|
|
<p style="font-size: 0.9em; color: #666;">✨ QR code contains the short URL for easier scanning! Share it - visitors will see your link collection. Use the edit URL to manage your links!</p>
|
|
</div>
|
|
`;
|
|
} else if (type === 'url_shortener') {
|
|
previewHTML += `
|
|
<div style="margin-top: 15px; padding: 15px; background: #e8f5e8; border-radius: 8px; text-align: left;">
|
|
<h4 style="margin-bottom: 10px; color: #2e7d32;">🔗 Short URL Created!</h4>
|
|
<p style="margin-bottom: 10px; font-size: 0.9em;"><strong>Short URL:</strong> <a href="${result.short_url}" target="_blank">${result.short_url}</a></p>
|
|
<p style="margin-bottom: 10px; font-size: 0.9em;"><strong>Original URL:</strong> <a href="${result.original_url}" target="_blank">${result.original_url}</a></p>
|
|
<p style="font-size: 0.9em; color: #666;">The QR code contains your short URL. When scanned, it will redirect to your original URL!</p>
|
|
<button onclick="copyToClipboard('${result.short_url}')" style="margin-top: 10px; padding: 8px 15px; background: #2e7d32; color: white; border: none; border-radius: 5px; cursor: pointer;">Copy Short URL</button>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
preview.innerHTML = previewHTML;
|
|
|
|
// Show download buttons
|
|
document.getElementById('download-section').classList.add('active');
|
|
|
|
// Refresh history
|
|
loadQRHistory();
|
|
} else {
|
|
alert('Error generating QR code: ' + result.error);
|
|
}
|
|
} catch (error) {
|
|
alert('Error: ' + error.message);
|
|
}
|
|
}
|
|
|
|
async function downloadQR(format = 'png') {
|
|
if (currentQRId) {
|
|
if (format === 'svg') {
|
|
window.open(`/api/download/${currentQRId}/svg`, '_blank');
|
|
} else {
|
|
window.open(`/api/download/${currentQRId}`, '_blank');
|
|
}
|
|
}
|
|
}
|
|
|
|
async function copyToClipboard() {
|
|
if (currentQRData) {
|
|
try {
|
|
const response = await fetch(currentQRData);
|
|
const blob = await response.blob();
|
|
await navigator.clipboard.write([
|
|
new ClipboardItem({ [blob.type]: blob })
|
|
]);
|
|
alert('QR code copied to clipboard!');
|
|
} catch (error) {
|
|
alert('Failed to copy to clipboard');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Copy to clipboard function
|
|
function copyToClipboard(text) {
|
|
navigator.clipboard.writeText(text).then(function() {
|
|
const btn = event.target;
|
|
const originalText = btn.textContent;
|
|
btn.textContent = 'Copied!';
|
|
btn.style.background = '#4caf50';
|
|
setTimeout(() => {
|
|
btn.textContent = originalText;
|
|
btn.style.background = '#2e7d32';
|
|
}, 1500);
|
|
}).catch(function(err) {
|
|
console.error('Could not copy text: ', err);
|
|
alert('Failed to copy to clipboard');
|
|
});
|
|
}
|
|
|
|
async function loadQRHistory() {
|
|
try {
|
|
const response = await fetch('/api/qr_codes');
|
|
const qrCodes = await response.json();
|
|
|
|
const historyList = document.getElementById('qr-history-list');
|
|
|
|
if (qrCodes.length === 0) {
|
|
historyList.innerHTML = '<p style="color: #666; text-align: center;">No QR codes generated yet</p>';
|
|
return;
|
|
}
|
|
|
|
historyList.innerHTML = qrCodes.map(qr => `
|
|
<div class="qr-item" data-type="${qr.type}">
|
|
<div class="qr-item-header">
|
|
<img src="${qr.preview}" alt="QR Code">
|
|
<div class="qr-item-info">
|
|
<h4>${qr.type.toUpperCase()}${qr.type === 'link_page' ? ' 🔗' : ''}</h4>
|
|
<p>Created: ${new Date(qr.created_at).toLocaleDateString()}</p>
|
|
</div>
|
|
</div>
|
|
<div class="qr-item-actions ${qr.type === 'link_page' ? 'full-width' : ''}">
|
|
<button class="btn btn-small btn-primary" onclick="downloadQRById('${qr.id}', 'png')" title="Download PNG">📥 PNG</button>
|
|
<button class="btn btn-small btn-success" onclick="downloadQRById('${qr.id}', 'svg')" title="Download SVG">🎨 SVG</button>
|
|
${qr.type === 'link_page' ? `<button class="btn btn-small" onclick="openLinkPage('${qr.id}')" style="background: #28a745;" title="Manage Links">📝 Edit</button>` : ''}
|
|
${qr.type === 'link_page' ? `<button class="btn btn-small" onclick="openStatistics('${qr.id}')" style="background: #17a2b8;" title="View Statistics">📊 Stats</button>` : ''}
|
|
<button class="btn btn-small btn-secondary" onclick="deleteQR('${qr.id}')" title="Delete QR Code">🗑️</button>
|
|
</div>
|
|
</div>
|
|
`).join('');
|
|
} catch (error) {
|
|
console.error('Failed to load QR history:', error);
|
|
}
|
|
}
|
|
|
|
async function downloadQRById(qrId, format = 'png') {
|
|
if (format === 'svg') {
|
|
window.open(`/api/download/${qrId}/svg`, '_blank');
|
|
} else {
|
|
window.open(`/api/download/${qrId}`, '_blank');
|
|
}
|
|
}
|
|
|
|
async function deleteQR(qrId) {
|
|
if (confirm('Are you sure you want to delete this QR code?')) {
|
|
try {
|
|
const response = await fetch(`/api/qr_codes/${qrId}`, {
|
|
method: 'DELETE'
|
|
});
|
|
|
|
if (response.ok) {
|
|
loadQRHistory();
|
|
} else {
|
|
alert('Failed to delete QR code');
|
|
}
|
|
} catch (error) {
|
|
alert('Error deleting QR code: ' + error.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function openLinkPage(qrId) {
|
|
try {
|
|
const response = await fetch(`/api/qr_codes/${qrId}`);
|
|
const qrData = await response.json();
|
|
|
|
if (qrData.page_id) {
|
|
window.open(`/edit/${qrData.page_id}`, '_blank');
|
|
} else {
|
|
alert('Link page not found');
|
|
}
|
|
} catch (error) {
|
|
alert('Error opening link page: ' + error.message);
|
|
}
|
|
}
|
|
|
|
async function openStatistics(qrId) {
|
|
try {
|
|
const response = await fetch(`/api/qr_codes/${qrId}`);
|
|
const qrData = await response.json();
|
|
|
|
if (qrData.page_id) {
|
|
window.open(`/stats/${qrData.page_id}`, '_blank');
|
|
} else {
|
|
alert('Link page not found');
|
|
}
|
|
} catch (error) {
|
|
alert('Error opening statistics page: ' + error.message);
|
|
}
|
|
}
|
|
|
|
// Load history on page load
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
loadQRHistory();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|