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 %> +
'> +<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> + + <%= hidden_field_tag("type", @type) if @type %> + + <%= hidden_field_tag('back_to', @back_to) %> + + <%= hidden_field_tag('success_back_to', @success_back_to) %> + + + <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> + + <% if environment.is_portal_community?(profile) %> +
+ <%= check_box(:article, :highlighted) %> + +
+ <% end %> + + <% button_bar do %> + <%= submit_button :save, _('Save') %> + <%= submit_button :save, _('Save and continue'), :name => "continue" %> + <% end %> + + <% unless @article.kind_of?(ProposalsDiscussionPlugin::Response) %> +
+ <%= modal_button :help, _('Why categorize?'), :action => 'why_categorize' %> +
+ + <%= select_categories(:article, _('Categorize your article')) %> + +
+ + <%= f.text_field('tag_list', :size => 64) %> + <%= content_tag( 'small', _('Separate tags with commas') ) %> + + + +
+ <%= options_for_article(@article, @tokenized_children) %> +
+ + <% button_bar do %> + <%= submit_button :save, _('Save') %> + + <% if @back_to %> + <%= button :cancel, _('Cancel'), @back_to %> + <% elsif @parent_id || @article.parent %> + <%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %> + <% else %> + <%= button :cancel, _('Cancel'), :action => 'index' %> + <% end %> + + <% unless @article.new_record? %> + <%= button :delete, _('Delete'), {:controller => :cms, :action => :destroy, :id => @article}, + :method => :post, :confirm => delete_article_message(@article) %> + <% end %> + <% end %> + <% end %> +<% end %> +
+ +<% if @article.display_media_panel? %> + <%= render :partial => 'text_editor_sidebar' %> +<% end %> + +
+ +<%= javascript_include_tag "article.js" %> diff --git a/views/cms/proposals_discussion_plugin/_response.html.erb b/views/cms/proposals_discussion_plugin/_response.html.erb new file mode 100644 index 0000000..0ab4ad7 --- /dev/null +++ b/views/cms/proposals_discussion_plugin/_response.html.erb @@ -0,0 +1,28 @@ +<%= required_fields_message %> + +<%= render :file => 'shared/tiny_mce' %> + +<% title_limit = 70 %> +<% abstract_limit = 140 %> + +
+ +
+ <%= required labelled_form_field _('Title'), limited_text_area(:article, :name, title_limit, 'title_textarea', :rows => 1) %> +
+ + <%= select_profile_folder(_('Parent folder:'), 'article[parent_id]', profile, @article.parent_id, {},{},{},:include_articles => true) %> + +
+ <%= labelled_form_field(_('Response'), text_area(:article, :body, :class => 'mceEditor')) %> +
+ + <%= hidden_field(:article, :parent_id) %> +
+ + diff --git a/views/proposals_discussion/_view_item_buttons.html.erb b/views/proposals_discussion/_view_item_buttons.html.erb new file mode 100644 index 0000000..0267009 --- /dev/null +++ b/views/proposals_discussion/_view_item_buttons.html.erb @@ -0,0 +1,6 @@ +<%= link_to( + content_tag('span', _('Reply') ), + {:action => 'new', :cms => true, :parent_id => article.id, :type => 'ProposalsDiscussionPlugin::Response', :back_to => request.original_url}, + {:class => 'button icon-child-article', :title => _('Reply') } + ) +%> -- libgit2 0.21.2