OSDN Git Service

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