Merge pull request #61 from ux/master

Improved compatibility with XSendFile apache2 module and Redmine 2.x
This commit is contained in:
Daniel Munn 2012-11-13 06:20:33 -08:00
commit 1987a6a0b8
4 changed files with 117 additions and 110 deletions

View File

@ -43,7 +43,7 @@
</div>
<%= render "custom_fields", :object => @folder %>
</div>
<%= form_tag({:action => :entries_operation, :id => @project, :folder_id => @folder}, :method => :post,
<%= form_tag({:action => :entries_operation, :id => @project, :folder_id => @folder}, :method => :post,
:class => "dmfs_entries", :id => "entries_form") do %>
<%= hidden_field_tag("action") %>
<div class="controls" style="float: left">
@ -52,7 +52,7 @@
<% if User.current.allowed_to?(:file_manipulation, @project) && (!@folder.nil? && !@folder.locked_for_user?) %>
<button type="button" id="entries_delete_button" title="<%=l(:title_delete_checked)%>"><%=l(:button_delete)%></button>
<% end %>
</div>
</div>
<table class="display entries" id="browser">
<thead>
<tr id="root">
@ -101,7 +101,7 @@
:title => l(:title_notifications_active_deactivate)) %>
<% else %>
<%= link_to_function(image_tag("notifynot.png", :plugin => :redmine_dmsf),
"manipulation_link('#{url_for(:action => 'notify_activate', :id => @project, :folder_id => subfolder)}')",
"manipulation_link('#{url_for(:action => 'notify_activate', :id => @project, :folder_id => subfolder)}')",
:title => l(:title_notifications_not_active_activate)) %>
<% end %>
</div>
@ -109,7 +109,7 @@
<div class="right_icon_box" style="width: 70px;">
<% if User.current.allowed_to?(:folder_manipulation, @project) %>
<div style="float: left">
<%= link_to(image_tag("edit.png", :class =>"detail_icon"),
<%= link_to(image_tag("edit.png", :class =>"detail_icon"),
{:action => "edit", :id => @project, :folder_id => subfolder },
:title => l(:link_edit, :title => h(subfolder.title))) unless subfolder.locked_for_user? %>
</div>
@ -119,7 +119,7 @@
<% if subfolder.locked? %>
<% if subfolder.unlockable? %>
<%= link_to_function(image_tag("unlock.png", :plugin => :redmine_dmsf),
"manipulation_link('#{url_for(:controller => "dmsf", :action => 'unlock',
"manipulation_link('#{url_for(:controller => "dmsf", :action => 'unlock',
:id => @project, :folder_id => subfolder)}')",
:title => l(:title_unlock_file))%>
<% else %>
@ -127,14 +127,14 @@
<% end %>
<% else %>
<%= link_to_function(image_tag("lock.png", :plugin => :redmine_dmsf),
"manipulation_link('#{url_for(:controller => "dmsf", :action => 'lock',
"manipulation_link('#{url_for(:controller => "dmsf", :action => 'lock',
:id => @project, :folder_id => subfolder)}')",
:title => l(:title_lock_file)) %>
<% end %>
&nbsp;
<% end %>
<%= link_to_function(image_tag("delete.png", :plugin => :redmine_dmsf),
"confirmation_link('#{url_for(:action => 'delete', :id => @project, :folder_id => @folder, :delete_folder_id => subfolder)}')",
"confirmation_link('#{url_for(:action => 'delete', :id => @project, :folder_id => @folder, :delete_folder_id => subfolder)}')",
:title => l(:title_delete)) unless (subfolder.locked_for_user?)%>
</div>
</div>
@ -161,7 +161,7 @@
<td class="modified">
<%= format_time(file.last_revision.updated_at) %>
<% if file.locked_for_user? %>
<%= link_to(image_tag("locked.png", :plugin => :redmine_dmsf),
<%= link_to(image_tag("locked.png", :plugin => :redmine_dmsf),
{:controller => "users", :action => "show", :id => file.lock.reverse[0].user },
:title => l(:title_locked_by_user, :user => file.lock.reverse[0].user.to_s)) %>
<% elsif file.locked? %>
@ -194,7 +194,7 @@
<% end %>
<div class="right_icon_box" style="width: 70px;">
<div style="float: left">
<%= link_to(image_tag("filedetails.png", :plugin => :redmine_dmsf, :class =>"detail_icon"),
<%= link_to(image_tag("filedetails.png", :plugin => :redmine_dmsf, :class =>"detail_icon"),
{:controller => "dmsf_files", :action => :show, :id => file },
:title => l(:link_details, :title =>h(file.last_revision.title))) %>
</div>
@ -212,7 +212,7 @@
<%= link_to_function(image_tag("lock.png", :plugin => :redmine_dmsf),
"manipulation_link('#{url_for(:controller => "dmsf_files", :action => 'lock', :id => file)}')",
:title => l(:title_lock_file)) %>
<% end %>
<% end %>
&nbsp;
<% end %>
<% if User.current.allowed_to?(:file_manipulation, @project) && !file.locked_for_user? %>
@ -240,7 +240,7 @@
jQuery("#entries_form").submit();
}
})
jQuery("#check_all_entries").click(function(event) {
var $this = jQuery(this);
if($this.prop("checked")) {
@ -248,7 +248,7 @@
} else {
jQuery("input[type=checkbox]", jQuery("#browser > tbody")).prop("checked", false);
}
})
})
</script>
<%
@ -261,7 +261,7 @@ sUrl = "jquery.dataTables/#{I18n.locale.to_s.downcase}.json" if I18n.locale && !
<%= stylesheet_link_tag "plupload/jquery.ui.plupload.css", :plugin => "redmine_dmsf" %>
<%= stylesheet_link_tag "jquery.dataTables/jquery-ui.dataTables.css", :plugin => "redmine_dmsf" %>
<%= stylesheet_link_tag "dmsf", :plugin => "redmine_dmsf" %>
<%= javascript_include_tag "jquery-1.6.1.min.js", :plugin => "redmine_dmsf" %>
<%= javascript_include_tag "jquery-ui-1.8.13.min.js", :plugin => "redmine_dmsf" %>
<%= javascript_include_tag "jquery.dataTables/jquery.dataTables.min.js", :plugin => "redmine_dmsf" %>
@ -289,7 +289,7 @@ sUrl = "jquery.dataTables/#{I18n.locale.to_s.downcase}.json" if I18n.locale && !
return "<%= l(:label_number_of_folders)%>: <%= @subfolders.length %>, <%= l(:label_number_of_documents)%>: <%= @files.length %>";
}
});
jQuery("[data-downloadurl]").each(function() {
var url = this.getAttribute("data-downloadurl");
if (this.addEventListener) {
@ -300,13 +300,17 @@ sUrl = "jquery.dataTables/#{I18n.locale.to_s.downcase}.json" if I18n.locale && !
},false);
}
});
jQuery("#entries_form").submit(function () {
jQuery(this).removeAttr('data-submitted');
});
});
function manipulation_link(action) {
jQuery("#entries_form").attr("action", action);
jQuery("#entries_form").submit();
};
function confirmation_link(action) {
if(!window.confirm("<%= l(:question_do_you_really_want_to_delete_this_entry) %>")) return;
jQuery("#entries_form").attr("action", action);
@ -315,6 +319,6 @@ sUrl = "jquery.dataTables/#{I18n.locale.to_s.downcase}.json" if I18n.locale && !
</script>
<% end %>
<%= render(:partial => "multi_upload") if (User.current.allowed_to?(:file_manipulation, @project) &&
<%= render(:partial => "multi_upload") if (User.current.allowed_to?(:file_manipulation, @project) &&
( @folder.nil? || (!@folder.nil? &&!@folder.locked_for_user?) ) ) %>
<br />

View File

@ -7,7 +7,7 @@
<h2>
<%= render(:partial => "/dmsf/path", :locals => {:path => path}) %>
/
<%= link_to(h(@file.title), {:controller => "dmsf_files", :action => "show", :id=> @file}) %>
<%= link_to(h(@file.title), {:controller => "dmsf_files", :action => "show", :id=> @file}) %>
<%= image_tag("notify.png", :plugin => "redmine_dmsf", :title => l(:title_notifications_active)) if @file.notification %>
</h2>
@ -17,21 +17,17 @@
<p>
<label for="target_project_id"><%=l(:label_target_project)%>:</label>
<%= select_tag("target_project_id",
project_tree_options_for_select(DmsfFile.allowed_target_projects_on_copy, :selected => @target_project),
:onchange => remote_function(:url => { :action => 'new' },
:method => :get,
:update => 'content',
:with => "Form.serialize('copyForm')")) %>
project_tree_options_for_select(DmsfFile.allowed_target_projects_on_copy, :selected => @target_project)) %>
</p>
<p>
<%= label_tag("target_folder_id", l(:label_target_folder) + ":") %>
<%= select_tag("target_folder_id",
options_for_select(DmsfFolder.directory_tree(@target_project),
<%= select_tag("target_folder_id",
options_for_select(DmsfFolder.directory_tree(@target_project),
:selected => (@target_folder.id unless @target_folder.nil?))) %>
</p>
</div>
<%= submit_tag(l(:button_copy)) %>
<% if User.current.allowed_to?(:file_manipulation, @project) %>
<button type="button" id="move_button" title="<%=l(:button_move)%>"><%=l(:button_move)%></button>
@ -44,6 +40,10 @@
jQuery("#copyForm").attr("action", "<%= url_for(:action => 'move', :id => @file) %>");
jQuery("#copyForm").submit();
});
jQuery("#target_project_id").change(function () {
jQuery("#content").load("<%= url_for(:action => 'new') %>", jQuery("#copyForm").serialize());
});
</script>
<% content_for :header_tags do %>

View File

@ -11,24 +11,26 @@
<p>
<label for="target_project_id"><%=l(:label_target_project)%>:</label>
<%= select_tag("target_project_id",
project_tree_options_for_select(DmsfFolder.allowed_target_projects_on_copy, :selected => @target_project),
:onchange => remote_function(:url => { :action => 'new' },
:method => :get,
:update => 'content',
:with => "Form.serialize('copyForm')")) %>
project_tree_options_for_select(DmsfFolder.allowed_target_projects_on_copy, :selected => @target_project)) %>
</p>
<p>
<%= label_tag("target_folder_id", l(:label_target_folder) + ":") %>
<%= select_tag("target_folder_id",
options_for_select(DmsfFolder.directory_tree(@target_project, @folder),
<%= select_tag("target_folder_id",
options_for_select(DmsfFolder.directory_tree(@target_project, @folder),
:selected => (@target_folder.id unless @target_folder.nil?))) %>
</p>
</div>
<%= submit_tag(l(:button_copy)) %>
<% end %>
<% end %>
<script type="text/javascript">
jQuery("#target_project_id").change(function () {
jQuery("#content").load("<%= url_for(:action => 'new') %>", jQuery("#copyForm").serialize());
});
</script>
<% content_for :header_tags do %>
<%= stylesheet_link_tag "dmsf", :plugin => "redmine_dmsf" %>
<%= javascript_include_tag "jquery-1.6.1.min.js", :plugin => "redmine_dmsf" %>

View File

@ -1,75 +1,76 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
#
# 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.
require 'zip/zip'
require 'zip/zipfilesystem'
require 'iconv'
class DmsfZip
attr_reader :files
def initialize()
@zip = Tempfile.new(["dmsf_zip",".zip"])
@zip_file = Zip::ZipOutputStream.new(@zip.path)
@files = []
end
def finish
@zip_file.close unless @zip_file.nil?
@zip.path unless @zip.nil?
end
def close
@zip_file.close unless @zip_file.nil?
@zip.close unless @zip.nil?
end
def add_file(file, root_path = nil)
string_path = file.folder.nil? ? "" : file.folder.dmsf_path_str + "/"
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
string_path += file.name
#TODO: somewhat ugly conversion problems handling bellow
begin
string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path)
rescue
end
@zip_file.put_next_entry(string_path)
File.open(file.last_revision.disk_file, "rb") do |f|
buffer = ""
while (buffer = f.read(8192))
@zip_file.write(buffer)
end
end
@files << file
end
def add_folder(folder, root_path = nil)
string_path = folder.dmsf_path_str + "/"
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
#TODO: somewhat ugly conversion problems handling bellow
begin
string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path)
rescue
end
@zip_file.put_next_entry(string_path)
folder.subfolders.visible.each { |subfolder| self.add_folder(subfolder, root_path) }
folder.files.visible.each { |file| self.add_file(file, root_path) }
end
end
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
#
# 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.
require 'zip/zip'
require 'zip/zipfilesystem'
require 'iconv'
class DmsfZip
attr_reader :files
def initialize()
@zip = Tempfile.new(["dmsf_zip",".zip"])
@zip.chmod(0644)
@zip_file = Zip::ZipOutputStream.new(@zip.path)
@files = []
end
def finish
@zip_file.close unless @zip_file.nil?
@zip.path unless @zip.nil?
end
def close
@zip_file.close unless @zip_file.nil?
@zip.close unless @zip.nil?
end
def add_file(file, root_path = nil)
string_path = file.folder.nil? ? "" : file.folder.dmsf_path_str + "/"
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
string_path += file.name
#TODO: somewhat ugly conversion problems handling bellow
begin
string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path)
rescue
end
@zip_file.put_next_entry(string_path)
File.open(file.last_revision.disk_file, "rb") do |f|
buffer = ""
while (buffer = f.read(8192))
@zip_file.write(buffer)
end
end
@files << file
end
def add_folder(folder, root_path = nil)
string_path = folder.dmsf_path_str + "/"
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
#TODO: somewhat ugly conversion problems handling bellow
begin
string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path)
rescue
end
@zip_file.put_next_entry(string_path)
folder.subfolders.visible.each { |subfolder| self.add_folder(subfolder, root_path) }
folder.files.visible.each { |file| self.add_file(file, root_path) }
end
end