diff --git a/app/inputs/uploader_input.rb b/app/inputs/uploader_input.rb new file mode 100644 index 0000000..fabdbad --- /dev/null +++ b/app/inputs/uploader_input.rb @@ -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 diff --git a/app/mailers/news_mailer.rb b/app/mailers/news_mailer.rb index e00a7c9..ca45278 100644 --- a/app/mailers/news_mailer.rb +++ b/app/mailers/news_mailer.rb @@ -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) diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index 46412f9..e46d204 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -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 diff --git a/app/models/survey/choice.rb b/app/models/survey/choice.rb index 0a8aa0d..6477423 100644 --- a/app/models/survey/choice.rb +++ b/app/models/survey/choice.rb @@ -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 diff --git a/app/views/neuigkeiten/show.html.erb b/app/views/neuigkeiten/show.html.erb index 4c5daf6..cd49339 100755 --- a/app/views/neuigkeiten/show.html.erb +++ b/app/views/neuigkeiten/show.html.erb @@ -36,6 +36,9 @@ <%= render partial: "neuigkeit_view", object: @neuigkeit %> +<% @neuigkeit.questions.each do |q| %> +<%= render q%> +<% end %>
" data-layout="standard" data-action="like" data-show-faces="true" data-share="true">
<% if can? :find_link , @neuigkeit %> diff --git a/app/views/news_mailer/neuigkeit_mail.html.erb b/app/views/news_mailer/neuigkeit_mail.html.erb index 8f85fcb..bb61c35 100644 --- a/app/views/news_mailer/neuigkeit_mail.html.erb +++ b/app/views/news_mailer/neuigkeit_mail.html.erb @@ -1,6 +1,10 @@ + + <%= stylesheet_link_tag "application", :media=>"all" %>

<%= @neuigkeit.title%>

-<%= 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") %> diff --git a/app/views/survey/choices/_choice.html.erb b/app/views/survey/choices/_choice.html.erb index fe40b0d..6cc8293 100644 --- a/app/views/survey/choices/_choice.html.erb +++ b/app/views/survey/choices/_choice.html.erb @@ -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 %> diff --git a/app/views/survey/choices/_form.html.erb b/app/views/survey/choices/_form.html.erb index 892fae7..f11f55b 100644 --- a/app/views/survey/choices/_form.html.erb +++ b/app/views/survey/choices/_form.html.erb @@ -5,9 +5,7 @@ <%= f.input :icon, :input_html=>{:id=>"iconfield"},:as=>:hidden %> - - <%= 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 %> diff --git a/app/views/survey/questions/_mail.html.erb b/app/views/survey/questions/_mail.html.erb new file mode 100644 index 0000000..793012b --- /dev/null +++ b/app/views/survey/questions/_mail.html.erb @@ -0,0 +1,6 @@ +<% question=mail %> +
+ <%= question.title%> <%=question.text%>
+ <% question.choices.each do |c| %> +
  • <%= render c %>
  • + <% end %> diff --git a/app/views/survey/questions/_question.html.erb b/app/views/survey/questions/_question.html.erb index 0440c8f..9b67ea4 100644 --- a/app/views/survey/questions/_question.html.erb +++ b/app/views/survey/questions/_question.html.erb @@ -11,7 +11,7 @@
  • <%= render c %>
  • <% end %> - <%= 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%> <% end %> diff --git a/config/environments/development.rb b/config/environments/development.rb index 53fb4c2..747988c 100755 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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