Delete files

This commit is contained in:
James Allen 2014-06-22 20:49:58 +01:00
parent 7556af6421
commit 84ac77795f
5 changed files with 89 additions and 6 deletions

View file

@ -92,7 +92,7 @@ module.exports = class Router
app.post '/project/:Project_id/:entity_type/:entity_id/rename', SecurityManager.requestCanModifyProject, EditorHttpController.renameEntity
app.post '/project/:Project_id/:entity_type/:entity_id/move', SecurityManager.requestCanModifyProject, EditorHttpController.moveEntity
app.post '/project/:Project_id/:entity_type/:entity_id/delete', SecurityManager.requestCanModifyProject, EditorHttpController.deleteEntity
app.delete '/project/:Project_id/:entity_type/:entity_id', SecurityManager.requestCanModifyProject, EditorHttpController.deleteEntity
app.post '/project/:Project_id/compile', SecurityManager.requestCanAccessProject, CompileController.compile
app.get '/Project/:Project_id/output/output.pdf', SecurityManager.requestCanAccessProject, CompileController.downloadPdf

View file

@ -30,7 +30,13 @@ aside#file-tree.ui-layout-west(ng-controller="FileTreeController")
tooltip-placement="bottom"
)
i.fa.fa-pencil
a(href, tooltip="Delete", tooltip-placement="bottom", tooltip-append-to-body="true")
a(
href,
ng-click="openDeleteModalForSelected()",
tooltip="Delete",
tooltip-placement="bottom",
tooltip-append-to-body="true"
)
i.fa.fa-trash-o
ul.list-unstyled.file-tree-list
@ -155,3 +161,20 @@ script(type="text/ng-template", id="uploadFileModalTemplate")
span Upload file(s)
.modal-footer
button.btn.btn-default(ng-click="cancel()") Cancel
script(type='text/ng-template', id='deleteEntityModalTemplate')
.modal-header
h3 Delete {{ entity.name }}
.modal-body
p Are you sure you want to permanently delete <strong>{{ entity.name }}</strong>?
.modal-footer
button.btn.btn-default(
ng-disabled="state.inflight"
ng-click="cancel()"
) Cancel
button.btn.btn-danger(
ng-disabled="state.inflight"
ng-click="delete()"
)
span(ng-hide="state.inflight") Delete
span(ng-show="state.inflight") Deleting...

View file

@ -45,6 +45,12 @@ define [
@$scope.$apply () ->
entity.name = name
@ide.socket.on "removeEntity", (entity_id) =>
entity = @findEntityById(entity_id)
return if !entity?
@$scope.$apply () =>
@_deleteEntityFromScope entity
findEntityById: (id) ->
@_findEntityByIdInFolder @$scope.rootFolder, id
@ -58,12 +64,12 @@ define [
return null
forEachEntity: (callback) ->
forEachEntity: (callback = (entity, parent_folder) ->) ->
@_forEachEntityInFolder(@$scope.rootFolder, callback)
_forEachEntityInFolder: (folder, callback) ->
for entity in folder.children or []
callback(entity)
callback(entity, folder)
if entity.children?
@_forEachEntityInFolder(entity, callback)
@ -176,3 +182,27 @@ define [
failure: (error) -> callback(error)
}
deleteEntity: (entity, callback = (error) ->) ->
# We'll wait for the socket.io notification to
# delete from scope.
$.ajax {
url: "/project/#{@ide.project_id}/#{entity.type}/#{entity.id}"
type: "DELETE"
contentType: "application/json; charset=utf-8"
headers:
"X-Csrf-Token": window.csrfToken
dataType: "json"
success: () -> callback()
failure: (error) -> callback(error)
}
_deleteEntityFromScope: (entity) ->
parent_folder = null
@forEachEntity (possible_entity, folder) ->
if possible_entity == entity
parent_folder = folder
if parent_folder?
index = parent_folder.children.indexOf(entity)
if index > -1
parent_folder.children.splice(index, 1)

View file

@ -27,6 +27,9 @@ define [
$scope.startRenamingSelected = () ->
$scope.$broadcast "rename:selected"
$scope.openDeleteModalForSelected = () ->
$scope.$broadcast "delete:selected"
]
App.controller "NewDocModalController", [

View file

@ -1,7 +1,7 @@
define [
"base"
], (App) ->
App.controller "FileTreeEntityController", ["$scope", "ide", ($scope, ide) ->
App.controller "FileTreeEntityController", ["$scope", "ide", "$modal", ($scope, ide, $modal) ->
$scope.select = () ->
ide.fileTreeManager.forEachEntity (entity) ->
entity.selected = false
@ -20,9 +20,36 @@ define [
$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')
]