OSDN Git Service

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