From 7022e5da1d2b9c60a111a09327f069e0aa3be1de Mon Sep 17 00:00:00 2001 From: Stella Date: Sat, 19 Apr 2014 16:40:40 +0300 Subject: [PATCH 1/3] show attachments to user --- .../event_attachments_controller.rb | 21 +++++++++---------- app/views/proposal/_form.html.haml | 18 +++++++++++++++- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/app/controllers/event_attachments_controller.rb b/app/controllers/event_attachments_controller.rb index 94ab8348..8734fe5b 100644 --- a/app/controllers/event_attachments_controller.rb +++ b/app/controllers/event_attachments_controller.rb @@ -95,19 +95,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.json { head :no_content } + + if @upload.destroy + flash[:notice] = "Deleted successfully attachment '#{@upload.title}' for proposal '#{@proposal.title}'" + else + flash[:error] = "Attachment could not be deleted." end + + redirect_back_or_to conference_proposal_index_path(@conference.short_title) 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 2d1e456f..5f773676 100644 --- a/app/views/proposal/_form.html.haml +++ b/app/views/proposal/_form.html.haml @@ -13,7 +13,6 @@ = 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 @@ -24,6 +23,23 @@ %b Public %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 %span.glyphicon.glyphicon-icon-plus.icon-white From a86b81e3c07ecf7dd0aad88d49af472f8348492c Mon Sep 17 00:00:00 2001 From: Stella Date: Mon, 21 Apr 2014 11:41:16 +0300 Subject: [PATCH 2/3] fix index: attachment json and proposal find --- app/controllers/event_attachments_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/event_attachments_controller.rb b/app/controllers/event_attachments_controller.rb index 8734fe5b..1efb2e7d 100644 --- a/app/controllers/event_attachments_controller.rb +++ b/app/controllers/event_attachments_controller.rb @@ -3,12 +3,12 @@ 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 respond_to do |format| format.html # index.html.erb - format.json { render json: @uploads.map{|upload| upload.to_jq_upload } } + format.json { render json: {files: @uploads.map{|upload| upload.to_jq_upload } }} end end From b5d7a49741c597380113d4cd0011288a6e3a58b9 Mon Sep 17 00:00:00 2001 From: Stella Date: Mon, 21 Apr 2014 21:09:32 +0300 Subject: [PATCH 3/3] 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) { %}