Commit b6e26e934c993e263a838f358e05f854e044c0ab
1 parent
5aa7a5fa
Exists in
master
and in
4 other branches
Backend structure to create responses for proposals
Showing
8 changed files
with
185 additions
and
0 deletions
Show diff stats
lib/proposals_discussion_plugin.rb
| ... | ... | @@ -17,6 +17,7 @@ class ProposalsDiscussionPlugin < Noosfero::Plugin |
| 17 | 17 | types = [] |
| 18 | 18 | parent_id = context.params[:parent_id] || (context.params[:article][:parent_id] unless context.params[:article].nil?) |
| 19 | 19 | parent = parent_id.present? ? context.profile.articles.find(parent_id) : nil |
| 20 | + types << ProposalsDiscussionPlugin::Response | |
| 20 | 21 | types << ProposalsDiscussionPlugin::Discussion |
| 21 | 22 | types << ProposalsDiscussionPlugin::Topic if parent.kind_of?(ProposalsDiscussionPlugin::Discussion) |
| 22 | 23 | if parent.kind_of?(ProposalsDiscussionPlugin::Topic) || ( parent.kind_of?(ProposalsDiscussionPlugin::Discussion) && !parent.allow_topics) |
| ... | ... | @@ -52,6 +53,14 @@ class ProposalsDiscussionPlugin < Noosfero::Plugin |
| 52 | 53 | [ProposalsDiscussionPlugin::API] |
| 53 | 54 | end |
| 54 | 55 | |
| 56 | + def extra_content_actions(article) | |
| 57 | + proc do | |
| 58 | + if article.kind_of? ProposalsDiscussionPlugin::Proposal | |
| 59 | + render :partial => 'proposals_discussion/view_item_buttons', :locals => {:article => article} | |
| 60 | + end | |
| 61 | + end | |
| 62 | + end | |
| 63 | + | |
| 55 | 64 | # schedule ranking job in initialization process |
| 56 | 65 | ProposalsDiscussionPlugin::RankingJob.new.schedule |
| 57 | 66 | ... | ... |
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +class ProposalsDiscussionPlugin::Response < TinyMceArticle | |
| 2 | + | |
| 3 | + validates_presence_of :body | |
| 4 | + | |
| 5 | + validate :check_parent_type | |
| 6 | + | |
| 7 | + def self.short_description | |
| 8 | + _("Proposal Response") | |
| 9 | + end | |
| 10 | + | |
| 11 | + def self.description | |
| 12 | + _("The response of a Proposal") | |
| 13 | + end | |
| 14 | + | |
| 15 | + protected | |
| 16 | + | |
| 17 | + def check_parent_type | |
| 18 | + unless parent.is_a? ProposalsDiscussionPlugin::Proposal | |
| 19 | + errors.add(:parent, N_('of Response needs be a Proposal')) | |
| 20 | + end | |
| 21 | + | |
| 22 | + # if self.body_changed? && (self.changed & attrs_validators).any? | |
| 23 | + # errors.add(:response, N_('only have "body" field')) | |
| 24 | + # end | |
| 25 | + end | |
| 26 | + | |
| 27 | +end | ... | ... |
196 Bytes
public/style.css
test/unit/proposal_test.rb
| ... | ... | @@ -124,4 +124,36 @@ class ProposalTest < ActiveSupport::TestCase |
| 124 | 124 | assert_equal [location], proposal.locations |
| 125 | 125 | end |
| 126 | 126 | |
| 127 | + should 'add a response to a proposal' do | |
| 128 | + proposal.save! | |
| 129 | + data = { | |
| 130 | + :name => 'Response', | |
| 131 | + :body => 'A response test', | |
| 132 | + :abstract => 'Test', | |
| 133 | + :parent => proposal, | |
| 134 | + :profile => profile | |
| 135 | + } | |
| 136 | + | |
| 137 | + response = create(ProposalsDiscussionPlugin::Response, data) | |
| 138 | + response.save! | |
| 139 | + | |
| 140 | + assert_equal proposal.id, response.parent.id | |
| 141 | + end | |
| 142 | + | |
| 143 | + should 'not add a response to a proposal without a body' do | |
| 144 | + proposal.save! | |
| 145 | + data = { | |
| 146 | + :name => 'Response', | |
| 147 | + :abstract => 'Test', | |
| 148 | + :parent => proposal, | |
| 149 | + :profile => profile | |
| 150 | + } | |
| 151 | + | |
| 152 | + err = assert_raises ActiveRecord::RecordInvalid do | |
| 153 | + response = create(ProposalsDiscussionPlugin::Response, data) | |
| 154 | + end | |
| 155 | + | |
| 156 | + assert_match "Body can't be blank", err.message | |
| 157 | + end | |
| 158 | + | |
| 127 | 159 | end | ... | ... |
| ... | ... | @@ -0,0 +1,79 @@ |
| 1 | +<%= error_messages_for 'article' %> | |
| 2 | + | |
| 3 | +<% if @article.archived? %> | |
| 4 | + <%= render :partial => 'archived_warning', :locals => {:article => @article} %> | |
| 5 | +<% end %> | |
| 6 | +<div class='<%= (@article.display_media_panel? ? 'with_media_panel' : 'no_media_panel') %>'> | |
| 7 | +<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> | |
| 8 | + | |
| 9 | + <%= hidden_field_tag("type", @type) if @type %> | |
| 10 | + | |
| 11 | + <%= hidden_field_tag('back_to', @back_to) %> | |
| 12 | + | |
| 13 | + <%= hidden_field_tag('success_back_to', @success_back_to) %> | |
| 14 | + | |
| 15 | + | |
| 16 | + <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> | |
| 17 | + | |
| 18 | + <% if environment.is_portal_community?(profile) %> | |
| 19 | + <div> | |
| 20 | + <%= check_box(:article, :highlighted) %> | |
| 21 | + <label for="article_highlighted"><%= _('Highlight this article')%></label> | |
| 22 | + </div> | |
| 23 | + <% end %> | |
| 24 | + | |
| 25 | + <% button_bar do %> | |
| 26 | + <%= submit_button :save, _('Save') %> | |
| 27 | + <%= submit_button :save, _('Save and continue'), :name => "continue" %> | |
| 28 | + <% end %> | |
| 29 | + | |
| 30 | + <% unless @article.kind_of?(ProposalsDiscussionPlugin::Response) %> | |
| 31 | + <div style='float: right'> | |
| 32 | + <%= modal_button :help, _('Why categorize?'), :action => 'why_categorize' %> | |
| 33 | + </div> | |
| 34 | + | |
| 35 | + <%= select_categories(:article, _('Categorize your article')) %> | |
| 36 | + | |
| 37 | + <br /> | |
| 38 | + | |
| 39 | + <%= f.text_field('tag_list', :size => 64) %> | |
| 40 | + <%= content_tag( 'small', _('Separate tags with commas') ) %> | |
| 41 | + | |
| 42 | + <script> | |
| 43 | + jQuery('#article_tag_list').inputosaurus({ | |
| 44 | + autoCompleteSource: <%= "'/myprofile/#{profile.identifier}/cms/search_tags'," %> | |
| 45 | + activateFinalResult : true | |
| 46 | + }) | |
| 47 | + </script> | |
| 48 | + | |
| 49 | + <div id='edit-article-options'> | |
| 50 | + <%= options_for_article(@article, @tokenized_children) %> | |
| 51 | + </div> | |
| 52 | + | |
| 53 | + <% button_bar do %> | |
| 54 | + <%= submit_button :save, _('Save') %> | |
| 55 | + | |
| 56 | + <% if @back_to %> | |
| 57 | + <%= button :cancel, _('Cancel'), @back_to %> | |
| 58 | + <% elsif @parent_id || @article.parent %> | |
| 59 | + <%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %> | |
| 60 | + <% else %> | |
| 61 | + <%= button :cancel, _('Cancel'), :action => 'index' %> | |
| 62 | + <% end %> | |
| 63 | + | |
| 64 | + <% unless @article.new_record? %> | |
| 65 | + <%= button :delete, _('Delete'), {:controller => :cms, :action => :destroy, :id => @article}, | |
| 66 | + :method => :post, :confirm => delete_article_message(@article) %> | |
| 67 | + <% end %> | |
| 68 | + <% end %> | |
| 69 | + <% end %> | |
| 70 | +<% end %> | |
| 71 | +</div> | |
| 72 | + | |
| 73 | +<% if @article.display_media_panel? %> | |
| 74 | + <%= render :partial => 'text_editor_sidebar' %> | |
| 75 | +<% end %> | |
| 76 | + | |
| 77 | +<br style='clear: both'/> | |
| 78 | + | |
| 79 | +<%= javascript_include_tag "article.js" %> | ... | ... |
views/cms/proposals_discussion_plugin/_response.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +<%= required_fields_message %> | |
| 2 | + | |
| 3 | +<%= render :file => 'shared/tiny_mce' %> | |
| 4 | + | |
| 5 | +<% title_limit = 70 %> | |
| 6 | +<% abstract_limit = 140 %> | |
| 7 | + | |
| 8 | +<div class="proposals-discussion-plugin"> | |
| 9 | + | |
| 10 | + <div class="title"> | |
| 11 | + <%= required labelled_form_field _('Title'), limited_text_area(:article, :name, title_limit, 'title_textarea', :rows => 1) %> | |
| 12 | + </div> | |
| 13 | + | |
| 14 | + <%= select_profile_folder(_('Parent folder:'), 'article[parent_id]', profile, @article.parent_id, {},{},{},:include_articles => true) %> | |
| 15 | + | |
| 16 | + <div class="body"> | |
| 17 | + <%= labelled_form_field(_('Response'), text_area(:article, :body, :class => 'mceEditor')) %> | |
| 18 | + </div> | |
| 19 | + | |
| 20 | + <%= hidden_field(:article, :parent_id) %> | |
| 21 | +</div> | |
| 22 | + | |
| 23 | +<script> | |
| 24 | +jQuery( document ).ready(function( $ ) { | |
| 25 | + limited_text_area('title_textarea', <%= title_limit %>); | |
| 26 | + limited_text_area('abstract_textarea', <%= abstract_limit %>); | |
| 27 | +}); | |
| 28 | +</script> | ... | ... |
| ... | ... | @@ -0,0 +1,6 @@ |
| 1 | +<%= link_to( | |
| 2 | + content_tag('span', _('Reply') ), | |
| 3 | + {:action => 'new', :cms => true, :parent_id => article.id, :type => 'ProposalsDiscussionPlugin::Response', :back_to => request.original_url}, | |
| 4 | + {:class => 'button icon-child-article', :title => _('Reply') } | |
| 5 | + ) | |
| 6 | +%> | ... | ... |