modal-create-page.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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='userPath', 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. userPath: '',
  24. isLoading: false,
  25. isInvalid: false
  26. }
  27. },
  28. computed: {
  29. isShown () {
  30. if(this.$store.state.modalCreatePage.shown) {
  31. this.makeSelection()
  32. }
  33. return this.$store.state.modalCreatePage.shown
  34. }
  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.userPath.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.userPath)
  50. if (this._.isEmpty(newDocPath)) {
  51. this.isInvalid = true
  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. this.userPath = (this._.isEmpty(this.currentPath)) ? 'new-page' : this.currentPath + '/new-page'
  61. }
  62. }
  63. </script>