Module: Irwi::Extensions::Controllers::WikiPages::InstanceMethods

Includes:
Irwi::Extensions::Controllers::WikiPageAttachments, Support::TemplateFinder
Defined in:
lib/irwi/extensions/controllers/wiki_pages.rb

Instance Method Summary collapse

Methods included from Irwi::Extensions::Controllers::WikiPageAttachments

#add_attachment, #remove_attachment

Instance Method Details

#allObject



94
95
96
97
98
# File 'lib/irwi/extensions/controllers/wiki_pages.rb', line 94

def all
  @pages = Irwi.config.paginator.paginate( page_class, :page => params[:page] ) # Loading and paginating all pages

  render_template 'all'
end

#compareObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/irwi/extensions/controllers/wiki_pages.rb', line 34

def compare
  return not_allowed unless history_allowed?

  if @page.new_record?
    render_template 'no'
  else
    new_num = params[:new].to_i || @page.last_version_number # Last version number
    old_num = params[:old].to_i || 1 # First version number

    old_num, new_num = new_num, old_num if new_num < old_num # Swapping them if last < first

    versions = @page.versions.between( old_num, new_num ) # Loading all versions between first and last

    @versions = Irwi.config.paginator.paginate( versions, :page => params[:page] ) # Paginating them

    @new_version = @versions.first.number == new_num ? @versions.first : versions.first # Loading next version
    @old_version = @versions.last.number == old_num ? @versions.last : versions.last # Loading previous version

    render_template 'compare'
  end
end

#destroyObject



86
87
88
89
90
91
92
# File 'lib/irwi/extensions/controllers/wiki_pages.rb', line 86

def destroy
  return not_allowed unless destroy_allowed?

  @page.destroy

  redirect_to url_for( :action => :show )
end

#editObject



62
63
64
65
66
# File 'lib/irwi/extensions/controllers/wiki_pages.rb', line 62

def edit
  return not_allowed unless show_allowed? && edit_allowed?

  render_template 'edit'
end

#historyObject



26
27
28
29
30
31
32
# File 'lib/irwi/extensions/controllers/wiki_pages.rb', line 26

def history
  return not_allowed unless history_allowed?

  @versions = Irwi.config.paginator.paginate( @page.versions, :page => params[:page] ) # Paginating them

  render_template( @page.new_record? ? 'no' : 'history' )
end

#newObject



56
57
58
59
60
# File 'lib/irwi/extensions/controllers/wiki_pages.rb', line 56

def new
  return not_allowed unless show_allowed? && edit_allowed?

  render_template 'new'
end

#showObject



20
21
22
23
24
# File 'lib/irwi/extensions/controllers/wiki_pages.rb', line 20

def show
  return not_allowed unless show_allowed?

  render_template( @page.new_record? ? 'no' : 'show' )
end

#updateObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/irwi/extensions/controllers/wiki_pages.rb', line 68

def update
  return not_allowed unless @page.new_record? || edit_allowed? # Check for rights (but not for new record, for it we will use second check only)

  @page.attributes = params[:page] # Assign new attributes
  @page.comment = params[:page][:comment]

  return not_allowed unless edit_allowed? # Double check: used beacause action may become invalid after attributes update

  @page.updator = @current_user # Assing user, which updated page
  @page.creator = @current_user if @page.new_record? # Assign it's creator if it's new page

  if !params[:preview] && (params[:cancel] || @page.save)
    redirect_to url_for( :action => :show, :path => @page.path.split('/') ) # redirect to new page's path (if it changed)
  else
    render_template 'edit'
  end
end