-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
213 lines (180 loc) · 8.27 KB
/
test.html
File metadata and controls
213 lines (180 loc) · 8.27 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Card</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f8f9fa; /* Light background for the page */
}
.form-label {
font-size: 1.25rem; /* Larger font size for labels */
font-weight: bold;
}
.card {
background-color: #e9ecef; /* Light gray background for the form */
}
.bg-red {
background-color: #FF5733 !important;
}
.bg-green {
background-color: #33FF57 !important;
}
.bg-blue {
background-color: #3357FF !important;
}
.bg-yellow {
background-color: #F1C40F !important;
}
.bg-purple {
background-color: #9B59B6 !important;
}
</style>
<script>
let jsonData = { "cards": [] }; // Placeholder for JSON data
// Function to load JSON data from the file
async function loadJSON() {
try {
const response = await fetch('test.json');
jsonData = await response.json();
displayCards();
} catch (error) {
console.error('Error loading JSON:', error);
}
}
// Function to add a new card
function addCard(event) {
event.preventDefault(); // Prevent form submission
// Get input values
const id = document.getElementById('card-id').value;
const title = document.getElementById('card-title').value;
const subTitle = document.getElementById('card-subtitle').value;
const description = document.getElementById('card-description').value;
const image = document.getElementById('card-image').value;
const backgroundColor = document.getElementById('card-backgroundColor').value;
const buttonText = document.getElementById('card-buttonText').value;
const buttonLink = document.getElementById('card-buttonLink').value;
const tags = document.getElementById('card-tags').value;
// Add the new card to the JSON structure
jsonData.cards.push({
id: parseInt(id),
title: title,
subTitle: subTitle,
description: description,
image: image,
backgroundColor: backgroundColor,
buttonText: buttonText,
buttonLink: buttonLink,
tags: tags
});
// Display the updated JSON data
displayCards();
// Clear the form
document.getElementById('card-form').reset();
// Save the updated JSON data (requires a backend to persist changes)
saveJSON();
}
// Function to display cards on the page
function displayCards() {
const cardsContainer = document.getElementById('cards-container');
cardsContainer.innerHTML = ''; // Clear existing content
jsonData.cards.forEach(card => {
const cardElement = document.createElement('div');
cardElement.classList.add('card', 'mb-3', 'p-3', 'shadow-sm');
cardElement.style.backgroundColor = card.backgroundColor; // Set card background color dynamically
cardElement.innerHTML = `
<p><strong>ID:</strong> ${card.id}</p>
<p><strong>Title:</strong> ${card.title}</p>
<p><strong>SubTitle:</strong> ${card.subTitle}</p>
<p><strong>Description:</strong> ${card.description}</p>
<p><strong>Image:</strong> <img src="${card.image}" alt="${card.title}" class="img-fluid" style="max-width: 100px;"></p>
<p><strong>Background Color:</strong> <span style="background-color: ${card.backgroundColor}; padding: 5px;">${card.backgroundColor}</span></p>
<p><strong>Button:</strong> <a href="${card.buttonLink}" class="btn btn-primary">${card.buttonText}</a></p>
<p><strong>Tags:</strong> ${card.tags}</p>
`;
cardsContainer.appendChild(cardElement);
});
}
// Function to save JSON data
async function saveJSON() {
try {
const response = await fetch('/save-json', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(jsonData)
});
if (response.ok) {
console.log('JSON data saved successfully.');
} else {
console.error('Error saving JSON:', await response.text());
}
} catch (error) {
console.error('Error saving JSON:', error);
}
}
// Load JSON data on page load
window.onload = loadJSON;
</script>
</head>
<body class="bg-warning">
<div class="container mt-5 bg-red">
<h1 class="text-center mb-4">Add a New Card</h1>
<form id="card-form" class="card p-4 shadow-sm bg-green" onsubmit="addCard(event)">
<div class="mb-3">
<label for="card-id" class="form-label">Card ID:</label>
<input type="number" id="card-id" class="form-control" required>
</div>
<div class="mb-3">
<label for="card-title" class="form-label">Card Title:</label>
<input type="text" id="card-title" class="form-control" required>
</div>
<div class="mb-3">
<label for="card-subtitle" class="form-label">Card SubTitle:</label>
<input type="text" id="card-subtitle" class="form-control">
</div>
<div class="mb-3">
<label for="card-description" class="form-label">Card Description:</label>
<textarea id="card-description" class="form-control" rows="4"></textarea>
</div>
<div class="mb-3">
<label for="card-image" class="form-label">Card Image URL:</label>
<input type="text" id="card-image" class="form-control" value="./media/photo/" required>
</div>
<div class="mb-3">
<label for="card-backgroundColor" class="form-label">Card Background Color:</label>
<select id="card-backgroundColor" class="form-select" required>
<option value="#FF5733" class="bg-red text-white">Red</option>
<option value="#33FF57" class="bg-green text-white">Green</option>
<option value="#3357FF" class="bg-blue text-white">Blue</option>
<option value="#F1C40F" class="bg-yellow text-dark">Yellow</option>
<option value="#9B59B6" class="bg-purple text-white">Purple</option>
</select>
</div>
<div class="mb-3">
<label for="card-buttonText" class="form-label">Button Text:</label>
<input type="text" id="card-buttonText" class="form-control" value="Go" required>
</div>
<div class="mb-3">
<label for="card-buttonLink" class="form-label">Button Link:</label>
<input type="text" id="card-buttonLink" class="form-control" required>
</div>
<div class="mb-3">
<label for="card-tags" class="form-label">Tags (comma-separated):</label>
<input type="text" id="card-tags" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary w-100">Add Card</button>
</form>
<h2 class="text-center mt-5">Existing Cards</h2>
<div id="cards-container" class="mt-4">
<!-- Cards will be displayed here -->
</div>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>