-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.html
More file actions
227 lines (213 loc) · 8.97 KB
/
Copy pathedit.html
File metadata and controls
227 lines (213 loc) · 8.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title data-translate="comic.title.edit">Edit Comic</title>
<link rel="stylesheet" href="styles.css">
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1 {
color: #333;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
}
input, select {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
input[type="number"] {
-moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
.button-group {
margin: 20px 0;
display: flex;
gap: 10px;
align-items: center;
}
button {
padding: 0 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s;
display: inline-flex;
align-items: center;
justify-content: center;
height: 38px;
line-height: 1;
min-width: 120px;
box-sizing: border-box;
background-color: #333;
color: white;
}
button:hover {
background-color: #555;
}
.nav-link {
display: inline-block;
margin-bottom: 20px;
color: #4CAF50;
text-decoration: none;
}
.nav-link:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<a href="index.html" class="nav-link" data-translate="navigation.backToMain">← Back to Main Page</a>
<h1 data-translate="comic.title.edit">Edit Comic</h1>
<form id="editComicForm" onsubmit="saveComic(event)">
<div class="form-group">
<label for="series" data-translate="comic.fields.series">Series</label>
<input type="text" id="series" required>
</div>
<div class="form-group">
<label for="title" data-translate="comic.fields.issueTitle">Title</label>
<input type="text" id="title" required>
</div>
<div class="form-group">
<label for="number" data-translate="comic.fields.issueNumber">Number</label>
<input type="number" id="number" required>
</div>
<div class="form-group">
<label for="writers" data-translate="comic.fields.writers">Writers</label>
<input type="text" id="writers" data-translate-placeholder="comic.form.writersHint">
</div>
<div class="form-group">
<label for="artists" data-translate="comic.fields.artists">Artists</label>
<input type="text" id="artists" data-translate-placeholder="comic.form.artistsHint">
</div>
<div class="form-group">
<label for="language" data-translate="comic.fields.language">Language</label>
<input type="text" id="language" list="languages">
<datalist id="languages"></datalist>
</div>
<div class="form-group">
<label for="publisher" data-translate="comic.fields.publisher">Publisher</label>
<input type="text" id="publisher">
</div>
<div class="form-group">
<label for="year" data-translate="comic.fields.year">Year</label>
<input type="number" id="year">
</div>
<div class="button-group">
<button type="submit" class="btn btn-primary" data-translate="comic.actions.save">Save Changes</button>
<a href="index.html" class="btn btn-secondary" data-translate="comic.actions.cancel">Cancel</a>
</div>
</form>
</div>
<script src="/translations.js"></script>
<script>
// Get comic ID from URL
const urlParams = new URLSearchParams(window.location.search);
const comicId = urlParams.get('id');
// Load comic data
async function loadComicData() {
try {
const response = await fetch(`/api/comics/${comicId}`);
if (!response.ok) throw new Error('Failed to load comic');
const comic = await response.json();
// Populate form fields
document.getElementById('series').value = comic.seriesTitle || '';
document.getElementById('title').value = comic.issueTitle || '';
document.getElementById('number').value = comic.issueNumber || '';
document.getElementById('writers').value = (Array.isArray(comic.writers) ? comic.writers : [comic.writer]).join(', ');
document.getElementById('artists').value = (Array.isArray(comic.artists) ? comic.artists : []).join(', ');
document.getElementById('language').value = comic.language || '';
document.getElementById('publisher').value = comic.publisher || '';
document.getElementById('year').value = comic.publicationYear || '';
} catch (error) {
console.error('Error loading comic:', error);
alert('Failed to load comic data');
}
}
// Handle form submission
async function saveComic(event) {
event.preventDefault();
const comicData = {
seriesTitle: document.getElementById('series').value,
issueTitle: document.getElementById('title').value,
issueNumber: parseInt(document.getElementById('number').value) || 1,
writers: document.getElementById('writers').value.split(',').map(w => w.trim()).filter(Boolean),
artists: document.getElementById('artists').value.split(',').map(a => a.trim()).filter(Boolean),
language: document.getElementById('language').value,
publisher: document.getElementById('publisher').value,
publicationYear: parseInt(document.getElementById('year').value) || null
};
try {
const response = await fetch(`/api/comics/${comicId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(comicData)
});
if (!response.ok) throw new Error('Failed to update comic');
window.location.href = 'index.html';
} catch (error) {
console.error('Error updating comic:', error);
alert('Failed to update comic');
}
}
// Load translations when the page loads
document.addEventListener('DOMContentLoaded', async () => {
try {
// Get the saved language from localStorage (set by main page)
const savedLang = localStorage.getItem('selectedLanguage') || 'en';
// Fetch translations
const response = await fetch('/translations');
if (!response.ok) throw new Error('Failed to load translations');
const data = await response.json();
// Set up translations
window.translations = data.translations;
window.availableLanguages = data.availableLanguages;
// Apply translations
translatePage();
// Set up language datalist
const languagesDatalist = document.getElementById('languages');
if (languagesDatalist) {
availableLanguages.forEach(lang => {
const option = document.createElement('option');
option.value = lang.name;
languagesDatalist.appendChild(option);
});
}
// Load comic data after translations are set up
await loadComicData();
} catch (error) {
console.error('Error loading translations:', error);
}
});
</script>
</body>
</html>