#48 Caching documents in the issue form
This commit is contained in:
parent
c7d469b70f
commit
5940486c77
@ -21,8 +21,8 @@
|
||||
%>
|
||||
|
||||
<span id="dmsf_attachments_fields">
|
||||
<% if defined?(container) && container && container.saved_attachments %>
|
||||
<% container.saved_attachments.each_with_index do |attachment, i| %>
|
||||
<% if defined?(container) && container && container.saved_dmsf_attachments %>
|
||||
<% container.saved_dmsf_attachments.each_with_index do |attachment, i| %>
|
||||
<span id="dmsf_attachments_p<%= i %>">
|
||||
<%= text_field_tag("dmsf_attachments[p#{i}][filename]", attachment.filename, :class => 'filename') +
|
||||
text_field_tag("dmsf_attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description') +
|
||||
|
||||
@ -24,6 +24,10 @@ module RedmineDmsf
|
||||
|
||||
class ControllerIssuesHook < RedmineDmsf::Hooks::Listener
|
||||
|
||||
def controller_issues_new_before_save(context={})
|
||||
controller_issues_before_save(context)
|
||||
end
|
||||
|
||||
def controller_issues_new_after_save(context={})
|
||||
controller_issues_after_save(context)
|
||||
# Copy documents from the source issue
|
||||
@ -40,12 +44,24 @@ module RedmineDmsf
|
||||
end
|
||||
end
|
||||
|
||||
def controller_issues_edit_before_save(context={})
|
||||
controller_issues_before_save(context)
|
||||
end
|
||||
|
||||
def controller_issues_edit_after_save(context={})
|
||||
controller_issues_after_save(context)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def controller_issues_before_save(context)
|
||||
if context.is_a?(Hash)
|
||||
issue = context[:issue]
|
||||
params = context[:params]
|
||||
issue.save_dmsf_attachments(params[:dmsf_attachments])
|
||||
end
|
||||
end
|
||||
|
||||
def controller_issues_after_save(context)
|
||||
# Create attached documents
|
||||
if context.is_a?(Hash)
|
||||
|
||||
@ -34,7 +34,7 @@ module RedmineDmsf
|
||||
html << '<p>'
|
||||
html << "<label>#{l(:label_document_plural)}</label>"
|
||||
html << context[:controller].send(:render_to_string,
|
||||
{:partial => 'dmsf_upload/form', :locals => { :multiple => true }})
|
||||
{:partial => 'dmsf_upload/form', :locals => { :container => issue, :multiple => true }})
|
||||
html << '</p>'
|
||||
html << '</div>'
|
||||
html.html_safe
|
||||
|
||||
@ -32,6 +32,19 @@ module RedmineDmsf
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def save_dmsf_attachments(dmsf_attachments)
|
||||
@saved_dmsf_attachments = []
|
||||
dmsf_attachments = dmsf_attachments.map(&:last)
|
||||
dmsf_attachments.each do |dmsf_attachment|
|
||||
a = Attachment.find_by_token(dmsf_attachment[:token])
|
||||
@saved_dmsf_attachments << a if a
|
||||
end
|
||||
end
|
||||
|
||||
def saved_dmsf_attachments
|
||||
@saved_dmsf_attachments || []
|
||||
end
|
||||
|
||||
def system_folder(create = false)
|
||||
parent = DmsfFolder.system.where(:project_id => self.project_id, :title => '.Issues').first
|
||||
if create && !parent
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user