diff --git a/app/assets/stylesheets/common/000_vars.css.scss b/app/assets/stylesheets/common/000_vars.css.scss index fb8bcf1ed..6279c968f 100644 --- a/app/assets/stylesheets/common/000_vars.css.scss +++ b/app/assets/stylesheets/common/000_vars.css.scss @@ -1,4 +1,4 @@ -$menu_color: #F7F7FF; +$menu_color: #F5F5FF; $link_color: hsl(213, 100%, 50%); $link_hover_color: lighten($link_color, 25%); $link_dark_color: darken($link_color, 25%); diff --git a/app/assets/stylesheets/specific/comments.css.scss b/app/assets/stylesheets/specific/comments.css.scss index 36a7360a6..7eaa842bb 100644 --- a/app/assets/stylesheets/specific/comments.css.scss +++ b/app/assets/stylesheets/specific/comments.css.scss @@ -15,6 +15,11 @@ div.comments-for-post { article.comment { margin-bottom: 2em; word-wrap: break-word; + padding: 5px; + + &[data-is-sticky="true"] { + background: $menu_color; + } div.author { width: 12em; @@ -40,7 +45,7 @@ div.comments-for-post { } } - article.comment.below-threshold { + article.comment.below-threshold:not([data-is-sticky="true"]) { opacity: 0.3; } @@ -48,10 +53,6 @@ div.comments-for-post { opacity: 1.0; } } - - div.comment-preview { - margin-bottom: 2em; - } } div#c-posts { @@ -146,3 +147,12 @@ div#c-comments { } } } + +form.edit_comment div.input.boolean { + display: inline-block; + + label { + font-weight: normal; + vertical-align: initial; + } +} diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index ff38ab0f6..75a33ec0c 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -23,12 +23,12 @@ class CommentsController < ApplicationController def update @comment = Comment.find(params[:id]) check_privilege(@comment) - @comment.update_attributes(params[:comment].permit(:body)) + @comment.update(update_params, :as => CurrentUser.role) respond_with(@comment, :location => post_path(@comment.post_id)) end def create - @comment = Comment.create(params[:comment]) + @comment = Comment.create(create_params, :as => CurrentUser.role) respond_with(@comment) do |format| format.html do if @comment.errors.any? @@ -110,4 +110,12 @@ private raise User::PrivilegeError end end + + def create_params + params.require(:comment).permit(:post_id, :body, :do_not_bump_post, :is_sticky) + end + + def update_params + params.require(:comment).permit(:body, :is_deleted, :is_sticky) + end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 1abb74bef..6a8cbbd35 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -12,7 +12,8 @@ class Comment < ActiveRecord::Base before_validation :initialize_updater after_create :update_last_commented_at_on_create after_destroy :update_last_commented_at_on_destroy - attr_accessible :body, :post_id, :do_not_bump_post, :is_deleted + attr_accessible :body, :post_id, :do_not_bump_post, :is_deleted, :as => [:member, :gold, :platinum, :builder, :janitor, :moderator, :admin] + attr_accessible :is_sticky, :as => [:moderator, :admin] mentionable( :message_field => :body, :user_field => :creator_id, @@ -34,11 +35,11 @@ class Comment < ActiveRecord::Base end def hidden(user) - where("score < ?", user.comment_threshold) + where("score < ? and is_sticky = false", user.comment_threshold) end def visible(user) - where("score >= ?", user.comment_threshold) + where("score >= ? or is_sticky = true", user.comment_threshold) end def deleted @@ -208,11 +209,11 @@ class Comment < ActiveRecord::Base end def delete! - update_attributes(:is_deleted => true) + update({ :is_deleted => true }, :as => CurrentUser.role) end def undelete! - update_attributes(:is_deleted => false) + update({ :is_deleted => false }, :as => CurrentUser.role) end end diff --git a/app/models/comment_vote.rb b/app/models/comment_vote.rb index 88ec2d084..accf9bc92 100644 --- a/app/models/comment_vote.rb +++ b/app/models/comment_vote.rb @@ -39,9 +39,6 @@ class CommentVote < ActiveRecord::Base if is_positive? && comment.creator == CurrentUser.user errors.add :base, "You cannot upvote your own comments" false - elsif is_negative? && comment.creator.is_admin? - errors.add :base, "You cannot downvote an admin comment" - false else true end diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 0c5b47949..6117a6051 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,5 +1,14 @@ +<%= error_messages_for :comment %> + <%= simple_form_for(comment, :html => {:class => "edit_comment"}) do |f| %> + <%= f.hidden_field :post_id %> <%= dtext_field "comment", "body", :value => comment.body, :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %> - <%= f.button :submit, "Submit" %> + <%= f.button :submit, "Submit", :data => { :disable_with => "Submitting..." } %> <%= dtext_preview_button "comment", "body", :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %> + <% if comment.new_record? %> + <%= f.input :do_not_bump_post, :label => "No bump" %> + <% end %> + <% if CurrentUser.is_moderator? %> + <%= f.input :is_sticky, :label => "Post as moderator" %> + <% end %> <% end %> diff --git a/app/views/comments/edit.html.erb b/app/views/comments/edit.html.erb index e68f0087c..26e62c7c5 100644 --- a/app/views/comments/edit.html.erb +++ b/app/views/comments/edit.html.erb @@ -2,13 +2,7 @@
<%= link_to "Post comment", new_comment_path, :class => "expand-comment-response" %>
- <%= render "comments/partials/new/form", :post => post %> + <%= render "comments/form", :post => post, :comment => post.comments.new %>