You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.3 KiB

  1. <template lang="pug">
  2. transition(:duration="400")
  3. .modal(v-show='isShown', v-cloak)
  4. transition(name='modal-background')
  5. .modal-background(v-show='isShown')
  6. .modal-container
  7. transition(name='modal-content')
  8. .modal-content(v-show='isShown')
  9. header.is-light-blue {{ $t('modal.createpagetitle') }}
  10. section
  11. label.label {{ $t('modal.createpagepath') }}
  12. p.control.is-fullwidth(v-bind:class='{ "is-loading": isLoading }')
  13. input.input(type='text', placeholder='page-name', v-model='userPath', ref='createPageInput', @keyup.enter='create', @keyup.esc='cancel')
  14. span.help.is-red(v-show='isInvalid') {{ $t('modal.createpageinvalid') }}
  15. footer
  16. a.button.is-grey.is-outlined(v-on:click='cancel') {{ $t('modal.discard') }}
  17. a.button.is-light-blue(v-on:click='create') {{ $t('modal.create') }}
  18. </template>
  19. <script>
  20. export default {
  21. name: 'modal-create-page',
  22. props: ['basepath'],
  23. data () {
  24. return {
  25. currentPath: '',
  26. userPath: '',
  27. isLoading: false,
  28. isInvalid: false
  29. }
  30. },
  31. computed: {
  32. isShown () {
  33. if(this.$store.state.modalCreatePage.shown) {
  34. this.makeSelection()
  35. }
  36. return this.$store.state.modalCreatePage.shown
  37. }
  38. },
  39. methods: {
  40. makeSelection: function () {
  41. let self = this;
  42. self._.delay(() => {
  43. let startPos = (self.currentPath.length > 0) ? self.currentPath.length + 1 : 0
  44. self.$helpers.form.setInputSelection(self.$refs.createPageInput, startPos, self.userPath.length)
  45. }, 100)
  46. },
  47. cancel: function () {
  48. this.$store.dispatch('modalCreatePage/close')
  49. },
  50. create: function () {
  51. this.isInvalid = false
  52. let newDocPath = this.$helpers.pages.makeSafePath(this.userPath)
  53. if (this._.isEmpty(newDocPath)) {
  54. this.isInvalid = true
  55. } else {
  56. this.isLoading = true
  57. window.location.assign('/create/' + newDocPath)
  58. }
  59. }
  60. },
  61. mounted () {
  62. this.currentPath = (this.basepath === 'home') ? '' : this.basepath
  63. this.userPath = (this._.isEmpty(this.currentPath)) ? 'new-page' : this.currentPath + '/new-page'
  64. }
  65. }
  66. </script>