comments
This commit is contained in:
3
app/assets/javascripts/comments.js.coffee
Normal file
3
app/assets/javascripts/comments.js.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
@@ -115,3 +115,4 @@ $box-background: white;
|
||||
|
||||
@import 'layout';
|
||||
@import 'calendars';
|
||||
@import 'formtastic-bootstrap'
|
||||
@@ -17,7 +17,10 @@ class BeispieleController < ApplicationController
|
||||
def show
|
||||
# @lva = params([:lva]) unless params([:lva]).nil?
|
||||
@beispiel = Beispiel.find(params[:id])
|
||||
redirect_to @beispiel.lva
|
||||
respond_to do |format|
|
||||
format.html { redirect_to @beispiel.lva }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
# GET /beispiele/new
|
||||
|
||||
83
app/controllers/comments_controller.rb
Normal file
83
app/controllers/comments_controller.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
class CommentsController < ApplicationController
|
||||
def index
|
||||
@comments=Comment.all
|
||||
end
|
||||
def show
|
||||
@comment = Comment.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @comment }
|
||||
end
|
||||
end
|
||||
def new
|
||||
@comment = Comment.new
|
||||
@comment.commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil?
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @comment }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
# GET /comments/1/edit
|
||||
def edit
|
||||
@comment = Comment.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /comments
|
||||
# POST /comments.json
|
||||
def create
|
||||
params_new= params[:comment].select {|i| !["commentable_id", "commentable_type"].include?(i)}
|
||||
|
||||
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)
|
||||
#raise @comment.to_yaml.to_s
|
||||
# @comment.commentable= c
|
||||
|
||||
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
if @comment
|
||||
format.html { redirect_to @comment.commentable, notice: 'Comment was successfully created.' }
|
||||
format.json { render json: @comment, status: :created, location: @comment }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: @comment.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /comments/1
|
||||
# PUT /comments/1.json
|
||||
def update
|
||||
|
||||
params[:comment].select! {|i| !["commentable_id", "commentable_type"].include?(i)}
|
||||
@comment = Comment.find(params[:id])
|
||||
@comment.commentable=params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil?
|
||||
respond_to do |format|
|
||||
|
||||
if @comment.update_attributes(params[:comment])
|
||||
format.html { redirect_to @comment.commentable, notice: 'Comment was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @comment.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /comments/1
|
||||
# DELETE /comments/1.json
|
||||
def destroy
|
||||
@comment = Comment.find(params[:id])
|
||||
@comment.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to comments_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
||||
2
app/helpers/comments_helper.rb
Normal file
2
app/helpers/comments_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CommentsHelper
|
||||
end
|
||||
@@ -4,6 +4,8 @@ class Ability
|
||||
def initialize(user)
|
||||
loggedin=!(user.nil?)
|
||||
user ||= User.new # guest user (not logged in)
|
||||
|
||||
can :manage, Comment
|
||||
#-----------------------------------------------------
|
||||
# Rechteverwaltung fuer Studien Modul
|
||||
can [:show, :index], Studium
|
||||
@@ -97,6 +99,8 @@ class Ability
|
||||
if user.has_role?("fetadmin")
|
||||
can :addfetuser, User
|
||||
can :addfetadmin, User
|
||||
can :edit, User
|
||||
can :manage, User
|
||||
end
|
||||
|
||||
if user.has_role?("newsadmin") || user.has_role?( "fetadmin") || user.has_role?( "fetuser")
|
||||
|
||||
@@ -16,7 +16,7 @@ class Beispiel < ActiveRecord::Base
|
||||
attr_accessible :desc, :name, :lva_id, :beispieldatei, :beispieldatei_cache, :datum
|
||||
acts_as_votable
|
||||
belongs_to :lva
|
||||
|
||||
include IsCommentable
|
||||
mount_uploader :beispieldatei, AttachmentUploader
|
||||
validates :beispieldatei, :presence => true
|
||||
validates :name, :presence => true
|
||||
@@ -35,4 +35,7 @@ class Beispiel < ActiveRecord::Base
|
||||
"delete_type" => "DELETE"
|
||||
}
|
||||
end
|
||||
def divid
|
||||
"beispiel_"+id.to_s
|
||||
end
|
||||
end
|
||||
|
||||
44
app/models/comment.rb
Normal file
44
app/models/comment.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
class Comment < ActiveRecord::Base
|
||||
attr_accessible :text,:anonym, :intern, :hidden
|
||||
# commentable depth, official, intern, anonym
|
||||
acts_as_votable
|
||||
acts_as_nested_set :scope => [:commentable_id, :commentable_type]
|
||||
belongs_to :commentable, :polymorphic=> true
|
||||
belongs_to :user
|
||||
validate :text, :presence=>true
|
||||
validate :user, :presence=>true
|
||||
validate :commentable, :presence=>true
|
||||
include IsCommentable
|
||||
|
||||
def self.build_for(set_commentable, user, text,attr={})
|
||||
c = new
|
||||
raise "Tried to build comment for non commentable" unless set_commentable.try(:is_commentable?)
|
||||
c.user=user
|
||||
c.text=text
|
||||
c.assign_attributes(attr)
|
||||
|
||||
unless set_commentable.class.to_s == "Comment"
|
||||
c.commentable=set_commentable
|
||||
c.save
|
||||
else
|
||||
|
||||
c.commentable=set_commentable.commentable
|
||||
c.save
|
||||
c.move_to_child_of(set_commentable)
|
||||
end
|
||||
c
|
||||
end
|
||||
def thumb_url
|
||||
t_url= user.fetprofile.picture.thumb.url unless user.nil? or user.fetprofile.nil?
|
||||
t_url
|
||||
end
|
||||
def divid
|
||||
"comment_" + id.to_s
|
||||
end
|
||||
def formid
|
||||
"comment_form_" + commentable_type + "_" + commentable_id.to_s
|
||||
end
|
||||
def self.formid_for(c)
|
||||
"comment_form_" + c.class.to_s + "_" + c.id.to_s
|
||||
end
|
||||
end
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
class Fetprofile < ActiveRecord::Base
|
||||
attr_accessible :active, :desc, :fetmailalias, :nachname, :picture, :short, :vorname, :memberships_attributes, :remove_picture, :picture_cache, :plz, :street, :city, :instant,:skype, :telnr, :hdynr, :birth_day, :birth_month, :birth_year,:geschlecht
|
||||
has_many :memberships, dependent: :delete_all
|
||||
has_many :memberships, dependent: :destroy
|
||||
has_many :gremien, :through=> :membership
|
||||
mount_uploader :picture, PictureUploader
|
||||
has_paper_trail
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
<div class="row-fluid contentbox">
|
||||
<div id="<%= beispiel.divid %>" class="contentbox">
|
||||
<div class="row-fluid">
|
||||
<div class="span8">
|
||||
|
||||
<b><%=link_to ffi1_icon("note20")+" " + beispiel.name, beispiel.beispieldatei.url, title: beispiel.desc %></b>
|
||||
@@ -7,7 +7,7 @@
|
||||
<%= I18n.t("file.size") + ": " + (beispiel.beispieldatei.size/1024.0).round(2).to_s %>KiB <br>
|
||||
<span class="linklist"><%=
|
||||
if can?(:like, beispiel)
|
||||
link_to ffi1_icon("like3")+" like" + "("+beispiel.get_likes.size.to_s+")", like_beispiel_path(beispiel),title: "liked by " + ((current_user.liked?(beispiel)) ? ("you and " + ((beispiel.get_likes.size - 1).to_s + " others")) : beispiel.get_likes.size.to_s)
|
||||
link_to ffi1_icon("like3")+" like" + "("+beispiel.get_likes.size.to_s+")", like_beispiel_path(beispiel),title: "liked by " + ((current_user.liked?(beispiel)) ? ("you and " + ((beispiel.get_likes.size - 1).to_s + " others")) : beispiel.get_likes.size.to_s), remote: true
|
||||
else
|
||||
"liked by " + beispiel.get_likes.size.to_s
|
||||
end
|
||||
@@ -15,7 +15,7 @@ end
|
||||
|
||||
<%=
|
||||
if can?(:dislike, beispiel)
|
||||
link_to ffi1_icon("dislike")+" dislike" + "("+beispiel.get_dislikes.size.to_s+")", dislike_beispiel_path(beispiel),title:"disliked by " + ((current_user.disliked?(beispiel)) ? ("you and " + ((beispiel.get_dislikes.size - 1).to_s + " others")) : beispiel.get_dislikes.size.to_s)
|
||||
link_to ffi1_icon("dislike")+" dislike" + "("+beispiel.get_dislikes.size.to_s+")", dislike_beispiel_path(beispiel),title:"disliked by " + ((current_user.disliked?(beispiel)) ? ("you and " + ((beispiel.get_dislikes.size - 1).to_s + " others")) : beispiel.get_dislikes.size.to_s) , remote: true
|
||||
else
|
||||
"disliked by " + beispiel.get_dislikes.size.to_s
|
||||
end
|
||||
@@ -23,10 +23,17 @@ end
|
||||
%>
|
||||
|
||||
<%= link_to ff_icon("icon-pencil")+" edit", edit_beispiel_path(beispiel) if can? :edit, beispiel%>
|
||||
<%= link_to ff_icon("icon-remove")+" delete", beispiel_path(beispiel), :method=>:delete, :data=>{:confirm=>I18n.t('beispiel.sure')} if can? :delete, beispiel %></br>
|
||||
<%= link_to ff_icon("icon-remove")+" delete", beispiel_path(beispiel), :method=>:delete, :data=>{:confirm=>I18n.t('beispiel.sure')} if can? :delete, beispiel %>
|
||||
<%= link_to "Refresh", beispiel, remote: true %></br>
|
||||
</span>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<%= beispiel.desc %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid"><div class="span12"><%= render partial:"comments/comments", object: beispiel.comments.roots %></div></div>
|
||||
<%= link_to "comment" , new_comment_path( commentable_type: "Beispiel", commentable_id: beispiel.id), remote:true %>
|
||||
<div id="<%= Comment.formid_for(beispiel) %>">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
1
app/views/beispiele/refresh.js.erb
Normal file
1
app/views/beispiele/refresh.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#<%= @beispiel.divid %>").replaceWith("<%= escape_javascript ( render @beispiel ) %>")
|
||||
1
app/views/beispiele/show.js.erb
Normal file
1
app/views/beispiele/show.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("<%= '#' + @beispiel.divid %>").replaceWith("<%= escape_javascript render @beispiel %>")
|
||||
12
app/views/comments/_comment.html.erb
Normal file
12
app/views/comments/_comment.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<div id="<%= comment.divid %>">
|
||||
<a class="pull-left media-object" href="#"><%= image_tag comment.thumb_url %></a>
|
||||
<div class="media-body">
|
||||
<b><%= comment.user.try(:email) %></b> (<%= I18n.l(comment.created_at) %>): <%= comment.text %>
|
||||
<%= link_to "comment" , new_comment_path( commentable_type: "Comment", commentable_id: comment.id), remote:true %>
|
||||
<%= render partial:"comments/comments", object: comment.children if comment.children.size >0 %>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="<%= Comment.formid_for(comment) %>">
|
||||
</div>
|
||||
</div>
|
||||
7
app/views/comments/_comments.html.erb
Normal file
7
app/views/comments/_comments.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<div class="contentbox">
|
||||
<ul class="unstyled media-list">
|
||||
<% comments.each do |c| %>
|
||||
<li class="media"><%= render c %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
14
app/views/comments/_form.html.erb
Normal file
14
app/views/comments/_form.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<div id="<%= form.formid %>">
|
||||
<%= semantic_form_for form , remote:true, html: {class: "form-inline"} do |f| %>
|
||||
<%= f.inputs do %>
|
||||
<%= f.input :commentable_id, as: :hidden %>
|
||||
<%= f.input :commentable_type, as: :hidden %>
|
||||
<%= f.input :text, as: :string %>
|
||||
<%= f.input :anonym %>
|
||||
<% end %>
|
||||
|
||||
<%= f.actions do %>
|
||||
<%= f.action :submit, :as => :input %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
6
app/views/comments/edit.html.erb
Normal file
6
app/views/comments/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<h1>Editing comment</h1>
|
||||
|
||||
<%= render 'form', object: @comment %>
|
||||
|
||||
<%= link_to 'Show', @comment %> |
|
||||
<%= link_to 'Back', comments_path %>
|
||||
21
app/views/comments/index.html.erb
Normal file
21
app/views/comments/index.html.erb
Normal file
@@ -0,0 +1,21 @@
|
||||
<h1>Listing comments</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @comments.each do |comment| %>
|
||||
<tr>
|
||||
<td><%= link_to 'Show', comment %></td>
|
||||
<td><%= link_to 'Edit', edit_comment_path(comment) %></td>
|
||||
<td><%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New Comment', new_comment_path %>
|
||||
5
app/views/comments/new.html.erb
Normal file
5
app/views/comments/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>New comment</h1>
|
||||
|
||||
<%= render partial: 'form', object: @comment %>
|
||||
|
||||
<%= link_to 'Back', comments_path %>
|
||||
1
app/views/comments/new.js.erb
Normal file
1
app/views/comments/new.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#<%= @comment.formid %>").replaceWith("<%= escape_javascript render partial: "form", object: @comment %>")
|
||||
6
app/views/comments/show.html.erb
Normal file
6
app/views/comments/show.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<%= render @comment %>
|
||||
|
||||
<%= link_to 'Edit', edit_comment_path(@comment) %> |
|
||||
<%= link_to 'Back', comments_path %>
|
||||
Reference in New Issue
Block a user