overleaf/services/web/public/coffee/app/ide/file-tree/controllers/FileTreeEntityController.coffee
2014-06-22 20:49:58 +01:00

55 lines
1.4 KiB
CoffeeScript

define [
"base"
], (App) ->
App.controller "FileTreeEntityController", ["$scope", "ide", "$modal", ($scope, ide, $modal) ->
$scope.select = () ->
ide.fileTreeManager.forEachEntity (entity) ->
entity.selected = false
$scope.entity.selected = true
$scope.inputs =
name: $scope.entity.name
$scope.startRenaming = () ->
$scope.entity.renaming = true
$scope.finishRenaming = () ->
delete $scope.entity.renaming
ide.fileTreeManager.renameEntity($scope.entity, $scope.inputs.name)
$scope.$on "rename:selected", () ->
$scope.startRenaming() if $scope.entity.selected
$scope.openDeleteModal = () ->
$modal.open(
templateUrl: "deleteEntityModalTemplate"
controller: "DeleteEntityModalController"
scope: $scope
)
$scope.$on "delete:selected", () ->
$scope.openDeleteModal() if $scope.entity.selected
if $scope.entity.type == "folder"
$scope.expanded = false
$scope.toggleExpanded = () ->
$scope.expanded = !$scope.expanded
]
App.controller "DeleteEntityModalController", [
"$scope", "ide", "$modalInstance",
($scope, ide, $modalInstance) ->
$scope.state =
inflight: false
$scope.delete = () ->
$scope.state.inflight = true
ide.fileTreeManager.deleteEntity $scope.entity, (error) ->
$scope.$apply () ->
$scope.state.inflight = false
$modalInstance.close()
$scope.cancel = () ->
$modalInstance.dismiss('cancel')
]