Module: CopyMove::Controller

Defined in:
lib/copy_move/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
# File 'lib/copy_move/controller.rb', line 3

def self.included(base)
  base.class_eval do
    before_filter :load_page, :only => [:copy_page, :copy_children, :copy_tree, :move_page]
  end
end

Instance Method Details

#copy_childrenObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/copy_move/controller.rb', line 22

def copy_children
  if request.request_method() == :get
    respond_to do |format|
      format.any {render :copy_children, :content_type => "text/html", :layout => false }
    end
  elsif request.request_method() == :post
    load_parent
    @new_page = @page.copy_with_children_to(@parent, params[:status_id])
    flash[:notice] = I18n.t('immediate_children_copied', :scope => :copy_move, :page => @page.title, :parent => @parent.title)
    redirect_to admin_pages_url
  end
end

#copy_pageObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/copy_move/controller.rb', line 9

def copy_page
  if request.request_method() == :get
    respond_to do |format|
      format.any {render :copy_page, :content_type => "text/html", :layout => false }
    end
  elsif request.request_method() == :post
    load_parent
    @new_page = @page.copy_to(@parent, params[:status_id])
    flash[:notice] = I18n.t('copied', :scope => :copy_move, :page => @page.title, :parent => @parent.title)
    redirect_to admin_pages_url
  end
end

#copy_treeObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/copy_move/controller.rb', line 35

def copy_tree
  if request.request_method() == :get
    respond_to do |format|
      format.any {render :copy_tree, :content_type => "text/html", :layout => false }
    end
  elsif request.request_method() == :post
    load_parent
    @new_page = @page.copy_tree_to(@parent, params[:status_id])
    flash[:notice] = I18n.t('descendants_copied', :scope => :copy_move, :page => @page.title, :parent => @parent.title)
    redirect_to admin_pages_url
  end
end

#move_pageObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/copy_move/controller.rb', line 48

def move_page
  if request.request_method() == :get
    respond_to do |format|
      format.any {render :move_page, :content_type => "text/html", :layout => false }
    end
  elsif request.request_method() == :post
    load_parent
    @page.move_under(@parent, params[:status_id])
    if @page.children.any?
      flash[:notice] = I18n.t('descendants_moved', :scope => :copy_move, :page => @page.title, :parent => @parent.title)
    else
      flash[:notice] = I18n.t('moved', :scope => :copy_move, :page => @page.title, :parent => @parent.title)          
    end
    redirect_to admin_pages_url
  end
  rescue CopyMove::CircularHierarchy => e
    flash[:error] = e.message
    redirect_to admin_pages_url
end