Commit 62c69722a012ea7770ae0e94ca30b2c899a01409

Authored by Rodrigo Souto
Committed by Daniela Feitosa
1 parent 3da73df7

Refactoring article lead and body

* Mergin all separate body and lead of all the article's type into one
    shared partial.
  * Adding the lead slide to the task (it was just showing instead of
    hiding and sliding when the 'Lead' button was clicked).

PS: This refactoring also fixes the AI1869.

(ActionItem1869)
app/views/cms/_event.rhtml
@@ -15,5 +15,4 @@ @@ -15,5 +15,4 @@
15 15
16 <%= labelled_form_field(_('Address:'), text_field(:article, :address)) %> 16 <%= labelled_form_field(_('Address:'), text_field(:article, :address)) %>
17 17
18 -<%= labelled_form_field(_('Information about the event:'), text_area(:article, :body, :cols => 64, :class => 'mceEditor')) %>  
19 - 18 +<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Information about the event:'} %>
app/views/cms/_textile_article.rhtml
@@ -5,17 +5,4 @@ @@ -5,17 +5,4 @@
5 <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %> 5 <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %>
6 6
7 <%= render :partial => 'translatable' %> 7 <%= render :partial => 'translatable' %>
8 -  
9 -<br style="clear: both;"/>  
10 -<%= button :add, _("Lead"), '#', :id => "lead-button", :style => "margin-left: 0px;" %>  
11 -<em><%= _('Used when a short version of your text is needed.') %></em>  
12 -  
13 -<div id="article-lead">  
14 - <%= labelled_form_field(_('Lead'), text_area(:article, 'abstract', :cols => 64, :rows => 10)) %>  
15 -</div>  
16 -<div style="margin-top: 10px;">  
17 - <%= labelled_form_field(_('Text'), text_area(:article, 'body', :cols => 64, :rows => 30)) %>  
18 -</div>  
19 -  
20 -<%= javascript_include_tag 'article'%>  
21 - 8 +<%= render :partial => 'shared/lead_and_body' %>
app/views/cms/_tiny_mce_article.rhtml
@@ -12,18 +12,5 @@ @@ -12,18 +12,5 @@
12 <% end %> 12 <% end %>
13 13
14 <%= render :partial => 'translatable' %> 14 <%= render :partial => 'translatable' %>
15 -  
16 - <br style="clear: both;"/>  
17 - <%= button :add, _("Lead"), '#', :id => "lead-button", :style => "margin-left: 0px;" %>  
18 - <em><%= _('Used when a short version of your text is needed.') %></em>  
19 -  
20 - <div id="article-lead">  
21 - <%= labelled_form_field(_('Lead'), text_area(:article, 'abstract', :style => 'width: 100%; height: 200px;', :class => 'mceEditor')) %>  
22 - </div>  
23 - <div style="margin-top: 10px;">  
24 - <%= labelled_form_field(_('Text'), text_area(:article, 'body', :style => 'width:100%; height: 500px;', :class => 'mceEditor')) %>  
25 - </div>  
26 - 15 + <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %>
27 </div> 16 </div>
28 -  
29 -<%= javascript_include_tag 'article' %>  
app/views/cms/suggest_an_article.rhtml
@@ -16,16 +16,7 @@ @@ -16,16 +16,7 @@
16 16
17 <%= required labelled_form_field(_('Email'), text_field(:task, 'email')) %> 17 <%= required labelled_form_field(_('Email'), text_field(:task, 'email')) %>
18 18
19 - <br style="clear: both;"/>  
20 - <%= button :add, _("Lead"), '#', :id => "lead-button", :style => "margin-left: 0px;" %>  
21 - <em><%= _('Used when a short version of your text is needed.') %></em>  
22 -  
23 - <div id="article-lead">  
24 - <%= labelled_form_field(_('Lead'), text_area(:task , 'article_abstract', :style => 'width: 100%; height: 200px;', :class => 'mceEditor')) %>  
25 - </div>  
26 - <div style="margin-top: 10px;">  
27 - <%= labelled_form_field(_('Text'), text_area(:task, 'article_body', :style => 'width:100%; height: 500px;', :class => 'mceEditor')) %>  
28 - </div> 19 + <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :object => :task, :abstract_method => 'article_abstract', :body_method => 'article_body'} %>
29 20
30 <div id="captcha"> 21 <div id="captcha">
31 <%= labelled_form_field(_("What is the result of '%s = ?'") % @task.captcha.task, text_field(:task, 'captcha_solution')) %> 22 <%= labelled_form_field(_("What is the result of '%s = ?'") % @task.captcha.task, text_field(:task, 'captcha_solution')) %>
@@ -39,5 +30,3 @@ @@ -39,5 +30,3 @@
39 <%= button :cancel, _('Cancel'), @back_to %> 30 <%= button :cancel, _('Cancel'), @back_to %>
40 <% end %> 31 <% end %>
41 <% end %> 32 <% end %>
42 -  
43 -<%= javascript_include_tag 'article' %>  
app/views/shared/_lead_and_body.rhtml 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +<% object ||= :article %>
  2 +<% abstract_label ||= 'Lead' %>
  3 +<% abstract_method ||= :abstract %>
  4 +<% body_label ||= 'Text' %>
  5 +<% body_method ||= :body %>
  6 +<% editor_type = defined?(tiny_mce) && tiny_mce ? 'mceEditor' : '' %>
  7 +<% lead_id ||= 0%>
  8 +<% f ||= false%>
  9 +
  10 +<br style="clear: both;"/>
  11 +<%= button :add, _("Lead"), '#', :class => "lead-button", :article_id => "#article-lead-"+lead_id.to_s, :style => "margin-left: 0px;" %>
  12 +<em><%= _('Used when a short version of your text is needed.') %></em>
  13 +
  14 +<div class='article-lead' id="article-lead-<%=lead_id.to_s%>">
  15 + <% if f %>
  16 + <%= labelled_form_field(_(abstract_label), f.text_area(abstract_method, :style => 'width: 98%; height: 200px;', :class => editor_type)) %>
  17 + <% else %>
  18 + <%= labelled_form_field(_(abstract_label), text_area(object, abstract_method, :style => 'width: 98%; height: 200px;', :class => editor_type)) %>
  19 + <% end %>
  20 +</div>
  21 +<div style="margin-top: 10px;">
  22 + <% if f %>
  23 + <%= labelled_form_field(_(body_label), f.text_area(body_method, :style => 'width: 98%; height: 400px;', :class => editor_type)) %>
  24 + <% else %>
  25 + <%= labelled_form_field(_(body_label), text_area(object, body_method, :style => 'width: 98%; height: 400px;', :class => editor_type)) %>
  26 + <% end %>
  27 +</div>
  28 +
  29 +<%= javascript_include_tag 'article'%>
