OSDN Git Service

temp
[pettanr/pettanr.git] / app / controllers / pictures_controller.rb
1 class PicturesController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   if MagicNumber['run_mode'] == 0
4     before_filter :authenticate_user, :only => []
5     before_filter :authenticate_author, :only => []
6   else
7     before_filter :authenticate_user, :only => []
8     before_filter :authenticate_resource_reader, :only => [:show, :credit, :search]
9     before_filter :authenticate_author, :only => []
10   end
11   before_filter :authenticate_admin!, :only => [:list, :browse]
12   
13   def show
14     @item = Picture.show(params[:id], @operators)
15
16     respond_to do |format|
17       opt = {:type => @item.mime_type, :disposition=>"inline"}
18       format.png { send_data(@item.restore(params[:subdir]), opt ) }
19       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
20       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
21       format.html {
22         @picture = @item
23       }
24       format_prof format
25       format.json { render :json => @item.to_json}
26     end
27   end
28   
29   def credit
30     @picture = Picture.show(params[:id], [@user, @admin, @demand_user])
31
32     respond_to do |format|
33       format.html { render :layout => false } # show.html.erb
34       format.json { render :json => @picture.to_json}
35     end
36   end
37   
38   def search
39     @pictures = Picture.list_by_md5(params[:md5])
40     
41     respond_to do |format|
42       format.html
43       format.json { render json: @pictures.to_json }
44     end
45   end
46   
47   def list
48     @pictures = Picture.all
49
50     respond_to do |format|
51       format.html { render layout: 'system' }# index.html.erb
52       format.json { render json: @pictures }
53     end
54   end
55
56   def browse
57     @picture = Picture.find(params[:id])
58
59     respond_to do |format|
60       format.html { render layout: 'system' } # show.html.erb
61       format.json { render json: @picture }
62     end
63   end
64 end