diff --git a/lib/ext/article.rb b/lib/ext/article.rb index 9fcc072..eb01c04 100644 --- a/lib/ext/article.rb +++ b/lib/ext/article.rb @@ -4,15 +4,14 @@ class Article has_many :paragraph_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'paragraph_id IS NOT NULL'] - validate :not_empty_paragraph_comments_removed + validate :body_change_with_comments - def not_empty_paragraph_comments_removed - if body && body_changed? - paragraphs_with_comments = Comment.find(:all, :select => 'distinct paragraph_id', :conditions => {:source_id => self.id}).map(&:paragraph_id).compact - paragraphs = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-paragraph_id'].to_i} - errors[:base] << (N_('Not empty paragraph comment cannot be removed')) unless (paragraphs_with_comments-paragraphs).empty? + def body_change_with_comments + if body && body_changed? && !self.comments.empty? + paragraphs_with_comments = self.comments.where("'article_id' IS NOT NULL") + errors[:base] << (N_('You are unable to change the body of the article when paragraphs are commented')) unless (paragraphs_with_comments).empty? end end - + end diff --git a/public/comment_paragraph_macro.js b/public/comment_paragraph_macro.js index 8a3aa24..a8af011 100644 --- a/public/comment_paragraph_macro.js +++ b/public/comment_paragraph_macro.js @@ -1,27 +1,7 @@ var comment_paragraph_anchor; - -function _a(x,y,val){ - // return depending on parameters - switch(arguments.length){ - case 0: return _a.a; - case 1: return _a.a[x]; - case 2: return _a.a[x][y]; - } - - // declare array if wasn't declared yet - if(typeof _a.a[x] == 'undefined') - _a.a[x] = []; - - _a.a[x][y] = val; -} -// declare static empty variable -_a.a = []; - -var ParagraphSelectionCache = {}; var lastParagraph = []; var lastSelectedArea = []; - function getIdCommentParagraph(paragraphId){ var idx = paragraphId.lastIndexOf('_'); return paragraphId.substring(idx+1, paragraphId.length) @@ -121,13 +101,16 @@ jQuery(document).ready(function($) { } //console.log(rootElement.innerHTML); - console.log(selected_area); - rangy.deserializeSelection(selected_area, rootElement); - cssApplier.toggleSelection(); + console.log("selected_area = '" + selected_area + "'"); + if(selected_area != ""){ + rangy.deserializeSelection(selected_area, rootElement); + cssApplier.toggleSelection(); + } }); $(document).on('mouseout', 'li.article-comment', function(){ var paragraph_id = $(this).find('input.paragraph_id').val(); + console.log("mouseout paragraph_id = " + paragraph_id); var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); console.log(lastParagraph[paragraph_id]); -- libgit2 0.21.2