Improvements
Former-commit-id: 75aaab2410d4e93a892f1c68d253ecf2c3def92b [formerly d9f37f49e3b705eb7a632b0f6e44cbabdfd296ac] [formerly 5ac5b5223ad348b589861a50f8ee41228a18d13f [formerly 7809b778bb2d65a3faff5dd5f928c1786f227def]] Former-commit-id: 30bac294d7bf5e875d4fb365321dc1fde16a50df [formerly df3d70ac1c0afcc4c7aed0a8e4ce2d2aa815ee0c] Former-commit-id: f82ccdf36a7d088cbd2a4a3ada53876e823a64e2
This commit is contained in:
82
_assets/src/components/DeletePrompt.vue
Normal file
82
_assets/src/components/DeletePrompt.vue
Normal file
@@ -0,0 +1,82 @@
|
||||
<template>
|
||||
<div class="prompt">
|
||||
<h3>Delete files</h3>
|
||||
<p v-show="req.kind !== 'listing'">Are you sure you want to delete this file/folder?</p>
|
||||
<p v-show="req.kind === 'listing'">Are you sure you want to delete {{ listing.selected.length }} file(s)?</p>
|
||||
<div>
|
||||
<button @click="submit" autofocus>Delete</button>
|
||||
<button @click="cancel" class="cancel">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import webdav from '../webdav'
|
||||
import page from '../page'
|
||||
|
||||
export default {
|
||||
name: 'delete-prompt',
|
||||
data: function () {
|
||||
return window.info
|
||||
},
|
||||
methods: {
|
||||
cancel: function (event) {
|
||||
this.showDelete = false
|
||||
},
|
||||
submit: function (event) {
|
||||
this.showDelete = false
|
||||
// buttons.setLoading('delete')
|
||||
|
||||
if (this.req.kind !== 'listing') {
|
||||
webdav.trash(window.location.pathname)
|
||||
.then(() => {
|
||||
// buttons.setDone('delete')
|
||||
page.open(page.removeLastDir(window.location.pathname))
|
||||
})
|
||||
.catch(error => {
|
||||
// buttons.setDone('delete', false)
|
||||
console.log(error)
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (this.listing.selected.length === 0) {
|
||||
// This shouldn't happen...
|
||||
return
|
||||
}
|
||||
|
||||
if (this.listing.selected.length === 1) {
|
||||
webdav.trash(this.req.data.items[this.listing.selected[0]].url)
|
||||
.then(() => {
|
||||
// buttons.setDone('delete')
|
||||
page.reload()
|
||||
})
|
||||
.catch(error => {
|
||||
// buttons.setDone('delete', false)
|
||||
console.log(error)
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// More than one item!
|
||||
let promises = []
|
||||
|
||||
for (let index of this.listing.selected) {
|
||||
promises.push(webdav.trash(this.req.data.items[index].url))
|
||||
}
|
||||
|
||||
Promise.all(promises)
|
||||
.then(() => {
|
||||
page.reload()
|
||||
// buttons.setDone('delete')
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error)
|
||||
// buttons.setDone('delete', false)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
73
_assets/src/components/RenamePrompt.vue
Normal file
73
_assets/src/components/RenamePrompt.vue
Normal file
@@ -0,0 +1,73 @@
|
||||
<template>
|
||||
<div class="prompt">
|
||||
<h3>Rename</h3>
|
||||
<p>Insert a new name for <code>{{ oldName() }}</code>:</p>
|
||||
<input autofocus type="text" @keyup.enter="submit" v-model.trim="name">
|
||||
<div>
|
||||
<button @click="submit" type="submit" autofocus>Rename</button>
|
||||
<button @click="cancel" class="cancel">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import page from '../page'
|
||||
import webdav from '../webdav'
|
||||
|
||||
var $ = window.info
|
||||
|
||||
export default {
|
||||
name: 'rename-prompt',
|
||||
data: function () {
|
||||
return {
|
||||
name: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
cancel: function (event) {
|
||||
$.showRename = false
|
||||
this.name = ''
|
||||
},
|
||||
oldName: function () {
|
||||
if ($.req.kind !== 'listing') {
|
||||
return $.req.data.name
|
||||
}
|
||||
|
||||
if ($.listing.selected.length === 0 || $.listing.selected.length > 1) {
|
||||
// This shouldn't happen.
|
||||
return
|
||||
}
|
||||
|
||||
return $.req.data.items[$.listing.selected[0]].name
|
||||
},
|
||||
submit: function (event) {
|
||||
let oldLink = ''
|
||||
let newLink = ''
|
||||
|
||||
if ($.req.kind !== 'listing') {
|
||||
oldLink = $.req.data.url
|
||||
} else {
|
||||
oldLink = $.req.data.items[$.listing.selected[0]].url
|
||||
}
|
||||
|
||||
newLink = page.removeLastDir(oldLink) + '/' + this.name
|
||||
|
||||
// buttons.setLoading('rename')
|
||||
|
||||
webdav.move(oldLink, newLink)
|
||||
.then(() => {
|
||||
// TODO: keep selected after reload?
|
||||
page.reload()
|
||||
// buttons.setDone('rename')
|
||||
}).catch(error => {
|
||||
// buttons.setDone('rename', false)
|
||||
console.log(error)
|
||||
})
|
||||
|
||||
this.name = ''
|
||||
$.showRename = false
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user