From 667f5b680e937206f7804d4d4ad005d6632600db Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Fri, 2 May 2014 18:55:38 +0200 Subject: [PATCH] attachments view --- app/controllers/themen_controller.rb | 19 ++++++++++++++----- app/views/attachments/_attachment.html.erb | 9 +++++++++ app/views/themen/_attachment_list.html.erb | 12 ++++++++++++ app/views/themen/_verw_liste.html.erb | 3 ++- app/views/themen/attachments.js.erb | 1 + app/views/themen/show.js.erb | 1 + app/views/themengruppen/show.html.erb | 3 +++ 7 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 app/views/attachments/_attachment.html.erb create mode 100644 app/views/themen/_attachment_list.html.erb create mode 100644 app/views/themen/attachments.js.erb create mode 100644 app/views/themen/show.js.erb diff --git a/app/controllers/themen_controller.rb b/app/controllers/themen_controller.rb index 2f5fa51..3a95e58 100644 --- a/app/controllers/themen_controller.rb +++ b/app/controllers/themen_controller.rb @@ -16,17 +16,19 @@ class ThemenController < ApplicationController # GET /themen/1.json def show @thema = Thema.find(params[:id]) - redirect_to :controller=>'themengruppen', :id=>@thema.themengruppe.id, :action=>:show, :anchor=> "thema_"+params[:id].to_s + @fragen=@thema.fragen @toolbar_elements = [{:icon=>:pencil, :hicon=>'icon-pencil', :text=>"Verwalten", :path=>verwalten_thema_path(@thema)}] @toolbar_elements = [{:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t('thema.edit'), :path=>edit_thema_path(@thema)}] @toolbar_elements << {:hicon=>'icon-remove-circle', :text=>I18n.t('thema.remove'), :path=>thema_path(@thema), :method=>:delete, :confirm=>I18n.t('thema.sure')} - # respond_to do |format| - # format.html # show.html.erb - # format.json { render json: @thema } - # end + respond_to do |format| + format.html { + redirect_to :controller=>'themengruppen', :id=>@thema.themengruppe.id, :action=>:show, :anchor=> "thema_"+params[:id].to_s + } + format.js + end end def verwalten @thema = Thema.find(params[:id]) @@ -83,6 +85,13 @@ class ThemenController < ApplicationController format.js end end + def attachments + @thema = Thema.find(params[:id]) + @attachments=@thema.attachments + respond_to do |format| + format.js + end + end # PUT /themen/1 # PUT /themen/1.json def update diff --git a/app/views/attachments/_attachment.html.erb b/app/views/attachments/_attachment.html.erb new file mode 100644 index 0000000..1fc66d3 --- /dev/null +++ b/app/views/attachments/_attachment.html.erb @@ -0,0 +1,9 @@ + <% data_ext = attachment.datei.file.extension.downcase %> + + <%= attachment.name %>
+ <% if (!["jpg","png","jpeg"].find_index(data_ext).nil?) %> + <%= image_tag attachment.datei.thumb.url %> + <% else %> + <%= image_tag "pdf-logo.jpg" %> + <% end %> + diff --git a/app/views/themen/_attachment_list.html.erb b/app/views/themen/_attachment_list.html.erb new file mode 100644 index 0000000..7b9c0cf --- /dev/null +++ b/app/views/themen/_attachment_list.html.erb @@ -0,0 +1,12 @@ + +<% attachment_list.each do |a| %> + + + + +<% end %> +
+<%= render a %> + +<%= link_to "Edit", edit_thema_attachment_path(a.thema,a) %> +
diff --git a/app/views/themen/_verw_liste.html.erb b/app/views/themen/_verw_liste.html.erb index cceba04..8783dbe 100644 --- a/app/views/themen/_verw_liste.html.erb +++ b/app/views/themen/_verw_liste.html.erb @@ -1,3 +1,4 @@ <% verw_liste.each do |thema| %> -
  • <%= thema.title %>

    <%= link_to edit_thema_path(thema),:remote=>true do %> Edit <% end %> <%= link_to fragen_thema_path(thema),:remote=>true do %> Fragen <% end %>
  • +
  • <%= thema.title %>

    +<%= link_to thema_path(thema),:remote=>true do %> Show <% end %> <%= link_to edit_thema_path(thema),:remote=>true do %> Edit <% end %> <%= link_to fragen_thema_path(thema),:remote=>true do %> Fragen <% end %><%= link_to attachments_thema_path(thema),:remote=>true do %> Attachments <% end %>
  • <% end %> diff --git a/app/views/themen/attachments.js.erb b/app/views/themen/attachments.js.erb new file mode 100644 index 0000000..79f8f32 --- /dev/null +++ b/app/views/themen/attachments.js.erb @@ -0,0 +1 @@ +$("#themaview").html("<%= escape_javascript(raw("

    "+I18n.t('thema.show')+"

    ")+render(:partial=>"themen/attachment_list", :object=>@attachments) )%>"); \ No newline at end of file diff --git a/app/views/themen/show.js.erb b/app/views/themen/show.js.erb new file mode 100644 index 0000000..a6cab1b --- /dev/null +++ b/app/views/themen/show.js.erb @@ -0,0 +1 @@ +$("#themaview").html("<%= escape_javascript(raw("

    "+I18n.t('thema.show')+"

    ")+render(:partial=>"themen/small", :object=>@thema) )%>"); \ No newline at end of file diff --git a/app/views/themengruppen/show.html.erb b/app/views/themengruppen/show.html.erb index d6b4f02..daf766d 100644 --- a/app/views/themengruppen/show.html.erb +++ b/app/views/themengruppen/show.html.erb @@ -28,6 +28,9 @@ <% thema.nlinks.each do |l| %>
  • <%= render l.neuigkeit %>
  • <% end %> + <% thema.nlinks.each do |l| %> +
  • <%= render l.neuigkeit %>
  • + <% end %>