Module: IrwiMod::Extensions::Controllers::WikiPages::InstanceMethods

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

Instance Method Summary collapse

Methods included from IrwiMod::Extensions::Controllers::WikiPageAttachments

#add_attachment, #remove_attachment

Instance Method Details

#allObject



101
102
103
104
# File 'lib/irwi_mod/extensions/controllers/wiki_pages.rb', line 101

def all
  do_search
  render_template 'all'
end

#compareObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/irwi_mod/extensions/controllers/wiki_pages.rb', line 41

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 = IrwiMod.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



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

def destroy
  return not_allowed unless destroy_allowed?

  @page.destroy

  redirect_to url_for( :action => :show )
end

#editObject



69
70
71
72
73
# File 'lib/irwi_mod/extensions/controllers/wiki_pages.rb', line 69

def edit
  return not_allowed unless show_allowed? && edit_allowed?

  render_template 'edit'
end

#historyObject



33
34
35
36
37
38
39
# File 'lib/irwi_mod/extensions/controllers/wiki_pages.rb', line 33

def history
  return not_allowed unless history_allowed?

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

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

#indexObject



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

def index
  return not_allowed unless show_allowed?
  
  do_search
  render_template 'index'
end

#newObject



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

def new
  return not_allowed unless show_allowed? && edit_allowed?

  render_template 'new'
end

#showObject



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

def show
  return not_allowed unless show_allowed?

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

#updateObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/irwi_mod/extensions/controllers/wiki_pages.rb', line 75

def update
  return not_allowed unless params[:page] && (@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 = @main_current_user # Assing user, which updated page
  @page.creator = @main_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