Merged ajax_upload branch (#3957).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10977 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
2304f5d42c
commit
ef25210aca
22 files changed
+442
-83
No files matched your search
@@ -300,6 +300,16 @@ class ApplicationController < ActionController::Base
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_attachments
|
||||
if (attachments = params[:attachments]).present?
|
||||
att = attachments.values.collect do |attachment|
|
||||
Attachment.find_by_token( attachment[:token] ) if attachment[:token].present?
|
||||
end
|
||||
att.compact!
|
||||
end
|
||||
@attachments = att || []
|
||||
end
|
||||
|
||||
# make sure that the user is a member of the project (or admin) if project is private
|
||||
# used as a before_filter for actions that do not require any particular permission on the project
|
||||
def check_project_privacy
|
||||
|
||||
@@ -85,15 +85,17 @@ class AttachmentsController < ApplicationController
|
||||
@attachment = Attachment.new(:file => request.raw_post)
|
||||
@attachment.author = User.current
|
||||
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
|
||||
saved = @attachment.save
|
||||
|
||||
if @attachment.save
|
||||
respond_to do |format|
|
||||
format.api { render :action => 'upload', :status => :created }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.api { render_validation_errors(@attachment) }
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.api {
|
||||
if saved
|
||||
render :action => 'upload', :status => :created
|
||||
else
|
||||
render_validation_errors(@attachment)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -101,9 +103,17 @@ class AttachmentsController < ApplicationController
|
||||
if @attachment.container.respond_to?(:init_journal)
|
||||
@attachment.container.init_journal(User.current)
|
||||
end
|
||||
# Make sure association callbacks are called
|
||||
@attachment.container.attachments.delete(@attachment)
|
||||
redirect_to_referer_or project_path(@project)
|
||||
if @attachment.container
|
||||
# Make sure association callbacks are called
|
||||
@attachment.container.attachments.delete(@attachment)
|
||||
else
|
||||
@attachment.destroy
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_referer_or project_path(@project) }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -19,6 +19,7 @@ class MessagesController < ApplicationController
|
||||
menu_item :boards
|
||||
default_search_scope :messages
|
||||
before_filter :find_board, :only => [:new, :preview]
|
||||
before_filter :find_attachments, :only => [:preview]
|
||||
before_filter :find_message, :except => [:new, :preview]
|
||||
before_filter :authorize, :except => [:preview, :edit, :destroy]
|
||||
|
||||
@@ -117,7 +118,6 @@ class MessagesController < ApplicationController
|
||||
|
||||
def preview
|
||||
message = @board.messages.find_by_id(params[:id])
|
||||
@attachements = message.attachments if message
|
||||
@text = (params[:message] || params[:reply])[:content]
|
||||
@previewed = message
|
||||
render :partial => 'common/preview'
|
||||
|
||||
@@ -16,12 +16,11 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class PreviewsController < ApplicationController
|
||||
before_filter :find_project
|
||||
before_filter :find_project, :find_attachments
|
||||
|
||||
def issue
|
||||
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
||||
if @issue
|
||||
@attachements = @issue.attachments
|
||||
@description = params[:issue] && params[:issue][:description]
|
||||
if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
|
||||
@description = nil
|
||||
@@ -37,7 +36,6 @@ class PreviewsController < ApplicationController
|
||||
def news
|
||||
if params[:id].present? && news = News.visible.find_by_id(params[:id])
|
||||
@previewed = news
|
||||
@attachments = news.attachments
|
||||
end
|
||||
@text = (params[:news] ? params[:news][:description] : nil)
|
||||
render :partial => 'common/preview'
|
||||
|
||||
@@ -37,6 +37,7 @@ class WikiController < ApplicationController
|
||||
before_filter :find_existing_or_new_page, :only => [:show, :edit, :update]
|
||||
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version]
|
||||
accept_api_auth :index, :show, :update, :destroy
|
||||
before_filter :find_attachments, :only => [:preview]
|
||||
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
@@ -293,7 +294,7 @@ class WikiController < ApplicationController
|
||||
# page is nil when previewing a new page
|
||||
return render_403 unless page.nil? || editable?(page)
|
||||
if page
|
||||
@attachements = page.attachments
|
||||
@attachments += page.attachments
|
||||
@previewed = page.content
|
||||
end
|
||||
@text = params[:content][:text]
|
||||
|
||||
@@ -597,8 +597,9 @@ module ApplicationHelper
|
||||
|
||||
def parse_inline_attachments(text, project, obj, attr, only_path, options)
|
||||
# when using an image link, try to use an attachment, if possible
|
||||
if options[:attachments] || (obj && obj.respond_to?(:attachments))
|
||||
attachments = options[:attachments] || obj.attachments
|
||||
if options[:attachments].present? || (obj && obj.respond_to?(:attachments))
|
||||
attachments = options[:attachments] || []
|
||||
attachments += obj.attachments if obj
|
||||
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
|
||||
filename, ext, alt, alttext = $1.downcase, $2, $3, $4
|
||||
# search for the picture in attachments
|
||||
|
||||
@@ -154,11 +154,19 @@ class Attachment < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def visible?(user=User.current)
|
||||
container && container.attachments_visible?(user)
|
||||
if container_id
|
||||
container && container.attachments_visible?(user)
|
||||
else
|
||||
author == user
|
||||
end
|
||||
end
|
||||
|
||||
def deletable?(user=User.current)
|
||||
container && container.attachments_deletable?(user)
|
||||
if container_id
|
||||
container && container.attachments_deletable?(user)
|
||||
else
|
||||
author == user
|
||||
end
|
||||
end
|
||||
|
||||
def image?
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
<span id="attachments_fields">
|
||||
<% if defined?(container) && container && container.saved_attachments %>
|
||||
<% container.saved_attachments.each_with_index do |attachment, i| %>
|
||||
<span class="icon icon-attachment" style="display:block; line-height:1.5em;">
|
||||
<%= h(attachment.filename) %> (<%= number_to_human_size(attachment.filesize) %>)
|
||||
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.id}.#{attachment.digest}" %>
|
||||
<span id="attachments_p<%= i %>">
|
||||
<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename') +
|
||||
text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description') +
|
||||
link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
|
||||
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<span id="attachments_fields">
|
||||
<span>
|
||||
<%= file_field_tag 'attachments[1][file]', :id => nil, :class => 'file',
|
||||
:onchange => "checkFileSize(this, #{Setting.attachment_max_size.to_i.kilobytes}, '#{escape_javascript(l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)))}');" -%>
|
||||
<%= text_field_tag 'attachments[1][description]', '', :id => nil, :class => 'description', :maxlength => 255, :placeholder => l(:label_optional_description) %>
|
||||
<%= link_to_function(image_tag('delete.png'), 'removeFileField(this)', :title => (l(:button_delete))) %>
|
||||
</span>
|
||||
</span>
|
||||
<span class="add_attachment"><%= link_to l(:label_add_another_file), '#', :onclick => 'addFileField(); return false;', :class => 'add_attachment' %>
|
||||
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</span>
|
||||
<span class="add_attachment">
|
||||
<%= file_field_tag 'attachments_files',
|
||||
:id => nil,
|
||||
:multiple => true,
|
||||
:onchange => 'addInputFiles(this);',
|
||||
:data => {
|
||||
:max_file_size => Setting.attachment_max_size.to_i.kilobytes,
|
||||
:max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
|
||||
:max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
|
||||
:upload_path => uploads_path(:format => 'js'),
|
||||
:description_placeholder => l(:label_optional_description)
|
||||
} %>
|
||||
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
|
||||
</span>
|
||||
|
||||
<%= javascript_include_tag 'attachments' %>
|
||||
@@ -0,0 +1 @@
|
||||
$('#attachments_<%= j params[:attachment_id] %>').remove();
|
||||
@@ -0,0 +1,9 @@
|
||||
var fileSpan = $('#attachments_<%= j params[:attachment_id] %>');
|
||||
$('<input>', { type: 'hidden', name: 'attachments[<%= j params[:attachment_id] %>][token]' } ).val('<%= j @attachment.token %>').appendTo(fileSpan);
|
||||
fileSpan.find('a.remove-upload')
|
||||
.attr({
|
||||
"data-remote": true,
|
||||
"data-method": 'delete',
|
||||
href: '<%= j attachment_path(@attachment, :attachment_id => params[:attachment_id], :format => 'js') %>'
|
||||
})
|
||||
.off('click');
|
||||
@@ -1,3 +1,3 @@
|
||||
<fieldset class="preview"><legend><%= l(:label_preview) %></legend>
|
||||
<%= textilizable @text, :attachments => @attachements, :object => @previewed %>
|
||||
<%= textilizable @text, :attachments => @attachments, :object => @previewed %>
|
||||
</fieldset>
|
||||
@@ -1,11 +1,11 @@
|
||||
<% if @notes %>
|
||||
<fieldset class="preview"><legend><%= l(:field_notes) %></legend>
|
||||
<%= textilizable @notes, :attachments => @attachements, :object => @issue %>
|
||||
<%= textilizable @notes, :attachments => @attachments, :object => @issue %>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
<% if @description %>
|
||||
<fieldset class="preview"><legend><%= l(:field_description) %></legend>
|
||||
<%= textilizable @description, :attachments => @attachements, :object => @issue %>
|
||||
<%= textilizable @description, :attachments => @attachments, :object => @issue %>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
Reference in new issue
Block a user