overleaf/services/web/frontend/js/ide/settings/controllers/ProjectNameController.js
Alf Eaton 1be43911b4 Merge pull request #3942 from overleaf/prettier-trailing-comma
Set Prettier's "trailingComma" setting to "es5"

GitOrigin-RevId: 9f14150511929a855b27467ad17be6ab262fe5d5
2021-04-28 02:10:01 +00:00

77 lines
2.3 KiB
JavaScript

/* eslint-disable
max-len,
no-return-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import App from '../../../base'
const MAX_PROJECT_NAME_LENGTH = 150
export default App.controller(
'ProjectNameController',
function ($scope, $element, settings, ide) {
const projectNameReadOnlyEl = $element.find('.name')[0]
$scope.state = {
renaming: false,
overflowed: false,
}
$scope.inputs = {}
$scope.startRenaming = function () {
$scope.inputs.name = $scope.project.name
$scope.state.renaming = true
return $scope.$emit('project:rename:start')
}
$scope.finishRenaming = function () {
$scope.state.renaming = false
const newName = $scope.inputs.name
if ($scope.project.name === newName) {
return
}
const oldName = $scope.project.name
$scope.project.name = newName
return settings
.saveProjectSettings({ name: $scope.project.name })
.catch(function (response) {
const { data, status } = response
$scope.project.name = oldName
if (status === 400) {
return ide.showGenericMessageModal('Error renaming project', data)
} else {
return ide.showGenericMessageModal(
'Error renaming project',
'Please try again in a moment'
)
}
})
}
ide.socket.on('projectNameUpdated', name =>
$scope.$apply(() => ($scope.project.name = name))
)
return $scope.$watch('project.name', function (name) {
if (name != null) {
window.document.title =
name + ` - Online LaTeX Editor ${ExposedSettings.appName}`
return $scope.$applyAsync(
() =>
// This ensures that the element is measured *after* the binding is done (i.e. project name is rendered).
($scope.state.overflowed =
projectNameReadOnlyEl.scrollWidth >
projectNameReadOnlyEl.clientWidth)
)
}
})
}
)