create.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template lang="pug">
  2. .modal(v-if='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-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='hide') Discard
  14. a.button.is-light-blue(v-on:click='create') Create
  15. </template>
  16. <script>
  17. import * as _ from 'lodash'
  18. import { makeSafePath } from '../helpers/pages'
  19. export default {
  20. name: 'modal-create',
  21. data () {
  22. return {
  23. entrypath: ''
  24. isInvalid: false,
  25. isLoading: false,
  26. isShown: false
  27. }
  28. },
  29. methods: {
  30. show: function () {
  31. this.isInvalid = false
  32. this.shown = true
  33. },
  34. hide: function () {
  35. this.shown = false
  36. },
  37. create: function () {
  38. this.isInvalid = false
  39. let newDocPath = makeSafePath(this.entrypath)
  40. if (_.isEmpty(newDocPath)) {
  41. this.isInvalid = true
  42. } else {
  43. $('#txt-create-prompt').parent().addClass('is-loading')
  44. window.location.assign('/create/' + newDocPath)
  45. }
  46. }
  47. },
  48. mounted () {
  49. this.entrypath = currentBasePath + '/new-page'
  50. }
  51. }
  52. </script>