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.

48 lines
1.3 KiB

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