-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.html
195 lines (188 loc) · 4.93 KB
/
index2.html
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
<!DOCTYPE html>
<html>
<head>
<title>
Vegas Jackpot Upload
</title>
<link rel="shortcut icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="upload.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="upload.js"></script>
<script>
const deleteImage = async (id) => {
let url = 'https://cloud.vegasegamingclub.com/api/media/' + id
try {
const res = await fetch(url, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
})
const response = await res.json()
if (response.status == 0) {
$('#' + id)
.parent('li')
.remove()
}
} catch (error) {
console.log('can not connect server', error)
}
}
const loadImage = async () => {
// load previous files
let url = 'https://cloud.vegasegamingclub.com/api/media/listing'
let data = {
order: [['created_at', 'DESC']],
limit: 10,
where: {
category: 'jackpot',
},
}
data = JSON.stringify(data)
try {
const res = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: data,
})
const response = await res.json()
console.log('res', response)
console.log('server response', response.rows)
const rows = response.rows
rows.map((i) => {
let img = $('<span class="thumb">').css(
'background-image',
'url(' +
'https://cloud.vegasegamingclub.com/api/media/' +
i.id +
')'
)
let cancelBtn = $(
'<a class="del hide" id="' + i.id + '" >✕</a>'
)
const li = $('<li></li>')
li.append(img)
li.append(cancelBtn)
$('#files').append(li)
})
} catch (error) {
console.log('can not connect server', error)
}
}
window.onload = function() {
let template = `<li>
<div class="progress-container">
<div class="progressor"></div>
<div class="progress-bar-container">
<div class="progress-bar">
</div>
</div>
<div class="cancel">cancel</div>
</div>
</li>`
let up = new Upload({
url: 'https://cloud.vegasegamingclub.com/api/media',
uploadingStaff: true,
list: '#files',
item: template,
progressor: '.progressor',
progressBar: '.progress-bar',
minWidth: 500,
minHeight: 300,
maxSize: 100000,
maxLength: 120,
allowedType: 'jpg|png|jpeg|gif',
form: document.getElementById('uploadform'),
onProgress: function(object) {},
onSubmit: function(object) {
console.log(object.name)
$(object)
.find('.cancel')
.on('click', function() {
up.cancel(object)
})
},
onLengthError: function() {
$('#notification')[0].innerHTML =
'you have reached the limit of 20 photos'
},
onTypeError: function(object) {
$('#notification')[0].innerHTML =
' is not a correct file type'
},
onDimensionError: function(object) {
// $('#notification')[0].innerHTML =
// 'image dimension has to be at least 650 x 350 or better'
},
onComplete: function(object, response) {
if (response.id.length) {
let img = $('<span class="thumb">').css(
'background-image',
'url(' + object.path + ')'
)
let cancelBtn = $(
'<a class="del hide" id="' +
response.id +
'" >✕</a>'
)
$(object).append(img)
$(object).append(cancelBtn)
$(object)
.find('.progress-container')
.hide()
}
},
onQueueComplete: function(object) {
// console.log('all completed')
},
})
document.querySelector('#upload').onchange = function() {
let sid = $('#sid').val()
if (sid.trim().length == 0) {
alert('please file staff driver before upload photo')
} else {
up.traverseFile(this.files)
}
}
// document.createElement('section').ondrop = function (evt) {
// up.traverseFile(evt.dataTransfer.files)
// this.className = ''
// evt.preventDefault()
// evt.stopPropagation()
// }
// loadImage()
// $('#files').on('click', 'a', function(e) {
// let id = $(e.target).attr('id')
// deleteImage(id)
// console.log('id', id)
// })
}
</script>
</head>
<body>
<h1 class="header">Staff Photo Upload</h1>
<form id="uploadform">
<div class="album" id="album">
<ul class="files sortable grid" id="files"></ul>
<div class="clearfix"></div>
<div class="stf">
<input id="sid" type="text" placeholder="Staff ID" />
</div>
<div id="drop-area">
<div class="upload-wrapper">
+ Choose Photos or Drop Photos Here
<input
id="upload"
class="upload"
type="file"
name="file"
/>
</div>
</div>
</div>
</form>
<div id="notification"></div>
</body>
</html>