mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Fix project folder delete action [SCI-8391]
This commit is contained in:
parent
ef8a518a83
commit
7a6fe5050d
6 changed files with 14 additions and 36 deletions
|
@ -101,30 +101,7 @@ var ProjectsIndex = (function() {
|
|||
|
||||
// init delete project folders
|
||||
function initDeleteFoldersToolbarButton() {
|
||||
$(projectsWrapper)
|
||||
.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)
|
||||
$(document)
|
||||
.on('ajax:success', '.delete-folders-form', function(ev, data) {
|
||||
$('.modal-project-folder-delete').modal('hide');
|
||||
HelperModule.flashAlertMsg(data.message, 'success');
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
.sn-action-toolbar {
|
||||
background: $color-concrete;
|
||||
z-index: 2;
|
||||
|
||||
.btn:hover {
|
||||
background: $color-white;
|
||||
|
|
|
@ -99,12 +99,12 @@ class ProjectFoldersController < ApplicationController
|
|||
def destroy_modal
|
||||
render json: {
|
||||
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
|
||||
|
||||
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
|
||||
project_folders.each do |folder|
|
||||
next if folder.projects.exists? || folder.project_folders.exists? || !can_manage_team?(current_team)
|
||||
|
|
|
@ -38,7 +38,8 @@ module Toolbars
|
|||
archive_action,
|
||||
restore_action,
|
||||
comments_action,
|
||||
activities_action
|
||||
activities_action,
|
||||
delete_folder_action
|
||||
].compact
|
||||
end
|
||||
|
||||
|
@ -116,7 +117,7 @@ module Toolbars
|
|||
|
||||
def archive_action
|
||||
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
|
||||
|
||||
{
|
||||
|
@ -132,7 +133,7 @@ module Toolbars
|
|||
|
||||
def restore_action
|
||||
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
|
||||
|
||||
{
|
||||
|
@ -148,7 +149,7 @@ module Toolbars
|
|||
|
||||
def delete_folder_action
|
||||
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
|
||||
|
||||
{
|
||||
|
@ -156,9 +157,8 @@ module Toolbars
|
|||
label: I18n.t('general.delete'),
|
||||
icon: 'fas fa-trash',
|
||||
button_class: 'delete-folders-btn',
|
||||
path: destroy_modal_project_folders_url,
|
||||
type: :request,
|
||||
request_method: :post
|
||||
path: destroy_modal_project_folders_path(project_folder_ids: @items.map(&:id)),
|
||||
type: 'remote-modal'
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<h2 class="modal-title"><%= t('projects.index.modal_delete_folders.title') %></h2>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
@ -17,7 +17,7 @@
|
|||
destroy_project_folders_path,
|
||||
class: 'btn btn-danger',
|
||||
form_class: 'delete-folders-form',
|
||||
params: { project_folders_ids: project_folders_ids },
|
||||
params: { project_folder_ids: project_folder_ids },
|
||||
remote: true %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -374,7 +374,7 @@ Rails.application.routes.draw do
|
|||
post 'move_to', to: 'project_folders#move_to', 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_modal', to: 'project_folders#destroy_modal', defaults: { format: 'json' }
|
||||
get 'destroy_modal', to: 'project_folders#destroy_modal', defaults: { format: 'json' }
|
||||
end
|
||||
end
|
||||
get 'project_folders/:project_folder_id', to: 'projects#index', as: :project_folder_projects
|
||||
|
|
Loading…
Reference in a new issue