Henrique Dias d5cd86da97 Correct method for new file/directory
Former-commit-id: ba718c759c20ea2fc0b6e443d410a026cdf731e7 [formerly 27ca216e8773da64bd81251d138661d95707bee6] [formerly 2dea38f7a513d75504ca881936853986892fb7ca [formerly d0e7631bc80498fae8cfcbd1f10447acb0fb96e5]]
Former-commit-id: 92ef66d89f03a418479dfff7c8c1e0aca46318f6 [formerly 05be2809de4e8c28616feb41385135a21ce78420]
Former-commit-id: 39f3711265d5e945c0c7c6a88c80ad8603a1aa77
2017-07-04 21:02:46 +01:00

52 lines
1.1 KiB
Vue

<template>
<div class="prompt">
<h3>New file</h3>
<p>Write the name of the new file.</p>
<input autofocus type="text" @keyup.enter="submit" v-model.trim="name">
<div>
<button class="ok" @click="submit">Create</button>
<button class="cancel" @click="$store.commit('closeHovers')">Cancel</button>
</div>
</div>
</template>
<script>
import url from '@/utils/url'
import api from '@/utils/api'
export default {
name: 'new-file',
data: function () {
return {
name: ''
}
},
methods: {
submit: function (event) {
event.preventDefault()
if (this.new === '') return
let uri = this.$route.path
if (this.$store.state.req.kind !== 'listing') {
uri = url.removeLastDir(uri) + '/'
}
uri += this.name
uri = uri.replace('//', '/')
api.post(uri)
.then(() => {
this.$router.push({ path: uri })
})
.catch(error => {
// TODO: show error message in a box
console.log(error)
})
this.$store.commit('closeHovers')
}
}
}
</script>