app/controllers/admin/attachments_controller.rb in alchemy_cms-2.0.rc2 vs app/controllers/admin/attachments_controller.rb in alchemy_cms-2.0.rc3
- old
+ new
@@ -1,25 +1,36 @@
class Admin::AttachmentsController < AlchemyController
protect_from_forgery :except => [:create]
+ before_filter :set_translation
filter_access_to :all
def index
- cond = "name LIKE '%#{params[:query]}%' OR filename LIKE '%#{params[:query]}%'"
- if params[:per_page] == 'all'
- @attachments = Attachment.where(cond).order(:name)
+ if in_overlay?
+ archive_overlay
else
- @attachments = Attachment.where(cond).paginate(
- :page => (params[:page] || 1),
- :per_page => (params[:per_page] || 20)
- ).order(:name)
+ cond = "name LIKE '%#{params[:query]}%' OR filename LIKE '%#{params[:query]}%'"
+ if params[:per_page] == 'all'
+ @attachments = Attachment.where(cond).order(:name)
+ else
+ @attachments = Attachment.where(cond).paginate(
+ :page => (params[:page] || 1),
+ :per_page => (params[:per_page] || 20)
+ ).order(:name)
+ end
end
end
def new
@attachment = Attachment.new
+ if in_overlay?
+ @while_assigning = true
+ @content = Content.find(params[:content_id], :select => 'id') if !params[:content_id].blank?
+ @swap = params[:swap]
+ @options = hashified_options
+ end
render :layout => false
end
def create
@attachment = Attachment.new(:uploaded_data => params[:Filedata])
@@ -32,11 +43,18 @@
@attachments = Attachment.where(cond).paginate(
:page => (params[:page] || 1),
:per_page => (params[:per_page] || 20)
).order(:name)
end
+ if in_overlay?
+ @while_assigning = true
+ @content = Content.find(params[:content_id], :select => 'id') if !params[:content_id].blank?
+ @swap = params[:swap]
+ @options = hashified_options
+ end
@message = _('File %{name} uploaded succesfully') % {:name => @attachment.name}
+ # Are we using the Flash uploader? Or the plain html file uploader?
if params[Rails.application.config.session_options[:key]].blank?
flash[:notice] = @message
redirect_to :action => :index
end
rescue Exception => e
@@ -74,24 +92,10 @@
flash[:notice] = ( _("File: '%{name}' deleted successfully") % {:name => name} )
page.redirect_to admin_attachments_path(:per_page => params[:per_page], :page => params[:page], :query => params[:query])
end
end
- def archive_overlay
- @content = Content.find(params[:content_id])
- @options = params[:options]
- if !params[:only].blank?
- condition = "filename LIKE '%.#{params[:only].join("' OR filename LIKE '%.")}'"
- elsif !params[:except].blank?
- condition = "filename NOT LIKE '%.#{params[:except].join("' OR filename NOT LIKE '%.")}'"
- else
- condition = ""
- end
- @attachments = Attachment.where(condition).order(:name)
- render :layout => false
- end
-
def show
@attachment = Attachment.find(params[:id])
send_file(
@attachment.public_filename,
{
@@ -109,8 +113,30 @@
:name => @attachment.filename,
:type => @attachment.content_type,
:disposition => 'attachment'
}
)
+ end
+
+private
+
+ def in_overlay?
+ !params[:content_id].blank?
+ end
+
+ def archive_overlay
+ @content = Content.find(params[:content_id])
+ @options = params[:options]
+ if !params[:only].blank?
+ condition = "filename LIKE '%.#{params[:only].join("' OR filename LIKE '%.")}'"
+ elsif !params[:except].blank?
+ condition = "filename NOT LIKE '%.#{params[:except].join("' OR filename NOT LIKE '%.")}'"
+ else
+ condition = ""
+ end
+ @attachments = Attachment.where(condition).order(:name)
+ respond_to do |format|
+ format.html { render :partial => 'archive_overlay' }
+ end
end
end