2017-05-27 02:23:05 +00:00
|
|
|
<template lang="pug">
|
2017-05-27 02:43:34 +00:00
|
|
|
transition(:duration="400")
|
|
|
|
.modal(v-show='isShown', v-cloak)
|
|
|
|
transition(name='modal-background')
|
|
|
|
.modal-background(v-show='isShown')
|
|
|
|
.modal-container
|
|
|
|
transition(name='modal-content')
|
|
|
|
.modal-content(v-show='isShown')
|
2017-05-30 01:58:33 +00:00
|
|
|
header.is-indigo {{ $t('modal.movepagetitle') }}
|
2017-05-27 02:43:34 +00:00
|
|
|
section
|
2017-05-30 01:58:33 +00:00
|
|
|
label.label {{ $t('modal.movepagepath') }}
|
2017-05-27 02:43:34 +00:00
|
|
|
p.control.is-fullwidth(v-bind:class='{ "is-loading": isLoading }')
|
2017-05-30 01:58:33 +00:00
|
|
|
input.input(type='text', v-bind:placeholder='$t("modal.movepageplaceholder")', v-model='movePath', ref='movePageInput', @keyup.enter='move', @keyup.esc='cancel')
|
|
|
|
span.help.is-red(v-show='isInvalid') {{ $t('modal.movepageinvalid') }}
|
|
|
|
span.note {{ $t('modal.movepagewarning') }}
|
2017-05-27 02:43:34 +00:00
|
|
|
footer
|
2017-05-30 01:58:33 +00:00
|
|
|
a.button.is-grey.is-outlined(v-on:click='cancel') {{ $t('modal.discard') }}
|
|
|
|
a.button.is-indigo(v-on:click='move') {{ $t('modal.move') }}
|
2017-05-27 02:23:05 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'modal-move-page',
|
|
|
|
props: ['currentPath'],
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
movePath: '',
|
|
|
|
isLoading: false,
|
|
|
|
isInvalid: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isShown () {
|
|
|
|
if(this.$store.state.modalMovePage.shown) {
|
|
|
|
this.movePath = this.currentPath
|
|
|
|
this.makeSelection()
|
|
|
|
}
|
|
|
|
return this.$store.state.modalMovePage.shown
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2017-07-08 21:33:09 +00:00
|
|
|
makeSelection() {
|
2017-05-27 02:23:05 +00:00
|
|
|
let self = this;
|
|
|
|
self._.delay(() => {
|
2017-07-08 21:33:09 +00:00
|
|
|
let startPos = (self._.includes(self.currentPath, '/')) ? self._.lastIndexOf(self.movePath, '/') + 1 : 0
|
2017-05-27 02:23:05 +00:00
|
|
|
self.$helpers.form.setInputSelection(self.$refs.movePageInput, startPos, self.movePath.length)
|
|
|
|
}, 100)
|
|
|
|
},
|
2017-07-08 21:33:09 +00:00
|
|
|
cancel() {
|
2017-05-27 02:23:05 +00:00
|
|
|
this.$store.dispatch('modalMovePage/close')
|
|
|
|
},
|
2017-07-08 21:33:09 +00:00
|
|
|
move () {
|
2017-05-27 02:23:05 +00:00
|
|
|
this.isInvalid = false
|
|
|
|
let newDocPath = this.$helpers.pages.makeSafePath(this.movePath)
|
2017-07-08 21:33:09 +00:00
|
|
|
if (this._.isEmpty(newDocPath) || newDocPath === this.currentPath || newDocPath === 'home') {
|
2017-05-27 02:23:05 +00:00
|
|
|
this.isInvalid = true
|
|
|
|
} else {
|
|
|
|
this.isLoading = true
|
|
|
|
this.$http.put(window.location.href, {
|
|
|
|
move: newDocPath
|
|
|
|
}).then(resp => {
|
|
|
|
return resp.json()
|
|
|
|
}).then(resp => {
|
|
|
|
if (resp.ok) {
|
|
|
|
window.location.assign('/' + newDocPath)
|
|
|
|
} else {
|
|
|
|
this.loading = false
|
|
|
|
self.$store.dispatch('alert', {
|
|
|
|
style: 'red',
|
2017-07-08 21:33:09 +00:00
|
|
|
icon: 'ui-2_square-remove-09',
|
2017-05-27 02:23:05 +00:00
|
|
|
msg: resp.msg
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
this.loading = false
|
|
|
|
self.$store.dispatch('alert', {
|
|
|
|
style: 'red',
|
2017-07-08 21:33:09 +00:00
|
|
|
icon: 'ui-2_square-remove-09',
|
2017-05-27 02:23:05 +00:00
|
|
|
msg: 'Error: ' + err.body.msg
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|