modal-create-page.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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', ref='createPageInput', @keyup.enter='create', @keyup.esc='cancel')
  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. export default {
  18. name: 'modal-create-page',
  19. props: ['basepath'],
  20. data () {
  21. return {
  22. currentPath: '',
  23. isLoading: false
  24. }
  25. },
  26. computed: {
  27. entrypath () { return this.$store.state.modalCreatePage.entrypath }
  28. isShown () {
  29. if(this.$store.state.modalCreatePage.shown) {
  30. this.makeSelection()
  31. }
  32. return this.$store.state.modalCreatePage.shown
  33. }
  34. isInvalid () { return this.$store.state.modalCreatePage.invalid }
  35. },
  36. methods: {
  37. makeSelection: function () {
  38. let self = this;
  39. self._.delay(() => {
  40. let startPos = (self.currentPath.length > 0) ? self.currentPath.length + 1 : 0
  41. self.$helpers.form.setInputSelection(self.$refs.createPageInput, startPos, self.entrypath.length)
  42. }, 100)
  43. },
  44. cancel: function () {
  45. this.$store.dispatch('modalCreatePage/close')
  46. },
  47. create: function () {
  48. this.isInvalid = false
  49. let newDocPath = this.$helpers.pages.makeSafePath(this.entrypath)
  50. if (this._.isEmpty(newDocPath)) {
  51. this.$store.createPage.commit('')
  52. } else {
  53. this.isLoading = true
  54. window.location.assign('/create/' + newDocPath)
  55. }
  56. }
  57. },
  58. mounted () {
  59. this.currentPath = (this.basepath === 'home') ? '' : this.basepath
  60. let newPage = (this._.isEmpty(this.currentPath)) ? 'new-page' : this.currentPath + '/new-page'
  61. this.$store.commit('modalCreatePage/pathChange', newPage)
  62. }
  63. }
  64. </script>