Updates :D

Former-commit-id: 4aab1964b9462d1fdee92999dd5a7d03f17b4457 [formerly 22352202547980b191886cf29f68ce8e9cc4c39b] [formerly 1a66bae34022092936c2912ea3a323a6984fe7e4 [formerly 1e7c4e6468b07dbb2b2726df4ff345371e2ec714]]
Former-commit-id: 94170b15369b05e8f4985e88242ba453b5545116 [formerly 2a0b57bebcd48c0189974f4f9e72679b5c67f37b]
Former-commit-id: 635be5ad2826c1659670997900122d024a46de24
This commit is contained in:
Henrique Dias
2017-06-29 14:16:08 +01:00
parent 60ffb88d8e
commit dd87a70157
13 changed files with 220 additions and 201 deletions

View File

@@ -2,7 +2,7 @@
<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>
<p v-show="req.kind === 'listing'">Are you sure you want to delete {{ selected.length }} file(s)?</p>
<div>
<button @click="submit" autofocus>Delete</button>
<button @click="cancel" class="cancel">Cancel</button>
@@ -14,6 +14,8 @@
import webdav from '../webdav'
import page from '../page'
var $ = window.info
export default {
name: 'delete-prompt',
data: function () {
@@ -21,13 +23,13 @@ export default {
},
methods: {
cancel: function (event) {
this.showDelete = false
$.showDelete = false
},
submit: function (event) {
this.showDelete = false
$.showDelete = false
// buttons.setLoading('delete')
if (this.req.kind !== 'listing') {
if ($.req.kind !== 'listing') {
webdav.trash(window.location.pathname)
.then(() => {
// buttons.setDone('delete')
@@ -41,13 +43,13 @@ export default {
return
}
if (this.listing.selected.length === 0) {
if ($.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)
if ($.selected.length === 1) {
webdav.trash($.req.data.items[$.selected[0]].url)
.then(() => {
// buttons.setDone('delete')
page.reload()
@@ -63,8 +65,8 @@ export default {
// More than one item!
let promises = []
for (let index of this.listing.selected) {
promises.push(webdav.trash(this.req.data.items[index].url))
for (let index of $.selected) {
promises.push(webdav.trash($.req.data.items[index].url))
}
Promise.all(promises)

View File

@@ -2,13 +2,13 @@
<div class="prompt">
<h3>File Information</h3>
<p v-show="listing.selected.length > 1">{{ listing.selected.length }} files selected.</p>
<p v-show="selected.length > 1">{{ selected.length }} files selected.</p>
<p v-show="listing.selected.length < 2"><strong>Display Name:</strong> {{ name() }}</p>
<p v-show="selected.length < 2"><strong>Display Name:</strong> {{ name() }}</p>
<p><strong>Size:</strong> <span id="content_length"></span>{{ humanSize() }}</p>
<p v-show="listing.selected.length < 2"><strong>Last Modified:</strong> {{ humanTime() }}</p>
<p v-show="selected.length < 2"><strong>Last Modified:</strong> {{ humanTime() }}</p>
<section v-show="dir() && listing.selected.length === 0">
<section v-show="dir() && selected.length === 0">
<p><strong>Number of files:</strong> {{ req.data.numFiles }}</p>
<p><strong>Number of directories:</strong> {{ req.data.numDirs }}</p>
</section>
@@ -37,43 +37,43 @@ export default {
},
methods: {
humanSize: function () {
if (this.listing.selected.length === 0 || this.req.kind !== 'listing') {
if (this.selected.length === 0 || this.req.kind !== 'listing') {
return filesize(this.req.data.size)
}
var sum = 0
for (let i = 0; i < this.listing.selected.length; i++) {
sum += this.req.data.items[this.listing.selected[i]].size
for (let i = 0; i < this.selected.length; i++) {
sum += this.req.data.items[this.selected[i]].size
}
return filesize(sum)
},
humanTime: function () {
if (this.listing.selected.length === 0) {
if (this.selected.length === 0) {
return moment(this.req.data.modified).fromNow()
}
return moment(this.req.data.items[this.listing.selected[0]]).fromNow()
return moment(this.req.data.items[this.selected[0]]).fromNow()
},
name: function () {
if (this.listing.selected.length === 0) {
if (this.selected.length === 0) {
return this.req.data.name
}
return this.req.data.items[this.listing.selected[0]].name
return this.req.data.items[this.selected[0]].name
},
dir: function () {
if (this.listing.selected.length > 1) {
if (this.selected.length > 1) {
// Don't show when multiple selected.
return true
}
if (this.listing.selected.length === 0) {
if (this.selected.length === 0) {
return this.req.data.isDir
}
return this.req.data.items[this.listing.selected[0]].isDir
return this.req.data.items[this.selected[0]].isDir
},
checksum: function (event, hash) {
event.preventDefault()
@@ -81,8 +81,8 @@ export default {
let request = new window.XMLHttpRequest()
let link
if (this.listing.selected.length) {
link = this.req.data.items[this.listing.selected[0]].url
if (this.selected.length) {
link = this.req.data.items[this.selected[0]].url
} else {
link = window.location.pathname
}

View File

@@ -31,12 +31,11 @@ import webdav from '../webdav.js'
import page from '../page.js'
import array from '../array.js'
var $ = window.info
export default {
name: 'item',
props: ['name', 'isDir', 'url', 'type', 'size', 'modified', 'index'],
data: function () {
return window.info.listing
},
methods: {
icon: function () {
if (this.isDir) return 'folder'
@@ -99,19 +98,19 @@ export default {
link.setAttribute('aria-selected', false)
})
this.selected.length = 0
$.selected = []
return false
},
click: function (event) {
if (this.selected.length !== 0) event.preventDefault()
if (this.selected.indexOf(this.index) === -1) {
if (!event.ctrlKey && !this.multiple) this.unselectAll()
if ($.selected.length !== 0) event.preventDefault()
if ($.selected.indexOf(this.index) === -1) {
if (!event.ctrlKey && !$.multiple) this.unselectAll()
this.$el.setAttribute('aria-selected', true)
this.selected.push(this.index)
$.selected.push(this.index)
} else {
this.$el.setAttribute('aria-selected', false)
this.selected = array.remove(this.selected, this.index)
$.selected = array.remove($.selected, this.index)
}
// this.handleSelectionChange()

View File

@@ -0,0 +1,122 @@
<template>
<div class="prompt">
<h3>Move</h3>
<p>Choose new house for your file(s)/folder(s):</p>
<ul class="file-list">
<li @click="select" @dblclick="next" v-for="item in items" :data-url="item.url">{{ item.name }}</li>
</ul>
<p>Currently navigating on: <code>{{ current }}</code>.</p>
<div>
<button class="ok" @click="move">Move</button>
<button class="cancel" @click="cancel">Cancel</button>
</div>
</div>
</template>
<script>
import page from '../page'
var $ = window.info
export default {
name: 'move-prompt',
data: function () {
return {
items: [],
current: window.location.pathname
}
},
mounted: function () {
if (window.location.pathname !== $.baseURL + '/') {
this.items.push({
name: '..',
url: page.removeLastDir(window.location.pathname) + '/'
})
}
if ($.req.kind === 'listing') {
for (let item of $.req.data.items) {
if (!item.isDir) continue
this.items.push({
name: item.name,
url: item.url
})
}
return
}
},
methods: {
cancel: function (event) {
$.showMove = false
},
move: function (event) {
console.log('Move')
},
next: function (event) {
console.log('Next')
let url = event.currentTarget.dataset.url
this.json(url)
.then((data) => {
this.current = url
this.items = []
if (url !== $.baseURL + '/') {
this.items.push({
name: '..',
url: page.removeLastDir(url) + '/'
})
}
let req = JSON.parse(data)
for (let item of req.data.items) {
if (!item.isDir) continue
this.items.push({
name: item.name,
url: item.url
})
}
})
.catch(e => console.log(e))
},
json: function (url) {
return new Promise((resolve, reject) => {
let request = new XMLHttpRequest()
request.open('GET', url)
request.setRequestHeader('Accept', 'application/json')
request.onload = () => {
if (request.status === 200) {
resolve(request.responseText)
} else {
reject(request.statusText)
}
}
request.onerror = () => reject(request.statusText)
request.send()
})
},
select: function (event) {
let el = event.currentTarget
if (el.getAttribute('aria-selected') === 'true') {
el.setAttribute('aria-selected', false)
return
}
let el2 = this.$el.querySelector('li[aria-selected=true]')
if (el2) {
el2.setAttribute('aria-selected', false)
}
el.setAttribute('aria-selected', true)
return
}
}
}
</script>

View File

@@ -4,7 +4,7 @@
<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="submit" type="submit">Rename</button>
<button @click="cancel" class="cancel">Cancel</button>
</div>
</div>
@@ -33,12 +33,12 @@ export default {
return $.req.data.name
}
if ($.listing.selected.length === 0 || $.listing.selected.length > 1) {
if ($.selected.length === 0 || $.selected.length > 1) {
// This shouldn't happen.
return
}
return $.req.data.items[$.listing.selected[0]].name
return $.req.data.items[$.selected[0]].name
},
submit: function (event) {
let oldLink = ''
@@ -47,7 +47,7 @@ export default {
if ($.req.kind !== 'listing') {
oldLink = $.req.data.url
} else {
oldLink = $.req.data.items[$.listing.selected[0]].url
oldLink = $.req.data.items[$.selected[0]].url
}
newLink = page.removeLastDir(oldLink) + '/' + this.name
@@ -56,6 +56,10 @@ export default {
webdav.move(oldLink, newLink)
.then(() => {
if ($.req.kind !== 'listing') {
page.open(newLink)
return
}
// TODO: keep selected after reload?
page.reload()
// buttons.setDone('rename')