app/views/tasks/_approve_article_accept_details.rhtml
@@ -4,21 +4,8 @@ @@ -4,21 +4,8 @@
4 <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task]", 'article_parent_id', task.target) %> 4 <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task]", 'article_parent_id', task.target) %>
5 <%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %> 5 <%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %>
6 6
7 -<div>  
8 - <% if task.article && task.article.tiny_mce? %>  
9 - <%= labelled_form_field(_('Lead'), f.text_area(:abstract, :style => 'width: 482px; height: 200px;', :class => 'mceEditor')) %>  
10 - <% else %>  
11 - <%= labelled_form_field(_('Lead'), f.text_area(:abstract, :style => 'width: 482px; height: 200px;')) %>  
12 - <% end %>  
13 -</div>  
14 -<em><%= _('Used when a short version your text is needed.') %></em> 7 +<% tiny = task.article && task.article.tiny_mce? ? {:tiny_mce => true} : {} %>
  8 +<%= render :partial => 'shared/lead_and_body', :locals => {:lead_id => task.id, :f => f}.merge(tiny)%>
15 9
16 -<div style="margin-top: 10px;">  
17 - <% if task.article && task.article.tiny_mce? %>  
18 - <%= labelled_form_field(_('Text'), f.text_area(:body, :style => 'width:482px; height: 500px;', :class => 'mceEditor')) %>  
19 - <% else %>  
20 - <%= labelled_form_field(_('Text'), f.text_area(:body, :style => 'width:482px; height: 500px;')) %>  
21 - <% end %>  
22 -</div>  
23 <%= labelled_form_field _('Comment for author'), f.text_field(:closing_statment, :style => 'width: 488px;') %> 10 <%= labelled_form_field _('Comment for author'), f.text_field(:closing_statment, :style => 'width: 488px;') %>
24 11
app/views/tasks/_suggest_article_accept_details.rhtml
@@ -9,11 +9,4 @@ @@ -9,11 +9,4 @@
9 <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task]", 'article_parent_id', task.target) %> 9 <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task]", 'article_parent_id', task.target) %>
10 <%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %> 10 <%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %>
11 11
12 -<div>  
13 - <%= labelled_form_field(_('Lead'), f.text_area(:article_abstract, :style => 'width: 482px; height: 200px;', :class => 'mceEditor')) %>  
14 -</div>  
15 -<em><%= _('Used when a short version your text is needed.') %></em>  
16 -  
17 -<div style="margin-top: 10px;">  
18 - <%= labelled_form_field(_('Text'), f.text_area(:article_body, :style => 'width:482px; height: 500px;', :class => 'mceEditor')) %>  
19 -</div> 12 +<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :f => f, :abstract_method => 'article_abstract', :body_method => 'article_body', :lead_id => task.id} %>
features/events.feature
@@ -206,3 +206,27 @@ Feature: events @@ -206,3 +206,27 @@ Feature: events
206 When I am on /profile/josesilva/events/2009/10/25 206 When I am on /profile/josesilva/events/2009/10/25
207 Then I should see "Unpublished event" 207 Then I should see "Unpublished event"
208 And I should see "25" link 208 And I should see "25" link
  209 +
  210 + Scenario: events have lead field
  211 + Given I am logged in as "josesilva"
  212 + And I am on josesilva's Event creation
  213 + Then I should see "Lead"
  214 +
  215 + Scenario: events lead should be shown on blogs with short format
  216 + Given I am logged in as "josesilva"
  217 + And I am on josesilva's control panel
  218 + And I follow "Configure blog"
  219 + And I select "First paragraph" from "How to display posts:"
  220 + And I press "Save"
  221 + And I follow "New post"
  222 + And I follow "Event"
  223 + And I follow "Lead"
  224 + And I fill in the following:
  225 + | Title | Leaded event |
  226 + | Information about the event | This is the real text.|
  227 + | Lead | This is the abstract. |
  228 + And I press "Save"
  229 + When I am on josesilva's blog
  230 + Then I should see "Leaded event"
  231 + And I should see "This is the abstract."
  232 + And I should not see "This is the real text."
