modify attachments

This commit is contained in:
Andreas Stephanides
2015-02-11 20:53:25 +01:00
parent 5439d33a3c
commit 29a35f76d8
9 changed files with 52 additions and 17 deletions

View File

@@ -13,6 +13,15 @@ class AttachmentsController < ApplicationController
# GET /attachments/1 # GET /attachments/1
# GET /attachments/1.json # GET /attachments/1.json
def set_titlepic
@attachment = Attachment.find(params[:id])
if @attachment.image?
@attachment.flag_titlepic = params[:titlepic]
@attachment.thema.titlepics << @attachment
@attachment.save
end
redirect_to @attachment.thema
end
def show def show
@attachment = Attachment.find(params[:id]) @attachment = Attachment.find(params[:id])

View File

@@ -12,12 +12,12 @@
class Attachment < ActiveRecord::Base class Attachment < ActiveRecord::Base
has_paper_trail has_paper_trail
attr_accessible :name, :datei, :datei_cache attr_accessible :name, :datei, :datei_cache,:flag_titlepic
belongs_to :thema belongs_to :thema
mount_uploader :datei, AttachmentUploader mount_uploader :datei, AttachmentUploader
validates :thema, :presence => true validates :thema, :presence => true
validates :name, :presence => true validates :name, :presence => true
belongs_to :parent, :polymorphic=>true
def image? def image?
# data_ext = datei.file.extension.downcase # data_ext = datei.file.extension.downcase

View File

@@ -22,6 +22,7 @@ include Rails.application.routes.url_helpers
validates :themengruppe, :presence => true validates :themengruppe, :presence => true
validates :title, :presence => true validates :title, :presence => true
validates :text, :presence => true validates :text, :presence => true
has_many :titlepics, :as=>:parent, :class_name=>'Attachment', :conditions=>{:flag_titlepic=>true}
has_many :meetings, :as=>:parent has_many :meetings, :as=>:parent
has_many :documents, :as=>:parent has_many :documents, :as=>:parent
scope :public, where(:isdraft=>false).includes(:themengruppe).where("themengruppen.public"=>true) scope :public, where(:isdraft=>false).includes(:themengruppe).where("themengruppen.public"=>true)

View File

@@ -12,6 +12,9 @@
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Actions</a> <a class="dropdown-toggle" data-toggle="dropdown" href="#">Actions</a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li> <li>
<%= link_to ff_icon("icon-pencil")+"Make Titlepic", set_titlepic_thema_attachment_path(a.thema,a,:params=>{:titlepic=>true}) %>
</li>
<li>
<%= link_to ff_icon("icon-pencil")+"Edit", edit_thema_attachment_path(a.thema,a) %> <%= link_to ff_icon("icon-pencil")+"Edit", edit_thema_attachment_path(a.thema,a) %>
</li><li> </li><li>
<%= link_to "Delete Attachment", thema_attachment_path(a.thema,a), method: "DELETE", confirm: "Sure?" , class: "btn-danger " %> <%= link_to "Delete Attachment", thema_attachment_path(a.thema,a), method: "DELETE", confirm: "Sure?" , class: "btn-danger " %>

View File

@@ -1,7 +1,8 @@
<% if can? :show, small %> <% if can? :show, small %>
<a name="thema_<%=small.id%>" href="#<%=small.id%>"> <a name="thema_<%=small.id%>" href="#<%=small.id%>">
<h2><%= small.title %> <%= link_to fa_icon("pencil"), verwalten_thema_path(small) if can? :edit, small %> </h2> <h2><%= link_to small.title,small %> <%= link_to fa_icon("pencil"), verwalten_thema_path(small) if can? :edit, small %> </h2>
</a> </a>
<%= image_tag small.titlepics.first.datei.url unless small.titlepics.first.nil? %>
<% if small.is_outdated? %> <% if small.is_outdated? %>
<div class="sticker sticker-red"> <%= I18n.t("thema.outdated") %> <%= link_to"Als aktuell markieren",is_updated_thema_path(small), :class=>:btn if can? :is_updated, small%></div> <div class="sticker sticker-red"> <%= I18n.t("thema.outdated") %> <%= link_to"Als aktuell markieren",is_updated_thema_path(small), :class=>:btn if can? :is_updated, small%></div>
<% end %> <% end %>

View File

@@ -1,19 +1,24 @@
<%= content_for :header do %> <%= content_for :header do %>
<title><%= @thema.title.to_s + " (" + @thema.themengruppe.title.to_s + ")" %></title> <title><%= @thema.title.to_s + " (" + @thema.themengruppe.title.to_s + ")" %></title>
<% unless @thema.attachments.first.nil? <%
# picture_url=URI(root_url) mog = {
# picture_url.path=@thema.picture.url(:locale=>nil, :theme=>nil)
end
%>
<% set_meta_tags :og => {
:title => @thema.title.to_s + " (" + @thema.themengruppe.title.to_s + ")", :title => @thema.title.to_s + " (" + @thema.themengruppe.title.to_s + ")",
:type => "article", :type => "article",
:description =>@thema.text_first_words, :description =>@thema.text_first_words,
:url=>thema_url(:theme=>nil) :url=>thema_url(:theme=>nil)
} }
%> %>
<%= display_meta_tags %>
<%=
unless @thema.titlepics.first.nil?
picture_url=URI(root_url)
picture_url.path=@thema.titlepics.first.datei.url(:locale=>nil, :theme=>nil)
mog[:image]= picture_url
end
%>
<%= mog.to_yaml %>
<%= display_meta_tags :og=> mog %>
<% end %> <% end %>
<p id="notice"><%= notice %></p> <p id="notice"><%= notice %></p>

View File

@@ -157,7 +157,11 @@
get :documents get :documents
get :meetings get :meetings
end end
resources :attachments resources :attachments do
member do
get :set_titlepic
end
end
end end
resources :calendars resources :calendars

View File

@@ -0,0 +1,7 @@
class AddParentToAttachment < ActiveRecord::Migration
def change
change_table :attachments do |t|
t.references :parent, :polymorphic=>{:default=>'Thema'}
end
end
end

View File

@@ -0,0 +1,5 @@
class AddFlagsToAttachment < ActiveRecord::Migration
def change
add_column :attachments, :flag_titlepic, :boolean
end
end