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.

86 lines
2.9 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-indigo Move document
  10. section
  11. label.label Enter the new document path:
  12. p.control.is-fullwidth(v-bind:class='{ "is-loading": isLoading }')
  13. input.input(type='text', placeholder='page-name', v-model='movePath', ref='movePageInput', @keyup.enter='move', @keyup.esc='cancel')
  14. span.help.is-red(v-show='isInvalid') This document path is invalid or not allowed!
  15. span.note Note that moving or renaming documents can lead to broken links. Make sure to edit any page that links to this document afterwards!
  16. footer
  17. a.button.is-grey.is-outlined(v-on:click='cancel') Discard
  18. a.button.is-indigo(v-on:click='move') Move
  19. </template>
  20. <script>
  21. export default {
  22. name: 'modal-move-page',
  23. props: ['currentPath'],
  24. data () {
  25. return {
  26. movePath: '',
  27. isLoading: false,
  28. isInvalid: false
  29. }
  30. },
  31. computed: {
  32. isShown () {
  33. if(this.$store.state.modalMovePage.shown) {
  34. this.movePath = this.currentPath
  35. this.makeSelection()
  36. }
  37. return this.$store.state.modalMovePage.shown
  38. }
  39. },
  40. methods: {
  41. makeSelection: function () {
  42. let self = this;
  43. self._.delay(() => {
  44. let startPos = (self._.includes(self.currentPath, '/') ? self._.lastIndexOf(self.movePath, '/') + 1 : 0
  45. self.$helpers.form.setInputSelection(self.$refs.movePageInput, startPos, self.movePath.length)
  46. }, 100)
  47. },
  48. cancel: function () {
  49. this.$store.dispatch('modalMovePage/close')
  50. },
  51. move: function () {
  52. this.isInvalid = false
  53. let newDocPath = this.$helpers.pages.makeSafePath(this.movePath)
  54. if (this._.isEmpty(newDocPath) || newDocPath === this.currentPath || newDocPath === 'home') {) {
  55. this.isInvalid = true
  56. } else {
  57. this.isLoading = true
  58. this.$http.put(window.location.href, {
  59. move: newDocPath
  60. }).then(resp => {
  61. return resp.json()
  62. }).then(resp => {
  63. if (resp.ok) {
  64. window.location.assign('/' + newDocPath)
  65. } else {
  66. this.loading = false
  67. self.$store.dispatch('alert', {
  68. style: 'red',
  69. icon: 'square-cross',
  70. msg: resp.msg
  71. })
  72. }
  73. }).catch(err => {
  74. this.loading = false
  75. self.$store.dispatch('alert', {
  76. style: 'red',
  77. icon: 'square-cross',
  78. msg: 'Error: ' + err.body.msg
  79. })
  80. })
  81. }
  82. }
  83. }
  84. }
  85. </script>