AutoCommit Sam Aug 1 14:03:01 CEST 2015
This commit is contained in:
162
app/inputs/uploader_input.rb
Normal file
162
app/inputs/uploader_input.rb
Normal file
@@ -0,0 +1,162 @@
|
||||
# A formtastic input which incorporates carrierwave uploader functionality.
|
||||
#
|
||||
# Intelligently adds the cache field, displays and links to the current
|
||||
# value if there is one, adds a class to the wrapper when replacing an
|
||||
# existing value, allows removing an existing value with the checkbox
|
||||
# taking into account validation requirements.
|
||||
#
|
||||
# There are several options:
|
||||
#
|
||||
# * Toggle the replacement field with `replaceable: true/false`.
|
||||
# * The replace file label is translatable as `replace_label` or using option `replace_label: "value"` (like `label`).
|
||||
# * Toggle the remove checkbox with `removable: true/false` (`true` overrides `required`).
|
||||
# * The remove checkbox label is translatable as `remove_label` or using option `remove_label: "value"` (like `label`).
|
||||
# * Override existing file display and links using `existing_html` and `existing_link_html` (like `wrapper_html`).
|
||||
#
|
||||
# Example: `form.input :file, as: "uploader"`
|
||||
#
|
||||
# Copyright (c) Samuel Cochran 2012, under the [MIT license](http://www.opensource.org/licenses/mit-license).
|
||||
class UploaderInput < Formtastic::Inputs::FileInput
|
||||
def linkable?
|
||||
options[:linkable] != false
|
||||
end
|
||||
|
||||
def replaceable?
|
||||
options[:replaceable] != false
|
||||
end
|
||||
|
||||
def removable?
|
||||
options[:removable] != false and (options[:removable] == true or not required?)
|
||||
end
|
||||
|
||||
def method_present?
|
||||
if object.respond_to?("#{method}?")
|
||||
object.send("#{method}?")
|
||||
else
|
||||
object.send(method).present?
|
||||
end
|
||||
end
|
||||
|
||||
def method_changed?
|
||||
if object.respond_to? "#{method}_changed?"
|
||||
object.send "#{method}_changed?"
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def method_was_present?
|
||||
if not method_changed?
|
||||
method_present?
|
||||
else
|
||||
object.send("#{method}_was").present?
|
||||
end
|
||||
end
|
||||
|
||||
def wrapper_html_options
|
||||
super.tap do |options|
|
||||
options[:class] << " replaceable" if replaceable?
|
||||
options[:class] << " removable" if removable?
|
||||
options[:class] << " present" if method_present?
|
||||
options[:class] << " changed" if method_changed?
|
||||
options[:class] << " was_present" if method_was_present?
|
||||
end
|
||||
end
|
||||
|
||||
def cache_html
|
||||
if method_changed?
|
||||
builder.hidden_field("#{method}_cache")
|
||||
end or "".html_safe
|
||||
end
|
||||
|
||||
def file_html
|
||||
builder.file_field(method, input_html_options)
|
||||
end
|
||||
|
||||
def existing_html_options
|
||||
expand_html_options(options[:existing_html]) do |opts|
|
||||
opts[:class] << "existing"
|
||||
end
|
||||
end
|
||||
|
||||
def existing_link_html_options
|
||||
expand_html_options(options[:existing_link_html]) do |opts|
|
||||
opts[:class] << "existing"
|
||||
end
|
||||
end
|
||||
|
||||
def existing_html
|
||||
if method_present?
|
||||
# TODO: Add classes based on mime type for icons, etc.
|
||||
existing = template.content_tag(:span, template.image_tag( object.send(method).thumb), existing_html_options)
|
||||
template.link_to_if linkable?, existing, object.send(method).url, existing_link_html_options
|
||||
end or "".html_safe
|
||||
end
|
||||
|
||||
def replace_label_html
|
||||
template.content_tag(:label, class: "replace_label") do
|
||||
template.content_tag(:span, localized_string(method, "Replace #{method.to_s.titleize}", :replace_label))
|
||||
end
|
||||
end
|
||||
|
||||
def replace_html
|
||||
if replaceable?
|
||||
replace_label_html <<
|
||||
file_html
|
||||
end or "".html_safe
|
||||
end
|
||||
|
||||
def remove_html
|
||||
if removable?
|
||||
template.content_tag(:label, class: "remove_label") do
|
||||
template.check_box_tag("#{object_name}[remove_#{method}]", "1", false, id: "#{sanitized_object_name}_remove_#{sanitized_method_name}") <<
|
||||
# XXX: There are probably better ways to do these translations using defaults.
|
||||
template.content_tag(:span, localized_string(method, "Remove #{method.to_s.titleize}", :remove_label))
|
||||
end
|
||||
end or "".html_safe
|
||||
end
|
||||
|
||||
def to_html
|
||||
input_wrapping do
|
||||
label_html <<
|
||||
cache_html <<
|
||||
if method_was_present?
|
||||
existing_html <<
|
||||
replace_html <<
|
||||
remove_html
|
||||
else
|
||||
existing_html <<
|
||||
file_html
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def expand_html_options opts
|
||||
(opts || {}).dup.tap do |opts|
|
||||
opts[:class] =
|
||||
case opts[:class]
|
||||
when Array
|
||||
opts[:class].dup
|
||||
when nil
|
||||
[]
|
||||
else
|
||||
[opts[:class].to_s]
|
||||
end
|
||||
opts[:data] =
|
||||
case opts[:data]
|
||||
when Hash
|
||||
opts[:data].dup
|
||||
when nil
|
||||
{}
|
||||
else
|
||||
{"" => opts[:data].to_s}
|
||||
end
|
||||
|
||||
yield opts if block_given?
|
||||
|
||||
opts[:class] = opts[:class].join(' ')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,7 +2,7 @@ class NewsMailer < ActionMailer::Base
|
||||
default from: "salzamt@fet.at"
|
||||
def neuigkeit_mail(email, neuigkeit_id)
|
||||
@neuigkeit= Neuigkeit.find(neuigkeit_id)
|
||||
|
||||
email = "" if Rails.env=="development"
|
||||
mail(to: email, subject: @neuigkeit.title)
|
||||
end
|
||||
def daily_newsletter(user_id)
|
||||
|
||||
@@ -23,6 +23,7 @@ class Neuigkeit < ActiveRecord::Base
|
||||
has_many :attachments, :as=>:parent
|
||||
has_one :title_pic, :class_name=>"Attachment", :as=>:parent, :conditions=>["attachments.flag_titlepic =?", true]
|
||||
|
||||
has_many :questions, :class_name=>"Survey::Question", as: :parent
|
||||
|
||||
validates :rubrik, :presence=>true
|
||||
validates :author, :presence=>true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Survey::Choice < ActiveRecord::Base
|
||||
belongs_to :question, class_name: 'Survey::Question'
|
||||
attr_accessible :picture, :sort, :text, :icon, :picture_cache
|
||||
attr_accessible :picture, :sort, :text, :icon, :picture_cache, :remove_picture
|
||||
has_many :answers, class_name: 'Survey::Answer'
|
||||
include ActionView::Helpers::TagHelper
|
||||
mount_uploader :picture, PictureUploader
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
<%= render partial: "neuigkeit_view", object: @neuigkeit %>
|
||||
</div>
|
||||
</div>
|
||||
<% @neuigkeit.questions.each do |q| %>
|
||||
<%= render q%>
|
||||
<% end %>
|
||||
<div class="fb-like" data-href"<%= rubrik_neuigkeit_url(@rubrik,@neuigkeit,{themes: nil, locale: nil})%>" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
|
||||
|
||||
<% if can? :find_link , @neuigkeit %>
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
<%= stylesheet_link_tag "application", :media=>"all" %>
|
||||
<h1>
|
||||
<%= @neuigkeit.title%>
|
||||
</h1>
|
||||
<%= image_tag "http://www.fet.at"+@neuigkeit.picture.big_thumb.url %>
|
||||
<%= image_tag @neuigkeit.picture.big_thumb.url(only_path:false) %>
|
||||
<%=url_for controller: "neuigkeiten",action: :show, :id=>@neuigkeit.id, only_path: false %>
|
||||
<%= raw(@neuigkeit.text) %>
|
||||
<%= render partial:"survey/questions/mail", object: @neuigkeit.questions.first unless @neuigkeit.questions.empty?%>
|
||||
<%= link_to "Auf Fet.at weiterlesen", rubrik_neuigkeit_url(@neuigkeit.rubrik, @neuigkeit,:locale=>:de, :theme=>nil,:host=> "www.fet.at") %>
|
||||
|
||||
@@ -7,7 +7,7 @@ if current_user.nil?
|
||||
else
|
||||
value=(current_user.id.nil?)? false : choice.answers.where(user_id: current_user.id).count>0
|
||||
cstyle=(value) ? "true" :"false"
|
||||
t= link_to(raw("" + choice.html+ (( choice.picture.nil?) ? "":image_tag(choice.picture.thumb.url))), answer_survey_question_path(choice.question, params: {survey_question: {selected: [choice.id]}}),class: "choice-"+cstyle )
|
||||
t= link_to(raw("" + choice.html+ (( choice.picture.nil? || choice.picture.to_s.empty?) ? "":image_tag(choice.picture.thumb.url))), answer_survey_question_path(choice.question, params: {survey_question: {selected: [choice.id]}}),class: "choice-"+cstyle )
|
||||
end
|
||||
|
||||
%>
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
|
||||
<%= f.input :icon, :input_html=>{:id=>"iconfield"},:as=>:hidden %>
|
||||
|
||||
<label>Bild</label>
|
||||
<%= image_tag(@choice.picture.thumb.url) unless @choice.picture.nil? %>
|
||||
<%= f.file_field :picture %>
|
||||
<%= f.input :picture, as: :uploader %>
|
||||
<%= f.hidden_field :picture_cache %>
|
||||
|
||||
<% end %>
|
||||
|
||||
6
app/views/survey/questions/_mail.html.erb
Normal file
6
app/views/survey/questions/_mail.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<% question=mail %>
|
||||
<div class="contentbox">
|
||||
<b><%= question.title%></b> <%=question.text%></div>
|
||||
<% question.choices.each do |c| %>
|
||||
<li><%= render c %></li>
|
||||
<% end %>
|
||||
@@ -11,7 +11,7 @@
|
||||
<li><%= render c %></li>
|
||||
<% end %>
|
||||
</ul></div>
|
||||
<%= render partial: "answeredquestion", object: question if question.answers.where(user_id: current_user.id).count>0%>
|
||||
<%= render partial: "survey/questions/answeredquestion", object: question if question.answers.where(user_id: current_user.id).count>0%>
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -16,7 +16,7 @@ Fetsite::Application.configure do
|
||||
# Don't care if the mailer can't send
|
||||
config.action_mailer.raise_delivery_errors = true
|
||||
config.action_mailer.delivery_method =:sendmail
|
||||
config.action_mailer.default_url_options = {} # :host => 'glonass.htu.tuwien.ac.at' }
|
||||
config.action_mailer.default_url_options = {:host=> "localhost", :port=>3000} # :host => 'glonass.htu.tuwien.ac.at' }
|
||||
# Print deprecation notices to the Rails logger
|
||||
config.active_support.deprecation = :log
|
||||
|
||||
|
||||
Reference in New Issue
Block a user