modal-create-page.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template lang="pug">
  2. .modal(v-bind:class='{ "is-active": isShown }')
  3. .modal-background
  4. .modal-container
  5. .modal-content
  6. header.is-light-blue Create New Document
  7. section
  8. label.label Enter the new document path:
  9. p.control.is-fullwidth(v-bind:class='{ "is-loading": isLoading }')
  10. input.input(type='text', placeholder='page-name', v-model='entrypath', autofocus)
  11. span.help.is-danger(v-show='isInvalid') This document path is invalid!
  12. footer
  13. a.button.is-grey.is-outlined(v-on:click='cancel') Discard
  14. a.button.is-light-blue(v-on:click='create') Create
  15. </template>
  16. <script>
  17. import { mapState } from 'vuex'
  18. export default {
  19. name: 'modal-create-page',
  20. props: ['basepath'],
  21. data () {
  22. return {
  23. isLoading: false
  24. }
  25. },
  26. computed: {
  27. entrypath () { return this.$store.state.modalCreatePage.entrypath }
  28. isShown () { return this.$store.state.modalCreatePage.shown }
  29. isInvalid () { return this.$store.state.modalCreatePage.invalid }
  30. },
  31. methods: {
  32. cancel: function () {
  33. this.$store.dispatch('modalCreatePage/close')
  34. },
  35. create: function () {
  36. this.isInvalid = false
  37. let newDocPath = this.helpers.pages.makeSafePath(this.entrypath)
  38. if (this._.isEmpty(newDocPath)) {
  39. this.$store.createPage.commit('')
  40. } else {
  41. this.isLoading = true
  42. window.location.assign('/create/' + newDocPath)
  43. }
  44. }
  45. },
  46. mounted () {
  47. this.$store.commit('modalCreatePage/pathChange', this.basepath + '/new-page')
  48. }
  49. }
  50. </script>