OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[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     filer_list
17   end
18   
19   def show
20     @item = Artist.show(params[:id], @operators)
21
22     respond_to do |format|
23       format.html {
24         @artist = @item
25       }
26       format_prof format
27       format.json { render :json => @item.to_json(Artist.show_json_opt) }
28     end
29   end
30
31   def count
32     list_count
33   end
34   
35   def new
36     @artist = Artist.new
37     @artist.supply_default 
38
39     respond_to do |format|
40       format.html
41       format.js
42       format.json { render json: @artist.to_json(Artist.show_json_opt) }
43     end
44   end
45
46   def edit
47     @artist = Artist.edit(params[:id], @operators)
48     respond_to do |format|
49       format.html 
50       format.js
51     end
52   end
53
54   def create
55     @artist = Artist.new()
56     @artist.supply_default 
57     @artist.attributes = params[:artist]
58     @artist.overwrite @operators
59     respond_to do |format|
60       if @artist.save
61         flash[:notice] = I18n.t('flash.notice.created', :model => Artist.model_name.human)
62         format.html { redirect_to root_path }
63         format.json { render json: @artist.to_json(Artist.show_json_opt), status: :created, location: @artist }
64       else
65         flash[:notice] = I18n.t('flash.notice.not_created', :model => Artist.model_name.human)
66         format.html { render action: "new" }
67         format.json { render json: @artist.errors, status: :unprocessable_entity }
68       end
69     end
70   end
71
72   def update
73     @artist = Artist.edit(params[:id], @operators)
74     @artist.attributes = params[:artist]
75     @artist.overwrite @operators
76
77     respond_to do |format|
78       if @artist.save
79         flash[:notice] = I18n.t('flash.notice.updated', :model => Artist.model_name.human)
80         format.html { redirect_to '/home/configure' }
81         format.json { head :ok }
82       else
83         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Artist.model_name.human)
84         format.html { render action: "edit" }
85         format.json { render json: @artist.errors, status: :unprocessable_entity }
86       end
87     end
88   end
89
90   def destroy
91     @artist = Artist.edit(params[:id], @operators)
92     @artist.destroy
93
94     respond_to do |format|
95       format.html { redirect_to artists_url }
96       format.json { head :ok }
97     end
98   end
99 end