diff --git a/plugins/community_track/lib/community_track_plugin/step.rb b/plugins/community_track/lib/community_track_plugin/step.rb index 92bb905..32d4f2a 100644 --- a/plugins/community_track/lib/community_track_plugin/step.rb +++ b/plugins/community_track/lib/community_track_plugin/step.rb @@ -1,6 +1,7 @@ class CommunityTrackPlugin::Step < Folder settings_items :hidden, :type => :boolean, :default => false + settings_items :tool_type, :type => String alias :tools :children @@ -48,11 +49,11 @@ class CommunityTrackPlugin::Step < Folder end def accept_comments? - false + true end - def enabled_tools - {TinyMceArticle => {:name => _('Article')}, Forum => {:name => _('Forum')}} + def self.enabled_tools + [TinyMceArticle, Forum] end def to_html(options = {}) @@ -89,6 +90,14 @@ class CommunityTrackPlugin::Step < Folder save! end + def tool_class + tool_type ? tool_type.constantize : nil + end + + def tool + tools.find(:first, :conditions => {:type => tool_type }) + end + class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id) def self.find(step_id) diff --git a/plugins/community_track/public/style.css b/plugins/community_track/public/style.css index 2125a35..686293e 100644 --- a/plugins/community_track/public/style.css +++ b/plugins/community_track/public/style.css @@ -199,3 +199,18 @@ width: 115px; background: url(/plugins/community_track/icons/calendar.png) right center no-repeat; } + +.step_list .step .tools { + text-align: center; +} + +.step_list .step .actions { + float: right; +} + +#article .step_list .step .actions .button { + color: #888; + background-color: transparent; + border: 0px; + background-image: none; +} diff --git a/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb b/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb index 02ba691..5684718 100644 --- a/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb +++ b/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb @@ -15,7 +15,7 @@ class ContentViewerControllerTest < ActionController::TestCase category = fast_create(Category, :name => "education") @track.add_category(category) - @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today, :tool_type => TinyMceArticle.name) user = create_user('testinguser') login_as(user.login) @@ -27,12 +27,12 @@ class ContentViewerControllerTest < ActionController::TestCase assert_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } end - should 'do not show actions for tracks when user has not permission for edit' do + should 'do not show actions for tracks when user has not permission to edit' do user = create_user('intruder') logout login_as(user.login) get :view_page, @track.url - assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } + assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'track actions' } } end should 'do not show new button at article toolbar for tracks' do @@ -64,17 +64,23 @@ class ContentViewerControllerTest < ActionController::TestCase assert_tag :tag => 'div', :attributes => { :class => 'tools' }, :descendant => { :tag => 'div', :attributes => { :class => 'item' } } end - should 'show actions for steps when user has permission for edit' do + should 'show actions for steps when user has permission to edit' do get :view_page, @step.url assert_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } end - should 'show actions for enabled tools in step' do + should 'show action for tiny mce article tool in step' do get :view_page, @step.url - assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newforum' } } assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newtext-html' } } end + should 'show action for forum tool in step' do + @step.tool_type = Forum.name + @step.save! + get :view_page, @step.url + assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newforum' } } + end + should 'do not show actions for steps when user has not permission for edit' do user = create_user('intruder') logout diff --git a/plugins/community_track/test/unit/community_track_plugin/step_test.rb b/plugins/community_track/test/unit/community_track_plugin/step_test.rb index 4803f55..35d7214 100644 --- a/plugins/community_track/test/unit/community_track_plugin/step_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin/step_test.rb @@ -258,8 +258,28 @@ class StepTest < ActiveSupport::TestCase end should 'return enabled tools for a step' do - assert_includes @step.enabled_tools, TinyMceArticle - assert_includes @step.enabled_tools, Forum + assert_includes CommunityTrackPlugin::Step.enabled_tools, TinyMceArticle + assert_includes CommunityTrackPlugin::Step.enabled_tools, Forum + end + + should 'return class for selected tool' do + @step.tool_type = 'Forum' + assert_equal Forum, @step.tool_class + end + + should 'return tool for selected type' do + @step.tool_type = 'Forum' + @step.save! + article = fast_create(Article, :parent_id => @step.id) + forum = fast_create(Forum, :parent_id => @step.id) + assert_equal forum, @step.tool + end + + should 'not return tool with different type' do + @step.tool_type = 'Forum' + @step.save! + article = fast_create(Article, :parent_id => @step.id) + assert_not_equal article, @step.tool end end diff --git a/plugins/community_track/views/cms/community_track_plugin/_step.rhtml b/plugins/community_track/views/cms/community_track_plugin/_step.rhtml index b371993..a807569 100644 --- a/plugins/community_track/views/cms/community_track_plugin/_step.rhtml +++ b/plugins/community_track/views/cms/community_track_plugin/_step.rhtml @@ -12,6 +12,8 @@ { :size => 14 }) )) %> + <%= labelled_form_field(_('Tool type'), select(:article, :tool_type, CommunityTrackPlugin::Step.enabled_tools.map {|t| [t.short_description, t.name]} )) %> + <%= hidden_field_tag('success_back_to', url_for(@article.parent.view_url)) %> <%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %> diff --git a/plugins/community_track/views/content_viewer/_step_item.rhtml b/plugins/community_track/views/content_viewer/_step_item.rhtml new file mode 100644 index 0000000..0765c7e --- /dev/null +++ b/plugins/community_track/views/content_viewer/_step_item.rhtml @@ -0,0 +1,25 @@ +