Commit 9daf39ec authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Adds an optional description to attachments.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1180 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 4b15dc10
...@@ -160,16 +160,20 @@ class ApplicationController < ActionController::Base ...@@ -160,16 +160,20 @@ class ApplicationController < ActionController::Base
end end
# TODO: move to model # TODO: move to model
def attach_files(obj, files) def attach_files(obj, attachments)
attachments = [] attached = []
if files && files.is_a?(Array) if attachments && attachments.is_a?(Hash)
files.each do |file| attachments.each_value do |attachment|
next unless file.size > 0 file = attachment['file']
a = Attachment.create(:container => obj, :file => file, :author => User.current) next unless file && file.size > 0
attachments << a unless a.new_record? a = Attachment.create(:container => obj,
:file => file,
:description => attachment['description'].to_s.strip,
:author => User.current)
attached << a unless a.new_record?
end end
end end
attachments attached
end end
# Returns the number of objects that should be displayed # Returns the number of objects that should be displayed
......
...@@ -21,6 +21,8 @@ class DocumentsController < ApplicationController ...@@ -21,6 +21,8 @@ class DocumentsController < ApplicationController
before_filter :find_document, :except => [:index, :new] before_filter :find_document, :except => [:index, :new]
before_filter :authorize before_filter :authorize
helper :attachments
def index def index
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
documents = @project.documents.find :all, :include => [:attachments, :category] documents = @project.documents.find :all, :include => [:attachments, :category]
......
...@@ -396,7 +396,7 @@ module ApplicationHelper ...@@ -396,7 +396,7 @@ module ApplicationHelper
def labelled_tabular_form_for(name, object, options, &proc) def labelled_tabular_form_for(name, object, options, &proc)
options[:html] ||= {} options[:html] ||= {}
options[:html].store :class, "tabular" options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc) form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
end end
......
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%> <span id="attachments_fields">
<%= image_to_function "add.png", "addFileField();return false" %></label> <%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil -%>
<%= text_field_tag 'attachments[1][description]', '', :size => 60, :id => nil %>
<%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p> <em><%= l(:label_optional_description) %></em>
</span>
<br />
<small><%= link_to l(:label_add_another_file), {}, :onclick => 'addFileField(); return false;' %>
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
</small>
<div class="attachments"> <div class="attachments">
<% for attachment in attachments %> <% for attachment in attachments %>
<p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' %> <p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' -%>
(<%= number_to_human_size attachment.filesize %>) <%= h(" - #{attachment.description}") unless attachment.description.blank? %>
<% unless options[:no_author] %> <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
<span class="author"><%= attachment.author.name %>, <%= format_date(attachment.created_on) %></span>
<% end %>
<% if options[:delete_url] %> <% if options[:delete_url] %>
<%= link_to image_tag('delete.png'), options[:delete_url].update({:attachment_id => attachment}), :confirm => l(:text_are_you_sure), :method => :post %> <%= link_to image_tag('delete.png'), options[:delete_url].update({:attachment_id => attachment}),
:confirm => l(:text_are_you_sure),
:method => :post,
:class => 'delete',
:title => l(:button_delete) %>
<% end %>
<% unless options[:no_author] %>
<span class="author"><%= attachment.author %>, <%= format_time(attachment.created_on) %></span>
<% end %> <% end %>
</p> </p>
<% end %> <% end %>
......
<p id="attachments_p">
<label for="attachment_file"><%=l(:label_attachment)%>
<%= image_to_function "add.png", "addFileField();return false" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %>
<em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em>
</p>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %> <% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %>
<%= render :partial => 'documents/form' %> <%= render :partial => 'documents/form' %>
<div class="box"> <div class="box">
<%= render :partial => 'common/attachments_form'%> <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
</div> </div>
<%= submit_tag l(:button_create) %> <%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %> <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<%= render :partial => 'documents/form' %> <%= render :partial => 'documents/form' %>
<div class="box"> <div class="box">
<%= render :partial => 'common/attachments_form'%> <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
</div> </div>
<%= submit_tag l(:button_create) %> <%= submit_tag l(:button_create) %>
......
...@@ -10,29 +10,17 @@ ...@@ -10,29 +10,17 @@
<div class="wiki"> <div class="wiki">
<%= textilizable @document.description, :attachments => @document.attachments %> <%= textilizable @document.description, :attachments => @document.attachments %>
</div> </div>
<br />
<h3><%= l(:label_attachment_plural) %></h3> <h3><%= l(:label_attachment_plural) %></h3>
<ul class="documents"> <%= link_to_attachments @attachments, :delete_url => (authorize_for('documents', 'destroy_attachment') ? {:controller => 'documents', :action => 'destroy_attachment', :id => @document} : nil) %>
<% for attachment in @attachments %>
<li>
<div class="contextual">
<%= link_to_if_authorized l(:button_delete), {:controller => 'documents', :action => 'destroy_attachment', :id => @document, :attachment_id => attachment}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
</div>
<%= link_to attachment.filename, :action => 'download', :id => @document, :attachment_id => attachment %>
(<%= number_to_human_size attachment.filesize %>)<br />
<span class="author"><%= authoring attachment.created_on, attachment.author %></span><br />
<%= lwr(:label_download, attachment.downloads) %>
</li>
<% end %>
</ul>
<br />
<% if authorize_for('documents', 'add_attachment') %> <% if authorize_for('documents', 'add_attachment') %>
<p><%= toggle_link l(:label_attachment_new), "add_attachment_form" %></p> <p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;",
<% form_tag({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular", :id => "add_attachment_form", :style => "display:none;") do %> :id => 'attach_files_link' %></p>
<%= render :partial => 'attachments/form' %> <% form_tag({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %>
<div class="box">
<p><%= render :partial => 'attachments/form' %></p>
</div>
<%= submit_tag l(:button_add) %> <%= submit_tag l(:button_add) %>
<% end %> <% end %>
<% end %> <% end %>
......
<% labelled_tabular_form_for :issue, @issue, <% labelled_tabular_form_for :issue, @issue,
:url => {:action => 'edit', :id => @issue}, :url => {:action => 'edit', :id => @issue},
:html => {:id => 'issue-form', :html => {:id => 'issue-form',
:class => nil,
:multipart => true} do |f| %> :multipart => true} do |f| %>
<%= error_messages_for 'issue' %> <%= error_messages_for 'issue' %>
<div class="box"> <div class="box">
<% if @edit_allowed || !@allowed_statuses.empty? %> <% if @edit_allowed || !@allowed_statuses.empty? %>
<fieldset> <fieldset class="tabular"><legend><%= l(:label_change_properties) %>
<legend><%= l(:label_change_properties) %>
<% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %> <% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %>
<small>(<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>)</small> <small>(<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>)</small>
<% end %> <% end %>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</fieldset> </fieldset>
<% end %> <% end %>
<% if authorize_for('timelog', 'edit') %> <% if authorize_for('timelog', 'edit') %>
<fieldset><legend><%= l(:button_log_time) %></legend> <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend>
<% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %> <% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %>
<div class="splitcontentleft"> <div class="splitcontentleft">
<p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p> <p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p>
...@@ -32,9 +32,7 @@ ...@@ -32,9 +32,7 @@
<%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
<%= wikitoolbar_for 'notes' %> <%= wikitoolbar_for 'notes' %>
<p id="attachments_p"><label><%=l(:label_attachment_new)%> <p><%=l(:label_attachment_plural)%><br /><%= render :partial => 'attachments/form' %></p>
<%= image_to_function 'add.png', 'addFileField();return false;' %></label>
<%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p>
</fieldset> </fieldset>
</div> </div>
......
...@@ -44,9 +44,7 @@ ...@@ -44,9 +44,7 @@
<%= render :partial => 'form_custom_fields', :locals => {:values => @custom_values} %> <%= render :partial => 'form_custom_fields', :locals => {:values => @custom_values} %>
<% if @issue.new_record? %> <% if @issue.new_record? %>
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%> <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
<%= image_to_function "add.png", "addFileField();return false" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p>
<% end %> <% end %>
<%= wikitoolbar_for 'issue_description' %> <%= wikitoolbar_for 'issue_description' %>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="box"> <div class="box">
<!--[form:message]--> <!--[form:message]-->
<p><label><%= l(:field_subject) %></label><br /> <p><label><%= l(:field_subject) %></label><br />
<%= f.text_field :subject, :required => true, :size => 120 %> <%= f.text_field :subject, :size => 120 %>
<% if !replying && User.current.allowed_to?(:edit_messages, @project) %> <% if !replying && User.current.allowed_to?(:edit_messages, @project) %>
<label><%= f.check_box :sticky %> Sticky</label> <label><%= f.check_box :sticky %> Sticky</label>
...@@ -12,11 +12,10 @@ ...@@ -12,11 +12,10 @@
<% end %> <% end %>
</p> </p>
<p><%= f.text_area :content, :required => true, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content' %></p> <p><%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content' %></p>
<%= wikitoolbar_for 'message_content' %> <%= wikitoolbar_for 'message_content' %>
<!--[eoform:message]--> <!--[eoform:message]-->
<span class="tabular"> <p><%= l(:label_attachment_plural) %><br />
<%= render :partial => 'attachments/form' %> <%= render :partial => 'attachments/form' %></p>
</span>
</div> </div>
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label> <p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label>
<%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p> <%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p>
<%= render :partial => 'attachments/form' %> <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
</div> </div>
<%= submit_tag l(:button_add) %> <%= submit_tag l(:button_add) %>
<% end %> <% end %>
\ No newline at end of file
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
<% for file in version.attachments %> <% for file in version.attachments %>
<tr class="<%= cycle("odd", "even") %>"> <tr class="<%= cycle("odd", "even") %>">
<td></td> <td></td>
<td><%= link_to file.filename, :controller => 'versions', :action => 'download', :id => version, :attachment_id => file %></td> <td><%= link_to(file.filename, {:controller => 'versions', :action => 'download', :id => version, :attachment_id => file},
:title => file.description) %></td>
<td align="center"><%= format_date(file.created_on) %></td> <td align="center"><%= format_date(file.created_on) %></td>
<td align="center"><%= number_to_human_size(file.filesize) %></td> <td align="center"><%= number_to_human_size(file.filesize) %></td>
<td align="center"><%= file.downloads %></td> <td align="center"><%= file.downloads %></td>
......
...@@ -25,10 +25,14 @@ ...@@ -25,10 +25,14 @@
<%= link_to_attachments @page.attachments, :delete_url => (authorize_for('wiki', 'destroy_attachment') ? {:controller => 'wiki', :action => 'destroy_attachment', :page => @page.title} : nil) %> <%= link_to_attachments @page.attachments, :delete_url => (authorize_for('wiki', 'destroy_attachment') ? {:controller => 'wiki', :action => 'destroy_attachment', :page => @page.title} : nil) %>
<% if authorize_for('wiki', 'add_attachment') %> <% if authorize_for('wiki', 'add_attachment') %>
<p><%= toggle_link l(:label_attachment_new), "add_attachment_form" %></p> <p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;",
<% form_tag({ :controller => 'wiki', :action => 'add_attachment', :page => @page.title }, :multipart => true, :class => "tabular", :id => "add_attachment_form", :style => "display:none;") do %> :id => 'attach_files_link' %></p>
<%= render :partial => 'attachments/form' %> <% form_tag({ :controller => 'wiki', :action => 'add_attachment', :page => @page.title }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %>
<div class="box">
<p><%= render :partial => 'attachments/form' %></p>
</div>
<%= submit_tag l(:button_add) %> <%= submit_tag l(:button_add) %>
<%= link_to l(:button_cancel), {}, :onclick => "Element.hide('add_attachment_form'); Element.show('attach_files_link'); return false;" %>
<% end %> <% end %>
<% end %> <% end %>
......
class AddAttachmentsDescription < ActiveRecord::Migration
def self.up
add_column :attachments, :description, :string
end
def self.down
remove_column :attachments, :description
end
end
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -497,6 +497,8 @@ label_scm: SCM ...@@ -497,6 +497,8 @@ label_scm: SCM
label_plugins: Plugins label_plugins: Plugins
label_ldap_authentication: LDAP authentication label_ldap_authentication: LDAP authentication
label_downloads_abbr: D/L label_downloads_abbr: D/L
label_optional_description: Optional description
label_add_another_file: Add another file
button_login: Login button_login: Login
button_submit: Submit button_submit: Submit
......
...@@ -603,3 +603,5 @@ label_date_range: Date range ...@@ -603,3 +603,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -604,3 +604,5 @@ label_date_range: Date range ...@@ -604,3 +604,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -497,6 +497,8 @@ label_scm: SCM ...@@ -497,6 +497,8 @@ label_scm: SCM
label_plugins: Plugins label_plugins: Plugins
label_ldap_authentication: Authentification LDAP label_ldap_authentication: Authentification LDAP
label_downloads_abbr: D/L label_downloads_abbr: D/L
label_optional_description: Description facultative
label_add_another_file: Ajouter un autre fichier
button_login: Connexion button_login: Connexion
button_submit: Soumettre button_submit: Soumettre
......
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -601,3 +601,5 @@ label_date_range: Date range ...@@ -601,3 +601,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -601,3 +601,5 @@ label_date_range: Date range ...@@ -601,3 +601,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -601,3 +601,5 @@ label_date_range: Date range ...@@ -601,3 +601,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -604,3 +604,5 @@ label_date_range: Date range ...@@ -604,3 +604,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -601,3 +601,5 @@ label_date_range: Date range ...@@ -601,3 +601,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -601,3 +601,5 @@ label_date_range: Date range ...@@ -601,3 +601,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -602,3 +602,5 @@ label_date_range: Date range ...@@ -602,3 +602,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -600,3 +600,5 @@ label_date_range: Date range ...@@ -600,3 +600,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -603,3 +603,5 @@ label_date_range: Date range ...@@ -603,3 +603,5 @@ label_date_range: Date range
label_last_week: last week label_last_week: last week
label_yesterday: yesterday label_yesterday: yesterday
label_last_month: last month label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
...@@ -10,15 +10,24 @@ function checkAll (id, checked) { ...@@ -10,15 +10,24 @@ function checkAll (id, checked) {
} }
} }
var fileFieldCount = 1;
function addFileField() { function addFileField() {
if (fileFieldCount >= 10) return false
fileFieldCount++;
var f = document.createElement("input"); var f = document.createElement("input");
f.type = "file"; f.type = "file";
f.name = "attachments[]"; f.name = "attachments[" + fileFieldCount + "][file]";
f.size = 30; f.size = 30;
var d = document.createElement("input");
p = document.getElementById("attachments_p"); d.type = "text";
d.name = "attachments[" + fileFieldCount + "][description]";
d.size = 60;
p = document.getElementById("attachments_fields");
p.appendChild(document.createElement("br")); p.appendChild(document.createElement("br"));
p.appendChild(f); p.appendChild(f);
p.appendChild(d);
} }
function showTab(name) { function showTab(name) {
......
...@@ -222,7 +222,11 @@ width: 200px; ...@@ -222,7 +222,11 @@ width: 200px;
.required {color: #bb0000;} .required {color: #bb0000;}
.summary {font-style: italic;} .summary {font-style: italic;}
#attachments_fields input[type=text] {margin-left: 8px; }
div.attachments p { margin:4px 0 2px 0; } div.attachments p { margin:4px 0 2px 0; }
div.attachments img { vertical-align: middle; }
div.attachments span.author { font-size: 0.9em; color: #888; }
/***** Flash & error messages ****/ /***** Flash & error messages ****/
#errorExplanation, div.flash, .nodata { #errorExplanation, div.flash, .nodata {
......
...@@ -44,7 +44,7 @@ class DocumentsControllerTest < Test::Unit::TestCase ...@@ -44,7 +44,7 @@ class DocumentsControllerTest < Test::Unit::TestCase
:document => { :title => 'DocumentsControllerTest#test_post_new', :document => { :title => 'DocumentsControllerTest#test_post_new',
:description => 'This is a new document', :description => 'This is a new document',
:category_id => 2}, :category_id => 2},
:attachments => [ ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/testfile.txt', 'text/plain') ] :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
assert_redirected_to 'projects/ecookbook/documents' assert_redirected_to 'projects/ecookbook/documents'
......
...@@ -300,7 +300,7 @@ class IssuesControllerTest < Test::Unit::TestCase ...@@ -300,7 +300,7 @@ class IssuesControllerTest < Test::Unit::TestCase
post :edit, post :edit,
:id => 1, :id => 1,
:notes => '', :notes => '',
:attachments => [ test_uploaded_file('testfile.txt', 'text/plain') ] :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
assert_redirected_to 'issues/show/1' assert_redirected_to 'issues/show/1'
j = Issue.find(1).journals.find(:first, :order => 'id DESC') j = Issue.find(1).journals.find(:first, :order => 'id DESC')
assert j.notes.blank? assert j.notes.blank?
......
...@@ -50,13 +50,14 @@ class IssuesTest < ActionController::IntegrationTest ...@@ -50,13 +50,14 @@ class IssuesTest < ActionController::IntegrationTest
post 'issues/edit/1', post 'issues/edit/1',
:notes => 'Some notes', :notes => 'Some notes',
:attachments => ([] << ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/testfile.txt', 'text/plain')) :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
assert_redirected_to "issues/show/1" assert_redirected_to "issues/show/1"
# make sure attachment was saved # make sure attachment was saved
attachment = Issue.find(1).attachments.find_by_filename("testfile.txt") attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
assert_kind_of Attachment, attachment assert_kind_of Attachment, attachment
assert_equal Issue.find(1), attachment.container assert_equal Issue.find(1), attachment.container
assert_equal 'This is an attachment', attachment.description
# verify the size of the attachment stored in db # verify the size of the attachment stored in db
#assert_equal file_data_1.length, attachment.filesize #assert_equal file_data_1.length, attachment.filesize
# verify that the attachment was written to disk # verify that the attachment was written to disk
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment