diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index d05b234..2d33a88 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -3,7 +3,7 @@ class AttachmentsController < ApplicationController # GET /attachments.json load_and_authorize_resource def index - @attachments = Attachment.all +# @attachments = Attachment.all respond_to do |format| format.html # index.html.erb @@ -11,28 +11,43 @@ class AttachmentsController < ApplicationController end end - # GET /attachments/1 - # GET /attachments/1.json + # GET + # sets the titlepic flag for one attachment for one parent object def set_titlepic - @attachment = Attachment.find(params[:id]) - if @attachment.image? - @attachment.flag_titlepic = params[:titlepic] - @attachment.thema.titlepics << @attachment + @attachment = Attachment.find(params[:id]) + if @attachment.image? # if attachment is an Image set flag + @attachment.parent.attachments.update_all("flag_titlepic=0") + @attachment.flag_titlepic=true @attachment.save end - redirect_to @attachment.thema + respond_to do |format| + format.html { + redirect_to @attachment} + format.js { + @parent=@attachment.parent + @attachments=@parent.attachments + render :refresh_list + } + end end + # GET refresh_list + # refresh the attachment list for a parent object + def refresh_list + @parent = params[:parent_type].constantize.find(params[:parent_id]) + @attachments=@parent.attachments + respond_to do |format| + format.js + end + end + #get /attachments/ID def show @attachment = Attachment.find(params[:id]) - respond_to do |format| format.html # show.html.erb - format.json { render json: @attachment } end end # GET /attachments/new - # GET /attachments/new.json def new @attachment = Attachment.new @thema = Thema.find(params[:thema_id]) @@ -58,10 +73,8 @@ class AttachmentsController < ApplicationController @thema = Thema.find_by_id(params[:thema_id]) # logger.info "gg" @attachment.thema = @thema - @attachment.name=@attachment.datei.filename - @action="create" - - + @attachment.name=@attachment.datei.filename + @action="create" # logger.info "sdf" respond_to do |format| if @attachment.save @@ -86,11 +99,11 @@ class AttachmentsController < ApplicationController # PUT /attachments/1.json def update @attachment = Attachment.find(params[:id]) - @thema = @attachment.thema - + @parent= @attachment.parent + respond_to do |format| if @attachment.update_attributes(params[:attachment]) - format.html { redirect_to @thema, notice: 'Attachment was successfully updated.' } + format.html { redirect_to @parent, notice: 'Attachment was successfully updated.' } format.json { head :no_content } format.js {@attachment=Attachment.new; render action:"create"} else diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 3c961c9..34f1839 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -1,2 +1,9 @@ module AttachmentsHelper + + def render_attachments_for(p) + a= Attachment.new + a.parent=p + render(partial:"attachments/attachment_list", object: p.attachments, locals: {editor: (can?(:edit, p)), parent: p} )+ ((can?(:edit, p))? (render partial:"attachments/form_bulk2", object: a ): "") + + end end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index b1e7883..705ddae 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -12,11 +12,13 @@ class Attachment < ActiveRecord::Base has_paper_trail - attr_accessible :name, :datei, :datei_cache,:flag_titlepic + attr_accessible :name, :datei, :datei_cache,:flag_titlepic,:parent_id, :parent_type belongs_to :thema mount_uploader :datei, AttachmentUploader - validates :thema, :presence => true +# validates :thema, :presence => true validates :name, :presence => true + scope :titlepic, ->{where(flag_titlepic: true)} + default_scope order("LOWER(name)") belongs_to :parent, :polymorphic=>true def image? @@ -24,6 +26,9 @@ class Attachment < ActiveRecord::Base # %w(jpg png jpeg).include?(data_ext) datei.image?(datei.file) end + def self.parent_attachment_list_id(parent) + "attachments_for_"+parent.class.to_s+"_"+parent.id.to_s + end def to_jq_upload { diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb index d08f8cd..407c604 100644 --- a/app/uploaders/attachment_uploader.rb +++ b/app/uploaders/attachment_uploader.rb @@ -29,14 +29,11 @@ end end version :thumb ,:if=>:image? do process :resize_to_fill => [64, 64] - process :convert => :jpg - def full_filename(for_file) - super.chomp(File.extname(super)) + '.jpg' - end end - version :cover , :if=>:image? do + + version :cover , :if=>:pdf? do process :cover process :resize_to_fit => [64,64] process :convert => :jpg @@ -44,9 +41,11 @@ end super.chomp(File.extname(super)) + '.jpg' end end + version :thumb_small , :if=>:image? do process :resize_to_fill => [32, 32] end + version :thumb_big , :if=>:image? do process :resize_to_fill => [200, 200] @@ -56,6 +55,10 @@ end end end + version :big_thumb , :if=>:image? do + process :resize_to_fill => [200,200] + end + version :resized, :if=>:image? do process :resize_to_fit => [1024,1024] end @@ -92,7 +95,9 @@ end def extention File.extname(full_filename(file.file)).downcase end - + def pdf?(for_file) + %w(.pdf).include?(File.extname(full_filename(for_file.file)).downcase) + end def image?(for_file) %w(.jpg .png .jpeg).include?(File.extname(full_filename(for_file.file)).downcase) end diff --git a/app/views/attachments/_attachment.html.erb b/app/views/attachments/_attachment.html.erb index 2b45971..f46acd5 100644 --- a/app/views/attachments/_attachment.html.erb +++ b/app/views/attachments/_attachment.html.erb @@ -4,6 +4,7 @@ <% if (!["jpg","png","jpeg"].find_index(data_ext).nil?) %> <%= image_tag attachment.datei.thumb.url %> <% else %> + <%= image_tag "pdf-logo.jpg" %> <% end %> <%= attachment.name %> diff --git a/app/views/attachments/_attachment_list.html.erb b/app/views/attachments/_attachment_list.html.erb new file mode 100644 index 0000000..02d40b9 --- /dev/null +++ b/app/views/attachments/_attachment_list.html.erb @@ -0,0 +1,30 @@ + + <% attachment_list.each do |a| %> + + + <% if editor %> + + <% end %> + + <% end %> +
+ <%= fa_icon("tag") if a.flag_titlepic %> + <%= link_to a.datei.url do %> + <%= render partial:"attachments/attachment_new", object: a %> + <% end %> + + +
diff --git a/app/views/attachments/_attachment_new.html.erb b/app/views/attachments/_attachment_new.html.erb new file mode 100644 index 0000000..197c819 --- /dev/null +++ b/app/views/attachments/_attachment_new.html.erb @@ -0,0 +1,14 @@ +<% attachment=attachment_new %> + <% data_ext = attachment.datei.file.try(:extension).try(:downcase) %> + + + <% if (!["jpg","png","jpeg"].find_index(data_ext).nil?) %> + <%= image_tag attachment.datei.thumb_small.url %> + <% elsif (!["pdf"].find_index(data_ext).nil?)%> + <%= image_tag attachment.datei.cover.url %> + + <% else %> + <%= ff_icon("ffi1-note20 fa-2x") %> + + <% end %> + <%= attachment.name %> diff --git a/app/views/attachments/_form_bulk2.html.erb b/app/views/attachments/_form_bulk2.html.erb new file mode 100644 index 0000000..16958a1 --- /dev/null +++ b/app/views/attachments/_form_bulk2.html.erb @@ -0,0 +1,145 @@ + +
+ <%= semantic_form_for [form_bulk2], :remote=>true, :html => { :multipart => true, :id => "fileupload" } do |f| %> + +
+ +
+
+ + + + Add files... + <%= f.file_field :datei, :multiple=>true %> + <%= f.input :parent_id , as: :hidden %> + <%= f.input :parent_type, as: :hidden %> + + + + + +
+
+ +
+
+
+
+
+
+ +
+
+ + +
+ <% end %> + +
+ + + + + + + + diff --git a/app/views/attachments/edit.html.erb b/app/views/attachments/edit.html.erb index 919ea5c..be5e0f3 100644 --- a/app/views/attachments/edit.html.erb +++ b/app/views/attachments/edit.html.erb @@ -3,4 +3,4 @@ <%= render 'form' %> -<%= link_to 'Back', thema_attachments_path(@attachment.thema,@attachment) %> +<%= link_to 'Back', attachments_path(@attachment) %> diff --git a/app/views/attachments/refresh_list.js.erb b/app/views/attachments/refresh_list.js.erb new file mode 100644 index 0000000..d4d1750 --- /dev/null +++ b/app/views/attachments/refresh_list.js.erb @@ -0,0 +1 @@ +$("#<%= Attachment.parent_attachment_list_id(@parent) %>").replaceWith("<%= escape_javascript ( render partial:"attachments/attachment_list", object:@attachments, locals: {editor: true, parent: @parent} ) %>") \ No newline at end of file diff --git a/app/views/attachments/show.html.erb b/app/views/attachments/show.html.erb index b43b363..2109dda 100644 --- a/app/views/attachments/show.html.erb +++ b/app/views/attachments/show.html.erb @@ -1,10 +1,10 @@

