OSDN Git Service

173ec173f751dcad46582c98ca16008edd8be20b
[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   before_filter :authenticate_admin!, :only => [:list, :browse]
12
13   @@model = Artist
14   def index
15     set_page params @@model, params
16     @items = @@model.list(@page, @page_size)
17     
18     respond_to do |format|
19       format.html {
20         @paginate = @@model.list_paginate(@page, @page_size)
21         render :template => 'system/filer', :locals => {
22           :filer => @filer.window(@items, @operators, @paginate)
23         }
24       }
25       format.json { render json: @items.to_json(@@model.list_json_opt) }
26     end
27   end
28
29   def show
30     @item = Artist.show(params[:id], @operators)
31
32     respond_to do |format|
33       format.html {
34         @artist = @item
35       }
36       format_prof format
37       format.json { render :json => @item.to_json(Artist.show_json_opt) }
38     end
39   end
40
41   def resource_pictures
42     @artist = Artist.show(params[:id], @operators)
43     @page = Author.page params[:page]
44     @page_size = Author.resource_picture_page_size params[:page_size]
45     @resource_pictures = ResourcePicture.himlist(@artist, @page, @page_size)
46     respond_to do |format|
47       format.html {
48         @paginate = ResourcePicture.himlist_paginate(@artist, @page, @page_size)
49       }
50       format.json { render json: @resource_pictures.to_json(ResourcePicture.list_json_opt) }
51     end
52   end
53   
54   def count
55     @artist = {:count => Artist.visible_count}
56     respond_to do |format|
57       format.json { render json: @artist.to_json }
58     end
59   end
60   
61   def list
62     @artists = Artist.all
63
64     respond_to do |format|
65       format.html { render layout: 'system' }
66       format.json { render json: @artists }
67     end
68   end
69
70   def browse
71     @artist = Artist.find(params[:id])
72
73     respond_to do |format|
74       format.html { render layout: 'system' }
75       format.json { render json: @artist }
76     end
77   end
78
79   def new
80     @artist = Artist.new
81     @artist.supply_default 
82
83     respond_to do |format|
84       format.html # new.html.erb
85       format.js
86       format.json { render json: @artist.to_json(Artist.show_json_opt) }
87     end
88   end
89
90   def edit
91     @artist = Artist.edit(params[:id], @operators)
92     respond_to do |format|
93       format.html 
94       format.js
95     end
96   end
97
98   def create
99     @artist = Artist.new()
100     @artist.supply_default 
101     @artist.attributes = params[:artist]
102     @artist.overwrite @operators
103     respond_to do |format|
104       if @artist.save
105         flash[:notice] = I18n.t('flash.notice.created', :model => Artist.model_name.human)
106         format.html { redirect_to root_path }
107         format.json { render json: @artist.to_json(Artist.show_json_opt), status: :created, location: @artist }
108       else
109         flash[:notice] = I18n.t('flash.notice.not_created', :model => Artist.model_name.human)
110         format.html { render action: "new" }
111         format.json { render json: @artist.errors, status: :unprocessable_entity }
112       end
113     end
114   end
115
116   def update
117     @artist = Artist.edit(params[:id], @operators)
118     @artist.attributes = params[:artist]
119     @artist.overwrite @operators
120
121     respond_to do |format|
122       if @artist.save
123         flash[:notice] = I18n.t('flash.notice.updated', :model => Artist.model_name.human)
124         format.html { redirect_to '/home/configure' }
125         format.json { head :ok }
126       else
127         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Artist.model_name.human)
128         format.html { render action: "edit" }
129         format.json { render json: @artist.errors, status: :unprocessable_entity }
130       end
131     end
132   end
133
134   def destroy
135     @artist = Artist.edit(params[:id], @operators)
136     @artist.destroy
137
138     respond_to do |format|
139       format.html { redirect_to artists_url }
140       format.json { head :ok }
141     end
142   end
143 end