diff --git a/app/controllers/dmsf_context_menus_controller.rb b/app/controllers/dmsf_context_menus_controller.rb
index b37a9aac..0fdcfbc9 100644
--- a/app/controllers/dmsf_context_menus_controller.rb
+++ b/app/controllers/dmsf_context_menus_controller.rb
@@ -25,17 +25,48 @@ class DmsfContextMenusController < ApplicationController
before_action :find_project
before_action :find_folder
- before_action :find_file, :except => [:trash]
+ before_action :find_dmsf_file
+ before_action :find_dmsf_folder
def dmsf
- @disabled = params[:ids].blank?
- render :layout => false
+ if @dmsf_file
+ @locked = @dmsf_file.locked?
+ @unlockable = @dmsf_file.unlockable? && (!@dmsf_file.locked_for_user?) &&
+ User.current.allowed_to?(:force_file_unlock, @project)
+ @allowed = User.current.allowed_to? :file_manipulation, @project
+ @email_allowed = User.current.allowed_to?(:email_documents, @project)
+ elsif @dmsf_folder
+ @locked = @dmsf_folder.locked?
+ @unlockable = @dmsf_folder.unlockable? && (!@dmsf_folder.locked_for_user?) &&
+ User.current.allowed_to?(:force_file_unlock, @project)
+ @allowed = User.current.allowed_to?(:folder_manipulation, @project)
+ @email_allowed = User.current.allowed_to?(:email_documents, @project)
+ elsif @dmsf_link
+ @allowed = User.current.allowed_to? :file_manipulation, @project
+ else
+ @allowed = User.current.allowed_to?(:folder_manipulation, @project) &&
+ User.current.allowed_to?(:file_delete, @project)
+ @email_allowed = User.current.allowed_to?(:email_documents, @project)
+ end
+ render layout: false
rescue ActiveRecord::RecordNotFound
render_404
end
def trash
- render :layout => false
+ if @dmsf_file
+ @allowed_restore = User.current.allowed_to? :file_manipulation, @project
+ @allowed_delete = User.current.allowed_to? :file_delete, @project
+ elsif @dmsf_folder
+ @allowed = User.current.allowed_to?(:folder_manipulation, @project)
+ elsif @dmsf_link
+ @allowed_restore = User.current.allowed_to? :file_manipulation, @project
+ @allowed_delete = User.current.allowed_to? :file_delete, @project
+ else
+ @allowed = User.current.allowed_to?(:folder_manipulation, @project) &&
+ User.current.allowed_to?(:file_manipulation, @project)
+ end
+ render layout: false
rescue ActiveRecord::RecordNotFound
render_404
end
@@ -50,16 +81,24 @@ class DmsfContextMenusController < ApplicationController
render_404
end
- def find_file
- if params[:ids].present?
- selected_files = params[:ids].select{ |x| x =~ /file-\d+/ }.map{ |x| $1.to_i if x =~ /file-(\d+)/ }
- selected_file_links = params[:ids].select{ |x| x =~ /file-link-\d+/ }.map{ |x| $1.to_i if x =~ /file-link-(\d+)/ }
- selected_file_links.each do |id|
- target_id = DmsfLink.where(id: id).pluck(:target_id).first
- selected_files << target_id if target_id && !selected_files.include?(target_id)
+ def find_dmsf_file
+ if (params[:ids].size == 1) && (!@dmsf_folder)
+ if params[:ids][0] =~ /file-(\d+)/
+ @dmsf_file = DmsfFile.find_by(id: $1)
+ elsif params[:ids][0] =~ /(file|url)-link-(\d+)/
+ @dmsf_link = DmsfLink.find_by(id: $2)
+ @dmsf_file = DmsfFile.find_by(id: @dmsf_link.target_id) if @dmsf_link && @dmsf_link.target_type != 'DmsfUrl'
end
- if (selected_files.size == 1) && (params[:ids].size == 1)
- @file = DmsfFile.find_by(id: selected_files[0])
+ end
+ end
+
+ def find_dmsf_folder
+ if (params[:ids].size == 1) && (!@dmsf_file)
+ if params[:ids][0] =~ /folder-(\d+)/
+ @dmsf_folder = DmsfFolder.find_by(id: $1)
+ elsif params[:ids][0] =~ /folder-link-(\d+)/
+ @dmsf_link = DmsfLink.find_by(id: $1)
+ @dmsf_folder = DmsfFolder.find_by(id: @dmsf_link.target_id) if @dmsf_link
end
end
end
diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb
index f1f9aff0..3aa9ab12 100644
--- a/app/models/dmsf_folder.rb
+++ b/app/models/dmsf_folder.rb
@@ -139,7 +139,7 @@ class DmsfFolder < ActiveRecord::Base
if locked?
errors[:base] << l(:error_folder_is_locked)
return false
- elsif !dmsf_folders.visible.empty? || !dmsf_files.visible.empty? || !dmsf_links.visible.empty?
+ elsif !empty?
errors[:base] << l(:error_folder_is_not_empty)
return false
end
@@ -152,6 +152,10 @@ class DmsfFolder < ActiveRecord::Base
end
end
+ def empty?
+ !(dmsf_folders.visible.exists? || dmsf_files.visible.exists? || dmsf_links.visible.exists?)
+ end
+
def deleted?
deleted == STATUS_DELETED
end
@@ -163,7 +167,7 @@ class DmsfFolder < ActiveRecord::Base
end
self.deleted = STATUS_ACTIVE
self.deleted_by_user = nil
- save!
+ save
end
def dmsf_path
diff --git a/app/views/dmsf/_dir.html.erb b/app/views/dmsf/_dir.html.erb
index 0db29774..b0b90fca 100644
--- a/app/views/dmsf/_dir.html.erb
+++ b/app/views/dmsf/_dir.html.erb
@@ -79,51 +79,7 @@
<% end %>
<% end %>
-
- <% if @folder_manipulation_allowed && !(subfolder && subfolder.system) %>
- <% if subfolder && subfolder.locked? %>
-
- <% if subfolder.unlockable? && (!subfolder.locked_for_user? || @force_file_unlock_allowed) %>
- <%= link_to('', unlock_dmsf_path(:id => project, :folder_id => subfolder),
- :title => subfolder.get_locked_title,
- :class => 'icon-only icon-unlock') %>
- <% else %>
-
- <% end %>
- <% else %>
- <% if subfolder %>
- <%= link_to('', edit_dmsf_path(:id => project, :folder_id => subfolder),
- :title => l(:link_edit, :title => h(subfolder.title)),
- :class => 'icon-only icon-edit') %>
- <% else %>
- <%= link_to('', edit_root_dmsf_path(:id => @project),
- :title => l(:link_edit, :title => l(:link_documents)),
- :class => 'icon-only icon-edit') %>
- <% end %>
- <% if subfolder %>
- <%= link_to('', lock_dmsf_path(:id => project, :folder_id => subfolder),
- :title => l(:title_lock_file),
- :class => 'icon-only icon-lock') %>
- <% else %>
-
- <% end %>
- <% if (subfolder && subfolder.notification) || (!subfolder && project.dmsf_notification) %>
- <%= link_to('', notify_deactivate_dmsf_path(:id => project, :folder_id => subfolder),
- :title => l(:title_notifications_active_deactivate),
- :class => 'icon-only icon-email') %>
- <% else %>
- <%= link_to('', notify_activate_dmsf_path(:id => project, :folder_id => subfolder),
- :title => l(:title_notifications_not_active_activate),
- :class => 'icon-only icon-email-add') %>
- <% end %>
- <%= link_to('', link ? dmsf_link_path(link) : delete_dmsf_path(:id => project, :folder_id => subfolder),
- :data => {:confirm => l(:text_are_you_sure)},
- :title => l(:title_delete),
- :method => :delete,
- :class => 'icon-only icon-del') %>
- <% end %>
- <% end %>
- |
+<%= link_to_context_menu %> |
<%= position %> |
0 |
<%= subfolder.modified.to_i if subfolder %> |
diff --git a/app/views/dmsf/_dir_trash.html.erb b/app/views/dmsf/_dir_trash.html.erb
index d785ca6f..d612721b 100644
--- a/app/views/dmsf/_dir_trash.html.erb
+++ b/app/views/dmsf/_dir_trash.html.erb
@@ -63,26 +63,7 @@
<% end %>
<% end %>
-
- <% if @folder_manipulation_allowed %>
- <%= link_to('', link ? restore_dmsf_link_path(:id => link) : restore_dmsf_path(:id => project, :folder_id => subfolder),
- :title => l(:title_restore),
- :class => 'icon-only icon-cancel') %>
- <% if link %>
- <%= link_to('', dmsf_link_path(:id => link, :commit => 'yes'),
- :data => {:confirm => l(:text_are_you_sure)},
- :method => :delete,
- :title => l(:title_delete),
- :class => 'icon-only icon-del') %>
- <% else %>
- <%= link_to('', delete_dmsf_path(:id => project, :folder_id => subfolder, :commit => 'yes'),
- :data => {:confirm => l(:text_are_you_sure)},
- :title => l(:title_delete),
- :method => :delete,
- :class => 'icon-only icon-del') %>
- <% end %>
- <% end %>
- |
+<%= link_to_context_menu %> |
0 |
0 |
<%= subfolder.modified.to_i if subfolder %> |
diff --git a/app/views/dmsf/_file.html.erb b/app/views/dmsf/_file.html.erb
index f394c0d3..fd5a706c 100644
--- a/app/views/dmsf/_file.html.erb
+++ b/app/views/dmsf/_file.html.erb
@@ -83,58 +83,7 @@
<% end %>
<% end %>
-
- <% if @file_manipulation_allowed %>
- <%= link_to('', dmsf_file_path(:id => file),
- :title => l(:link_details, :title => h(file.last_revision.title)),
- :class => 'icon-only icon-edit') %>
- <% if !file.locked? %>
- <%= link_to('', lock_dmsf_files_path(:id => file),
- :title => l(:title_lock_file),
- :class => 'icon-only icon-lock') %>
- <% elsif file.unlockable? && (!file.locked_for_user? || @force_file_unlock_allowed) %>
- <%= link_to('', unlock_dmsf_files_path(:id => file),
- :title => file.get_locked_title,
- :class => 'icon-only icon-unlock') %>
- <% else %>
-
- <% end %>
- <% if !file.locked? %>
- <% if file.notification %>
- <%= link_to('', notify_deactivate_dmsf_files_path(:id => file),
- :title => l(:title_notifications_active_deactivate),
- :class => 'icon-only icon-email') %>
- <% else %>
- <%= link_to('', notify_activate_dmsf_files_path(:id => file),
- :title => l(:title_notifications_not_active_activate),
- :class => 'icon-only icon-email-add') %>
- <% end %>
- <% if link %>
- <%= link_to('', dmsf_link_path(link),
- :data => {:confirm => l(:text_are_you_sure)},
- :title => l(:title_delete),
- :method => :delete,
- :class => 'icon-only icon-del') %>
- <% else %>
- <% if @file_delete_allowed %>
- <%= link_to('', dmsf_file_path(:id => file),
- :data => {:confirm => l(:text_are_you_sure)},
- :title => l(:title_delete),
- :method => :delete,
- :class => 'icon-only icon-del') %>
- <% else %>
-
- <% end %>
- <% end %>
- <% else %>
-
-
- <% end %>
- <% end %>
- <%= render(:partial => 'dmsf_workflows/approval_workflow_button',
- :locals => {:file => file, :file_approval_allowed => @file_approval_allowed,
- :workflows_available => @workflows_available, :project => project, :wf => wf, :dmsf_link_id => nil }) %>
- |
+<%= link_to_context_menu %> |
<%= position %> |
<%= file.last_revision.size %> |
<%= file.last_revision.updated_at.to_i %> |
diff --git a/app/views/dmsf/_file_trash.html.erb b/app/views/dmsf/_file_trash.html.erb
index 38b6c26e..4784678f 100644
--- a/app/views/dmsf/_file_trash.html.erb
+++ b/app/views/dmsf/_file_trash.html.erb
@@ -63,20 +63,7 @@
<% end %>
<% end %>
-
- <% if @file_manipulation_allowed %>
- <%= link_to('', link ? restore_dmsf_link_path(:id => link) : restore_dmsf_file_path(:id => file),
- :title => l(:title_restore),
- :class => 'icon-only icon-cancel') %>
- <% end %>
- <% if @file_delete_allowed %>
- <%= link_to('', link ? dmsf_link_path(:id => link, :commit => 'yes') : dmsf_file_path(:id => file, :commit => 'yes'),
- :data => {:confirm => l(:text_are_you_sure)},
- :method => :delete,
- :title => l(:title_delete),
- :class => 'icon-only icon-del') %>
- <% end %>
- |
+<%= link_to_context_menu %> |
1 |
<%= file.last_revision.size %> |
<%= file.last_revision.updated_at.to_i %> |
diff --git a/app/views/dmsf/_tree_view.erb b/app/views/dmsf/_tree_view.erb
index f8b35509..2c414cf7 100644
--- a/app/views/dmsf/_tree_view.erb
+++ b/app/views/dmsf/_tree_view.erb
@@ -67,6 +67,6 @@
- <%= render(:partial => 'dmsf/dmsf_rows') %>
+ <%= render partial: 'dmsf/dmsf_rows' %>
diff --git a/app/views/dmsf/_url.html.erb b/app/views/dmsf/_url.html.erb
index 40144f52..e6b93111 100644
--- a/app/views/dmsf/_url.html.erb
+++ b/app/views/dmsf/_url.html.erb
@@ -66,21 +66,7 @@
|
<% end %>
<% end %>
-
-
-
-
- <% if @file_delete_allowed %>
- <%= link_to('',
- dmsf_link_path(link),
- :data => {:confirm => l(:text_are_you_sure)},
- :method => :delete,
- :title => l(:title_delete),
- :class => "icon icon-del") %>
- <% else %>
-
- <% end %>
- |
+<%= link_to_context_menu %> |
<%= position %> |
|
link.updated_at.to_i |
diff --git a/app/views/dmsf/_url_trash.html.erb b/app/views/dmsf/_url_trash.html.erb
index c0c9f3ac..c7ceb139 100644
--- a/app/views/dmsf/_url_trash.html.erb
+++ b/app/views/dmsf/_url_trash.html.erb
@@ -62,15 +62,7 @@
|
<% end %>
<% end %>
-
- <%= link_to_if(@file_manipulation_allowed, '', restore_dmsf_link_path(:id => link),
- :title => l(:title_restore), :class => "icon icon-cancel") %>
- <% if @file_delete_allowed %>
- <%= link_to_if(@file_delete_allowed, '', dmsf_link_path(:id => link, :commit => 'yes'),
- :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,
- :title => l(:title_delete), :class => "icon icon-del" ) %>
- <% end %>
- |
+<%= link_to_context_menu %> |
1 |
|
<%= link.updated_at.to_i %> |
diff --git a/app/views/dmsf/edit.html.erb b/app/views/dmsf/edit.html.erb
index 80111e0a..cd9b76d8 100644
--- a/app/views/dmsf/edit.html.erb
+++ b/app/views/dmsf/edit.html.erb
@@ -55,7 +55,7 @@
<% unless @folder.locked? %>
<%= link_to(l(:button_delete), delete_dmsf_path(:id => @project, :folder_id => @folder),
:data => {:confirm => l(:text_are_you_sure)},
- :title => l(:title_delete), :class => 'icon icon-del', :method => :delete) %>
+ :title => l(:button_delete), :class => 'icon icon-del', :method => :delete) %>
<% end %>
<% end %>
diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb
index ee3e971c..00f0d711 100644
--- a/app/views/dmsf/show.html.erb
+++ b/app/views/dmsf/show.html.erb
@@ -82,8 +82,7 @@
<% end %>
-<%= render(:partial => 'path',
- :locals => {:folder => @folder, :filename => nil, :title => nil}) %>
+<%= render partial: 'path', locals: { folder: @folder, filename: nil, title: nil } %>