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')
|
2017-05-30 01:58:33 +00:00
|
|
|
header.is-light-blue {{ $t('modal.createpagetitle') }}
|
2017-05-27 02:43:34 +00:00
|
|
|
section
|
2017-05-30 01:58:33 +00:00
|
|
|
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')
|
2017-05-30 01:58:33 +00:00
|
|
|
span.help.is-red(v-show='isInvalid') {{ $t('modal.createpageinvalid') }}
|
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-light-blue(v-on:click='create') {{ $t('modal.create') }}
|
2017-05-21 03:21:16 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2017-05-26 00:54:03 +00:00
|
|
|
name: 'modal-create-page',
|
|
|
|
props: ['basepath'],
|
2017-05-21 03:21:16 +00:00
|
|
|
data () {
|
|
|
|
return {
|
2017-05-26 04:12:38 +00:00
|
|
|
currentPath: '',
|
2017-05-26 22:30:40 +00:00
|
|
|
userPath: '',
|
|
|
|
isLoading: false,
|
|
|
|
isInvalid: false
|
2017-05-21 03:21:16 +00:00
|
|
|
}
|
|
|
|
},
|
2017-05-26 00:54:03 +00:00
|
|
|
computed: {
|
2017-05-26 04:12:38 +00:00
|
|
|
isShown () {
|
|
|
|
if(this.$store.state.modalCreatePage.shown) {
|
|
|
|
this.makeSelection()
|
|
|
|
}
|
|
|
|
return this.$store.state.modalCreatePage.shown
|
|
|
|
}
|
2017-05-26 00:54:03 +00:00
|
|
|
},
|
2017-05-21 03:21:16 +00:00
|
|
|
methods: {
|
2017-05-26 04:12:38 +00:00
|
|
|
makeSelection: function () {
|
|
|
|
let self = this;
|
|
|
|
self._.delay(() => {
|
|
|
|
let startPos = (self.currentPath.length > 0) ? self.currentPath.length + 1 : 0
|
2017-05-26 22:30:40 +00:00
|
|
|
self.$helpers.form.setInputSelection(self.$refs.createPageInput, startPos, self.userPath.length)
|
2017-05-26 04:12:38 +00:00
|
|
|
}, 100)
|
|
|
|
},
|
2017-05-23 04:27:16 +00:00
|
|
|
cancel: function () {
|
2017-05-26 00:54:03 +00:00
|
|
|
this.$store.dispatch('modalCreatePage/close')
|
2017-05-21 03:21:16 +00:00
|
|
|
},
|
|
|
|
create: function () {
|
|
|
|
this.isInvalid = false
|
2017-05-26 22:30:40 +00:00
|
|
|
let newDocPath = this.$helpers.pages.makeSafePath(this.userPath)
|
2017-05-26 00:54:03 +00:00
|
|
|
if (this._.isEmpty(newDocPath)) {
|
2017-05-26 22:30:40 +00:00
|
|
|
this.isInvalid = true
|
2017-05-21 03:21:16 +00:00
|
|
|
} else {
|
2017-05-23 04:27:16 +00:00
|
|
|
this.isLoading = true
|
2017-05-21 03:21:16 +00:00
|
|
|
window.location.assign('/create/' + newDocPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
2017-05-26 04:12:38 +00:00
|
|
|
this.currentPath = (this.basepath === 'home') ? '' : this.basepath
|
2017-05-26 22:30:40 +00:00
|
|
|
this.userPath = (this._.isEmpty(this.currentPath)) ? 'new-page' : this.currentPath + '/new-page'
|
2017-05-21 03:21:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|