<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/views/admin/pages/_copy_move_extra_td.haml</filename>
    </added>
    <added>
      <filename>app/views/admin/pages/_copy_move_extra_th.haml</filename>
    </added>
    <added>
      <filename>app/views/admin/pages/_copy_move_popup.haml</filename>
    </added>
    <added>
      <filename>lib/copy_move/model.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -4,7 +4,7 @@ module CopyMoveHelper
     list = homes.inject([]) do |l, home|
       l.concat build_tree(home, [])
     end
-    select_tag 'parent_id', options, options_for_select(list)
+    select_tag 'parent_id', options_for_select(list)
   end
   
   def build_tree(page, list, level = 0)</diff>
      <filename>app/helpers/copy_move_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,10 +7,10 @@ class CopyMoveExtension &lt; Radiant::Extension
 
   define_routes do |map|
     map.with_options(:controller =&gt; &quot;admin/pages&quot;) do |cm|
-      cm.copy_admin_page          'admin/pages/:id/copy',          :action =&gt; 'copy'
-      cm.copy_children_admin_page 'admin/pages/:id/copy_children', :action =&gt; 'copy_children'
-      cm.copy_tree_admin_page     'admin/pages/:id/copy_tree',     :action =&gt; 'copy_tree'
-      cm.move_admin_page          'admin/pages/:id/move',          :action =&gt; 'move'
+      cm.copy_page_admin_page     '/admin/pages/:id/copy_page',     :action =&gt; 'copy_page'
+      cm.copy_children_admin_page '/admin/pages/:id/copy_children', :action =&gt; 'copy_children'
+      cm.copy_tree_admin_page     '/admin/pages/:id/copy_tree',     :action =&gt; 'copy_tree'
+      cm.move_admin_page          '/admin/pages/:id/move',          :action =&gt; 'move'
     end
   end
 
@@ -19,8 +19,9 @@ class CopyMoveExtension &lt; Radiant::Extension
       include CopyMove::Controller
       helper :copy_move
     end
-    Page.class_eval { include CopyMove }
+    Page.class_eval { include CopyMove::Model }
     admin.page.index.add :sitemap_head, 'copy_move_extra_th'
     admin.page.index.add :node, 'copy_move_extra_td', :after =&gt; &quot;add_child_column&quot;