features/suggest_article.feature
@@ -21,3 +21,24 @@ Feature: suggest article @@ -21,3 +21,24 @@ Feature: suggest article
21 And I follow "Process requests" 21 And I follow "Process requests"
22 And I should see "suggested the publication of the article" 22 And I should see "suggested the publication of the article"
23 Then I should see "Highlight this article" within ".task_box" 23 Then I should see "Highlight this article" within ".task_box"
  24 +
  25 + Scenario: an article is suggested and the admin approve it
  26 + Given I am on Sample Community's blog
  27 + And I follow "Suggest an article"
  28 + And I fill in the following:
  29 + | Title | Suggestion |
  30 + | Your name | Some Guy |
  31 + | Email | someguy@somewhere.com |
  32 + | Lead | This is my suggestion's lead |
  33 + | Text | I like free software |
  34 + And I press "Save"
  35 + And I am logged in as "joaosilva"
  36 + And I go to Sample Community's control panel
  37 + When I follow "Process requests"
  38 + Then I should see "suggested the publication of the article: Suggestion."
  39 + When I choose "Accept"
  40 + And I select "sample-community/Blog" from "Select the folder where the article must be published"
  41 + And I press "Apply!"
  42 + And I go to Sample Community's blog
  43 + Then I should see "Suggestion"
  44 + Then I should see "I like free software"
features/support/paths.rb
@@ -27,6 +27,12 @@ module NavigationHelpers @@ -27,6 +27,12 @@ module NavigationHelpers
27 when /^(.*)'s homepage$/ 27 when /^(.*)'s homepage$/
28 '/%s' % Profile.find_by_name($1).identifier 28 '/%s' % Profile.find_by_name($1).identifier
29 29
  30 + when /^(.*)'s blog$/
  31 + '/%s/blog' % Profile.find_by_name($1).identifier
  32 +
  33 + when /^(.*)'s (.+) creation$/
  34 + '/myprofile/%s/cms/new?type=%s' % [Profile.find_by_name($1).identifier,$2]
  35 +
30 when /^(.*)'s sitemap/ 36 when /^(.*)'s sitemap/
31 '/profile/%s/sitemap' % Profile.find_by_name($1).identifier 37 '/profile/%s/sitemap' % Profile.find_by_name($1).identifier
32 38
public/javascripts/article.js
1 (function($) { 1 (function($) {
2 - $("#lead-button").click(function(){ 2 + $(".lead-button").live('click', function(){
  3 + article_id = this.getAttribute("article_id");
3 $(this).toggleClass('icon-add').toggleClass('icon-remove'); 4 $(this).toggleClass('icon-add').toggleClass('icon-remove');
4 - $('#article-lead').slideToggle(); 5 + $(article_id).slideToggle();
5 return false; 6 return false;
6 }) 7 })
7 $("#body-button").click(function(){ 8 $("#body-button").click(function(){
public/stylesheets/application.css
@@ -1004,7 +1004,7 @@ code input { @@ -1004,7 +1004,7 @@ code input {
1004 font-weight: normal; 1004 font-weight: normal;
1005 } 1005 }
1006 1006
1007 -#article-lead, 1007 +.article-lead,
1008 #article-body-field { 1008 #article-body-field {
1009 margin-top: 10px; 1009 margin-top: 10px;
1010 display: none; 1010 display: none;