2018-11-05 05:06:39 -05:00
|
|
|
/* 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
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../../base'
|
|
|
|
const MAX_PROJECT_NAME_LENGTH = 150
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
export default App.controller(
|
|
|
|
'ProjectNameController',
|
|
|
|
function ($scope, $element, settings, ide) {
|
|
|
|
const projectNameReadOnlyEl = $element.find('.name')[0]
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.state = {
|
|
|
|
renaming: false,
|
|
|
|
overflowed: false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.inputs = {}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.startRenaming = function () {
|
|
|
|
$scope.inputs.name = $scope.project.name
|
|
|
|
$scope.state.renaming = true
|
|
|
|
return $scope.$emit('project:rename:start')
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$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'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
ide.socket.on('projectNameUpdated', name =>
|
|
|
|
$scope.$apply(() => ($scope.project.name = name))
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|