Merge pull request #458 from differentreality/remove_attachments

remove attachments
This commit is contained in:
Henne Vogelsang 2014-08-22 14:19:26 +02:00
commit 0f1051d24e
10 changed files with 1 additions and 293 deletions

View file

@ -51,7 +51,6 @@ gem 'bootstrap3-datetimepicker-rails', '~> 3.0.2'
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-fileupload-rails'
gem 'cocoon'
# Use gravtastic for user avatars

View file

@ -164,9 +164,6 @@ GEM
i18n (0.6.11)
inversion (0.12.3)
loggability (~> 0.4)
jquery-fileupload-rails (0.4.1)
actionpack (>= 3.1)
railties (>= 3.1)
jquery-rails (3.1.0)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
@ -431,7 +428,6 @@ DEPENDENCIES
guard-rspec (~> 4.2.8)
haml-rails
hoptoad_notifier (~> 2.3)
jquery-fileupload-rails
jquery-rails
letter_opener
mina

View file

@ -12,7 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery-fileupload
//= require jquery.dataTables
//= require cocoon
//= require bootstrap

View file

@ -1,7 +1,6 @@
/*
*= require strap-on
*= require formtastic-bootstrap
*= require jquery.fileupload-ui
*= require jquery.dataTables_themeroller
*= require osem
*= require osem-rating

View file

@ -1,110 +0,0 @@
class EventAttachmentsController < ApplicationController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :proposal, class: Event
load_and_authorize_resource :upload, class: EventAttachment, through: :proposal
before_filter :verify_user
skip_before_filter :verify_user, only: [:show]
def index
@uploads = @proposal.event_attachments
@uploads = @uploads.map{|upload| upload.to_jq_upload }
respond_to do |format|
format.html # index.html.erb
format.json { render json: @uploads.to_json}
end
end
def show
if @upload.public?
send_file @upload.attachment.path
return
end
if current_user.nil?
verify_user
return
end
if organizer_or_admin? || current_user == upload.event.submitter
send_file @upload.attachment.path
else
raise ActionController::RoutingError.new('Not Found')
end
end
def new
@upload = EventAttachment.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @upload }
end
end
def edit; end
def create
params[:event_attachment][:title] = params[:title][0]
params[:event_attachment][:public] = false
params[:event_attachment][:event_id] = params[:proposal_id]
if cannot? :create, EventAttachment
begin
current_user.events.find(params[:proposal_id])
rescue
# They certainly aren't allowed to attach a file to someone else's proposal
raise ActionController::RoutingError.new('Invalid proposal')
end
end
if params.has_key?(:public)
params[:event_attachment][:public] = true
end
@upload = EventAttachment.new(params[:event_attachment])
respond_to do |format|
if @upload.save
format.html do
render json: [@upload.to_jq_upload].to_json,
content_type: 'text/html',
layout: false
end
format.json do
render json: [@upload.to_jq_upload].to_json, status: :created,
location: conference_proposal_event_attachment_path(@upload.event.conference.short_title, @upload.event, @upload)
end
else
format.html { render action: "new" }
format.json { render json: @upload.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @upload.update_attributes(params[:upload])
format.html { redirect_to @upload, notice: 'Upload was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @upload.errors, status: :unprocessable_entity }
end
end
end
def destroy
if can? :destroy, @proposal
@upload = @proposal.event_attachments.find(params[:id])
end
@upload.destroy if !@upload.nil?
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.json { head :no_content }
end
end
end

View file

@ -19,7 +19,6 @@ class ProposalController < ApplicationController
def edit
authorize! :edit, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
@attachments = @event.event_attachments
end
def create

View file

@ -140,10 +140,5 @@ class Ability
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
# View commercials of confirmed events
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
can :manage, EventAttachment do |ea|
Event.find(ea.event_id).event_users.where(user_id: user.id).present?
end
can :create, EventAttachment
end
end

View file

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

View file

@ -110,36 +110,6 @@
- if @conference.call_for_papers && @conference.call_for_papers.rating && @conference.call_for_papers.rating > 0
= render :partial => "voting"
- if @event.event_attachments.size > 0
%table.table
%thead
%th
%b Filename
%th
%b Title
%th
%b Size
%th
%b Public?
%th
%tbody
- @event.event_attachments.each do |a|
%tr
%td
= link_to a.attachment_file_name, conference_proposal_event_attachment_path(@conference.short_title, @event.id, a.id)
%td
= a.title
%td
= number_to_human_size a.attachment_file_size
%td
- if a.public?
Public
- else
Not Public
%td
= link_to "Delete", conference_proposal_event_attachment_path(@conference.short_title, @event.id, a.id),
:method => :delete, :confirm => "Are you sure you want to delete this attachment? It's permanant!"
.row
= link_to "Comments (#{@comment_count})", "#", :id => "event-comment-link"
#comments-div
@ -153,4 +123,4 @@
%br
- @comments.each do |comment|
%div
= raw format_comments(comment)
= raw format_comments(comment)

View file

@ -6,8 +6,6 @@
= link_to "Proposal", "#proposal-content", "data-toggle"=>"tab"
%li
= link_to 'Commercials', '#commercials-content', 'data-toggle'=>'tab'
%li
= link_to "Attachments", "#attachment-content", "data-toggle"=>"tab"
.tab-content
#proposal-content.tab-pane.active
= render 'proposal/proposal_form'
@ -34,114 +32,3 @@
- if can? :create, @event.commercials.new
%hr
= link_to 'Add Commercial', new_conference_proposal_commercial_path(@conference.short_title, @event.id), class: 'btn btn-primary'
#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|
%table.table.table-striped
%thead
%th
%th
%b Filename
%th
%b Title
%th
%b Size
%th
%b Public
%th
%th
%tbody.files
.row-fluid.fileupload-buttonbar
.btn.btn-success.fileinput-button
%span.fa.fa-plus
Add files...
= f.file_field :attachment
= f.hidden_field :event_id, :value => @event.id
:javascript
$(document).ready( function() {
$('#fileupload').fileupload();
$('#fileupload').bind('fileuploadsubmit', function (e, data) {
var inputs = data.context.find(':input');
if (inputs.filter('[required][value=""]').first().focus().length) {
return false;
}
data.formData = inputs.serializeArray();
});
$.getJSON($('#fileupload').prop('action'), function (files) {
var fu = $('#fileupload').data('fileupload'),
template;
fu._adjustMaxNumberOfFiles(-files.length);
template = fu._renderDownload(files)
.appendTo($('#fileupload .files'));
fu._reflow = fu._transition && template.length &&
template[0].offsetWidth;
template.addClass('in');
$('#loading').remove();
});
} );
:plain
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td class="preview"><span class="fade"></span></td>
<td class="name"><span>{%=file.name%}</span>
<div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div>
</td>
<td class="name"><input type="text" name="title[]" value="{%=file.name%}"/></td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
<td class="name"><input checked type="checkbox" name="public">Public</input></td>
{% if (file.error) { %}
<td class="error"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
{% } else if (o.files.valid && !i) { %}
<td class="start">{% if (!o.options.autoUpload) { %}
<button class="btn btn-primary">
<span class="fa fa-upload"></span>
<span>{%=locale.fileupload.start%}</span>
</button>
{% } %}</td>
{% } else { %}
<td></td>
{% } %}
<td class="cancel">{% if (!i) { %}
<button class="btn btn-warning">
<span class="fa fa-times"></span>
<span>{%=locale.fileupload.cancel%}</span>
</button>
{% } %}</td>
</tr>
{% } %}
</script>
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-download fade">
{% if (file.error) { %}
<td>{%=file.title%}</td>
<td class="name">{%=file.name%}</td>
<td class="size">{%=o.formatFileSize(file.size)%}</td>
<td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
{% } else { %}
<td class="preview">{% if (file.thumbnail_url) { %}
<a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
{% } %}</td>
<td class="name">
<a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
</td>
<td>{%=file.title%}</td>
<td class="size">{%=o.formatFileSize(file.size)%}</td>
<td>{%=file.public%}</td>
{% } %}
<td class="delete" colspan="2">
<button class="btn btn-danger pull-right" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
<span class="fa fa-trash-o"></i>
<span>{%=locale.fileupload.destroy%}</span>
</button>
</td>
</tr>
{% } %}
</script>