Class: Caboose::PageTemplatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/page_templates_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_json, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#admin_createObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/caboose/page_templates_controller.rb', line 17

def admin_create
  return unless user_is_allowed('templates', 'add')
  resp = Caboose::StdClass.new({'error' => nil,'redirect' => nil})
  @template = PageTemplate.new
  @template.title = params[:title]
  @template.category_id = params[:category_id]
  @template.save
  resp.redirect = "/admin/templates/#{@template.id}"
  render :json => resp
end

#admin_deleteObject



67
68
69
70
71
72
73
# File 'app/controllers/caboose/page_templates_controller.rb', line 67

def admin_delete
  return if !user_is_allowed('templates', 'delete') || !@site.is_master
  prop = PageTemplate.find(params[:id])    
  resp = Caboose::StdClass.new('redirect' => "/admin/templates")
  prop.destroy    
  render :json => resp
end

#admin_editObject



61
62
63
64
# File 'app/controllers/caboose/page_templates_controller.rb', line 61

def admin_edit
  return if !user_is_allowed('templates', 'edit') || !@site.is_master
  @template = PageTemplate.find(params[:id])
end

#admin_indexObject



6
7
8
9
# File 'app/controllers/caboose/page_templates_controller.rb', line 6

def admin_index
  return if !user_is_allowed('templates', 'view') || !@site.is_master
  @categories = PageTemplateCategory.order(:sort_order).all
end

#admin_newObject



12
13
14
# File 'app/controllers/caboose/page_templates_controller.rb', line 12

def admin_new
  return if !user_is_allowed('templates', 'add') || !@site.is_master
end

#admin_updateObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/caboose/page_templates_controller.rb', line 29

def admin_update
  return unless ((user_is_allowed_to 'edit', 'templates') && @site.is_master)
  resp = Caboose::StdClass.new
  templates = params[:id] == 'bulk' ? params[:model_ids].collect{ |rid| PageTemplate.find(rid) } : [PageTemplate.find(params[:id])] 
  params.each do |k,v|
    case k
      when "title" then templates.each { |r| r.title = v }
      when "page_id" then templates.each { |r| r.page_id = v }
      when "description" then templates.each { |r| r.description = v }
      when "category_id" then templates.each { |r| r.category_id = v }
      when "sort_order" then templates.each { |r| r.sort_order = v }
    end
  end
  templates.each do |r|
    r.save
  end
  resp.success = true
  render :json => resp
end

#admin_update_screenshotObject



50
51
52
53
54
55
56
57
58
# File 'app/controllers/caboose/page_templates_controller.rb', line 50

def admin_update_screenshot
  render :json => false and return unless user_is_allowed_to 'edit', 'templates'    
  resp = Caboose::StdClass.new({ 'attributes' => {} })
  template = PageTemplate.find(params[:id])
  template.screenshot = params[:screenshot]
  template.save
  resp.attributes['image'] = { 'value' => template.screenshot.url(:small) }
  render :text => resp.to_json
end