From 5e881faef2a63dcbcae566ec8877aec7f5591413 Mon Sep 17 00:00:00 2001 From: Stella Date: Mon, 21 Apr 2014 21:13:25 +0300 Subject: [PATCH] fix controller (find and json output). Now attachments get listed (no preview though) --- .../event_attachments_controller.rb | 19 ++++++++++--------- app/views/proposal/_form.html.haml | 17 +++++++++-------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/controllers/event_attachments_controller.rb b/app/controllers/event_attachments_controller.rb index 94ab8348..ac52bdb4 100644 --- a/app/controllers/event_attachments_controller.rb +++ b/app/controllers/event_attachments_controller.rb @@ -3,12 +3,13 @@ class EventAttachmentsController < ApplicationController skip_before_filter :verify_user, :only => [:show] def index - @proposal = current_user.person.events.find(params[:proposal_id]) + @proposal = Event.find(params[:proposal_id]) @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.map{|upload| upload.to_jq_upload } } + format.json { render json: @uploads.to_json} end end @@ -95,18 +96,18 @@ class EventAttachmentsController < ApplicationController end def destroy - if organizer_or_admin? - @upload = Upload.find(params[:id]) - else - @proposal = current_user.person.events.find(params[:proposal_id]) + @proposal = Event.find(params[:proposal_id]) + + if organizer_or_admin? || current_user.person == @proposal.submitter @upload = @proposal.event_attachments.find(params[:id]) end - + @upload.destroy if !@upload.nil? - + respond_to do |format| - format.html { redirect_to uploads_url } + 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 diff --git a/app/views/proposal/_form.html.haml b/app/views/proposal/_form.html.haml index 2d1e456f..e8c8d17d 100644 --- a/app/views/proposal/_form.html.haml +++ b/app/views/proposal/_form.html.haml @@ -23,7 +23,10 @@ %th %b Public %th + %th %tbody.files + + .row-fluid.fileupload-buttonbar .btn.btn-success.fileinput-button %span.glyphicon.glyphicon-icon-plus.icon-white @@ -60,16 +63,15 @@ {% for (var i=0, file; file=o.files[i]; i++) { %} - {%=file.name%} + {%=file.name%} +
+ {%=o.formatFileSize(file.size)%} Public {% if (file.error) { %} - {%=locale.fileupload.error%} {%=locale.fileupload.errors[file.error] || file.error%} + {%=locale.fileupload.error%} {%=locale.fileupload.errors[file.error] || file.error%} {% } else if (o.files.valid && !i) { %} - -
- {% if (!o.options.autoUpload) { %} {% } %} {% } else { %} - + {% } %} {% if (!i) { %}