OSDN Git Service

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