diff --git a/after_init.rb b/after_init.rb index b973635d..e9d3f472 100644 --- a/after_init.rb +++ b/after_init.rb @@ -37,7 +37,8 @@ def init {:dmsf => [:new, :create, :delete, :edit, :save, :edit_root, :save_root, :lock, :unlock, :notify_activate, :notify_deactivate, :restore], :dmsf_folder_permissions => [:new, :append, :autocomplete_for_user], - :dmsf_folders_copy => [:new, :copy, :move]} + :dmsf_folders_copy => [:new, :copy, :move], + :dmsf_context_menus => [:dmsf]} pmap.permission :file_manipulation, {:dmsf_files => [:create_revision, :lock, :unlock, :delete_revision, :notify_activate, :notify_deactivate, :restore], @@ -46,7 +47,7 @@ def init :dmsf_links => [:new, :create, :destroy, :restore, :autocomplete_for_project, :autocomplete_for_folder], :dmsf_files_copy => [:new, :copy, :move], - } + :dmsf_context_menus => [:dmsf]} pmap.permission :file_delete, { :dmsf => [:trash, :delete_entries], :dmsf_files => [:delete]} diff --git a/app/controllers/dmsf_context_menus_controller.rb b/app/controllers/dmsf_context_menus_controller.rb new file mode 100644 index 00000000..f2852819 --- /dev/null +++ b/app/controllers/dmsf_context_menus_controller.rb @@ -0,0 +1,42 @@ +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-18 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class DmsfContextMenusController < ApplicationController + + helper :context_menus + + def dmsf + selected_files = params[:files] || [] + selected_file_links = params[:file_links] || [] + if selected_file_links.present? + selected_file_links.each do |id| + link = DmsfLink.find_by_id id + selected_files << link.target_id if link && !selected_files.include?(link.target_id.to_s) + end + end + if selected_files.size == 1 + @file = DmsfFile.find selected_files[0] + end + render :layout => false + rescue ActiveRecord::RecordNotFound + render_404 + end + +end \ No newline at end of file diff --git a/app/views/dmsf/_dmsf_rows.erb b/app/views/dmsf/_dmsf_rows.erb index 146baa8d..578ea2bc 100644 --- a/app/views/dmsf/_dmsf_rows.erb +++ b/app/views/dmsf/_dmsf_rows.erb @@ -1,6 +1,28 @@ +<% + # encoding: utf-8 + # + # Redmine plugin for Document Management System "Features" + # + # Copyright © 2011-18 Karel Pičman + # + # This program is free software; you can redistribute it and/or + # modify it under the terms of the GNU General Public License + # as published by the Free Software Foundation; either version 2 + # of the License, or (at your option) any later version. + # + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with this program; if not, write to the Free Software + # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +%> + <% parent = @folder ? @folder : @project %> <% DmsfHelper.all_children_sorted(parent, @pos, @idnt).each do |obj, position| %> - <% classes = "dmsf_tree idnt-#{@idnt}" %> + <% classes = "dmsf_tree idnt-#{@idnt} hascontextmenu" %> <% if obj.is_a?(DmsfFolder) && ((obj.dmsf_folders.visible.count > 0) || (obj.dmsf_files.visible.count > 0) || (obj.dmsf_links.visible.count > 0)) %> <% classes += ' idnt dmsf_collapsed dmsf-not-loaded' %> <% id = "id='#{obj.id}span'".html_safe %> diff --git a/app/views/dmsf/_list_view.erb b/app/views/dmsf/_list_view.erb index a90a31bb..a2a9b5b9 100644 --- a/app/views/dmsf/_list_view.erb +++ b/app/views/dmsf/_list_view.erb @@ -64,8 +64,9 @@ + <% classes = 'dir hascontextmenu' %> <% @subfolders.each do |subfolder| %> - + <%= render(:partial => 'dir', :locals => { :project => @project, @@ -77,12 +78,13 @@ :position => 0 }) %> <% end %> + <% classes = 'dmsf_gray hascontextmenu' %> <% @dir_links.each do |link| %> <% unless link.target_project %> <% Rails.logger.error "Error: dmsf_link id #{link.id} has no target!" %> <% next %> <% end %> - + <%= render(:partial => 'dir', :locals => { :project => link.target_project, @@ -94,12 +96,13 @@ :position => 0}) %> <% end %> + <% classes = 'file hascontextmenu' %> <% @files.each do |file| %> <% unless file.last_revision %> <% Rails.logger.error "Error: dmsf_file id #{file.id} has no revision!" %> <% next %> <% end %> - + <%= render(:partial => 'file', :locals => { :project => @project, :file => file, @@ -110,24 +113,25 @@ :position => 1 }) %> <% end %> + <% classes = 'dmsf_gray hascontextmenu' %> <% @file_links.each do |link| %> <% unless link.target_file.last_revision %> <% Rails.logger.error "Error: dmsf_file id #{link.target_id} has no revision!" %> <% next %> - <% end %> - - <%= render(:partial => 'file', :locals => { - :project => link.target_project, - :file => link.target_file, - :link => link, - :id => link.id, - :name => 'file_links[]', - :title => link.name, - :position => 1}) %> - + <% end %> + + <%= render(:partial => 'file', :locals => { + :project => link.target_project, + :file => link.target_file, + :link => link, + :id => link.id, + :name => 'file_links[]', + :title => link.name, + :position => 1}) %> + <% end %> <% @url_links.each do |link| %> - + <%= render(:partial => 'url', :locals => { :project => link.target_project, :file => link.target_file, diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index 924a3cb5..8b17436b 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -84,7 +84,7 @@ <%= error_messages_for('dmsf_workflow') %> <%= form_tag(entries_operations_dmsf_path(:id => @project, :folder_id => @folder), :method => :post, - :class => 'dmsf_entries', :id => 'entries_form') do %> + :class => 'dmsf_entries', :id => 'entries_form', :data => {:cm_url => dmsf_context_menu_path}) do %> <%= hidden_field_tag('action') %>
<%= submit_tag(l(:button_download), :title => l(:title_download_checked), :name => 'download_entries') if @file_view_allowed %> @@ -119,6 +119,8 @@
<% end %> +<%= context_menu %> + <%= late_javascript_tag do %> $('#entries_delete_button').click(function () { if (window.confirm("<%= l(:text_are_you_sure) %>")) { diff --git a/app/views/dmsf/trash.html.erb b/app/views/dmsf/trash.html.erb index 0a8e987f..93f2c5f2 100644 --- a/app/views/dmsf/trash.html.erb +++ b/app/views/dmsf/trash.html.erb @@ -32,8 +32,8 @@ <%= error_messages_for('dmsf_workflow') %> -<%= form_tag({:action => :entries_operation, :id => @project, :folder_id => @folder}, :method => :post, - :class => 'dmsf_entries', :id => 'entries_form') do %> +<%= form_tag(entries_operations_dmsf_path(:id => @project, :folder_id => @folder), :method => :post, + :class => 'dmsf_entries', :id => 'entries_form', :data => {:cm_url => dmsf_context_menu_path}) do %> <%= hidden_field_tag('action') %>
<% if @file_manipulation_allowed && @folder_manipulation_allowed %> @@ -88,8 +88,9 @@ + <% classes = 'dir hascontextmenu' %> <% @subfolders.each do |subfolder| %> - + <%= render(:partial => 'dir_trash', :locals => { :project => @project, @@ -100,8 +101,9 @@ :title => subfolder.title }) %> <% end %> + <% classes = 'dmsf_gray hascontextmenu' %> <% @dir_links.each do |link| %> - + <%= render(:partial => 'dir_trash', :locals => { :project => link.target_project, @@ -112,12 +114,13 @@ :title => link.name }) %> <% end %> + <% classes = 'file hascontextmenu' %> <% @files.each do |file| %> <% unless file.last_revision %> <% Rails.logger.error "Error: dmsf_file id #{file.id} has no revision!" %> <% next %> <% end %> - + <%= render(:partial => 'file_trash', :locals => { :project => @project, :file => file, @@ -127,6 +130,7 @@ :title => file.title }) %> <% end %> + <% classes = 'dmsf_gray hascontextmenu' %> <% @file_links.each do |link| %> <% unless link.target_file %> <% Rails.logger.error "Error: dmsf_link id #{link.id} has no target file!" %> @@ -136,7 +140,7 @@ <% Rails.logger.error "Error: dmsf_file id #{link.target_id} has no revision!" %> <% next %> <% end %> - + <%= render(:partial => 'file_trash', :locals => { :project => link.target_project, :file => link.target_file, @@ -147,7 +151,7 @@ <% end %> <% @url_links.each do |link| %> - + <%= render(:partial => 'url_trash', :locals => { :project => link.target_project, :file => link.target_file, @@ -162,6 +166,8 @@
<% end %> +<%= context_menu %> + <%= late_javascript_tag do %> $('#entries_delete_button').click(function() { if(window.confirm("<%= l(:text_are_you_sure) %>")) { diff --git a/app/views/dmsf_context_menus/dmsf.html.erb b/app/views/dmsf_context_menus/dmsf.html.erb new file mode 100644 index 00000000..0826bf5e --- /dev/null +++ b/app/views/dmsf_context_menus/dmsf.html.erb @@ -0,0 +1,34 @@ +<% + # encoding: utf-8 + # + # Redmine plugin for Document Management System "Features" + # + # Copyright © 2011-18 Karel Pičman + # + # This program is free software; you can redistribute it and/or + # modify it under the terms of the GNU General Public License + # as published by the Free Software Foundation; either version 2 + # of the License, or (at your option) any later version. + # + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with this program; if not, write to the Free Software + # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +%> + +
    +
  • + <% if @file && @file.last_revision %> + <% url = "ms-word:ofe|u|#{Setting.protocol.strip}://#{Setting.host_name.strip}/#{Addressable::URI.escape(@file.project.identifier)}/" %> + <% if @file.dmsf_folder %> + <% url << @file.dmsf_folder.dmsf_path_str %> + <% end %> + <% url << @file.name %> + <% end %> + <%= context_menu_link l(:button_edit), url, :class => 'icon-edit', :disabled => url.blank? %> +
  • +
diff --git a/config/routes.rb b/config/routes.rb index 4b761339..2b354526 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,6 +53,9 @@ if Redmine::Plugin.installed? :redmine_dmsf post '/projects/:id/dmsf/append_email', :controller => 'dmsf', :action => 'append_email', :as => 'append_email_dmsf' get '/projects/:id/dmsf/autocomplete_for_user', :controller => 'dmsf', :action => 'autocomplete_for_user' + # dmsf_context_menu_controller + match '/projects/:id/dmsf/context_menu', :to => 'dmsf_context_menus#dmsf', :as => 'dmsf_context_menu', :via => [:get, :post] + # # dmsf_state controller # /projects//dmsf/state