forked from taranjeetsingh9/PetConnectBackend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-personal-listing.html
More file actions
381 lines (331 loc) · 15.6 KB
/
create-personal-listing.html
File metadata and controls
381 lines (331 loc) · 15.6 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>List Your Pet for Fostering</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50 min-h-screen">
<!-- Navigation -->
<nav class="bg-white shadow-sm border-b">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex items-center">
<h1 class="text-xl font-bold text-indigo-700">PetConnect</h1>
</div>
<div class="flex items-center space-x-4">
<button onclick="window.location.href='pet-browser.html'"
class="text-gray-700 hover:text-indigo-600">
Browse Pets
</button>
<button onclick="window.location.href='user-listings.html'"
class="text-gray-700 hover:text-indigo-600">
My Listings
</button>
<button onclick="window.location.href='user-profile.html'"
class="text-gray-700 hover:text-indigo-600">
My Profile
</button>
<button id="logoutBtn"
class="bg-red-500 text-white px-4 py-2 rounded-lg hover:bg-red-600">
Logout
</button>
</div>
</div>
</div>
</nav>
<div class="max-w-2xl mx-auto py-8 px-4 sm:px-6 lg:px-8">
<div class="bg-white rounded-xl shadow-lg p-6">
<!-- Progress Steps -->
<div class="flex justify-between mb-8">
<div class="flex-1 text-center">
<div class="w-8 h-8 bg-indigo-600 text-white rounded-full flex items-center justify-center mx-auto mb-2">1</div>
<p class="text-sm font-medium text-indigo-600">Pet Details</p>
</div>
<div class="flex-1 text-center">
<div class="w-8 h-8 bg-gray-300 text-gray-600 rounded-full flex items-center justify-center mx-auto mb-2">2</div>
<p class="text-sm font-medium text-gray-500">Photos</p>
</div>
<div class="flex-1 text-center">
<div class="w-8 h-8 bg-gray-300 text-gray-600 rounded-full flex items-center justify-center mx-auto mb-2">3</div>
<p class="text-sm font-medium text-gray-500">Review</p>
</div>
</div>
<h1 class="text-3xl font-bold text-gray-900 mb-2">List Your Pet for Fostering</h1>
<p class="text-gray-600 mb-6">Help your pet find a temporary loving home while you're away</p>
<form id="petListingForm" class="space-y-6" enctype="multipart/form-data">
<!-- Basic Information -->
<div class="border-b border-gray-200 pb-6">
<h2 class="text-xl font-semibold text-gray-900 mb-4">Basic Information</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Pet Name *</label>
<input type="text" id="petName" required
class="w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Breed</label>
<input type="text" id="petBreed"
class="w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="e.g., Golden Retriever, Mixed">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Age (years)</label>
<input type="number" id="petAge" min="0" max="30"
class="w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Gender *</label>
<select id="petGender" required
class="w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
<option value="">Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Foster Duration *</label>
<select id="duration" required
class="w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
<option value="">Select Duration</option>
<option value="short_term">Short Term (1-2 weeks)</option>
<option value="medium_term">Medium Term (3-4 weeks)</option>
<option value="long_term">Long Term (1+ months)</option>
</select>
</div>
</div>
</div>
<!-- Description & Care -->
<div class="border-b border-gray-200 pb-6">
<h2 class="text-xl font-semibold text-gray-900 mb-4">Description & Care</h2>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Description *</label>
<textarea id="description" required rows="4"
class="w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="Tell potential fosters about your pet's personality, likes, dislikes, etc."></textarea>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Care Instructions</label>
<textarea id="careInstructions" rows="3"
class="w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="Feeding schedule, exercise needs, medication, special care requirements..."></textarea>
</div>
</div>
</div>
<!-- Location & Contact -->
<div class="border-b border-gray-200 pb-6">
<h2 class="text-xl font-semibold text-gray-900 mb-4">Location & Contact</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Location *</label>
<input type="text" id="location" required
class="w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="City, State">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Contact Info *</label>
<input type="text" id="contactInfo" required
class="w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="Phone number or email">
<p class="text-xs text-gray-500 mt-1">This will be shown to potential fosters</p>
</div>
</div>
</div>
<!-- Photos -->
<div class="pb-6">
<h2 class="text-xl font-semibold text-gray-900 mb-4">Photos</h2>
<div class="border-2 border-dashed border-gray-300 rounded-lg p-6 text-center">
<input type="file" id="petImages" multiple accept="image/*" required
class="hidden">
<div id="uploadArea" class="cursor-pointer">
<svg class="mx-auto h-12 w-12 text-gray-400" stroke="currentColor" fill="none" viewBox="0 0 48 48">
<path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<p class="mt-2 text-sm text-gray-600">Click to upload photos</p>
<p class="text-xs text-gray-500">PNG, JPG, GIF up to 15MB each</p>
</div>
<div id="imagePreview" class="mt-4 grid grid-cols-2 md:grid-cols-4 gap-4 hidden">
<!-- Images will be previewed here -->
</div>
</div>
<p class="text-xs text-gray-500 mt-2">Upload at least one clear photo of your pet</p>
</div>
<!-- Submit Button -->
<div class="flex justify-end space-x-4">
<button type="button" onclick="window.location.href='pet-browser.html'"
class="px-6 py-3 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50">
Cancel
</button>
<button type="submit"
class="px-6 py-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 font-medium">
Create Listing
</button>
</div>
</form>
<!-- Result Message -->
<div id="resultMessage" class="mt-4 p-4 rounded-lg hidden"></div>
</div>
</div>
<script>
const token = localStorage.getItem('token');
if (!token) {
window.location.href = 'index.html';
}
// DOM Elements
const uploadArea = document.getElementById('uploadArea');
const petImagesInput = document.getElementById('petImages');
const imagePreview = document.getElementById('imagePreview');
const form = document.getElementById('petListingForm');
// File Upload Handling
uploadArea.addEventListener('click', () => {
petImagesInput.click();
});
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.classList.add('border-indigo-500', 'bg-indigo-50');
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.classList.remove('border-indigo-500', 'bg-indigo-50');
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.classList.remove('border-indigo-500', 'bg-indigo-50');
petImagesInput.files = e.dataTransfer.files;
handleFileSelection();
});
petImagesInput.addEventListener('change', handleFileSelection);
function handleFileSelection() {
const files = petImagesInput.files;
if (files.length > 0) {
imagePreview.innerHTML = '';
imagePreview.classList.remove('hidden');
uploadArea.classList.add('hidden');
Array.from(files).forEach((file, index) => {
if (file.type.startsWith('image/')) {
const reader = new FileReader();
reader.onload = function(e) {
const div = document.createElement('div');
div.className = 'relative group';
div.innerHTML = `
<img src="${e.target.result}" class="w-full h-32 object-cover rounded-lg">
<button type="button" onclick="removeImage(${index})"
class="absolute -top-2 -right-2 bg-red-500 text-white rounded-full w-6 h-6 flex items-center justify-center text-xs opacity-0 group-hover:opacity-100 transition-opacity">
×
</button>
${index === 0 ? '<div class="absolute top-2 left-2 bg-blue-500 text-white text-xs px-2 py-1 rounded">Primary</div>' : ''}
`;
imagePreview.appendChild(div);
};
reader.readAsDataURL(file);
}
});
} else {
imagePreview.classList.add('hidden');
uploadArea.classList.remove('hidden');
}
}
function removeImage(index) {
const dt = new DataTransfer();
const files = petImagesInput.files;
for (let i = 0; i < files.length; i++) {
if (i !== index) {
dt.items.add(files[i]);
}
}
petImagesInput.files = dt.files;
handleFileSelection();
}
// Form Submission
form.addEventListener('submit', async (e) => {
e.preventDefault();
// Validate form
if (!validateForm()) return;
const submitBtn = form.querySelector('button[type="submit"]');
submitBtn.disabled = true;
submitBtn.textContent = 'Creating Listing...';
try {
const formData = new FormData();
// Add form fields
formData.append('name', document.getElementById('petName').value);
formData.append('breed', document.getElementById('petBreed').value);
formData.append('age', document.getElementById('petAge').value);
formData.append('gender', document.getElementById('petGender').value);
formData.append('description', document.getElementById('description').value);
formData.append('careInstructions', document.getElementById('careInstructions').value);
formData.append('location', document.getElementById('location').value);
formData.append('contactInfo', document.getElementById('contactInfo').value);
formData.append('duration', document.getElementById('duration').value);
// Add images
const imageFiles = petImagesInput.files;
for (let i = 0; i < imageFiles.length; i++) {
formData.append('images', imageFiles[i]);
}
const response = await fetch('http://localhost:5001/api/pet-files/user-pet/upload', {
method: 'POST',
headers: {
'x-auth-token': token
},
body: formData
});
const result = await response.json();
if (response.ok) {
showMessage('Pet listing created successfully! Your pet is now visible to potential fosters.', 'success');
form.reset();
imagePreview.classList.add('hidden');
uploadArea.classList.remove('hidden');
// Redirect to listings page after 2 seconds
setTimeout(() => {
window.location.href = 'user-listings.html';
}, 2000);
} else {
showMessage(result.msg || 'Failed to create listing', 'error');
}
} catch (error) {
console.error('Error creating listing:', error);
showMessage('Network error. Please try again.', 'error');
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'Create Listing';
}
});
function validateForm() {
const requiredFields = [
'petName', 'petGender', 'description', 'location', 'contactInfo', 'duration'
];
for (const fieldId of requiredFields) {
const field = document.getElementById(fieldId);
if (!field.value.trim()) {
showMessage(`Please fill in the ${field.labels[0].textContent}`, 'error');
field.focus();
return false;
}
}
if (petImagesInput.files.length === 0) {
showMessage('Please upload at least one photo of your pet', 'error');
return false;
}
return true;
}
function showMessage(message, type) {
const messageDiv = document.getElementById('resultMessage');
messageDiv.textContent = message;
messageDiv.className = `mt-4 p-4 rounded-lg ${
type === 'success' ? 'bg-green-100 text-green-700 border border-green-200' : 'bg-red-100 text-red-700 border border-red-200'
}`;
messageDiv.classList.remove('hidden');
setTimeout(() => {
messageDiv.classList.add('hidden');
}, 5000);
}
// Logout
document.getElementById('logoutBtn').addEventListener('click', () => {
localStorage.removeItem('token');
window.location.href = 'index.html';
});
</script>
</body>
</html>