+    admin.page.index.add :bottom, 'copy_move_popup'
   end
 end</diff>
      <filename>copy_move_extension.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,47 +5,4 @@ module CopyMove
       super(&quot;Page #{record.title} cannot be made a descendant of itself.&quot;)
     end
   end
-
-  def new_slug_and_title_under(parent)
-    test_page = self.clone
-    test_page.parent = parent
-    until test_page.valid?
-      index = (index || 0) + 1
-      test_page.title = &quot;#{title} (Copy#{' '+index if index &gt; 1})&quot;
-      test_page.slug = &quot;#{slug}-#{index}&quot;
-    end
-    {:slug =&gt; test_page.slug, :title =&gt; test_page.title}
-  end
-
-  def move_under(parent)
-    raise CircularHierarchy.new(self) if parent == self || parent.ancestors.include?(self)
-    update_attributes!(:parent_id =&gt; parent.id)
-  end
-
-  def copy_to(parent, status = nil)
-    parent.children.build(copiable_attributes.symbolize_keys.merge(new_slug_and_title_under(parent))).tap do |new_page|
-      self.parts.each do |part|
-        new_page.parts &lt;&lt; part.clone
-      end
-      new_page.status_id = status || new_page.status_id
-      new_page.save!
-    end
-  end
-
-  def copy_with_children_to(parent, status = nil)
-    copy_to(parent, status).tap do |new_page|
-      children.each {|child| child.copy_to(new_page, status) }
-    end
-  end
-  
-  def copy_tree_to(parent, status = nil)
-    copy_to(parent, status).tap do |new_page|
-      children.each {|child| child.copy_tree_to(new_page, status) }
-    end
-  end
-  
-  private
-  def copiable_attributes
-    self.attributes.dup.delete_if {|k,v| [:id, :parent_id].include?(k.to_sym) }
-  end
 end
\ No newline at end of file</diff>
      <filename>lib/copy_move.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,87 +5,45 @@ module CopyMove
         before_filter do |c|
           c.include_stylesheet 'admin/copy_move'
         end
-        before_filter :load_model, :only =&gt; [:copy, :copy_children, :copy_tree, :move]
-        before_filter :load_parent, :only =&gt; [:copy, :copy_children, :copy_tree, :move]
+        before_filter :load_page, :only =&gt; [:copy_page, :copy_children, :copy_tree, :move]
+        before_filter :load_parent, :only =&gt; [:copy_page, :copy_children, :copy_tree, :move]
       end
     end
 
-    def copy
-      @new_page = @page.copy_to(@parent)
-      respond_to do |wants|
-        wants.html do
-          flash[:notice] = &quot;A copy of &lt;strong&gt;#{@page.title}&lt;/strong&gt; was created under &lt;strong&gt;#{@parent.title}&lt;/strong&gt;.&quot;
-          redirect_to admin_pages_url
-        end
-        wants.xml do
-          render :xml =&gt; @new_page, :status =&gt; :created, :location =&gt; admin_page_url(@new_page, :format =&gt; params[:format])
-        end
-        wants.json do
-          render :json =&gt; @new_page, :status =&gt; :created, :location =&gt; admin_page_url(@new_page, :format =&gt; params[:format])
-        end
-      end
+    def copy_page
+      @new_page = @page.copy_to(@parent, params[:status_id])
+      flash[:notice] = &quot;A copy of &lt;strong&gt;#{@page.title}&lt;/strong&gt; was created under &lt;strong&gt;#{@parent.title}&lt;/strong&gt;.&quot;
+      redirect_to admin_pages_url
     end
 
     def copy_children
-      @new_page = @page.copy_with_children_to(@parent)
-      respond_to do |wants|
-        wants.html do
-          flash[:notice] = &quot;Copies of &lt;strong&gt;#{@page.title}&lt;/strong&gt; and its immediate children were created under &lt;strong&gt;#{@parent.title}&lt;/strong&gt;.&quot;
-          redirect_to admin_pages_url
-        end
-        wants.xml do
-          render :xml =&gt; @new_page, :status =&gt; :created, :location =&gt; admin_page_url(@new_page, :format =&gt; params[:format])
-        end
-        wants.json do
-          render :json =&gt; @new_page, :status =&gt; :created, :location =&gt; admin_page_url(@new_page, :format =&gt; params[:format])
-        end
-      end
+      @new_page = @page.copy_with_children_to(@parent, params[:status_id])
+      flash[:notice] = &quot;Copies of &lt;strong&gt;#{@page.title}&lt;/strong&gt; and its immediate children were created under &lt;strong&gt;#{@parent.title}&lt;/strong&gt;.&quot;
+      redirect_to admin_pages_url
     end
 
     def copy_tree
-      @new_page = @page.copy_tree_to(@parent)
-      respond_to do |wants|
-        wants.html do
-          flash[:notice] = &quot;Copies of &lt;strong&gt;#{@page.title}&lt;/strong&gt; and all its descendants were created under &lt;strong&gt;#{@parent.title}&lt;/strong&gt;.&quot;
-          redirect_to admin_pages_url
-        end
-        wants.xml do
-          render :xml =&gt; @new_page, :status =&gt; :created, :location =&gt; admin_page_url(@new_page, :format =&gt; params[:format])
-        end
-        wants.json do
-          render :json =&gt; @new_page, :status =&gt; :created, :location =&gt; admin_page_url(@new_page, :format =&gt; params[:format])
-        end
-      end
+      @new_page = @page.copy_tree_to(@parent, params[:status_id])
+      flash[:notice] = &quot;Copies of &lt;strong&gt;#{@page.title}&lt;/strong&gt; and all its descendants were created under &lt;strong&gt;#{@parent.title}&lt;/strong&gt;.&quot;
+      redirect_to admin_pages_url
     end
 
     def move
       @page.move_under(@parent)
-      respond_to do |wants|
-        wants.html do
-          flash[:notice] = &quot;Page &lt;strong&gt;#{@page.title}&lt;/strong&gt; and all its descendants were moved under &lt;strong&gt;#{@parent.title}&lt;/strong&gt;.&quot;
-          redirect_to admin_pages_url
-        end
-        wants.xml do
-          render :xml =&gt; @page
-        end
-        wants.json do
-          render :json =&gt; @page
-        end
-      end
+      flash[:notice] = &quot;Page &lt;strong&gt;#{@page.title}&lt;/strong&gt; and all its descendants were moved under &lt;strong&gt;#{@parent.title}&lt;/strong&gt;.&quot;
+      redirect_to admin_pages_url
     rescue CopyMove::CircularHierarchy =&gt; e
-      respond_to do |wants|
-        wants.html do
-          flash[:error] = e.message
-          redirect_to admin_pages_url
-        end
-        wants.xml { render :xml =&gt; e, :status =&gt; :conflict }
-        wants.json { render :json =&gt; e, :status =&gt; :conflict }
-      end
+      flash[:error] = e.message
+      redirect_to admin_pages_url
     end
     
     private
     def load_parent
       @parent = Page.find(params[:parent_id])
     end
+    
+    def load_page
+      self.model = @page = Page.find(params[:id])
+    end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/copy_move/controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,9 +7,9 @@ describe Admin::PagesController do
   end
   
   describe &quot;routes&quot; do
-    it &quot;should route URLs to the copy action&quot; do
-      route_for(:controller =&gt; &quot;admin/pages&quot;, :action =&gt; &quot;copy&quot;, :id =&gt; &quot;1&quot;).should == &quot;/admin/pages/1/copy&quot;
-      params_from(:post, &quot;/admin/pages/1/copy&quot;).should == {:controller =&gt; &quot;admin/pages&quot;, :action =&gt; &quot;copy&quot;, :id =&gt; &quot;1&quot;}
+    it &quot;should route URLs to the copy_page action&quot; do
+      route_for(:controller =&gt; &quot;admin/pages&quot;, :action =&gt; &quot;copy_page&quot;, :id =&gt; &quot;1&quot;).should == &quot;/admin/pages/1/copy_page&quot;
+      params_from(:post, &quot;/admin/pages/1/copy_page&quot;).should == {:controller =&gt; &quot;admin/pages&quot;, :action =&gt; &quot;copy_page&quot;, :id =&gt; &quot;1&quot;}
     end
     
     it &quot;should route URLs to the copy_children action&quot; do
@@ -21,11 +21,16 @@ describe Admin::PagesController do
       route_for(:controller =&gt; &quot;admin/pages&quot;, :action =&gt; &quot;copy_tree&quot;, :id =&gt; &quot;1&quot;).should == &quot;/admin/pages/1/copy_tree&quot;
       params_from(:post, &quot;/admin/pages/1/copy_tree&quot;).should == {:controller =&gt; &quot;admin/pages&quot;, :action =&gt; &quot;copy_tree&quot;, :id =&gt; &quot;1&quot;}
     end
+    
+    it &quot;should route URLs to the move action&quot; do
+      route_for(:controller =&gt; &quot;admin/pages&quot;, :action =&gt; &quot;move&quot;, :id =&gt; &quot;1&quot;).should == &quot;/admin/pages/1/move&quot;
+      params_from(:post, &quot;/admin/pages/1/move&quot;).should == {:controller =&gt; &quot;admin/pages&quot;, :action =&gt; &quot;move&quot;, :id =&gt; &quot;1&quot;}
+    end
   end
   
-  describe &quot;POST to /admin/pages/:id/copy&quot; do
+  describe &quot;POST to /admin/pages/:id/copy_page&quot; do
     before :each do
-      post :copy, :id =&gt; page_id(:first), :parent_id =&gt; page_id(:another)
+      post :copy_page, :id =&gt; page_id(:first), :parent_id =&gt; page_id(:another)
     end
     
     it &quot;should load the page&quot; do</diff>
      <filename>spec/controllers/copy_move_controller_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -26,7 +26,6 @@ describe CopyMove do
     it &quot;should move to a new parent&quot; do
       @page = pages(:first)
       lambda { @page.move_under(pages(:another)) }.should_not raise_error
-      @page.reload.parent.should == pages(:another)
     end
   end
   
@@ -55,6 +54,11 @@ describe CopyMove do
       @new_page = @page.copy_to(pages(:another), Status[:draft].id)
       @new_page.status.should == Status[:draft]
     end
+    
+    it &quot;should ignore a blank status&quot; do
+      @new_page = @page.copy_to(pages(:another), '   ')
+      @new_page.status.should == Status[:published]
+    end
   end
   
   describe &quot;copying the page with first-level children&quot; do</diff>
      <filename>spec/models/copy_move_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>app/controllers/copy_move_controller.rb</filename>
    </removed>
    <removed>
      <filename>app/views/admin/pages/_copy_move_extra_td.rhtml</filename>
    </removed>
    <removed>
      <filename>app/views/admin/pages/_copy_move_extra_th.rhtml</filename>
    </removed>
    <removed>
      <filename>app/views/copy_move/index.rhtml</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>c12feaadbe7981c2c590904da5533fd8889dfacf</id>
    </parent>
  </parents>
  <author>
    <name>Sean Cribbs</name>
    <email>seancribbs@gmail.com</email>
  </author>
  <url>http://github.com/pilu/radiant-copy-move/commit/df0b237f24a393de6370a7b78dab40358aae356d</url>
  <id>df0b237f24a393de6370a7b78dab40358aae356d</id>
  <committed-date>2009-08-11T05:28:48-07:00</committed-date>
  <authored-date>2009-07-24T07:25:50-07:00</authored-date>
  <message>Implement new interface.

Signed-off-by: Andrea Franz &lt;andrea@gravityblast.com&gt;</message>
  <tree>ed701c723df365c407be2735a347fd5cd7dad34b</tree>
  <committer>
    <name>Andrea Franz</name>
    <email>andrea@gravityblast.com</email>
  </committer>
</commit>
