Commit 815ab990059907fff601f5f6d60658dcbf66c504
1 parent
f031d101
Exists in
staging
and in
4 other branches
validation to forbbid changes to commented articles
Showing
2 changed files
with
12 additions
and
30 deletions
Show diff stats
plugins/comment_paragraph/lib/ext/article.rb
... | ... | @@ -4,15 +4,14 @@ class Article |
4 | 4 | |
5 | 5 | has_many :paragraph_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'paragraph_id IS NOT NULL'] |
6 | 6 | |
7 | - validate :not_empty_paragraph_comments_removed | |
7 | + validate :body_change_with_comments | |
8 | 8 | |
9 | - def not_empty_paragraph_comments_removed | |
10 | - if body && body_changed? | |
11 | - paragraphs_with_comments = Comment.find(:all, :select => 'distinct paragraph_id', :conditions => {:source_id => self.id}).map(&:paragraph_id).compact | |
12 | - paragraphs = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-paragraph_id'].to_i} | |
13 | - errors[:base] << (N_('Not empty paragraph comment cannot be removed')) unless (paragraphs_with_comments-paragraphs).empty? | |
9 | + def body_change_with_comments | |
10 | + if body && body_changed? && !self.comments.empty? | |
11 | + paragraphs_with_comments = self.comments.where("'article_id' IS NOT NULL") | |
12 | + errors[:base] << (N_('You are unable to change the body of the article when paragraphs are commented')) unless (paragraphs_with_comments).empty? | |
14 | 13 | end |
15 | 14 | end |
16 | - | |
15 | + | |
17 | 16 | end |
18 | 17 | ... | ... |
plugins/comment_paragraph/public/comment_paragraph_macro.js
1 | 1 | var comment_paragraph_anchor; |
2 | - | |
3 | -function _a(x,y,val){ | |
4 | - // return depending on parameters | |
5 | - switch(arguments.length){ | |
6 | - case 0: return _a.a; | |
7 | - case 1: return _a.a[x]; | |
8 | - case 2: return _a.a[x][y]; | |
9 | - } | |
10 | - | |
11 | - // declare array if wasn't declared yet | |
12 | - if(typeof _a.a[x] == 'undefined') | |
13 | - _a.a[x] = []; | |
14 | - | |
15 | - _a.a[x][y] = val; | |
16 | -} | |
17 | -// declare static empty variable | |
18 | -_a.a = []; | |
19 | - | |
20 | -var ParagraphSelectionCache = {}; | |
21 | 2 | var lastParagraph = []; |
22 | 3 | var lastSelectedArea = []; |
23 | 4 | |
24 | - | |
25 | 5 | function getIdCommentParagraph(paragraphId){ |
26 | 6 | var idx = paragraphId.lastIndexOf('_'); |
27 | 7 | return paragraphId.substring(idx+1, paragraphId.length) |
... | ... | @@ -121,13 +101,16 @@ jQuery(document).ready(function($) { |
121 | 101 | } |
122 | 102 | |
123 | 103 | //console.log(rootElement.innerHTML); |
124 | - console.log(selected_area); | |
125 | - rangy.deserializeSelection(selected_area, rootElement); | |
126 | - cssApplier.toggleSelection(); | |
104 | + console.log("selected_area = '" + selected_area + "'"); | |
105 | + if(selected_area != ""){ | |
106 | + rangy.deserializeSelection(selected_area, rootElement); | |
107 | + cssApplier.toggleSelection(); | |
108 | + } | |
127 | 109 | }); |
128 | 110 | |
129 | 111 | $(document).on('mouseout', 'li.article-comment', function(){ |
130 | 112 | var paragraph_id = $(this).find('input.paragraph_id').val(); |
113 | + console.log("mouseout paragraph_id = " + paragraph_id); | |
131 | 114 | var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); |
132 | 115 | console.log(lastParagraph[paragraph_id]); |
133 | 116 | ... | ... |