OSDN Git Service

3f980c1857072a5043c9458c19cd6c18715e029c
[pettanr/pettanr.git] / app / controllers / artists_controller.rb
1 class ArtistsController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
4     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
5   else
6     before_filter :authenticate_resource_reader, :only => [:index, :show, :resource_pictures]
7     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
8     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
9   end
10
11   def self.model
12     Artist
13   end
14   
15   def index
16     public_list
17   end
18
19   def resource_pictures
20     has_many_list
21   end
22   
23   def show
24     @item = Artist.show(params[:id], @operators)
25
26     respond_to do |format|
27       format.html {
28         @artist = @item
29       }
30       format_prof format
31       format.json { render :json => @item.to_json(Artist.show_json_opt) }
32     end
33   end
34
35   def count
36     @artist = {:count => Artist.visible_count}
37     respond_to do |format|
38       format.json { render json: @artist.to_json }
39     end
40   end
41   
42   def new
43     @artist = Artist.new
44     @artist.supply_default 
45
46     respond_to do |format|
47       format.html
48       format.js
49       format.json { render json: @artist.to_json(Artist.show_json_opt) }
50     end
51   end
52
53   def edit
54     @artist = Artist.edit(params[:id], @operators)
55     respond_to do |format|
56       format.html 
57       format.js
58     end
59   end
60
61   def create
62     @artist = Artist.new()
63     @artist.supply_default 
64     @artist.attributes = params[:artist]
65     @artist.overwrite @operators
66     respond_to do |format|
67       if @artist.save
68         flash[:notice] = I18n.t('flash.notice.created', :model => Artist.model_name.human)
69         format.html { redirect_to root_path }
70         format.json { render json: @artist.to_json(Artist.show_json_opt), status: :created, location: @artist }
71       else
72         flash[:notice] = I18n.t('flash.notice.not_created', :model => Artist.model_name.human)
73         format.html { render action: "new" }
74         format.json { render json: @artist.errors, status: :unprocessable_entity }
75       end
76     end
77   end
78
79   def update
80     @artist = Artist.edit(params[:id], @operators)
81     @artist.attributes = params[:artist]
82     @artist.overwrite @operators
83
84     respond_to do |format|
85       if @artist.save
86         flash[:notice] = I18n.t('flash.notice.updated', :model => Artist.model_name.human)
87         format.html { redirect_to '/home/configure' }
88         format.json { head :ok }
89       else
90         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Artist.model_name.human)
91         format.html { render action: "edit" }
92         format.json { render json: @artist.errors, status: :unprocessable_entity }
93       end
94     end
95   end
96
97   def destroy
98     @artist = Artist.edit(params[:id], @operators)
99     @artist.destroy
100
101     respond_to do |format|
102       format.html { redirect_to artists_url }
103       format.json { head :ok }
104     end
105   end
106 end