From b5d7a49741c597380113d4cd0011288a6e3a58b9 Mon Sep 17 00:00:00 2001 From: Stella Date: Mon, 21 Apr 2014 21:09:32 +0300 Subject: [PATCH] fix json output in controller, now it lists attachments as it should (no preview though). --- .../event_attachments_controller.rb | 16 +++++---- app/views/proposal/_form.html.haml | 33 +++++-------------- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/app/controllers/event_attachments_controller.rb b/app/controllers/event_attachments_controller.rb index 1efb2e7d..ac52bdb4 100644 --- a/app/controllers/event_attachments_controller.rb +++ b/app/controllers/event_attachments_controller.rb @@ -5,10 +5,11 @@ class EventAttachmentsController < ApplicationController def index @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: {files: @uploads.map{|upload| upload.to_jq_upload } }} + format.json { render json: @uploads.to_json} end end @@ -101,12 +102,13 @@ class EventAttachmentsController < ApplicationController @upload = @proposal.event_attachments.find(params[:id]) end - if @upload.destroy - flash[:notice] = "Deleted successfully attachment '#{@upload.title}' for proposal '#{@proposal.title}'" - else - flash[:error] = "Attachment could not be deleted." - end + @upload.destroy if !@upload.nil? - redirect_back_or_to conference_proposal_index_path(@conference.short_title) + 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 \ No newline at end of file diff --git a/app/views/proposal/_form.html.haml b/app/views/proposal/_form.html.haml index 5f773676..e8c8d17d 100644 --- a/app/views/proposal/_form.html.haml +++ b/app/views/proposal/_form.html.haml @@ -13,6 +13,7 @@ = 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 @@ -22,23 +23,9 @@ %th %b Public %th + %th %tbody.files - - @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-fluid.fileupload-buttonbar .btn.btn-success.fileinput-button @@ -76,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) { %}