Class: Admin::PageTemplatesController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/page_templates_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/admin/page_templates_controller.rb', line 34

def create
  add_sid(:page_template)
  @page_template = PageTemplate.new(params[:page_template])
  
  if PageTemplate.count==0
    @page_template.is_default = 1
  end
  @page_template.user_id = current_user.id
  @page_template.system_id = _sid
  if @page_template.save
    Activity.add(_sid, "Created Page Template '#{@page_template.name}'", current_user.id, "Page Template")
    redirect_to [:admin, @page_template], :notice => "Successfully created page template."
  else
    render :action => 'new'
  end
end

#destroyObject



66
67
68
69
70
71
# File 'app/controllers/admin/page_templates_controller.rb', line 66

def destroy
  @page_template = PageTemplate.where(:id=>params[:id]).sys(_sid).first
  Activity.add(_sid, "Deleted Page Template '#{@page_template.name}'", current_user.id, "Page Template")
  @page_template.destroy
  redirect_to admin_page_templates_url, :notice => "Successfully destroyed page template."
end

#editObject



51
52
53
# File 'app/controllers/admin/page_templates_controller.rb', line 51

def edit
  @page_template = PageTemplate.where(:id=>params[:id]).sys(_sid).first
end

#indexObject



22
23
24
# File 'app/controllers/admin/page_templates_controller.rb', line 22

def index
  @page_templates = PageTemplate.sys(_sid).page(params[:page]).per(50)
end

#mappingObject



4
5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/admin/page_templates_controller.rb', line 4

def mapping
  template = PageTemplate.sys(_sid).where(:id=>params[:id]).first
  page = template.pages.first

  if page==nil
    render :js=>"$('#error_explanation').html('You must have already created at least one page with the \'#{template.name}\' template to use it for this page.').show();"
    return
  end

  render :json=>page.current_content.map { |field| field.field_name }
end

#newObject



30
31
32
# File 'app/controllers/admin/page_templates_controller.rb', line 30

def new
  @page_template = PageTemplate.new
end

#pagesObject



16
17
18
19
20
# File 'app/controllers/admin/page_templates_controller.rb', line 16

def pages
 @page_template = PageTemplate.sys(_sid).where(:id=>params[:id]).first

 @pages = @page_template.pages.includes(:status).page(params[:page]).per(100)
end

#showObject



26
27
28
# File 'app/controllers/admin/page_templates_controller.rb', line 26

def show
  @page_template = PageTemplate.sys(_sid).where(:id=>params[:id]).includes(:mobile_version).first
end

#updateObject



55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/admin/page_templates_controller.rb', line 55

def update
  @page_template = PageTemplate.where(:id=>params[:id]).sys(_sid).first
  @page_template.user_id = current_user.id
  if @page_template.update_attributes(params[:page_template])
    Activity.add(_sid, "Updated Page Template '#{@page_template.name}'", current_user.id, "Page Template")
    redirect_to [:admin, @page_template], :notice  => "Successfully updated page template."
  else
    render :action => 'edit'
  end
end