OSDN Git Service

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