2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
2016-02-23 10:00:04 -05:00
|
|
|
MAX_PROJECT_NAME_LENGTH = 150
|
2017-03-31 11:36:58 -04:00
|
|
|
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
|
2017-03-31 11:36:58 -04:00
|
|
|
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
|
2014-10-07 06:06:37 -04:00
|
|
|
newName = $scope.inputs.name
|
2016-02-23 10:00:04 -05:00
|
|
|
if !newName? or newName.length == 0 or newName.length > MAX_PROJECT_NAME_LENGTH
|
|
|
|
return
|
2016-03-09 09:47:49 -05:00
|
|
|
if $scope.project.name == newName
|
|
|
|
return
|
2016-02-23 10:00:04 -05:00
|
|
|
$scope.project.name = newName
|
2014-10-07 06:06:37 -04:00
|
|
|
settings.saveProjectSettings({name: $scope.project.name})
|
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"
|
2017-03-31 11:36:58 -04:00
|
|
|
$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
|
|
|
]
|