ProjectNameController.js 2.3 KB

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