From 0a334939ce0fdf6d65a863e6e4881b247017aedb Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 16 Jun 2014 16:13:09 +0100 Subject: [PATCH] Confirm deletes and leaves --- services/web/app/views/project/list.jade | 25 ++++++- .../web/public/coffee/project-list.coffee | 67 +++++++++++++++---- 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/services/web/app/views/project/list.jade b/services/web/app/views/project/list.jade index 9d1b68a28c..2c7fbcc4fd 100644 --- a/services/web/app/views/project/list.jade +++ b/services/web/app/views/project/list.jade @@ -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 diff --git a/services/web/public/coffee/project-list.coffee b/services/web/public/coffee/project-list.coffee index 195ce40d8d..9e6405e35d 100644 --- a/services/web/public/coffee/project-list.coffee +++ b/services/web/public/coffee/project-list.coffee @@ -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