OSDN Git Service

t#30143:au and ar change
[pettanr/pettanr.git] / app / controllers / artists_controller.rb
1 class ArtistsController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   before_filter :authenticate_user!, :only => [:index, :show, :new, :create, :edit, :update, :destroy]
4   before_filter :authenticate_author, :only => [:index, :show, :new, :create, :edit, :update, :destroy]
5   before_filter :authenticate_admin!, :only => [:list, :browse]
6
7   # GET /artists
8   # GET /artists.json
9   def index
10     @page = Artist.page params[:page]
11     @page_size = Artist.page_size params[:page_size]
12     @artists = Artist.list(@page, @page_size)
13
14     respond_to do |format|
15       format.html # index.html.erb
16       format.json { render :json => @artists.to_json(Artist.list_json_opt) }
17     end
18   end
19
20   # GET /artists/1
21   # GET /artists/1.json
22   def show
23     @ar = Artist.show(params[:id], @author)
24
25     respond_to do |format|
26       format.html # show.html.erb
27       format.json { render :json => @ar.to_json(Artist.show_json_opt) }
28     end
29   end
30
31   def count
32     @ar = {:count => Artist.visible_count}
33     respond_to do |format|
34       format.json { render json: @ar.to_json }
35     end
36   end
37   
38   def list
39     @artists = Artist.all
40
41     respond_to do |format|
42       format.html { render layout: 'system' }
43       format.json { render json: @artists }
44     end
45   end
46
47   def browse
48     @ar = Artist.find(params[:id])
49
50     respond_to do |format|
51       format.html { render layout: 'system' }
52       format.json { render json: @ar }
53     end
54   end
55
56   # GET /artists/new
57   # GET /artists/new.json
58   def new
59     @ar = Artist.new
60     @ar.supply_default 
61
62     respond_to do |format|
63       format.html # new.html.erb
64       format.js
65       format.json { render json: @ar.to_json(Artist.show_json_opt) }
66     end
67   end
68
69   # GET /artists/1/edit
70   def edit
71     @ar = Artist.edit(params[:id], @author)
72     respond_to do |format|
73       format.html 
74       format.js
75     end
76   end
77
78   # POST /artists
79   # POST /artists.json
80   def create
81     @ar = Artist.new()
82     @ar.supply_default 
83     @ar.attributes = params[:artist]
84     @ar.overwrite @author
85     respond_to do |format|
86       if @ar.save
87         format.html { redirect_to root_path, notice: 'Artist was successfully created.' }
88         format.json { render json: @ar.to_json(Artist.show_json_opt), status: :created, location: @artist }
89       else
90         format.html { render action: "new" }
91         format.json { render json: @ar.errors, status: :unprocessable_entity }
92       end
93     end
94   end
95
96   # PUT /artists/1
97   # PUT /artists/1.json
98   def update
99     @ar = Artist.edit(params[:id], @author)
100     @ar.attributes = params[:artist]
101     @ar.overwrite @author
102
103     respond_to do |format|
104       if @ar.save
105         format.html { redirect_to '/home/configure', notice: 'Artist was successfully updated.' }
106         format.json { head :ok }
107       else
108         format.html { render action: "edit" }
109         format.json { render json: @ar.errors, status: :unprocessable_entity }
110       end
111     end
112   end
113
114   # DELETE /artists/1
115   # DELETE /artists/1.json
116   def destroy
117     @ar = Artist.edit(params[:id], @author)
118     @ar.destroy
119
120     respond_to do |format|
121       format.html { redirect_to artists_url }
122       format.json { head :ok }
123     end
124   end
125 end