wikijs-fork/client/js/components/modal-create-page.vue

68 lines
2.2 KiB
Vue
Raw Normal View History

2017-05-21 03:21:16 +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')
header.is-light-blue {{ $t('modal.createpagetitle') }}
2017-05-27 02:43:34 +00:00
section
label.label {{ $t('modal.createpagepath') }}
2017-05-27 02:43:34 +00:00
p.control.is-fullwidth(v-bind:class='{ "is-loading": isLoading }')
input.input(type='text', placeholder='page-name', v-model='userPath', ref='createPageInput', @keyup.enter='create', @keyup.esc='cancel')
span.help.is-red(v-show='isInvalid') {{ $t('modal.createpageinvalid') }}
2017-05-27 02:43:34 +00:00
footer
a.button.is-grey.is-outlined(v-on:click='cancel') {{ $t('modal.discard') }}
a.button.is-light-blue(v-on:click='create') {{ $t('modal.create') }}
2017-05-21 03:21:16 +00:00
</template>
<script>
2017-10-30 01:36:05 +00:00
export default {
name: 'modal-create-page',
props: ['basepath'],
data () {
return {
currentPath: '',
userPath: '',
isLoading: false,
isInvalid: false
}
},
computed: {
isShown () {
if (this.$store.state.modalCreatePage.shown) {
this.makeSelection()
2017-05-21 03:21:16 +00:00
}
2017-10-30 01:36:05 +00:00
return this.$store.state.modalCreatePage.shown
}
},
methods: {
makeSelection: function () {
let self = this
self._.delay(() => {
let startPos = (self.currentPath.length > 0) ? self.currentPath.length + 1 : 0
self.$helpers.form.setInputSelection(self.$refs.createPageInput, startPos, self.userPath.length)
}, 100)
2017-05-21 03:21:16 +00:00
},
2017-10-30 01:36:05 +00:00
cancel: function () {
this.$store.dispatch('modalCreatePage/close')
},
2017-10-30 01:36:05 +00:00
create: function () {
this.isInvalid = false
let newDocPath = this.$helpers.pages.makeSafePath(this.userPath)
if (this._.isEmpty(newDocPath)) {
this.isInvalid = true
} else {
this.isLoading = true
window.location.assign('/create/' + newDocPath)
2017-05-21 03:21:16 +00:00
}
}
2017-10-30 01:36:05 +00:00
},
mounted () {
this.currentPath = (this.basepath === 'home') ? '' : this.basepath
this.userPath = (this._.isEmpty(this.currentPath)) ? 'new-page' : this.currentPath + '/new-page'
2017-05-21 03:21:16 +00:00
}
2017-10-30 01:36:05 +00:00
}
2017-05-21 03:21:16 +00:00
</script>