diff --git a/lib/proposals_discussion_plugin.rb b/lib/proposals_discussion_plugin.rb index edec7a2..dbe6db5 100644 --- a/lib/proposals_discussion_plugin.rb +++ b/lib/proposals_discussion_plugin.rb @@ -17,6 +17,7 @@ class ProposalsDiscussionPlugin < Noosfero::Plugin types = [] parent_id = context.params[:parent_id] || (context.params[:article][:parent_id] unless context.params[:article].nil?) parent = parent_id.present? ? context.profile.articles.find(parent_id) : nil + types << ProposalsDiscussionPlugin::Response types << ProposalsDiscussionPlugin::Discussion types << ProposalsDiscussionPlugin::Topic if parent.kind_of?(ProposalsDiscussionPlugin::Discussion) if parent.kind_of?(ProposalsDiscussionPlugin::Topic) || ( parent.kind_of?(ProposalsDiscussionPlugin::Discussion) && !parent.allow_topics) @@ -52,6 +53,14 @@ class ProposalsDiscussionPlugin < Noosfero::Plugin [ProposalsDiscussionPlugin::API] end + def extra_content_actions(article) + proc do + if article.kind_of? ProposalsDiscussionPlugin::Proposal + render :partial => 'proposals_discussion/view_item_buttons', :locals => {:article => article} + end + end + end + # schedule ranking job in initialization process ProposalsDiscussionPlugin::RankingJob.new.schedule diff --git a/lib/proposals_discussion_plugin/response.rb b/lib/proposals_discussion_plugin/response.rb new file mode 100644 index 0000000..9913560 --- /dev/null +++ b/lib/proposals_discussion_plugin/response.rb @@ -0,0 +1,27 @@ +class ProposalsDiscussionPlugin::Response < TinyMceArticle + + validates_presence_of :body + + validate :check_parent_type + + def self.short_description + _("Proposal Response") + end + + def self.description + _("The response of a Proposal") + end + + protected + + def check_parent_type + unless parent.is_a? ProposalsDiscussionPlugin::Proposal + errors.add(:parent, N_('of Response needs be a Proposal')) + end + + # if self.body_changed? && (self.changed & attrs_validators).any? + # errors.add(:response, N_('only have "body" field')) + # end + end + +end diff --git a/public/images/reply.png b/public/images/reply.png new file mode 100644 index 0000000..19d3dc2 Binary files /dev/null and b/public/images/reply.png differ diff --git a/public/style.css b/public/style.css index 9b1f5f6..33fbb40 100644 --- a/public/style.css +++ b/public/style.css @@ -402,3 +402,7 @@ div.confirm_evaluation_button a.disabled { margin-top: 15px; margin-left: 10px; } + +.icon-child-article { + background-image: url('/plugins/proposals_discussion/images/reply.png'); +} diff --git a/test/unit/proposal_test.rb b/test/unit/proposal_test.rb index 877bfdc..e9dad70 100644 --- a/test/unit/proposal_test.rb +++ b/test/unit/proposal_test.rb @@ -124,4 +124,36 @@ class ProposalTest < ActiveSupport::TestCase assert_equal [location], proposal.locations end + should 'add a response to a proposal' do + proposal.save! + data = { + :name => 'Response', + :body => 'A response test', + :abstract => 'Test', + :parent => proposal, + :profile => profile + } + + response = create(ProposalsDiscussionPlugin::Response, data) + response.save! + + assert_equal proposal.id, response.parent.id + end + + should 'not add a response to a proposal without a body' do + proposal.save! + data = { + :name => 'Response', + :abstract => 'Test', + :parent => proposal, + :profile => profile + } + + err = assert_raises ActiveRecord::RecordInvalid do + response = create(ProposalsDiscussionPlugin::Response, data) + end + + assert_match "Body can't be blank", err.message + end + end diff --git a/views/cms/edit.html.erb b/views/cms/edit.html.erb new file mode 100644 index 0000000..0b788f8 --- /dev/null +++ b/views/cms/edit.html.erb @@ -0,0 +1,79 @@ +<%= error_messages_for 'article' %> + +<% if @article.archived? %> + <%= render :partial => 'archived_warning', :locals => {:article => @article} %> +<% end %> +