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



23
24
25
26
27
28
29
30
# File 'lib/junebug/controllers.rb', line 23

def get page_name, version = nil
  redirect("#{Junebug.config['url']}/login") and return unless logged_in?
  @page_title = "Edit #{page_name}"
  @page = Page.find(:first, :conditions=>['title = ?', page_name])
  @page = Page.create(:title => page_name, :user_id=>@state.user.id) unless @page
  @page = @page.versions.find_by_version(version) unless version.nil? or version == @page.version.to_s
  render :edit
end

#post(page_name) ⇒ Object

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



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

def post page_name
  redirect("#{Junebug.config['url']}/login") and return unless logged_in?
  if input.submit == 'save'
    if ! input.quicksave
      attrs = { :body => input.post_body, :title => input.post_title, :user_id =>@state.user.id }
      attrs[:readonly] = input.post_readonly if is_admin?
      Page.find_or_create_by_title(page_name).update_attributes(attrs)
    else
      attrs = { :body => input.post_body }
      attrs[:readonly] = input.post_readonly if is_admin?
      page = Page.find_by_title(page_name)
      current_version = page.find_version(page.version)
      current_version.update_attributes(attrs)
      page.without_revision { page.update_attributes(attrs) }
    end
    # redirect Show, input.post_title
    redirect "#{Junebug.config['url']}/#{input.post_title.gsub(/ /,'+')}"
  else # cancel
    redirect "#{Junebug.config['url']}/#{page_name.gsub(/ /,'+')}"
  end
end