Permalink
Browse files

Small refactoring.

  • Loading branch information...
1 parent 3499c7a commit d694c2a28c4e722294ef19862159a768f630a8c1 @mvz mvz committed Feb 19, 2012
Showing with 12 additions and 18 deletions.
  1. +12 −18 app/controllers/admin/content_controller.rb
View
30 app/controllers/admin/content_controller.rb
@@ -91,16 +91,7 @@ def autosave
@article = Article.get_or_build_article(id)
@article.text_filter = current_user.text_filter if current_user.simple_editor?
- # This is ugly, but I have to check whether or not the article is
- # published to create the dummy draft I'll replace later so that the
- # published article doesn't get overriden on the front
- if @article.published and @article.id
- parent_id = @article.id
- @article = Article.drafts.child_of(parent_id).first || Article.new
- @article.allow_comments = this_blog.default_allow_comments
- @article.allow_pings = this_blog.default_allow_pings
- @article.parent_id = parent_id
- end
+ get_fresh_or_existing_draft_for_article
@article.attributes = params[:article]
@article.published = false
@@ -124,6 +115,16 @@ def autosave
protected
+ def get_fresh_or_existing_draft_for_article
+ if @article.published and @article.id
+ parent_id = @article.id
+ @article = Article.drafts.child_of(parent_id).first || Article.new
+ @article.allow_comments = this_blog.default_allow_comments
+ @article.allow_pings = this_blog.default_allow_pings
+ @article.parent_id = parent_id
+ end
+ end
+
attr_accessor :resources, :categories, :resource, :category
def do_add_or_remove_fu
@@ -147,14 +148,7 @@ def new_or_edit
@post_types = PostType.find(:all)
if request.post?
if params[:article][:draft]
- # XXX: Straight copy from autosave. Refactor!
- if @article.published and @article.id
- parent_id = @article.id
- @article = Article.drafts.child_of(parent_id).first || Article.new
- @article.allow_comments = this_blog.default_allow_comments
- @article.allow_pings = this_blog.default_allow_pings
- @article.parent_id = parent_id
- end
+ get_fresh_or_existing_draft_for_article
else
if not @article.parent_id.nil?
@article = Article.find(@article.parent_id)

0 comments on commit d694c2a

Please sign in to comment.