<%= notice %>

-

Name: <%= @attachment.name %> + <%= render @attachment %>

<%= link_to 'Edit', edit_attachment_path(@attachment) %> | -<%= link_to 'Back', attachments_path %> +<%= link_to 'Back', polymorphic_path(@attachment.parent) %> diff --git a/app/views/documents/_document.html.erb b/app/views/documents/_document.html.erb index d66e778..d1563f6 100644 --- a/app/views/documents/_document.html.erb +++ b/app/views/documents/_document.html.erb @@ -4,5 +4,5 @@ <%= fa_icon("file-text") %> <%= link_to document.name, document %> - <%= link_to "edit", edit_document_path(document),:remote=>true if can? :edit, document %> + <%= link_to "rename", edit_document_path(document),:remote=>true if can? :edit, document %> diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index 124e77d..8dcb20b 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -17,7 +17,10 @@ <% end %> + + +<%= render_attachments_for(@document) %> diff --git a/app/views/neuigkeiten/show.html.erb b/app/views/neuigkeiten/show.html.erb index 3474e89..02b4b50 100755 --- a/app/views/neuigkeiten/show.html.erb +++ b/app/views/neuigkeiten/show.html.erb @@ -78,6 +78,9 @@ end <%= render @neuigkeit.meeting %> <% end%>
<%= link_to "new Calentry", new_calentry_path(:object_id=>@neuigkeit.id, :object_type=>"Neuigkeit"), :remote=>true if can? :edit, @neuigkeit %>
+ +<%= %> +<%= render_attachments_for(@neuigkeit) %> <%= render 'layouts/pretty_toolbar', :object=> @toolbar_elements %> <%= render partial: 'nlink_list_whole', :object=>@neuigkeit.nlinks %> diff --git a/app/views/themen/_attachment_verwalten.html.erb b/app/views/themen/_attachment_verwalten.html.erb index e4180d9..91c79b1 100644 --- a/app/views/themen/_attachment_verwalten.html.erb +++ b/app/views/themen/_attachment_verwalten.html.erb @@ -1,12 +1,7 @@
-Titlepics -<% @thema.titlepics.each do |tp| %> -<%= link_to image_tag(tp.datei.thumb.url) , set_titlepic_thema_attachment_path(tp.thema,tp,:params=>{:titlepic=>false}) %> -<% end %>
- List -<%= render partial: "themen/attachment_list", object:@thema.attachments ,locals: {:editor => true}%> -
-Form -<%= render :partial=>"attachments/form_bulk" %> +<%= render_attachments_for(@thema) %> + + +
diff --git a/app/views/themen/_small.html.erb b/app/views/themen/_small.html.erb index 4b570d3..2719210 100644 --- a/app/views/themen/_small.html.erb +++ b/app/views/themen/_small.html.erb @@ -78,7 +78,7 @@ <% unless small.hideattachment %> -<%= render partial: "themen/attachment_list", object: small.attachments, locals:{editor: false} unless small.attachments.empty? %> +<%= render partial: "attachments/attachment_list", object: small.attachments, locals:{editor: false, parent: small} unless small.attachments.empty? %> <% end %>
diff --git a/config/routes.rb b/config/routes.rb index b38910c..7df49cd 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -158,13 +158,21 @@ get :documents get :meetings end - resources :attachments do + resources :attachments do member do get :set_titlepic end end + + end + resources :attachments do + member do + get :set_titlepic + end + collection do + get :refresh_list + end end - resources :calendars get 'verwalten/calendars', :controller=>:calendars, :action=>:verwalten, :as=>'calendars_verwalten' resources :calentries