OSDN Git Service

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