OSDN Git Service

t#29400:itr3?
[pettanr/pettanr.git] / app / controllers / system_pictures_controller.rb
1 class SystemPicturesController < ApplicationController
2   layout 'test' if Pettanr::TestLayout
3   before_filter :authenticate_user!, :only => [:index, :show]
4   before_filter :authenticate_admin!, :only => [:list, :browse, :new, :create]
5
6   # GET /system_pictures
7   # GET /system_pictures.json
8   def index
9     @page = SystemPicture.page params[:page]
10     @page_size = SystemPicture.page_size params[:page_size]
11     @system_pictures = SystemPicture.list(@page, @page_size)
12
13     respond_to do |format|
14       format.html # index.html.erb
15       format.json { render json: @system_pictures.to_json(SystemPicture.list_json_opt) }
16     end
17   end
18
19   # GET /system_pictures/1
20   # GET /system_pictures/1.json
21   def show
22     @system_picture = SystemPicture.show(params[:id], @author)
23     
24     respond_to do |format|
25       opt = {:type => @system_picture.mime_type, :disposition=>"inline"}
26       format.png { send_data(@system_picture.restore, opt ) }
27       format.gif { send_data(@system_picture.restore, opt ) }
28       format.jpeg { send_data(@system_picture.restore, opt ) }
29       format.html # show.html.erb
30       format.json { render json: @system_picture.to_json(SystemPicture.show_json_opt)}
31     end
32   end
33
34   def list
35     @system_pictures = SystemPicture.all
36
37     respond_to do |format|
38       format.html { render layout: 'system' }
39       format.json { render json: @system_pictures }
40     end
41   end
42
43   def browse
44     @system_picture = SystemPicture.find(params[:id])
45
46     respond_to do |format|
47       format.html { render layout: 'system' }
48       format.json { render json: @system_picture}
49     end
50   end
51
52   def new
53     respond_to do |format|
54       format.html # new.html.erb
55     end
56   end
57
58   # POST /system_pictures
59   # POST /system_pictures.json
60   def create
61     @imager = PettanImager.load set_image params[:system_picture][:file]
62
63     respond_to do |format|
64       @system_picture = SystemPicture.store @imager
65       if @system_picture
66         format.html { redirect_to @system_picture, notice: 'system picture was successfully created.' }
67         format.json { render json: @system_picture.to_json(SystemPicture.show_json_opt), status: :created, location: @system_picture }
68       else
69         format.html { render action: "new" }
70         format.json { render json: {}, status: :unprocessable_entity }
71       end
72     end
73   end
74
75 end