summaryrefslogtreecommitdiff
blob: 1e5de16c4923142af84f17263baaf420d9efdde4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
81
82
83
84
85
class Admin::TemplatesController < ApplicationController
  before_filter :admin_access_required

  # GET /admin/templates
  # GET /admin/templates.json
  def index
    @templates = Template.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => @templates }
    end
  end

  # GET /admin/templates/1
  # GET /admin/templates/1.json
  def show
    @template = Template.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render :json => @template }
    end
  end

  # GET /admin/templates/new
  # GET /admin/templates/new.json
  def new
    @template = Template.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render :json => @template }
    end
  end

  # GET /admin/templates/1/edit
  def edit
    @template = Template.find(params[:id])
  end

  # POST /admin/templates
  # POST /admin/templates.json
  def create
    @template = Template.new(params[:template].permit(:name, :text, :target, :enabled))

    respond_to do |format|
      if @template.save
        format.html { redirect_to admin_template_path(@template), :notice => 'Template was successfully created.' }
        format.json { render :json => @template, :status => :created, :location => @template }
      else
        format.html { render :action => "new" }
        format.json { render :json => @template.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /admin/templates/1
  # PUT /admin/templates/1.json
  def update
    @template = Template.find(params[:id])

    respond_to do |format|
      if @template.update_attributes(params[:template].permit(:name, :text, :target, :enabled))
        format.html { redirect_to admin_template_path(@template), :notice => 'Template was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render :action => "edit" }
        format.json { render :json => @template.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /admin/templates/1
  # DELETE /admin/templates/1.json
  def destroy
    @template = Template.find(params[:id])
    @template.destroy

    respond_to do |format|
      format.html { redirect_to admin_templates_url }
      format.json { head :ok }
    end
  end
end