* reworked folder manipulation
git-svn-id: http://redmine-dmsf.googlecode.com/svn/trunk/redmine_dmsf@38 5e329b0b-a2ee-ea63-e329-299493fc886d
This commit is contained in:
parent
4cd99ee598
commit
9e8a26bd9d
@ -21,22 +21,47 @@ class DmsfDetailController < ApplicationController
|
||||
|
||||
before_filter :find_project
|
||||
before_filter :authorize
|
||||
before_filter :find_folder, :only => [:create_folder, :delete_folder, :save_folder,
|
||||
before_filter :find_parent, :only => [:folder_new, :create_folder, :save_folder, :folder_detail]
|
||||
before_filter :find_folder, :only => [:delete_folder, :save_folder,
|
||||
:upload_files, :commit_files, :folder_detail]
|
||||
before_filter :find_file, :only => [:save_file, :delete_file, :file_detail]
|
||||
|
||||
def create_folder
|
||||
@new_folder = DmsfFolder.create_from_params(@project, @folder, params[:dmsf_folder])
|
||||
if @new_folder.valid?
|
||||
flash[:notice] = l(:notice_folder_created)
|
||||
Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} created folder #{@project.identifier}://#{@new_folder.dmsf_path_str}"
|
||||
else
|
||||
flash[:error] = l(:error_folder_creation_failed) + ": " + l(:error_folder_title_must_be_entered)
|
||||
end
|
||||
|
||||
redirect_to({:controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder})
|
||||
def folder_new
|
||||
@pathfolder = @parent
|
||||
render :action => "folder_detail"
|
||||
end
|
||||
|
||||
|
||||
def create_folder
|
||||
@folder = DmsfFolder.new(params[:dmsf_folder])
|
||||
@folder.project = @project
|
||||
@folder.folder = @parent
|
||||
@folder.user = User.current
|
||||
if @folder.save
|
||||
flash[:notice] = l(:notice_folder_created)
|
||||
Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} created folder #{@project.identifier}://#{@folder.dmsf_path_str}"
|
||||
redirect_to({:controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder})
|
||||
else
|
||||
@pathfolder = @parent
|
||||
render :action => "folder_detail"
|
||||
end
|
||||
end
|
||||
|
||||
def folder_detail
|
||||
@pathfolder = copy_folder(@folder)
|
||||
end
|
||||
|
||||
def save_folder
|
||||
@pathfolder = copy_folder(@folder)
|
||||
@folder.attributes = params[:dmsf_folder]
|
||||
if @folder.save
|
||||
Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} updated folder #{@project.identifier}://#{@folder.dmsf_path_str}"
|
||||
flash[:notice] = l(:notice_folder_details_were_saved)
|
||||
redirect_to :controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder
|
||||
else
|
||||
render :action => "folder_detail"
|
||||
end
|
||||
end
|
||||
|
||||
def delete_folder
|
||||
check_project(@delete_folder = DmsfFolder.find(params[:delete_folder_id]))
|
||||
if !@delete_folder.nil?
|
||||
@ -54,32 +79,6 @@ class DmsfDetailController < ApplicationController
|
||||
render_403
|
||||
end
|
||||
|
||||
def folder_detail
|
||||
end
|
||||
|
||||
def save_folder
|
||||
@folder.description = params[:description]
|
||||
|
||||
if params[:title].blank?
|
||||
flash.now[:error] = l(:error_folder_title_must_be_entered)
|
||||
render "folder_detail"
|
||||
return
|
||||
end
|
||||
|
||||
@folder.name = params[:title]
|
||||
|
||||
if !@folder.valid?
|
||||
flash.now[:error] = l(:error_folder_title_is_already_used)
|
||||
render "folder_detail"
|
||||
return
|
||||
end
|
||||
|
||||
@folder.save!
|
||||
Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} updated folder #{@project.identifier}://#{@folder.dmsf_path_str}"
|
||||
flash[:notice] = l(:notice_folder_details_were_saved)
|
||||
redirect_to :controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder
|
||||
end
|
||||
|
||||
#TODO: show lock/unlock history
|
||||
def file_detail
|
||||
end
|
||||
@ -207,6 +206,12 @@ class DmsfDetailController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def copy_folder(folder)
|
||||
copy = folder.clone
|
||||
copy.id = folder.id
|
||||
copy
|
||||
end
|
||||
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
end
|
||||
@ -218,6 +223,13 @@ class DmsfDetailController < ApplicationController
|
||||
render_403
|
||||
end
|
||||
|
||||
def find_parent
|
||||
@parent = DmsfFolder.find(params[:parent_id]) if params.keys.include?("parent_id")
|
||||
check_project(@parent)
|
||||
rescue DmsfAccessError
|
||||
render_403
|
||||
end
|
||||
|
||||
def find_file
|
||||
check_project(@file = DmsfFile.find(params[:file_id]))
|
||||
rescue DmsfAccessError
|
||||
|
||||
@ -33,16 +33,7 @@ class DmsfFolder < ActiveRecord::Base
|
||||
["dmsf_folder_id is NULL and project_id = :project_id", {:project_id => project.id}], :order => "name ASC")
|
||||
end
|
||||
|
||||
def self.create_from_params(project, parent_folder, params)
|
||||
new_folder = DmsfFolder.new(params)
|
||||
new_folder.project = project
|
||||
new_folder.folder = parent_folder
|
||||
new_folder.user = User.current
|
||||
new_folder.save
|
||||
new_folder
|
||||
end
|
||||
|
||||
def dmsf_path
|
||||
def dmsf_path
|
||||
folder = self
|
||||
path = []
|
||||
while !folder.nil?
|
||||
|
||||
@ -3,13 +3,13 @@
|
||||
<div class="contextual">
|
||||
<% if User.current.allowed_to?(:folder_manipulation, @project) %>
|
||||
<% unless @folder.nil? %>
|
||||
<%= link_to(image_tag("filedetails.png", :plugin => "redmine_dmsf", :style => "vertical-align: text-top;"),
|
||||
<%= link_to(image_tag("edit.png", :style => "vertical-align: text-top;"),
|
||||
{:controller => "dmsf_detail", :action => "folder_detail", :id => @project, :folder_id => @folder },
|
||||
:title => l(:link_details, :title => h(@folder.name))) %> |
|
||||
<% end %>
|
||||
<% form_for(DmsfFolder.new, :url => {:controller => "dmsf_detail", :action => "create_folder", :id => @project, :folder_id => @folder}, :html => {:method=>:post}) do |f| %>
|
||||
Title: <%= f.text_field(:name) %><%= f.submit(l(:submit_create_folder)) %>
|
||||
:title => l(:link_edit, :title => h(@folder.name))) %>
|
||||
<% end %>
|
||||
<%= link_to(image_tag("add.png", :style => "vertical-align: text-top;"),
|
||||
{:controller => "dmsf_detail", :action => "folder_new", :id => @project, :parent_id => @folder },
|
||||
:title => l(:link_create_folder)) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@ -71,9 +71,9 @@ form_tag({:action => "entries_operation", :id => @project, :folder_id => @folder
|
||||
<div class="right_icon_box" style="width: 70px;">
|
||||
<% if User.current.allowed_to?(:folder_manipulation, @project) %>
|
||||
<div style="float: left">
|
||||
<%= link_to(image_tag("filedetails.png", :plugin => "redmine_dmsf", :class =>"detail_icon"),
|
||||
<%= link_to(image_tag("edit.png", :class =>"detail_icon"),
|
||||
{:controller => "dmsf_detail", :action => "folder_detail", :id => @project, :folder_id => subfolder },
|
||||
:title => l(:link_details, :title => h(subfolder.name))) %>
|
||||
:title => l(:link_edit, :title => h(subfolder.name))) %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div style="float: right">
|
||||
|
||||
@ -2,27 +2,29 @@
|
||||
|
||||
<div class="contextual">
|
||||
</div>
|
||||
|
||||
<% create = @pathfolder == @parent %>
|
||||
<h2>
|
||||
<%= render(:partial => "/dmsf/path", :locals => {:path => @folder.dmsf_path}) %>
|
||||
<%= render(:partial => "/dmsf/path", :locals => {:path => @pathfolder.dmsf_path}) %>
|
||||
<%= "/ New Folder" if create %>
|
||||
</h2>
|
||||
|
||||
<% form_tag({:action => "save_folder", :id => @project, :folder_id => @folder},
|
||||
:method=>:post, :multipart => true, :class => "tabular") do %>
|
||||
<% form_for(:dmsf_folder, @folder, :url => {:action => create ? "create_folder" : "save_folder", :id => @project, :folder_id => @folder, :parent_id => @parent},
|
||||
:html => {:method=>:post, :class => "tabular"}) do |f| %>
|
||||
<%= error_messages_for("folder") %>
|
||||
<div class="box">
|
||||
<p>
|
||||
<%= label_tag("title", "Title:") %>
|
||||
<%= text_field_tag("title", @folder.name, :size => "32") %>
|
||||
<%= label_tag("dmsf_folder_name", "Title:") %>
|
||||
<%= f.text_field(:name, :size => "32") %>
|
||||
</p>
|
||||
<p>
|
||||
<%= label_tag("description", "Description:") %>
|
||||
<%= text_area_tag("description", @folder.description, :rows => 15, :class => "wiki-edit") %>
|
||||
<%= label_tag("dmsf_folder_description", "Description:") %>
|
||||
<%= f.text_area(:description, :rows => 15, :class => "wiki-edit") %>
|
||||
</p>
|
||||
</div>
|
||||
<%= submit_tag("Save") %>
|
||||
<%= submit_tag(create ? "Create" : "Save") %>
|
||||
<% end %>
|
||||
|
||||
<%= wikitoolbar_for "description" %>
|
||||
<%= wikitoolbar_for "dmsf_folder_description" %>
|
||||
|
||||
<% content_for :header_tags do %>
|
||||
<%= stylesheet_link_tag "dmsf", :plugin => "redmine_dmsf" %>
|
||||
|
||||
@ -37,7 +37,9 @@ cs:
|
||||
:warning_file_notifications_already_deactivated: "File notifications already deactivated"
|
||||
:notice_file_notifications_deactivated: "File notifications deactivated"
|
||||
:link_details: "%{title} details"
|
||||
:submit_create_folder: "Create folder"
|
||||
:link_edit: "Edit %{title}"
|
||||
:submit_create: "Create"
|
||||
:link_create_folder: "Create folder"
|
||||
:title_check_uncheck_all_for_zip_download_or_email: "Check/Uncheck all for zip download or email"
|
||||
:link_title: "Title"
|
||||
:link_size: "Size"
|
||||
@ -68,7 +70,6 @@ cs:
|
||||
:label_email_documents: "Documents"
|
||||
:label_email_body: "Body"
|
||||
:label_email_send: "Send"
|
||||
|
||||
:title_notifications_active: "Notifications active"
|
||||
:label_file_size: "File size"
|
||||
:heading_file_upload: "Upload"
|
||||
|
||||
@ -37,7 +37,9 @@ de:
|
||||
:warning_file_notifications_already_deactivated: "File notifications already deactivated"
|
||||
:notice_file_notifications_deactivated: "File notifications deactivated"
|
||||
:link_details: "%{title} details"
|
||||
:submit_create_folder: "Create folder"
|
||||
:link_edit: "Edit %{title}"
|
||||
:submit_create: "Create"
|
||||
:link_create_folder: "Create folder"
|
||||
:title_check_uncheck_all_for_zip_download_or_email: "Check/Uncheck all for zip download or email"
|
||||
:link_title: "Title"
|
||||
:link_size: "Size"
|
||||
|
||||
@ -37,7 +37,9 @@ en-GB:
|
||||
:warning_file_notifications_already_deactivated: "File notifications already deactivated"
|
||||
:notice_file_notifications_deactivated: "File notifications deactivated"
|
||||
:link_details: "%{title} details"
|
||||
:submit_create_folder: "Create folder"
|
||||
:link_edit: "Edit %{title}"
|
||||
:submit_create: "Create"
|
||||
:link_create_folder: "Create folder"
|
||||
:title_check_uncheck_all_for_zip_download_or_email: "Check/Uncheck all for zip download or email"
|
||||
:link_title: "Title"
|
||||
:link_size: "Size"
|
||||
|
||||
@ -37,7 +37,9 @@ en:
|
||||
:warning_file_notifications_already_deactivated: "File notifications already deactivated"
|
||||
:notice_file_notifications_deactivated: "File notifications deactivated"
|
||||
:link_details: "%{title} details"
|
||||
:submit_create_folder: "Create folder"
|
||||
:link_edit: "Edit %{title}"
|
||||
:submit_create: "Create"
|
||||
:link_create_folder: "Create folder"
|
||||
:title_check_uncheck_all_for_zip_download_or_email: "Check/Uncheck all for zip download or email"
|
||||
:link_title: "Title"
|
||||
:link_size: "Size"
|
||||
|
||||
@ -37,7 +37,9 @@ es:
|
||||
:warning_file_notifications_already_deactivated: "File notifications already deactivated"
|
||||
:notice_file_notifications_deactivated: "File notifications deactivated"
|
||||
:link_details: "%{title} details"
|
||||
:submit_create_folder: "Create folder"
|
||||
:link_edit: "Edit %{title}"
|
||||
:submit_create: "Create"
|
||||
:link_create_folder: "Create folder"
|
||||
:title_check_uncheck_all_for_zip_download_or_email: "Check/Uncheck all for zip download or email"
|
||||
:link_title: "Title"
|
||||
:link_size: "Size"
|
||||
|
||||
@ -37,7 +37,9 @@ fr:
|
||||
:warning_file_notifications_already_deactivated: "File notifications already deactivated"
|
||||
:notice_file_notifications_deactivated: "File notifications deactivated"
|
||||
:link_details: "%{title} details"
|
||||
:submit_create_folder: "Create folder"
|
||||
:link_edit: "Edit %{title}"
|
||||
:submit_create: "Create"
|
||||
:link_create_folder: "Create folder"
|
||||
:title_check_uncheck_all_for_zip_download_or_email: "Check/Uncheck all for zip download or email"
|
||||
:link_title: "Title"
|
||||
:link_size: "Size"
|
||||
|
||||
@ -37,7 +37,9 @@ ru:
|
||||
:warning_file_notifications_already_deactivated: "File notifications already deactivated"
|
||||
:notice_file_notifications_deactivated: "File notifications deactivated"
|
||||
:link_details: "%{title} details"
|
||||
:submit_create_folder: "Create folder"
|
||||
:link_edit: "Edit %{title}"
|
||||
:submit_create: "Create"
|
||||
:link_create_folder: "Create folder"
|
||||
:title_check_uncheck_all_for_zip_download_or_email: "Check/Uncheck all for zip download or email"
|
||||
:link_title: "Title"
|
||||
:link_size: "Size"
|
||||
|
||||
2
init.rb
2
init.rb
@ -48,7 +48,7 @@ Redmine::Plugin.register :redmine_dmsf do
|
||||
permission :user_preferences, {:dmsf_state => [:user_pref, :user_pref_save]}
|
||||
permission :view_dmsf_files, {:dmsf => [:download_file, :download_revision, :entries_operation, :email_entries_send],
|
||||
:dmsf_detail => [:file_detail]}
|
||||
permission :folder_manipulation, {:dmsf_detail => [:create_folder, :delete_folder, :folder_detail, :save_folder]}
|
||||
permission :folder_manipulation, {:dmsf_detail => [:folder_new, :create_folder, :delete_folder, :folder_detail, :save_folder]}
|
||||
permission :file_manipulation, {:dmsf_detail => [:upload_files, :upload_file, :commit_files, :save_file, :delete_file],
|
||||
:dmsf_state => [:lock_file, :unlock_file]}
|
||||
permission :file_approval, {:dmsf_detail => [:approve_file, :delete_revision],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user