AutoCommit Sam Aug 1 23:03:02 CEST 2015

This commit is contained in:
Andreas Stephanides
2015-08-01 23:03:02 +02:00
parent 2b01a87d15
commit 9933718750
8 changed files with 22 additions and 30 deletions

View File

@@ -6,7 +6,6 @@ before_filter :decode_commentable_type
@comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order @comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
format.json { render json: @comment }
format.js format.js
end end
@@ -16,26 +15,17 @@ before_filter :decode_commentable_type
respond_to do |format| respond_to do |format|
format.js format.js
end end
end end
def show def show
@comment = Comment.find(params[:id]) @comment = Comment.find(params[:id])
respond_to do |format| respond_to do |format|
# format.html # show.html.erb
format.js format.js
format.json { render json: @comment }
end end
end end
def new def new
@comment = Comment.new @comment = Comment.new
@comment.commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil? @comment.commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil?
respond_to do |format| respond_to do |format|
format.html # new.html.erb
format.json { render json: @comment }
format.js format.js
end end
end end
@@ -53,19 +43,16 @@ before_filter :decode_commentable_type
c = params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil? c = params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil?
@comment = Comment.build_for(c, current_user,"", params_new) @comment = Comment.build_for(c, current_user,"", params_new)
if @comment.parent_object.class==Comment if @comment.parent_object.class==Comment
@comments= @comment.parent_object.children @comments= @comment.parent_object.children
else else
@comments=@comment.parent_object.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order @comments=@comment.parent_object.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order
end end
respond_to do |format| respond_to do |format|
if @comment if @comment
format.html { redirect_to @comment.commentable, notice: 'Comment was successfully created.', show_comments: true }
format.json { render json: @comment, status: :created, location: @comment }
format.js format.js
else else
format.html { render action: "new" }
format.json { render json: @comment.errors, status: :unprocessable_entity }
format.js {render action:"new"} format.js {render action:"new"}
end end
end end
@@ -95,13 +82,10 @@ end
def destroy def destroy
@comment = Comment.find(params[:id]) @comment = Comment.find(params[:id])
@commentable=@comment.commentable @commentable=@comment.commentable
@comment.destroy @comment.destroy
@comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order @comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order
respond_to do |format| respond_to do |format|
format.html { redirect_to @commentable, :action=>"show"}
format.json { head :no_content }
format.js format.js
end end
end end

View File

@@ -1,7 +1,7 @@
class Survey::Choice < ActiveRecord::Base class Survey::Choice < ActiveRecord::Base
belongs_to :question, class_name: 'Survey::Question' belongs_to :question, class_name: 'Survey::Question'
attr_accessible :picture, :sort, :text, :icon, :picture_cache, :remove_picture, :question_id attr_accessible :picture, :sort, :text, :icon, :picture_cache, :remove_picture, :question_id
has_many :answers, class_name: 'Survey::Answer' has_many :answers, class_name: 'Survey::Answer', dependent: :destroy
include ActionView::Helpers::TagHelper include ActionView::Helpers::TagHelper
mount_uploader :picture, PictureUploader mount_uploader :picture, PictureUploader
def to_s def to_s

View File

@@ -1,7 +1,7 @@
class Survey::Question < ActiveRecord::Base class Survey::Question < ActiveRecord::Base
attr_accessible :text, :title, :typ, :choice_ids attr_accessible :text, :title, :typ, :choice_ids
belongs_to :parent, polymorphic: true belongs_to :parent, polymorphic: true
has_many :choices has_many :choices, dependent: :destroy
has_many :answers, through: :choices has_many :answers, through: :choices
include IsCommentable include IsCommentable
@@ -22,8 +22,10 @@ class Survey::Question < ActiveRecord::Base
cid= cid - found_ids cid= cid - found_ids
Survey::Answer.where(user_id: user.id, choice_id: found_ids).delete_all Survey::Answer.where(user_id: user.id, choice_id: found_ids).delete_all
else else
if self.typ == 0
Survey::Answer.where(user_id: user.id, choice_id: self.choice_ids).delete_all Survey::Answer.where(user_id: user.id, choice_id: self.choice_ids).delete_all
end end
end
cid.each do |c| cid.each do |c|
if self.choice_ids.include?(c) if self.choice_ids.include?(c)
a=Survey::Answer.new(user_id: user.id, choice_id: c.to_i) a=Survey::Answer.new(user_id: user.id, choice_id: c.to_i)

View File

@@ -1,5 +1,7 @@
<div id="<%= divid_for(comment) %>"> <div id="<%= divid_for(comment) %>">
<% if (!comment.anonym) %>
<a class="pull-left media-object" href="#"><%= image_tag comment.thumb_url %></a> <a class="pull-left media-object" href="#"><%= image_tag comment.thumb_url %></a>
<% end %>
<div class="media-body"> <div class="media-body">
<b><%= (!comment.anonym) ? comment.user.try(:email) : "Anonym" %> <b><%= (!comment.anonym) ? comment.user.try(:email) : "Anonym" %>
</b> (<%= I18n.l(comment.created_at) %>) </b> (<%= I18n.l(comment.created_at) %>)

View File

@@ -34,10 +34,12 @@
<%= notice %> <%= notice %>
</p> </p>
<%= render partial: "neuigkeit_view", object: @neuigkeit %> <%= render partial: "neuigkeit_view", object: @neuigkeit %>
</div>
<% @neuigkeit.questions.each do |q| %> <% @neuigkeit.questions.each do |q| %>
<%= render q%> <%= render q%>
<% end %> <% end %>
</div>
</div> </div>
<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> <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>

View File

@@ -15,4 +15,5 @@ end
<%= t %> <%= link_to fa_icon("pencil"), edit_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true <%= t %> <%= link_to fa_icon("pencil"), edit_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true
%> %>
<%= link_to fa_icon("pencil"), delete_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true %>
<% end %> <% end %>

View File

@@ -4,9 +4,9 @@
<% end %> <% end %>
<% else %> <% else %>
<div class="contentbox" id ="<%= divid_for(question) %>" style=""> <div class="contentbox" id ="<%= divid_for(question) %>" style="">
<div class="contentbox"> <div >
<b><%= question.title%></b> <%=question.text%><%= link_to fa_icon("pencil"), edit_survey_question_path(question) , class: "btn btn-link navbar-btn" , remote: true%></div> <b><%= question.title%></b> <%=question.text%><%= link_to fa_icon("pencil"), edit_survey_question_path(question) , class: "btn btn-link navbar-btn" , remote: true%>
<div class="contentbox">
<ul class="choice-list"> <ul class="choice-list">
<% question.choices.each do |c| %> <% question.choices.each do |c| %>
<li><%= render c %></li> <li><%= render c %></li>

View File

@@ -0,0 +1 @@
$('#<%= divid_for(@survey_question) %>').replaceWith("<%= escape_javascript(render partial: "form", object: @survey_question) %>")