From fb99d557341454b9f26da50460ee1872aad1a42e Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 1 Aug 2015 13:03:01 +0200 Subject: [PATCH] AutoCommit Sam Aug 1 13:03:01 CEST 2015 --- app/controllers/comments_controller.rb | 7 +++++-- app/controllers/survey/choices_controller.rb | 4 ++++ app/models/survey/choice.rb | 5 +++-- app/views/beispiele/_beispiel.html.erb | 16 ---------------- app/views/comments/_comment.html.erb | 3 +++ app/views/comments/_comments_block.html.erb | 8 +++----- app/views/survey/choices/_choice.html.erb | 10 ++++++---- app/views/survey/choices/_form.html.erb | 13 +++++++++---- app/views/survey/choices/edit.js.erb | 1 + .../survey/questions/_answeredquestion.html.erb | 2 +- .../themes/blue2/beispiele/_beispiel.html.erb | 2 ++ 11 files changed, 37 insertions(+), 34 deletions(-) create mode 100644 app/views/survey/choices/edit.js.erb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 5d64e40..0c95d0d 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -53,8 +53,11 @@ 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? @comment = Comment.build_for(c, current_user,"", params_new) - @comments=@comment.parent_object.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order - + if @comment.parent_object.class==Comment + @comments= @comment.parent_object.children +else + @comments=@comment.parent_object.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order +end respond_to do |format| if @comment format.html { redirect_to @comment.commentable, notice: 'Comment was successfully created.', show_comments: true } diff --git a/app/controllers/survey/choices_controller.rb b/app/controllers/survey/choices_controller.rb index 1cc2696..08f0959 100644 --- a/app/controllers/survey/choices_controller.rb +++ b/app/controllers/survey/choices_controller.rb @@ -35,6 +35,10 @@ class Survey::ChoicesController < ApplicationController # GET /survey/choices/1/edit def edit @choice = Survey::Choice.find(params[:id]) + respond_to do |format| + format.html + format.js + end end # POST /survey/choices diff --git a/app/models/survey/choice.rb b/app/models/survey/choice.rb index e27a842..0a8aa0d 100644 --- a/app/models/survey/choice.rb +++ b/app/models/survey/choice.rb @@ -1,12 +1,13 @@ class Survey::Choice < ActiveRecord::Base belongs_to :question, class_name: 'Survey::Question' - attr_accessible :picture, :sort, :text + attr_accessible :picture, :sort, :text, :icon, :picture_cache has_many :answers, class_name: 'Survey::Answer' include ActionView::Helpers::TagHelper + mount_uploader :picture, PictureUploader def to_s self.text end def html - content_tag("i","", class: self.picture ) + self.text + content_tag("i","", class: self.icon ) + self.text end end diff --git a/app/views/beispiele/_beispiel.html.erb b/app/views/beispiele/_beispiel.html.erb index d5f0356..8499bf7 100644 --- a/app/views/beispiele/_beispiel.html.erb +++ b/app/views/beispiele/_beispiel.html.erb @@ -39,19 +39,3 @@ <% end %> - <%= link_to "comment" , new_comment_path( commentable_type: "Beispiel", commentable_id: beispiel.id), remote:true if can? :comment, beispiel %> - <%= link_to "comments:.."+beispiel.comments.count().to_s, comments_path(commentable_type: "Beispiel", commentable_id: beispiel.id), remote:true, id: Comment.switchshowid_for(beispiel) %> -
-
- <% unless beispiel.comments.roots.empty? %> -
-
-
- <%= render partial:"comments/comments", object: beispiel.comments.order(:created_at).roots.reverse_order if params[:show_comments] %> -
-
-
- <% end %> - - - diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 098b241..3fc04ed 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -14,6 +14,9 @@
">
+
+ <%= render partial:"comments/comments", object: comment.children.order(:created_at).reverse_order if comment.children.size >0 %> +
diff --git a/app/views/comments/_comments_block.html.erb b/app/views/comments/_comments_block.html.erb index 3eec841..6b88bb1 100644 --- a/app/views/comments/_comments_block.html.erb +++ b/app/views/comments/_comments_block.html.erb @@ -1,13 +1,11 @@ <%= link_to "Comment" , new_comment_path( commentable_type: comments_block.class.to_s.gsub("::","_"), commentable_id: comments_block.id), remote:true if can? :comment, comments_block %> <%# This is the button to add a new comment %> -<%= link_to "comments:.."+ comments_block.comments.count().to_s, comments_path(commentable_type: "Survey_Question", commentable_id: comments_block.id), remote:true, id: Comment.switchshowid_for( comments_block) %> <%# load the comments in the comments block %> +<%= link_to "comments:.."+ comments_block.comments.count().to_s, comments_path(commentable_type: comments_block.class.to_s.gsub("::","_"), commentable_id: comments_block.id), remote:true, id: Comment.switchshowid_for( comments_block) %> <%# load the comments in the comments block %>
">
<% unless comments_block.comments.roots.empty? %> -
-
+
<%= render partial:"comments/comments", object: comments_block.comments.order(:created_at).roots.reverse_order if params[:show_comments] %><%# can? fehlt!%>
-
-
+ <% end %> diff --git a/app/views/survey/choices/_choice.html.erb b/app/views/survey/choices/_choice.html.erb index 4b8ce9b..fe40b0d 100644 --- a/app/views/survey/choices/_choice.html.erb +++ b/app/views/survey/choices/_choice.html.erb @@ -1,16 +1,18 @@ -
+ <% if current_user.nil? t=choice.text 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), answer_survey_question_path(choice.question, params: {survey_question: {selected: [choice.id]}}),class: "choice-"+cstyle + 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 ) end %> -<%= t %> <%= link_to fa_icon("pencil"), edit_survey_choice_path(choice) , class: "btn btn-link navbar-btn" +<%= t %> <%= link_to fa_icon("pencil"), edit_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true %> -
+<% end %> diff --git a/app/views/survey/choices/_form.html.erb b/app/views/survey/choices/_form.html.erb index e1abf93..892fae7 100644 --- a/app/views/survey/choices/_form.html.erb +++ b/app/views/survey/choices/_form.html.erb @@ -1,12 +1,17 @@ <%= semantic_form_for @choice do |f| %> <%= f.inputs do %> <%= f.input :text %> + Choose Icon + + <%= f.input :icon, :input_html=>{:id=>"iconfield"},:as=>:hidden %> + + + <%= image_tag(@choice.picture.thumb.url) unless @choice.picture.nil? %> + <%= f.file_field :picture %> + <%= f.hidden_field :picture_cache %> - <%= f.input :sort %> - <%= f.input :picture, :input_html=>{:id=>"iconfield"} %> <% end %> - Choose Icon - + <%= f.actions do %> <%= f.action :submit, :as => :input %> <% end %> diff --git a/app/views/survey/choices/edit.js.erb b/app/views/survey/choices/edit.js.erb new file mode 100644 index 0000000..3731b77 --- /dev/null +++ b/app/views/survey/choices/edit.js.erb @@ -0,0 +1 @@ +$('#<%= divid_for( @choice) %>').replaceWith("<%= escape_javascript( render partial:"form", object: @choice )%>"); diff --git a/app/views/survey/questions/_answeredquestion.html.erb b/app/views/survey/questions/_answeredquestion.html.erb index a95cad5..554a364 100644 --- a/app/views/survey/questions/_answeredquestion.html.erb +++ b/app/views/survey/questions/_answeredquestion.html.erb @@ -1,4 +1,4 @@ -
+
<%= answeredquestion.title%>
    diff --git a/app/views/themes/blue2/beispiele/_beispiel.html.erb b/app/views/themes/blue2/beispiele/_beispiel.html.erb index 55224d1..6141faf 100644 --- a/app/views/themes/blue2/beispiele/_beispiel.html.erb +++ b/app/views/themes/blue2/beispiele/_beispiel.html.erb @@ -27,4 +27,6 @@
<% end %> + +<%= render_comments_for(beispiel) %>