Class: Junebug::Controllers::Edit

Inherits:
R
  • Object
show all
Defined in:
lib/junebug/controllers.rb

Instance Method Summary collapse

Instance Method Details

#get(page_name, version = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/junebug/controllers.rb', line 31

def get page_name, version = nil
  redirect("/login?return_to=#{CGI::escape('/'+page_name+'/edit')}") and return unless logged_in?
  page_name_spc = page_name.gsub(/_/,' ')
  @page = Page.find_by_title(page_name_spc)
  if @page.nil?
    @page = Page.new(:title=>page_name_spc, :body=>'')
  else
    # check for version request
    @page = @page.versions.find_by_version(version) unless version.nil? or version == @page.version.to_s
  end
  render :edit
end

#post(page_name) ⇒ Object

FIXME: no error checking, also no verify quicksave/readonly rights



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/junebug/controllers.rb', line 45

def post page_name
  redirect('/login') and return unless logged_in? # shouldn't be here
  page_name_spc = page_name.gsub(/_/,' ')
  @page = Page.find_by_title(page_name_spc)
  if input.submit == 'cancel'
    @page ? redirect(Show, page_name) : redirect(Junebug.startpage)
  else
    attrs = { :body => input.post_body }
    attrs[:readonly] = input.post_readonly if is_admin?
    if input.submit == 'minor edit'
      current_version = @page.find_version(@page.version)
      current_version.update_attributes(attrs)
      @page.without_revision { @page.update_attributes(attrs) }
      redirect Show, page_name_spc.gsub(/ /,'_') # don't allow pagename changes as minor edits
    else
      attrs[:title] = input.post_title
      if input.submit == 'preview'
        @show_preview = true
        if @page
          @page.attributes = attrs
        else
          @page = Page.new(attrs)
        end
        render :edit
      elsif input.submit == 'save'
        attrs[:user_id] = @state.user.id # don't set this until save
        if @page
          @page.update_attributes(attrs)
        else
          @page = Page.create(attrs)
        end
        redirect Show, input.post_title.gsub(/ /,'_')
      end
    end
  end
end