-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-edit-event-add-image.php
More file actions
110 lines (87 loc) · 2.87 KB
/
admin-edit-event-add-image.php
File metadata and controls
110 lines (87 loc) · 2.87 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit Event</title>
</head>
<body>
<style>
#image-upload-wrap {
width: 100%;
}
</style>
<div class="content-block">
<form id="add-image-form" class="grid-form">
<div class="full-span">
<div id="image-upload-wrap"></div>
</div>
<div class="full-span">
<label>License</label>
<select id="image-license"></select>
</div>
<div class="full-span">
<label>Created by (photographer, designer etc.)</label>
<input id="image-creator"></input>
</div>
<div class="full-span">
<label>Copyright</label>
<input id="image-copyright"></input>
</div>
<div class="full-span">
<label>Alternate text</label>
<input id="image-alt-text"></input>
</div>
<div class="span-2">
<label>Horizontal focus</label>
<input id="image-focus-x"></input>
</div>
<div class="span-2">
<label>Vertical focus</label>
<input id="image-focus-y"></input>
</div>
<div class="full-span-buttons">
<button>Cancel</button>
<button type="submit">Upload</button>
</div>
</form>
</div>
<script>
var container = document.getElementById("image-upload-wrap");
var uploader = createImageUploader(container);
document.getElementById('add-image-form').addEventListener('submit', async function (e) {
e.preventDefault();
const file = uploader.getFile();
if (!file) {
alert("Please select an image first!");
return;
}
const formData = new FormData();
formData.append("image", file);
formData.append("license", document.getElementById("image-license").value);
formData.append("creator", document.getElementById("image-creator").value);
formData.append("copyright", document.getElementById("image-copyright").value);
formData.append("alt_text", document.getElementById("image-alt-text").value);
formData.append("focus_x", document.getElementById("image-focus-x").value);
formData.append("focus_y", document.getElementById("image-focus-y").value);
for (const [key, value] of formData.entries()) {
console.log(key, value);
}
try {
const response = await fetch("http://localhost:9090/api/admin/image/upload", {
method: "POST",
body: formData,
credentials: "include" // Send cookies if needed
});
if (response.ok) {
alert("Upload successful!");
} else {
const error = await response.json();
alert("Upload failed: " + (error.error || response.statusText));
}
} catch (err) {
alert("Upload error: " + err.message);
}
});
</script>
</body>
</html>