diff --git a/app/controllers/dmsf_detail_controller.rb b/app/controllers/dmsf_detail_controller.rb index fc5da019..7da30302 100644 --- a/app/controllers/dmsf_detail_controller.rb +++ b/app/controllers/dmsf_detail_controller.rb @@ -80,8 +80,34 @@ class DmsfDetailController < ApplicationController render_403 end - #TODO: show lock/unlock history def file_detail + @revision = @file.last_revision.clone + @revision.comment = "" + end + + #TODO: separate control for approval + #TODO: don't create revision if nothing change + def save_file + if @file.locked_for_user? + flash[:error] = l(:error_file_is_locked) + redirect_to :action => "file_detail", :id => @project, :file_id => @file + else + new_revision = params[:dmsf_file_revision] + DmsfFileRevision.from_saved_file(@file, new_revision) + if @file.locked? + @file.unlock + flash[:notice] = l(:notice_file_unlocked) + ", " + end + @file.reload + flash[:notice] = (flash[:notice].nil? ? "" : flash[:notice]) + l(:notice_file_revision_created) + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} created new revision of file #{@project.identifier}://#{@file.dmsf_path_str}" + begin + DmsfMailer.deliver_files_updated(User.current, [@file]) + rescue ActionView::MissingTemplate => e + Rails.logger.error "Could not send email notifications: " + e + end + end + redirect_to :action => "file_detail", :id => @project, :file_id => @file end def delete_file @@ -181,30 +207,6 @@ class DmsfDetailController < ApplicationController redirect_to :controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder end - #TODO: separate control for approval - #TODO: don't create revision if nothing change - def save_file - if @file.locked_for_user? - flash[:error] = l(:error_file_is_locked) - else - saved_file = params[:file] - DmsfFileRevision.from_saved_file(@file, saved_file) - if @file.locked? - @file.unlock - flash[:notice] = l(:notice_file_unlocked) + ", " - end - @file.reload - flash[:notice] = (flash[:notice].nil? ? "" : flash[:notice]) + l(:notice_file_revision_created) - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} created new revision of file #{@project.identifier}://#{@file.dmsf_path_str}" - begin - DmsfMailer.deliver_files_updated(User.current, [@file]) - rescue ActionView::MissingTemplate => e - Rails.logger.error "Could not send email notifications: " + e - end - end - redirect_to :action => "file_detail", :id => @project, :file_id => @file - end - private def copy_folder(folder) diff --git a/app/views/dmsf_detail/_file_locked.html.erb b/app/views/dmsf_detail/_file_locked.html.erb deleted file mode 100644 index 2f58a463..00000000 --- a/app/views/dmsf_detail/_file_locked.html.erb +++ /dev/null @@ -1 +0,0 @@ -
<%= l(:info_file_locked) %>
\ No newline at end of file diff --git a/app/views/dmsf_detail/_file_new_revision.html.erb b/app/views/dmsf_detail/_file_new_revision.html.erb index 2bc3e816..6f324dfa 100644 --- a/app/views/dmsf_detail/_file_new_revision.html.erb +++ b/app/views/dmsf_detail/_file_new_revision.html.erb @@ -1,3 +1,9 @@ +<%= l(:info_file_locked) %>
+ <% else %> <% disabled_workflow = [] selected_workflow = nil @@ -12,57 +18,70 @@ else selected_workflow = @file.last_revision.workflow end -form_tag({:action => "save_file", :id => @project, :file_id => @file}, - :method=>:post, :multipart => true, :class => "tabular") do +form_for(:dmsf_file_revision, @revision, :url => {:action => "save_file", :id => @project, :file_id => @file}, + :html => {:method=>:post, :multipart => true}) do |f| %> -