Commit d7eeb588ac745c9e0c8a9ed3bb0ac76464a8bb6e
1 parent
82270a3f
Exists in
clone_article
Add option to clone an article
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
5 changed files
with
47 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -144,7 +144,13 @@ class CmsController < MyProfileController | @@ -144,7 +144,13 @@ class CmsController < MyProfileController | ||
144 | article_data = environment.enabled?('articles_dont_accept_comments_by_default') ? { :accept_comments => false } : {} | 144 | article_data = environment.enabled?('articles_dont_accept_comments_by_default') ? { :accept_comments => false } : {} |
145 | article_data.merge!(params[:article]) if params[:article] | 145 | article_data.merge!(params[:article]) if params[:article] |
146 | article_data.merge!(:profile => profile) if profile | 146 | article_data.merge!(:profile => profile) if profile |
147 | - @article = klass.new(article_data) | 147 | + |
148 | + if params[:clone] | ||
149 | + current_article = profile.articles.find(params[:id]) | ||
150 | + @article = current_article.dup | ||
151 | + else | ||
152 | + @article = klass.new(article_data) | ||
153 | + end | ||
148 | 154 | ||
149 | parent = check_parent(params[:parent_id]) | 155 | parent = check_parent(params[:parent_id]) |
150 | if parent | 156 | if parent |
app/helpers/application_helper.rb
@@ -931,6 +931,26 @@ module ApplicationHelper | @@ -931,6 +931,26 @@ module ApplicationHelper | ||
931 | article_helper.cms_label_for_edit | 931 | article_helper.cms_label_for_edit |
932 | end | 932 | end |
933 | 933 | ||
934 | + def label_for_clone_article(article) | ||
935 | + klass = class_to_s(article.class) | ||
936 | + _("Clone #{klass}") | ||
937 | + end | ||
938 | + | ||
939 | + def class_to_s(article_type) | ||
940 | + classes = { | ||
941 | + Folder => _("folder"), | ||
942 | + Blog => _("blog"), | ||
943 | + Event => _("event"), | ||
944 | + Forum => _("forum"), | ||
945 | + } | ||
946 | + | ||
947 | + if classes.has_key?(article_type) | ||
948 | + classes[article_type] | ||
949 | + else | ||
950 | + _("article") | ||
951 | + end | ||
952 | + end | ||
953 | + | ||
934 | def add_rss_feed_to_head(title, url) | 954 | def add_rss_feed_to_head(title, url) |
935 | content_for :feeds do | 955 | content_for :feeds do |
936 | tag(:link, :rel => 'alternate', :type => 'application/rss+xml', :title => title, :href => url_for(url)) | 956 | tag(:link, :rel => 'alternate', :type => 'application/rss+xml', :title => title, :href => url_for(url)) |
app/views/content_viewer/_article_toolbar.html.erb
@@ -30,6 +30,10 @@ | @@ -30,6 +30,10 @@ | ||
30 | <% end %> | 30 | <% end %> |
31 | 31 | ||
32 | <%= modal_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) unless remove_content_button(:new, @page) %> | 32 | <%= modal_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) unless remove_content_button(:new, @page) %> |
33 | + | ||
34 | + <% content = content_tag('span', label_for_clone_article(@page)) %> | ||
35 | + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'new', :id => @page.id, :clone => true, :type => @page.class }) %> | ||
36 | + <%= expirable_button @page, :clone, content, url %> | ||
33 | <% end %> | 37 | <% end %> |
34 | 38 | ||
35 | <% if @page.accept_uploads? && @page.allow_create?(user) %> | 39 | <% if @page.accept_uploads? && @page.allow_create?(user) %> |
test/functional/cms_controller_test.rb
@@ -1811,6 +1811,14 @@ class CmsControllerTest < ActionController::TestCase | @@ -1811,6 +1811,14 @@ class CmsControllerTest < ActionController::TestCase | ||
1811 | assert_equal 'first version', assigns(:article).name | 1811 | assert_equal 'first version', assigns(:article).name |
1812 | end | 1812 | end |
1813 | 1813 | ||
1814 | + should 'clone article with its content' do | ||
1815 | + article = profile.articles.create(:name => 'first version') | ||
1816 | + | ||
1817 | + get :new, :profile => profile.identifier, :id => article.id, :clone => true, :type => 'TinyMceArticle' | ||
1818 | + | ||
1819 | + assert_match article.name, @response.body | ||
1820 | + end | ||
1821 | + | ||
1814 | should 'save article with content from older version' do | 1822 | should 'save article with content from older version' do |
1815 | article = profile.articles.create(:name => 'first version') | 1823 | article = profile.articles.create(:name => 'first version') |
1816 | article.name = 'second version'; article.save | 1824 | article.name = 'second version'; article.save |
test/unit/application_helper_test.rb
@@ -1009,6 +1009,14 @@ class ApplicationHelperTest < ActionView::TestCase | @@ -1009,6 +1009,14 @@ class ApplicationHelperTest < ActionView::TestCase | ||
1009 | assert html.include?("onClick=\"toggle_fullwidth('#article')\"") | 1009 | assert html.include?("onClick=\"toggle_fullwidth('#article')\"") |
1010 | end | 1010 | end |
1011 | 1011 | ||
1012 | + should "return the related class string" do | ||
1013 | + assert_equal "Clone folder", label_for_clone_article(Folder.new) | ||
1014 | + assert_equal "Clone blog", label_for_clone_article(Blog.new) | ||
1015 | + assert_equal "Clone event", label_for_clone_article(Event.new) | ||
1016 | + assert_equal "Clone forum", label_for_clone_article(Forum.new) | ||
1017 | + assert_equal "Clone article", label_for_clone_article(TinyMceArticle.new) | ||
1018 | + end | ||
1019 | + | ||
1012 | protected | 1020 | protected |
1013 | include NoosferoTestHelper | 1021 | include NoosferoTestHelper |
1014 | 1022 |