This commit is contained in:
Stella Rouzi 2014-07-22 21:28:42 +00:00
commit ce9950755e
3 changed files with 32 additions and 32 deletions

View file

@ -1,6 +1,6 @@
class EventAttachmentsController < ApplicationController class EventAttachmentsController < ApplicationController
before_filter :verify_user before_filter :verify_user
skip_before_filter :verify_user, :only => [:show] skip_before_filter :verify_user, only: [:show]
def index def index
@proposal = Event.find(params[:proposal_id]) @proposal = Event.find(params[:proposal_id])
@ -53,7 +53,7 @@ class EventAttachmentsController < ApplicationController
if !organizer_or_admin? if !organizer_or_admin?
begin begin
event = current_user.events.find(params[:proposal_id]) event = current_user.events.find(params[:proposal_id])
rescue Exception => e rescue => e
# They certainly aren't allowed to attach a file to someone else's proposal # They certainly aren't allowed to attach a file to someone else's proposal
raise ActionController::RoutingError.new('Invalid proposal') raise ActionController::RoutingError.new('Invalid proposal')
end end
@ -67,14 +67,15 @@ class EventAttachmentsController < ApplicationController
respond_to do |format| respond_to do |format|
if @upload.save if @upload.save
format.html { format.html {
render :json => [@upload.to_jq_upload].to_json, render json: [@upload.to_jq_upload].to_json,
:content_type => 'text/html', content_type: 'text/html',
:layout => false layout: false
} }
format.json { render json: [@upload.to_jq_upload].to_json, status: :created, format.json { render json: { files: [@upload.to_jq_upload] }, status: :created,
location: conference_proposal_event_attachment_path(@upload.event.conference.short_title, @upload.event, @upload) } location: conference_proposal_event_attachment_path(
@upload.event.conference.short_title, @upload.event, @upload) }
else else
format.html { render action: "new" } format.html { render action: 'new' }
format.json { render json: @upload.errors, status: :unprocessable_entity } format.json { render json: @upload.errors, status: :unprocessable_entity }
end end
end end
@ -89,7 +90,7 @@ class EventAttachmentsController < ApplicationController
format.html { redirect_to @upload, notice: 'Upload was successfully updated.' } format.html { redirect_to @upload, notice: 'Upload was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: "edit" } format.html { render action: 'edit' }
format.json { render json: @upload.errors, status: :unprocessable_entity } format.json { render json: @upload.errors, status: :unprocessable_entity }
end end
end end
@ -106,7 +107,8 @@ class EventAttachmentsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_back_or_to conference_proposal_index_path(@conference.short_title), :notice => "Deleted successfully attachment '#{@upload.title}' for proposal '#{@proposal.title}'" } format.html { redirect_back_or_to conference_proposal_index_path(@conference.short_title),
notice: "Deleted successfully attachment '#{@upload.title}' for proposal '#{@proposal.title}'" }
format.json { head :no_content } format.json { head :no_content }
end end

View file

@ -4,26 +4,24 @@ class EventAttachment < ActiveRecord::Base
belongs_to :event belongs_to :event
attr_accessible :public, :attachment, :event_id, :title attr_accessible :public, :attachment, :event_id, :title
has_attached_file :attachment, :path => ":rails_root/storage/:rails_env/attachments/:id/:style/:basename.:extension" has_attached_file :attachment, path: ':rails_root/storage/:rails_env/attachments/:id/:style/:basename.:extension'
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
do_not_validate_attachment_file_type :attachment
def to_jq_upload def to_jq_upload
{ {
"name" => read_attribute(:attachment_file_name), 'name' => read_attribute(:attachment_file_name),
"size" => read_attribute(:attachment_file_size), 'size' => read_attribute(:attachment_file_size),
"title" => read_attribute(:title), 'title' => read_attribute(:title),
"public" => read_attribute(:public), 'public' => read_attribute(:public),
# "url" => attachment.url(:original), # "url" => attachment.url(:original),
"url" => conference_proposal_event_attachment_path(self.event.conference.short_title, self.event_id, self.id), 'url' => conference_proposal_event_attachment_path(event.conference.short_title, event_id, id),
"delete_url" => conference_proposal_event_attachment_path(self.event.conference.short_title, self.event_id, self.id), 'delete_url' => conference_proposal_event_attachment_path(event.conference.short_title, event_id, id),
"delete_type" => "DELETE" 'delete_type' => 'DELETE'
} }
end end
#:path => ":rails_root/public/system/:attachment/:id/:style/:filename", #:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
# :url => "/system/:attachment/:id/:style/:filename" # :url => "/system/:attachment/:id/:style/:filename"
# has_paper_trail :meta => {:associated_id => :event_id, :associated_type => "Event"} # has_paper_trail :meta => {:associated_id => :event_id, :associated_type => "Event"}
end end

View file

@ -3,14 +3,14 @@
.tabbable .tabbable
%ul.nav.nav-tabs %ul.nav.nav-tabs
%li.active %li.active
= link_to "Proposal", "#proposal-content", "data-toggle"=>"tab" = link_to 'Proposal', '#proposal-content', 'data-toggle'=>'tab'
%li %li
= link_to "Attachments", "#attachment-content", "data-toggle"=>"tab" = link_to 'Attachments', '#attachment-content', 'data-toggle'=>'tab'
.tab-content .tab-content
#proposal-content.tab-pane.active #proposal-content.tab-pane.active
= render 'proposal/proposal_form' = render 'proposal/proposal_form'
#attachment-content.tab-pane #attachment-content.tab-pane
= form_for EventAttachment.new, :url => conference_proposal_event_attachment_index_path(@conference.short_title, @event), :html => { :multipart => true, :id => "fileupload" } do |f| = form_for EventAttachment.new, url: conference_proposal_event_attachment_index_path(@conference.short_title, @event), html: { multipart: true, id: 'fileupload' } do |f|
%table.table.table-striped %table.table.table-striped
%thead %thead
%th %th
@ -45,7 +45,7 @@
data.formData = inputs.serializeArray(); data.formData = inputs.serializeArray();
}); });
$.getJSON($('#fileupload').prop('action'), function (files) { $.getJSON($('#fileupload').prop('action'), function (files) {
var fu = $('#fileupload').data('fileupload'), var fu = $('#fileupload').data('blueimpFileupload'),
template; template;
fu._adjustMaxNumberOfFiles(-files.length); fu._adjustMaxNumberOfFiles(-files.length);
template = fu._renderDownload(files) template = fu._renderDownload(files)