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