overleaf/services/web/public/coffee/ide/settings/controllers/ProjectNameController.coffee

45 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2014-07-08 07:02:26 -04:00
define [
"base"
], (App) ->
2016-02-23 10:00:04 -05:00
MAX_PROJECT_NAME_LENGTH = 150
App.controller "ProjectNameController", ["$scope", "$element", "settings", "ide", ($scope, $element, settings, ide) ->
projectNameReadOnlyEl = $element.find(".name")[0]
2014-07-08 07:02:26 -04:00
$scope.state =
renaming: false
overflowed: false
2014-07-08 07:02:26 -04:00
$scope.inputs = {}
$scope.startRenaming = () ->
$scope.inputs.name = $scope.project.name
$scope.state.renaming = true
$scope.$emit "project:rename:start"
$scope.finishRenaming = () ->
2016-02-23 10:00:04 -05:00
$scope.state.renaming = false
newName = $scope.inputs.name
if $scope.project.name == newName
return
oldName = $scope.project.name
2016-02-23 10:00:04 -05:00
$scope.project.name = newName
settings.saveProjectSettings({name: $scope.project.name})
.catch (response) ->
{ data, status } = response
$scope.project.name = oldName
if status == 400
ide.showGenericMessageModal("Error renaming project", data)
else
ide.showGenericMessageModal("Error renaming project", "Please try again in a moment")
2014-07-08 07:02:26 -04:00
ide.socket.on "projectNameUpdated", (name) ->
$scope.$apply () ->
$scope.project.name = name
$scope.$watch "project.name", (name) ->
if name?
window.document.title = name + " - Online LaTeX Editor ShareLaTeX"
$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)
2014-07-08 07:02:26 -04:00
]