">
<h1 class="text-xl font-semibold mb-4">{% trans "Request a Pickup" %}</h1>
-<div x-data="pickupForm()">
+<div x-data="pickupForm()" x-init="setupPreview()">
<div class="bg-white rounded shadow p-4" >
<form x-ref="form" id="pickup-form" method="post" enctype="multipart/form-data" class="space-y-4">
{% csrf_token %}
@@ -24,7 +24,8 @@
</div>
</div>
{{ form.materials|attr:"x-ref:materials"|as_crispy_field }}
- {{ form.photos|attr:"x-ref:photos"|as_crispy_field }}
+ {{ form.photos|attr:"x-ref:photos"|attr:"accept:image/*"|as_crispy_field }}
+ <div x-ref="photos_preview" id="photos-preview" class="mt-2 grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2"></div>
<div>
<button id="open-review" class="btn btn-primary" type="button" @click="openReview">Review & Submit</button>
</div>
@@ -67,6 +68,43 @@
function pickupForm(){
return {
rv: {name:'', email:'', phone:'', address:'', preferred_at:'', materials:'', photos: []},
+ setupPreview(){
+ const input = this.$refs.photos;
+ const render = () => this.renderPreviews(input && input.files ? Array.from(input.files) : []);
+ if (input) {
+ input.addEventListener('change', render);
+ // Initial render (in case the browser retained selection)
+ render();
+ }
+ },
+ renderPreviews(files){
+ const wrap = this.$refs.photos_preview;
+ if (!wrap) return;
+ // Clear existing
+ while (wrap.firstChild) wrap.removeChild(wrap.firstChild);
+ if (!files || files.length === 0) return;
+ files.forEach(f => {
+ const item = document.createElement('div');
+ item.className = 'relative border rounded overflow-hidden bg-white shadow-sm';
+ if (f.type && f.type.startsWith('image/')) {
+ const img = document.createElement('img');
+ img.src = URL.createObjectURL(f);
+ img.alt = f.name;
+ img.className = 'w-full h-24 object-cover';
+ item.appendChild(img);
+ } else {
+ const box = document.createElement('div');
+ box.className = 'h-24 flex items-center justify-center text-xs text-gray-600 p-2 text-center';
+ box.textContent = f.name;
+ item.appendChild(box);
+ }
+ const cap = document.createElement('div');
+ cap.className = 'absolute bottom-0 left-0 right-0 bg-black/50 text-white text-[10px] px-1 py-0.5 truncate';
+ cap.textContent = f.name;
+ item.appendChild(cap);
+ wrap.appendChild(item);
+ });
+ },
openReview(){
console.log(this.$refs.form)
const fd = new FormData(this.$refs.form);
@@ -86,7 +124,7 @@
if(this.$refs.dialog.close){ this.$refs.dialog.close(); } else { this.$refs.dialog.removeAttribute('open'); }
this.$refs.form.submit();
}
- }
}
+}
</script>
{% endblock %}
|
||
| 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 |
|
|
|
||
| 1 | 1 |
|
| 2 | 2 |
|
| 3 |
|
|
| 4 |
|
|
| 3 | 5 |
|
| 4 | 6 |
|
| 5 | 7 |
|
| 6 | 8 |
|
| 7 | 9 |
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 8 | 14 |
|
| 9 | 15 |
|
| 10 | 16 |
|
|
||
| 5 | 5 |
|
| 6 | 6 |
|
| 7 | 7 |
|
| 8 |
|
|
| 8 |
|
|
| 9 | 9 |
|
| 10 | 10 |
|
| 11 | 11 |
|
| 12 | 12 |
|
| 13 |
|
|
| 13 |
|
|
| 14 | 14 |
|
| 15 | 15 |
|
| 16 | 16 |
|
| 17 | 17 |
|
| 18 | 18 |
|
| 19 | 19 |
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 20 | 23 |
|
| 21 | 24 |
|
| 22 | 25 |
|
|
||
| 42 | 45 |
|
| 43 | 46 |
|
| 44 | 47 |
|
| 48 |
|
|
| 45 | 49 |
|
| 46 | 50 |
|
| 47 | 51 |
|
|
||
| 54 | 58 |
|
| 55 | 59 |
|
| 56 | 60 |
|
| 61 |
|
|
| 57 | 62 |
|
| 58 | 63 |
|
| 59 | 64 |
|
|
||
| 153 | 158 |
|
| 154 | 159 |
|
| 155 | 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 |
|
|
| 156 | 196 |
|
| 157 | 197 |
|
| 158 | 198 |
|
|
||
| 178 | 218 |
|
| 179 | 219 |
|
| 180 | 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 |
|
|
|
||
| 171 | 171 |
|
| 172 | 172 |
|
| 173 | 173 |
|
| 174 |
|
|
| 174 | 175 |
|
| 175 | 176 |
|
| 176 | 177 |
|
|
||
| 183 | 184 |
|
| 184 | 185 |
|
| 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 |
|
|
| 186 | 230 |
|
| 187 | 231 |
|
| 188 | 232 |
|
|
||
| 8 | 8 |
|
| 9 | 9 |
|
| 10 | 10 |
|
| 11 |
|
|
| 12 |
|
|
| 11 |
|
|
| 13 | 12 |
|
| 14 | 13 |
|
| 15 | 14 |
|
|
||
| 20 | 19 |
|
| 21 | 20 |
|
| 22 | 21 |
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 23 | 34 |
|
| 24 | 35 |
|
| 25 | 36 |
|
|
||
| 35 | 46 |
|
| 36 | 47 |
|
| 37 | 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 |
|
|
| 38 | 88 |
|
| 39 | 89 |
|
| 40 | 90 |
|
|
||
| 46 | 96 |
|
| 47 | 97 |
|
| 48 | 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 |
|
|
| 49 | 131 |
|
|
||
| 153 | 153 |
|
| 154 | 154 |
|
| 155 | 155 |
|
| 156 |
|
|
| 156 |
|
|
| 157 | 157 |
|
| 158 | 158 |
|
| 159 | 159 |
|
|
||
| 223 | 223 |
|
| 224 | 224 |
|
| 225 | 225 |
|
| 226 |
|
|
| 226 | 227 |
|
| 228 |
|
|
| 229 |
|
|
| 227 | 230 |
|
| 228 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
| 229 | 234 |
|
| 230 | 235 |
|
| 231 | 236 |
|
| 237 |
|
|
| 238 |
|
|
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| 232 | 242 |
|
| 233 | 243 |
|
| 234 | 244 |
|
|
||
| 239 | 249 |
|
| 240 | 250 |
|
| 241 | 251 |
|
| 252 |
|
|
| 253 |
|
|
| 254 |
|
|
| 242 | 255 |
|
| 243 | 256 |
|
| 244 | 257 |
|
| 245 | 258 |
|
| 246 | 259 |
|
| 247 | 260 |
|
| 248 |
|
|
| 261 |
|
|
| 262 |
|
|
| 249 | 263 |
|
| 250 | 264 |
|
| 251 | 265 |
|