Commit 134036ebcb6bad31ffce9436afa4ba8d81c0797b
1 parent
1f5c99ee
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
saving selected content
Showing
5 changed files
with
44 additions
and
8 deletions
Show diff stats
plugins/comment_paragraph/lib/comment_paragraph_plugin.rb
... | ... | @@ -19,7 +19,8 @@ class CommentParagraphPlugin < Noosfero::Plugin |
19 | 19 | arr = [] |
20 | 20 | arr << hidden_field_tag('comment[id]', comment.id) |
21 | 21 | arr << hidden_field_tag('comment[paragraph_id]', paragraph_id) if paragraph_id |
22 | - arr << hidden_field_tag('comment[comment_paragraph_selected_area]', comment.comment_paragraph_selected_area) if comment.comment_paragraph_selected_area | |
22 | + arr << hidden_field_tag('comment[comment_paragraph_selected_area]', comment.comment_paragraph_selected_area) unless comment.comment_paragraph_selected_area.blank? | |
23 | + arr << hidden_field_tag('comment[comment_paragraph_selected_content]', comment.comment_paragraph_selected_content) unless comment.comment_paragraph_selected_content.blank? | |
23 | 24 | arr |
24 | 25 | } |
25 | 26 | end | ... | ... |
plugins/comment_paragraph/lib/ext/comment.rb
... | ... | @@ -3,14 +3,20 @@ require_dependency 'comment' |
3 | 3 | class Comment |
4 | 4 | |
5 | 5 | scope :without_paragraph, :conditions => {:paragraph_id => nil } |
6 | - | |
6 | + | |
7 | 7 | settings_items :comment_paragraph_selected_area, :type => :string |
8 | - | |
8 | + settings_items :comment_paragraph_selected_content, :type => :string | |
9 | + | |
9 | 10 | scope :in_paragraph, proc { |paragraph_id| { |
10 | 11 | :conditions => ['paragraph_id = ?', paragraph_id] |
11 | 12 | } |
12 | 13 | } |
13 | 14 | |
14 | - attr_accessible :paragraph_id, :comment_paragraph_selected_area, :id | |
15 | + attr_accessible :paragraph_id, :comment_paragraph_selected_area, :id, :comment_paragraph_selected_content | |
16 | + | |
17 | + before_validation do |comment| | |
18 | + comment.comment_paragraph_selected_area = nil if comment.comment_paragraph_selected_area.blank? | |
19 | + comment.comment_paragraph_selected_content = nil if comment_paragraph_selected_content.blank? | |
20 | + end | |
15 | 21 | |
16 | 22 | end | ... | ... |
plugins/comment_paragraph/public/comment_paragraph_macro.js
... | ... | @@ -40,6 +40,12 @@ jQuery(document).ready(function($) { |
40 | 40 | return false; |
41 | 41 | }); |
42 | 42 | |
43 | + //Clears all old selected_area and selected_content after submit comment | |
44 | + $('[name|=commit]').click(function(){ | |
45 | + $('.selected_area').val(""); | |
46 | + $('.selected_content').val(""); | |
47 | + }); | |
48 | + | |
43 | 49 | $('#cancel-comment').die(); |
44 | 50 | $(document.body).on("click", '#cancel-comment', function(){ |
45 | 51 | $("div.side-comment").hide(); |
... | ... | @@ -51,7 +57,7 @@ jQuery(document).ready(function($) { |
51 | 57 | div.addClass('opened'); |
52 | 58 | } |
53 | 59 | } |
54 | - | |
60 | + | |
55 | 61 | rangy.init(); |
56 | 62 | cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false}); |
57 | 63 | //Add marked text bubble |
... | ... | @@ -164,9 +170,9 @@ jQuery(document).ready(function($) { |
164 | 170 | } catch(e) { |
165 | 171 | return; |
166 | 172 | } |
173 | + form = $('#page-comment-form-' + paragraphId).find('form'); | |
167 | 174 | |
168 | 175 | //Register the area the has been selected at input.selected_area |
169 | - form = $('#page-comment-form-' + paragraphId).find('form'); | |
170 | 176 | if (form.find('input.selected_area').length === 0){ |
171 | 177 | $('<input>').attr({ |
172 | 178 | class: 'selected_area', |
... | ... | @@ -177,8 +183,20 @@ jQuery(document).ready(function($) { |
177 | 183 | }else{ |
178 | 184 | form.find('input.selected_area').val(selected_area) |
179 | 185 | } |
186 | + //Register the content being selected at input.comment_paragraph_selected_content | |
187 | + var selected_content = getSelectionText(); | |
188 | + if(selected_content.length > 0) | |
189 | + if (form.find('input.selected_content').length === 0){ | |
190 | + $('<input>').attr({ | |
191 | + class: 'selected_content', | |
192 | + type: 'hidden', | |
193 | + name: 'comment[comment_paragraph_selected_content]', | |
194 | + value: selected_content | |
195 | + }).appendTo(form) | |
196 | + }else{ | |
197 | + form.find('input.selected_content').val(selected_content) | |
198 | + } | |
180 | 199 | rootElement.focus(); |
181 | - | |
182 | 200 | }); |
183 | 201 | |
184 | 202 | function processAnchor(){ | ... | ... |
plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | +include ActionView::Helpers::FormTagHelper | |
2 | 3 | |
3 | 4 | class CommentParagraphPluginTest < ActiveSupport::TestCase |
4 | 5 | |
... | ... | @@ -25,4 +26,13 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
25 | 26 | assert plugin.stylesheet? |
26 | 27 | end |
27 | 28 | |
29 | + should 'not add comment_paragraph_selected_area if comment_paragraph_selected_area is blank' do | |
30 | + comment = Comment.new | |
31 | + comment.comment_paragraph_selected_area = "" | |
32 | + comment.paragraph_id = 2 | |
33 | + cpp = CommentParagraphPlugin.new | |
34 | + prok = cpp.comment_form_extra_contents({:comment=>comment, :paragraph_id=>4}) | |
35 | + assert_nil /comment_paragraph_selected_area/.match(prok.call.inspect) | |
36 | + end | |
37 | + | |
28 | 38 | end | ... | ... |
plugins/comment_paragraph/views/comment/comment_extra.html.erb
1 | 1 | <input type="hidden" value="<%= comment.comment_paragraph_selected_area%>" class="paragraph_comment_area" /> |
2 | -<input type="hidden" value="<%= comment.paragraph_id%>" class="paragraph_id" /> | |
2 | +<input type="hidden" value="<%= comment.paragraph_id%>" class="paragraph_id" /><input type="hidden" value="<%= comment.comment_paragraph_selected_content%>" class="paragraph_selected_content" /> | |
3 | +<input type="hidden" value="<%= comment.comment_paragraph_selected_content%>" class="paragraph_selected_content" /> | ... | ... |