Confirm deletes and leaves

This commit is contained in:
James Allen 2014-06-16 16:13:09 +01:00
parent 3a969876e0
commit 0a334939ce
2 changed files with 76 additions and 16 deletions

View file

@ -110,7 +110,7 @@ block content
data-original-title="Delete",
data-toggle="tooltip",
data-placement="bottom",
ng-click="archiveSelectedProjects()"
ng-click="openArchiveProjectsModal()"
)
i.fa.fa-trash-o
@ -305,6 +305,27 @@ block content
span(ng-hide="state.inflight") Create
span(ng-show="state.inflight") Creating...
script(type='text/ng-template', id='deleteProjectsModalTemplate')
.modal-header
h3 {{action}} Projects
.modal-body
div(ng-show="projectsToDelete.length > 0")
p You are about to delete the following projects:
ul
li(ng-repeat="project in projectsToDelete | orderBy:'name'")
strong {{project.name}}
div(ng-show="projectsToLeave.length > 0")
p You are about to leave the following projects:
ul
li(ng-repeat="project in projectsToLeave | orderBy:'name'")
strong {{project.name}}
.modal-footer
button.btn.btn-default(
ng-click="cancel()"
) Cancel
button.btn.btn-danger(
ng-click="delete()"
) {{action}}
script(type="text/ng-template", id="uploadProjectModalTemplate")
.modal-header
@ -312,4 +333,4 @@ block content
.modal-body(ng-fine-upload)
span Upload a zipped project
.modal-footer
button.btn.btn-default.cancel(ng-click="cancel()") Cancel
button.btn.btn-default(ng-click="cancel()") Cancel

View file

@ -138,6 +138,11 @@ ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http, $q) -
tag.project_ids = remaining_project_ids
return removed_project_ids
$scope._removeProjectFromList = (project) ->
index = $scope.projects.indexOf(project)
if index > -1
$scope.projects.splice(index, 1)
$scope.removeSelectedProjectsFromTag = (tag) ->
selected_project_ids = $scope.getSelectedProjectIds()
selected_projects = $scope.getSelectedProjects()
@ -300,24 +305,43 @@ ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http, $q) -
scope: $scope
)
$scope.archiveSelectedProjects = () ->
$scope.openArchiveProjectsModal = () ->
modalInstance = $modal.open(
templateUrl: "deleteProjectsModalTemplate"
controller: "DeleteProjectsModalController"
resolve:
projects: () -> $scope.getSelectedProjects()
)
modalInstance.result.then () ->
$scope.archiveOrLeaveSelectedProjects()
$scope.archiveOrLeaveSelectedProjects = () ->
selected_projects = $scope.getSelectedProjects()
selected_project_ids = $scope.getSelectedProjectIds()
for project in selected_projects
project.archived = true
# Remove project from any tags
for tag in $scope.tags
$scope._removeProjectIdsFromTagArray(tag, selected_project_ids)
for project_id in selected_project_ids
$http {
method: "DELETE"
url: "/project/#{project_id}"
headers:
"X-CSRF-Token": window.csrfToken
}
for project in selected_projects
if project.accessLevel == "owner"
project.archived = true
$http {
method: "DELETE"
url: "/project/#{project.id}"
headers:
"X-CSRF-Token": window.csrfToken
}
else
$scope._removeProjectFromList project
$http {
method: "POST"
url: "/project/#{project.id}/leave"
headers:
"X-CSRF-Token": window.csrfToken
}
$scope.updateVisibleProjects()
@ -327,9 +351,7 @@ ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http, $q) -
# Remove projects from array
for project in selected_projects
index = $scope.projects.indexOf(project)
if index > -1
$scope.projects.splice(index, 1)
$scope._removeProjectFromList project
# Remove project from any tags
for tag in $scope.tags
@ -492,6 +514,23 @@ ProjectPageApp.controller 'NewProjectModalController', ($scope, $modalInstance,
$scope.cancel = () ->
$modalInstance.dismiss('cancel')
ProjectPageApp.controller 'DeleteProjectsModalController', ($scope, $modalInstance, $timeout, projects) ->
$scope.projectsToDelete = projects.filter (project) -> project.accessLevel == "owner"
$scope.projectsToLeave = projects.filter (project) -> project.accessLevel != "owner"
if $scope.projectsToLeave.length > 0 and $scope.projectsToDelete.length > 0
$scope.action = "Delete & Leave"
else if $scope.projectsToLeave.length == 0 and $scope.projectsToDelete.length > 0
$scope.action = "Delete"
else
$scope.action = "Leave"
$scope.delete = () ->
$modalInstance.close()
$scope.cancel = () ->
$modalInstance.dismiss('cancel')
ProjectPageApp.directive 'ngFineUpload', ($timeout) ->
return (scope, element, attrs) ->
new qq.FineUploader