Fix project folder delete action [SCI-8391]

This commit is contained in:
Martin Artnik 2023-05-04 14:59:16 +02:00
parent ef8a518a83
commit 7a6fe5050d
6 changed files with 14 additions and 36 deletions

View file

@ -101,30 +101,7 @@ var ProjectsIndex = (function() {
// init delete project folders // init delete project folders
function initDeleteFoldersToolbarButton() { function initDeleteFoldersToolbarButton() {
$(projectsWrapper) $(document)
.on('ajax:before', '.delete-folders-btn', function() {
let buttonForm = $(this);
buttonForm.find('input[name="project_folders_ids[]"]').remove();
selectedProjectFolders.forEach(function(id) {
$('<input>').attr({
type: 'hidden',
name: 'project_folders_ids[]',
value: id
}).appendTo(buttonForm);
});
})
.on('ajax:success', '.delete-folders-btn', function(ev, data) {
// Add and show modal
let deleteModal = $(data.html);
$(projectsWrapper).append(deleteModal);
deleteModal.modal('show');
// Remove modal when it gets closed
deleteModal.on('hidden.bs.modal', function() {
$(this).remove();
});
});
$(projectsWrapper)
.on('ajax:success', '.delete-folders-form', function(ev, data) { .on('ajax:success', '.delete-folders-form', function(ev, data) {
$('.modal-project-folder-delete').modal('hide'); $('.modal-project-folder-delete').modal('hide');
HelperModule.flashAlertMsg(data.message, 'success'); HelperModule.flashAlertMsg(data.message, 'success');

View file

@ -1,5 +1,6 @@
.sn-action-toolbar { .sn-action-toolbar {
background: $color-concrete; background: $color-concrete;
z-index: 2;
.btn:hover { .btn:hover {
background: $color-white; background: $color-white;

View file

@ -99,12 +99,12 @@ class ProjectFoldersController < ApplicationController
def destroy_modal def destroy_modal
render json: { render json: {
html: render_to_string(partial: 'projects/index/modals/project_folder_delete.html.erb', html: render_to_string(partial: 'projects/index/modals/project_folder_delete.html.erb',
locals: { project_folders_ids: params[:project_folders_ids] }) locals: { project_folder_ids: params[:project_folder_ids] })
} }
end end
def destroy def destroy
project_folders = current_team.project_folders.where(id: params[:project_folders_ids]) project_folders = current_team.project_folders.where(id: params[:project_folder_ids])
counter = 0 counter = 0
project_folders.each do |folder| project_folders.each do |folder|
next if folder.projects.exists? || folder.project_folders.exists? || !can_manage_team?(current_team) next if folder.projects.exists? || folder.project_folders.exists? || !can_manage_team?(current_team)

View file

@ -38,7 +38,8 @@ module Toolbars
archive_action, archive_action,
restore_action, restore_action,
comments_action, comments_action,
activities_action activities_action,
delete_folder_action
].compact ].compact
end end
@ -116,7 +117,7 @@ module Toolbars
def archive_action def archive_action
return unless @items.all? do |item| return unless @items.all? do |item|
item.is_a?(Project) ? can_archive_project?(item) : can_manage_team?(item.team) item.is_a?(Project) && can_archive_project?(item)
end end
{ {
@ -132,7 +133,7 @@ module Toolbars
def restore_action def restore_action
return unless @items.all? do |item| return unless @items.all? do |item|
item.is_a?(Project) ? can_restore_project?(item) : item.archived? && can_manage_team?(item.team) item.is_a?(Project) && can_restore_project?(item)
end end
{ {
@ -148,7 +149,7 @@ module Toolbars
def delete_folder_action def delete_folder_action
return unless @items.all? do |item| return unless @items.all? do |item|
item.is_a?(Folder) && can_delete_project_folder?(item) item.is_a?(ProjectFolder) && can_delete_project_folder?(item)
end end
{ {
@ -156,9 +157,8 @@ module Toolbars
label: I18n.t('general.delete'), label: I18n.t('general.delete'),
icon: 'fas fa-trash', icon: 'fas fa-trash',
button_class: 'delete-folders-btn', button_class: 'delete-folders-btn',
path: destroy_modal_project_folders_url, path: destroy_modal_project_folders_path(project_folder_ids: @items.map(&:id)),
type: :request, type: 'remote-modal'
request_method: :post
} }
end end

View file

@ -8,7 +8,7 @@
<h2 class="modal-title"><%= t('projects.index.modal_delete_folders.title') %></h2> <h2 class="modal-title"><%= t('projects.index.modal_delete_folders.title') %></h2>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p><%= t('projects.index.modal_delete_folders.description_1_html', number: project_folders_ids.size) %></p> <p><%= t('projects.index.modal_delete_folders.description_1_html', number: project_folder_ids.size) %></p>
<p><%= t('projects.index.modal_delete_folders.description_2') %></p> <p><%= t('projects.index.modal_delete_folders.description_2') %></p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
@ -17,7 +17,7 @@
destroy_project_folders_path, destroy_project_folders_path,
class: 'btn btn-danger', class: 'btn btn-danger',
form_class: 'delete-folders-form', form_class: 'delete-folders-form',
params: { project_folders_ids: project_folders_ids }, params: { project_folder_ids: project_folder_ids },
remote: true %> remote: true %>
</div> </div>
</div> </div>

View file

@ -374,7 +374,7 @@ Rails.application.routes.draw do
post 'move_to', to: 'project_folders#move_to', defaults: { format: 'json' } post 'move_to', to: 'project_folders#move_to', defaults: { format: 'json' }
get 'move_to_modal', to: 'project_folders#move_to_modal', defaults: { format: 'json' } get 'move_to_modal', to: 'project_folders#move_to_modal', defaults: { format: 'json' }
post 'destroy', to: 'project_folders#destroy', as: 'destroy', defaults: { format: 'json' } post 'destroy', to: 'project_folders#destroy', as: 'destroy', defaults: { format: 'json' }
post 'destroy_modal', to: 'project_folders#destroy_modal', defaults: { format: 'json' } get 'destroy_modal', to: 'project_folders#destroy_modal', defaults: { format: 'json' }
end end
end end
get 'project_folders/:project_folder_id', to: 'projects#index', as: :project_folder_projects get 'project_folders/:project_folder_id', to: 'projects#index', as: :project_folder_projects