diff --git a/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb b/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb
index e30eb63..701e944 100644
--- a/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb
+++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb
@@ -19,7 +19,8 @@ class CommentParagraphPlugin < Noosfero::Plugin
arr = []
arr << hidden_field_tag('comment[id]', comment.id)
arr << hidden_field_tag('comment[paragraph_id]', paragraph_id) if paragraph_id
- arr << hidden_field_tag('comment[comment_paragraph_selected_area]', comment.comment_paragraph_selected_area) if comment.comment_paragraph_selected_area
+ arr << hidden_field_tag('comment[comment_paragraph_selected_area]', comment.comment_paragraph_selected_area) unless comment.comment_paragraph_selected_area.blank?
+ arr << hidden_field_tag('comment[comment_paragraph_selected_content]', comment.comment_paragraph_selected_content) unless comment.comment_paragraph_selected_content.blank?
arr
}
end
diff --git a/plugins/comment_paragraph/lib/ext/comment.rb b/plugins/comment_paragraph/lib/ext/comment.rb
index 225137b..5401e1f 100644
--- a/plugins/comment_paragraph/lib/ext/comment.rb
+++ b/plugins/comment_paragraph/lib/ext/comment.rb
@@ -3,14 +3,20 @@ require_dependency 'comment'
class Comment
scope :without_paragraph, :conditions => {:paragraph_id => nil }
-
+
settings_items :comment_paragraph_selected_area, :type => :string
-
+ settings_items :comment_paragraph_selected_content, :type => :string
+
scope :in_paragraph, proc { |paragraph_id| {
:conditions => ['paragraph_id = ?', paragraph_id]
}
}
- attr_accessible :paragraph_id, :comment_paragraph_selected_area, :id
+ attr_accessible :paragraph_id, :comment_paragraph_selected_area, :id, :comment_paragraph_selected_content
+
+ before_validation do |comment|
+ comment.comment_paragraph_selected_area = nil if comment.comment_paragraph_selected_area.blank?
+ comment.comment_paragraph_selected_content = nil if comment_paragraph_selected_content.blank?
+ end
end
diff --git a/plugins/comment_paragraph/public/comment_paragraph_macro.js b/plugins/comment_paragraph/public/comment_paragraph_macro.js
index 2cfc7f2..b86f13a 100644
--- a/plugins/comment_paragraph/public/comment_paragraph_macro.js
+++ b/plugins/comment_paragraph/public/comment_paragraph_macro.js
@@ -40,6 +40,12 @@ jQuery(document).ready(function($) {
return false;
});
+ //Clears all old selected_area and selected_content after submit comment
+ $('[name|=commit]').click(function(){
+ $('.selected_area').val("");
+ $('.selected_content').val("");
+ });
+
$('#cancel-comment').die();
$(document.body).on("click", '#cancel-comment', function(){
$("div.side-comment").hide();
@@ -51,7 +57,7 @@ jQuery(document).ready(function($) {
div.addClass('opened');
}
}
-
+
rangy.init();
cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false});
//Add marked text bubble
@@ -164,9 +170,9 @@ jQuery(document).ready(function($) {
} catch(e) {
return;
}
+ form = $('#page-comment-form-' + paragraphId).find('form');
//Register the area the has been selected at input.selected_area
- form = $('#page-comment-form-' + paragraphId).find('form');
if (form.find('input.selected_area').length === 0){
$('').attr({
class: 'selected_area',
@@ -177,8 +183,20 @@ jQuery(document).ready(function($) {
}else{
form.find('input.selected_area').val(selected_area)
}
+ //Register the content being selected at input.comment_paragraph_selected_content
+ var selected_content = getSelectionText();
+ if(selected_content.length > 0)
+ if (form.find('input.selected_content').length === 0){
+ $('').attr({
+ class: 'selected_content',
+ type: 'hidden',
+ name: 'comment[comment_paragraph_selected_content]',
+ value: selected_content
+ }).appendTo(form)
+ }else{
+ form.find('input.selected_content').val(selected_content)
+ }
rootElement.focus();
-
});
function processAnchor(){
diff --git a/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb b/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb
index 7700920..1866fb6 100644
--- a/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb
+++ b/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/../test_helper'
+include ActionView::Helpers::FormTagHelper
class CommentParagraphPluginTest < ActiveSupport::TestCase
@@ -25,4 +26,13 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase
assert plugin.stylesheet?
end
+ should 'not add comment_paragraph_selected_area if comment_paragraph_selected_area is blank' do
+ comment = Comment.new
+ comment.comment_paragraph_selected_area = ""
+ comment.paragraph_id = 2
+ cpp = CommentParagraphPlugin.new
+ prok = cpp.comment_form_extra_contents({:comment=>comment, :paragraph_id=>4})
+ assert_nil /comment_paragraph_selected_area/.match(prok.call.inspect)
+ end
+
end
diff --git a/plugins/comment_paragraph/views/comment/comment_extra.html.erb b/plugins/comment_paragraph/views/comment/comment_extra.html.erb
index 5fb240b..a775456 100644
--- a/plugins/comment_paragraph/views/comment/comment_extra.html.erb
+++ b/plugins/comment_paragraph/views/comment/comment_extra.html.erb
@@ -1,2 +1,3 @@
-
+
+
--
libgit2 0.21.2