diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-02-29 19:46:58 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-02-29 19:46:58 +0000 |
commit | 9daf39ec5242a6a87efb9c862952e176d4314856 (patch) | |
tree | 78ac3c4012e88e4f907e0d5a075956402af67684 /app | |
parent | 4b15dc10c10d9cb54d156457cc7d6823dac55520 (diff) | |
download | redmine-9daf39ec5242a6a87efb9c862952e176d4314856.tar.gz redmine-9daf39ec5242a6a87efb9c862952e176d4314856.zip |
Adds an optional description to attachments.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1180 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/application.rb | 20 | ||||
-rw-r--r-- | app/controllers/documents_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 2 | ||||
-rw-r--r-- | app/views/attachments/_form.rhtml | 13 | ||||
-rw-r--r-- | app/views/attachments/_links.rhtml | 17 | ||||
-rw-r--r-- | app/views/common/_attachments_form.rhtml | 6 | ||||
-rw-r--r-- | app/views/documents/index.rhtml | 2 | ||||
-rw-r--r-- | app/views/documents/new.rhtml | 2 | ||||
-rw-r--r-- | app/views/documents/show.rhtml | 26 | ||||
-rw-r--r-- | app/views/issues/_edit.rhtml | 10 | ||||
-rw-r--r-- | app/views/issues/_form.rhtml | 4 | ||||
-rw-r--r-- | app/views/messages/_form.rhtml | 9 | ||||
-rw-r--r-- | app/views/projects/add_file.rhtml | 2 | ||||
-rw-r--r-- | app/views/projects/list_files.rhtml | 3 | ||||
-rw-r--r-- | app/views/wiki/show.rhtml | 10 |
15 files changed, 63 insertions, 65 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 3644c396a..7510d503e 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -160,16 +160,20 @@ class ApplicationController < ActionController::Base end # TODO: move to model - def attach_files(obj, files) - attachments = [] - if files && files.is_a?(Array) - files.each do |file| - next unless file.size > 0 - a = Attachment.create(:container => obj, :file => file, :author => User.current) - attachments << a unless a.new_record? + def attach_files(obj, attachments) + attached = [] + if attachments && attachments.is_a?(Hash) + attachments.each_value do |attachment| + file = attachment['file'] + next unless file && file.size > 0 + a = Attachment.create(:container => obj, + :file => file, + :description => attachment['description'].to_s.strip, + :author => User.current) + attached << a unless a.new_record? end end - attachments + attached end # Returns the number of objects that should be displayed diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 93f25c495..7e732b9b6 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -21,6 +21,8 @@ class DocumentsController < ApplicationController before_filter :find_document, :except => [:index, :new] before_filter :authorize + helper :attachments + def index @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' documents = @project.documents.find :all, :include => [:attachments, :category] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index af493b034..b9318a3f7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -396,7 +396,7 @@ module ApplicationHelper def labelled_tabular_form_for(name, object, options, &proc) 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) end diff --git a/app/views/attachments/_form.rhtml b/app/views/attachments/_form.rhtml index 18f08c6be..094668f9d 100644 --- a/app/views/attachments/_form.rhtml +++ b/app/views/attachments/_form.rhtml @@ -1,4 +1,9 @@ -<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> +<span id="attachments_fields"> +<%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil -%> +<%= text_field_tag 'attachments[1][description]', '', :size => 60, :id => nil %> +<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> diff --git a/app/views/attachments/_links.rhtml b/app/views/attachments/_links.rhtml index cce11292e..4d485548b 100644 --- a/app/views/attachments/_links.rhtml +++ b/app/views/attachments/_links.rhtml @@ -1,12 +1,17 @@ <div class="attachments"> <% for attachment in attachments %> - <p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' %> - (<%= number_to_human_size attachment.filesize %>) - <% unless options[:no_author] %> - <span class="author"><%= attachment.author.name %>, <%= format_date(attachment.created_on) %></span> - <% end %> +<p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' -%> +<%= h(" - #{attachment.description}") unless attachment.description.blank? %> + <span class="size">(<%= number_to_human_size attachment.filesize %>)</span> <% 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 %> </p> <% end %> diff --git a/app/views/common/_attachments_form.rhtml b/app/views/common/_attachments_form.rhtml deleted file mode 100644 index 673f4a52e..000000000 --- a/app/views/common/_attachments_form.rhtml +++ /dev/null @@ -1,6 +0,0 @@ -<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> diff --git a/app/views/documents/index.rhtml b/app/views/documents/index.rhtml index ff58c2b2f..14d997360 100644 --- a/app/views/documents/index.rhtml +++ b/app/views/documents/index.rhtml @@ -10,7 +10,7 @@ <% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %> <%= render :partial => 'documents/form' %> <div class="box"> -<%= render :partial => 'common/attachments_form'%> +<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> </div> <%= submit_tag l(:button_create) %> <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %> diff --git a/app/views/documents/new.rhtml b/app/views/documents/new.rhtml index 4f728da79..639b4f292 100644 --- a/app/views/documents/new.rhtml +++ b/app/views/documents/new.rhtml @@ -4,7 +4,7 @@ <%= render :partial => 'documents/form' %> <div class="box"> -<%= render :partial => 'common/attachments_form'%> +<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> </div> <%= submit_tag l(:button_create) %> diff --git a/app/views/documents/show.rhtml b/app/views/documents/show.rhtml index 3014387bd..aa90c5518 100644 --- a/app/views/documents/show.rhtml +++ b/app/views/documents/show.rhtml @@ -10,29 +10,17 @@ <div class="wiki"> <%= textilizable @document.description, :attachments => @document.attachments %> </div> -<br /> <h3><%= l(:label_attachment_plural) %></h3> -<ul class="documents"> -<% 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 /> - +<%= link_to_attachments @attachments, :delete_url => (authorize_for('documents', 'destroy_attachment') ? {:controller => 'documents', :action => 'destroy_attachment', :id => @document} : nil) %> <% if authorize_for('documents', 'add_attachment') %> -<p><%= toggle_link l(:label_attachment_new), "add_attachment_form" %></p> - <% form_tag({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular", :id => "add_attachment_form", :style => "display:none;") do %> - <%= render :partial => 'attachments/form' %> +<p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;", + :id => 'attach_files_link' %></p> + <% 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) %> <% end %> <% end %> diff --git a/app/views/issues/_edit.rhtml b/app/views/issues/_edit.rhtml index f9b234d85..2e00ab520 100644 --- a/app/views/issues/_edit.rhtml +++ b/app/views/issues/_edit.rhtml @@ -1,12 +1,12 @@ <% labelled_tabular_form_for :issue, @issue, :url => {:action => 'edit', :id => @issue}, :html => {:id => 'issue-form', + :class => nil, :multipart => true} do |f| %> <%= error_messages_for 'issue' %> <div class="box"> <% if @edit_allowed || !@allowed_statuses.empty? %> - <fieldset> - <legend><%= l(:label_change_properties) %> + <fieldset class="tabular"><legend><%= l(:label_change_properties) %> <% 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> <% end %> @@ -15,7 +15,7 @@ </fieldset> <% end %> <% 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| %> <div class="splitcontentleft"> <p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p> @@ -32,9 +32,7 @@ <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> <%= wikitoolbar_for 'notes' %> - <p id="attachments_p"><label><%=l(:label_attachment_new)%> - <%= 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> + <p><%=l(:label_attachment_plural)%><br /><%= render :partial => 'attachments/form' %></p> </fieldset> </div> diff --git a/app/views/issues/_form.rhtml b/app/views/issues/_form.rhtml index 20ca666c4..1742d1391 100644 --- a/app/views/issues/_form.rhtml +++ b/app/views/issues/_form.rhtml @@ -44,9 +44,7 @@ <%= render :partial => 'form_custom_fields', :locals => {:values => @custom_values} %> <% if @issue.new_record? %> -<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> +<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> <% end %> <%= wikitoolbar_for 'issue_description' %> diff --git a/app/views/messages/_form.rhtml b/app/views/messages/_form.rhtml index aa0355070..540811ec3 100644 --- a/app/views/messages/_form.rhtml +++ b/app/views/messages/_form.rhtml @@ -4,7 +4,7 @@ <div class="box"> <!--[form:message]--> <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) %> <label><%= f.check_box :sticky %> Sticky</label> @@ -12,11 +12,10 @@ <% end %> </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' %> <!--[eoform:message]--> -<span class="tabular"> -<%= render :partial => 'attachments/form' %> -</span> +<p><%= l(:label_attachment_plural) %><br /> +<%= render :partial => 'attachments/form' %></p> </div> diff --git a/app/views/projects/add_file.rhtml b/app/views/projects/add_file.rhtml index 839275373..0ee55083d 100644 --- a/app/views/projects/add_file.rhtml +++ b/app/views/projects/add_file.rhtml @@ -7,7 +7,7 @@ <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> -<%= render :partial => 'attachments/form' %> +<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> </div> <%= submit_tag l(:button_add) %> <% end %>
\ No newline at end of file diff --git a/app/views/projects/list_files.rhtml b/app/views/projects/list_files.rhtml index 47b262388..e02077d8e 100644 --- a/app/views/projects/list_files.rhtml +++ b/app/views/projects/list_files.rhtml @@ -23,7 +23,8 @@ <% for file in version.attachments %> <tr class="<%= cycle("odd", "even") %>"> <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"><%= number_to_human_size(file.filesize) %></td> <td align="center"><%= file.downloads %></td> diff --git a/app/views/wiki/show.rhtml b/app/views/wiki/show.rhtml index 6f1df124b..77d82884f 100644 --- a/app/views/wiki/show.rhtml +++ b/app/views/wiki/show.rhtml @@ -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) %> <% if authorize_for('wiki', 'add_attachment') %> -<p><%= toggle_link l(:label_attachment_new), "add_attachment_form" %></p> -<% form_tag({ :controller => 'wiki', :action => 'add_attachment', :page => @page.title }, :multipart => true, :class => "tabular", :id => "add_attachment_form", :style => "display:none;") do %> - <%= render :partial => 'attachments/form' %> +<p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;", + :id => 'attach_files_link' %></p> +<% 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) %> +<%= link_to l(:button_cancel), {}, :onclick => "Element.hide('add_attachment_form'); Element.show('attach_files_link'); return false;" %> <% end %> <% end %> |