-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwithout-vue.html
357 lines (331 loc) Β· 11.5 KB
/
without-vue.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Nextcloud file picker demo</title>
</head>
<body>
<header>
</header>
<main>
<h1>Nextcloud file picker</h1>
<h2>
This is an example page importing the file picker wrapper.
<br>
No need to use Vue.js to include this component in your web application ππ
Checkout the <a href="https://github.com/julien-nc/nextcloud-webdav-filepicker/blob/master/examples/without-vue.html">source file</a>
</h2>
<p>
You can try the file picker with your Nextcloud instance from this page.
<br>
Make sure you installed the
<a href="https://apps.nextcloud.com/apps/webapppassword">WebAppPassword app</a>
and added <b id="domainToAuthorize"></b> as allowed origin in WebAppPassword settings.
</p>
<br>
<p>
When following fields are changed, corresponding component update methods are called.
</p>
<h3>Authentication</h3>
<p>
Leave login and password fields empty to let the file picker open an authentication popup and get a temporary app password (web login flow).
</p>
<input id="url" type="text" placeholder="Nextcloud address" value="https://localhost/dev/server">
<input id="login" type="text" placeholder="login" value="">
<input id="password" type="password" placeholder="password" value="">
<input id="accessToken" type="password" placeholder="OAuth access token" value="">
<h3>Theme color</h3>
<label for="color">Main file picker color</label>
<input id="color" type="color" value="#0082c9">
<br>
<label for="darkmode">Dark mode</label>
<input id="darkmode" type="checkbox">
<h3>Custom button which calls the "getFilesPath" method</h3>
<button id="selectButton">My custom button to select files</button>
<h3>Custom button which calls the "getFilesLink" method</h3>
<button id="linkButton">My custom button to get files link</button>
<h3>
File picker component
</h3>
<p>
NcWebdavFilePicker component is mounted under the following line. It shows every button by default.
</p>
<hr>
<div id="mount_point"></div>
<hr>
<h3>Results</h3>
<p id="results"></p>
<div class="ribbon">
<a href="https://github.com/julien-nc/nextcloud-webdav-filepicker" target="_blank">Repository and documentation</a>
</div>
</main>
<footer style="position: fixed; bottom: 0; right: 0; background: rgba(0, 0, 0, 0.1);">
Dev version
</footer>
</body>
<!--script src="../js/filePickerWrapper.js"></script-->
<script>
function main() {
// get url values
const uri = window.location.search.substring(1)
const params = new URLSearchParams(uri)
const login = params.get('login')
if (login) {
document.getElementById('login').value = login
}
const password = params.get('password')
if (password) {
document.getElementById('password').value = password
}
const accessToken = params.get('accessToken')
if (accessToken) {
document.getElementById('accessToken').value = accessToken
}
const url = params.get('url')
if (url) {
document.getElementById('url').value = url
}
const color = params.get('color')
if (color) {
document.getElementById('color').value = '#' + color
}
const darkmode = params.get('darkMode')
if (darkmode) {
document.getElementById('darkmode').checked = darkmode === '1'
}
const initialUrl = document.getElementById('url').value
const initialLogin = document.getElementById('login').value
const initialPassword = document.getElementById('password').value
const initialAccessToken = document.getElementById('accessToken').value
const initialColor = document.getElementById('color').value
const initialDarkMode = document.getElementById('darkmode').checked
const filepicker = window.createFilePicker('mount_point', {
url: initialUrl,
login: initialLogin,
password: initialPassword,
accessToken: initialAccessToken,
useCookies: false,
themeColor: initialColor,
darkMode: initialDarkMode,
displayPreviews: true,
displayQuotaRefresh: true,
multipleDownload: true,
multipleUpload: true,
closeOnError: false,
enableGetFilesPath: true,
enableGetFilesLink: true,
enableDownloadFiles: true,
enableGetSaveFilePath: true,
enableGetUploadFileLink: true,
enableUploadFiles: true,
useWebapppassword: true,
// language: 'de',
// language: 'de-DE',
// oidcConfigLocation: 'http://localhost/oidc-config.json',
// oidcConfig: {
// openIdConnect: {
// authority: 'http://localhost:8080/auth/realms/myrealm/.well-known/openid-configuration',
// client_id: 'superclient',
// client_secret: 'be4e2e3e-506e-4078-8919-5067edfa722a',
// popup_redirect_uri: 'http://localhost/oidc-callback.html',
// response_type: 'code',
// scope: 'openid email profile',
// automaticSilentRenew: true,
// accessTokenExpiringNotificationTime: 50,
// },
// },
})
// monitor form value change
document.getElementById('login').addEventListener('input', (e) => {
filepicker.updateLogin(e.target.value)
})
document.getElementById('password').addEventListener('input', (e) => {
filepicker.updatePassword(e.target.value)
})
document.getElementById('accessToken').addEventListener('input', (e) => {
filepicker.updateAccessToken(e.target.value)
})
document.getElementById('url').addEventListener('input', (e) => {
filepicker.updateUrl(e.target.value)
})
document.getElementById('color').addEventListener('change', (e) => {
filepicker.setMainColor(e.target.value)
})
document.getElementById('darkmode').addEventListener('change', (e) => {
filepicker.setDarkMode(e.target.checked)
})
document.getElementById('selectButton').addEventListener('click', (e) => {
filepicker.getFilesPath()
})
document.getElementById('linkButton').addEventListener('click', (e) => {
filepicker.getFilesLink({
expirationDate: new Date('2050-01-01'),
protectionPassword: 'example passwd',
allowEdition: true,
linkLabel: 'custom link label',
})
})
// events coming from the file picker
document.addEventListener('filepicker-unauthorized', (e) => {
console.debug('file picker got an unauthorized response')
console.debug(e.detail)
})
document.addEventListener('get-files-path', (e) => {
console.debug('no vue, received "get-files-path" event')
console.debug(e.detail)
const resultsP = document.getElementById('results')
resultsP.innerHTML = 'Path of selected files:'
e.detail.selection.forEach((path) => {
const p = document.createElement('p')
p.textContent = path
resultsP.appendChild(p)
})
})
document.addEventListener('get-save-file-path', (e) => {
console.debug('no vue, received "get-save-file-path" event')
console.debug(e.detail)
document.getElementById('results').innerHTML = `Selected target directory: ${e.detail.path}`
})
document.addEventListener('upload-path-link-generated', (e) => {
console.debug('no vue, received "upload-path-link-generated" event')
console.debug(e.detail)
const resultsP = document.getElementById('results')
resultsP.innerHTML = `File upload link in ${e.detail.targetDir}:`
const p = document.createElement('p')
p.textContent = e.detail.link
resultsP.appendChild(p)
})
document.addEventListener('get-files-link', (e) => {
console.debug('no vue, received "get-files-link" event')
console.debug(e.detail)
const resultsP = document.getElementById('results')
resultsP.innerHTML = ''
if (e.detail.shareLinks) {
const pl = document.createElement('p')
pl.textContent = 'Nextcloud public links:'
resultsP.appendChild(pl)
e.detail.shareLinks.forEach((link) => {
const pp = document.createElement('p')
pp.textContent = 'path: "' + link.path + '" '
const a = document.createElement('a')
a.textContent = link.url
a.setAttribute('href', link.url)
pp.appendChild(a)
resultsP.appendChild(pp)
})
} else {
const pl = document.createElement('p')
pl.textContent = 'Nextcloud public links creation failed. Link options are:'
resultsP.appendChild(pl)
for (const k in e.detail.linkOptions) {
const pp = document.createElement('p')
pp.textContent = k + ': "' + e.detail.linkOptions[k] + '" '
resultsP.appendChild(pp)
}
}
const p = document.createElement('p')
p.textContent = 'List of paths:'
resultsP.appendChild(p)
e.detail.pathList.forEach((path) => {
const pp = document.createElement('p')
pp.textContent = path
resultsP.appendChild(pp)
})
const po = document.createElement('p')
po.textContent = 'OCS URL to create share link: ' + e.detail.ocsUrl
resultsP.appendChild(po)
const pl = document.createElement('p')
pl.textContent = 'Generic share link: ' + e.detail.genericShareLink
resultsP.appendChild(pl)
})
document.addEventListener('files-uploaded', (e) => {
console.debug('no vue, received "files-uploaded" event')
console.debug(e.detail)
const resultsP = document.getElementById('results')
resultsP.innerHTML = ''
if (e.detail.successFiles.length > 0) {
const p = document.createElement('p')
p.textContent = `These files were uploaded in ${e.detail.targetDir}:`
resultsP.appendChild(p)
e.detail.successFiles.forEach((f) => {
const p = document.createElement('p')
p.textContent = f.name
resultsP.appendChild(p)
})
}
if (e.detail.errorFiles.length > 0) {
const p = document.createElement('p')
p.textContent = '!!! Those files could not be uploaded:'
resultsP.appendChild(p)
e.detail.errorFiles.forEach((f) => {
const p = document.createElement('p')
p.textContent = f.name
resultsP.appendChild(p)
})
}
})
document.addEventListener('files-downloaded', (e) => {
console.debug('download errors')
console.debug(e.detail.errorFilePaths)
const files = e.detail.successFiles
console.debug('no vue, something was downloaded')
const resultsP = document.getElementById('results')
resultsP.innerHTML = 'Downloaded files: <br>'
files.forEach(file => {
console.debug('File : ' + file.name)
console.debug(file)
const reader = new FileReader()
reader.readAsText(file)
reader.onload = () => {
console.debug(reader.result)
const p = document.createElement('P')
p.textContent = 'File ' + file.name + ': ' + reader.result.slice(0, 100) + '...'
resultsP.appendChild(p)
}
reader.onerror = () => {
console.error('Impossible to read downloaded file')
console.debug(reader.error)
}
})
})
document.addEventListener('filepicker-closed', (e) => {
console.debug('Filepicker CLOSED')
})
document.addEventListener('filepicker-manually-closed', (e) => {
console.debug('Filepicker manually CLOSED')
})
}
document.addEventListener('DOMContentLoaded', (event) => {
document.getElementById('domainToAuthorize').textContent = window.location.protocol + '//' + window.location.host
import('../js/filePickerWrapper.js').then(() => { main() })
})
</script>
<style type="text/css">
.ribbon {
background-color: #0082c9;
overflow: hidden;
white-space: nowrap;
position: fixed;
right: -70px;
top: 75px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-box-shadow: 0 0 10px #888;
-moz-box-shadow: 0 0 10px #888;
box-shadow: 0 0 10px #888;
}
.ribbon a {
border: 1px solid #faa;
color: #fff;
display: block;
font: bold 100% 'Helvetica Neue', Helvetica, Arial, sans-serif;
margin: 1px 0;
padding: 10px 50px;
text-align: center;
text-decoration: none;
text-shadow: 0 0 5px #444;
}
</style>