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.

47 lines
1.5 KiB

  1. /* global $, _, alerts, currentBasePath */
  2. // -> Move Existing Document
  3. if (currentBasePath !== '') {
  4. $('.btn-move-prompt').removeClass('is-hidden')
  5. }
  6. let moveInitialDocument = _.lastIndexOf(currentBasePath, '/') + 1
  7. $('.btn-move-prompt').on('click', (ev) => {
  8. $('#txt-move-prompt').val(currentBasePath)
  9. $('#modal-move-prompt').toggleClass('is-active')
  10. setInputSelection($('#txt-move-prompt').get(0), moveInitialDocument, currentBasePath.length) // eslint-disable-line no-undef
  11. $('#txt-move-prompt').removeClass('is-danger').next().addClass('is-hidden')
  12. })
  13. $('#txt-move-prompt').on('keypress', (ev) => {
  14. if (ev.which === 13) {
  15. $('.btn-move-go').trigger('click')
  16. }
  17. })
  18. $('.btn-move-go').on('click', (ev) => {
  19. let newDocPath = makeSafePath($('#txt-move-prompt').val()) // eslint-disable-line no-undef
  20. if (_.isEmpty(newDocPath) || newDocPath === currentBasePath || newDocPath === 'home') {
  21. $('#txt-move-prompt').addClass('is-danger').next().removeClass('is-hidden')
  22. } else {
  23. $('#txt-move-prompt').parent().addClass('is-loading')
  24. $.ajax(window.location.href, {
  25. data: {
  26. move: newDocPath
  27. },
  28. dataType: 'json',
  29. method: 'PUT'
  30. }).then((rData, rStatus, rXHR) => {
  31. if (rData.ok) {
  32. window.location.assign('/' + newDocPath)
  33. } else {
  34. alerts.pushError('Something went wrong', rData.error)
  35. }
  36. }, (rXHR, rStatus, err) => {
  37. alerts.pushError('Something went wrong', 'Save operation failed.')
  38. })
  39. }
  40. })