ProjectNameController.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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('ProjectNameController', function(
  17. $scope,
  18. $element,
  19. settings,
  20. ide
  21. ) {
  22. const projectNameReadOnlyEl = $element.find('.name')[0]
  23. $scope.state = {
  24. renaming: false,
  25. overflowed: false
  26. }
  27. $scope.inputs = {}
  28. $scope.startRenaming = function() {
  29. $scope.inputs.name = $scope.project.name
  30. $scope.state.renaming = true
  31. return $scope.$emit('project:rename:start')
  32. }
  33. $scope.finishRenaming = function() {
  34. $scope.state.renaming = false
  35. const newName = $scope.inputs.name
  36. if ($scope.project.name === newName) {
  37. return
  38. }
  39. const oldName = $scope.project.name
  40. $scope.project.name = newName
  41. return settings
  42. .saveProjectSettings({ name: $scope.project.name })
  43. .catch(function(response) {
  44. const { data, status } = response
  45. $scope.project.name = oldName
  46. if (status === 400) {
  47. return ide.showGenericMessageModal('Error renaming project', data)
  48. } else {
  49. return ide.showGenericMessageModal(
  50. 'Error renaming project',
  51. 'Please try again in a moment'
  52. )
  53. }
  54. })
  55. }
  56. ide.socket.on('projectNameUpdated', name =>
  57. $scope.$apply(() => ($scope.project.name = name))
  58. )
  59. return $scope.$watch('project.name', function(name) {
  60. if (name != null) {
  61. window.document.title =
  62. name + ` - Online LaTeX Editor ${ExposedSettings.appName}`
  63. return $scope.$applyAsync(
  64. () =>
  65. // This ensures that the element is measured *after* the binding is done (i.e. project name is rendered).
  66. ($scope.state.overflowed =
  67. projectNameReadOnlyEl.scrollWidth >
  68. projectNameReadOnlyEl.clientWidth)
  69. )
  70. }
  71. })
  72. })