ProjectNameController.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. import App from '../../../base'
  15. const MAX_PROJECT_NAME_LENGTH = 150
  16. export default App.controller(
  17. 'ProjectNameController',
  18. function ($scope, $element, settings, ide) {
  19. const projectNameReadOnlyEl = $element.find('.name')[0]
  20. $scope.state = {
  21. renaming: false,
  22. overflowed: false,
  23. }
  24. $scope.inputs = {}
  25. $scope.startRenaming = function () {
  26. $scope.inputs.name = $scope.project.name
  27. $scope.state.renaming = true
  28. return $scope.$emit('project:rename:start')
  29. }
  30. $scope.finishRenaming = function () {
  31. $scope.state.renaming = false
  32. const newName = $scope.inputs.name
  33. if ($scope.project.name === newName) {
  34. return
  35. }
  36. const oldName = $scope.project.name
  37. $scope.project.name = newName
  38. return settings
  39. .saveProjectSettings({ name: $scope.project.name })
  40. .catch(function (response) {
  41. const { data, status } = response
  42. $scope.project.name = oldName
  43. if (status === 400) {
  44. return ide.showGenericMessageModal('Error renaming project', data)
  45. } else {
  46. return ide.showGenericMessageModal(
  47. 'Error renaming project',
  48. 'Please try again in a moment'
  49. )
  50. }
  51. })
  52. }
  53. ide.socket.on('projectNameUpdated', name =>
  54. $scope.$apply(() => ($scope.project.name = name))
  55. )
  56. return $scope.$watch('project.name', function (name) {
  57. if (name != null) {
  58. window.document.title =
  59. name + ` - Online LaTeX Editor ${ExposedSettings.appName}`
  60. return $scope.$applyAsync(
  61. () =>
  62. // This ensures that the element is measured *after* the binding is done (i.e. project name is rendered).
  63. ($scope.state.overflowed =
  64. projectNameReadOnlyEl.scrollWidth >
  65. projectNameReadOnlyEl.clientWidth)
  66. )
  67. }
  68. })
  69. }
  70. )