OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
1 class ResourcePicturesController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
4     before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
5   else
6     before_filter :authenticate_resource_reader, :only => [
7       :index, :show, :credit, 
8       :by_original_picture, :by_license_group, :by_license, :by_artist
9     ]
10     before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
11     before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
12   end
13   
14   def index
15     filer_list
16   end
17   
18   def by_original_picture
19     filer_list
20   end
21   
22   def by_license_group
23     filer_list
24   end
25   
26   def by_license
27     filer_list
28   end
29   
30   def by_artist
31     filer_list
32   end
33   
34   def show_html_format format
35     format.html {
36       @item.boosts 'post'
37     }
38   end
39   
40   def show
41     set_show
42     respond_to do |format|
43       opt = {:type => @item.mime_type, :disposition=>"inline"}
44       format.png { send_data(@item.restore(params[:subdir]), opt ) }
45       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
46       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
47       show_html_format format
48       show_prof_format format
49       show_json_format format
50     end
51   end
52   
53   def credit
54     @resource_picture = ResourcePicture.show(params[:id], @operators)
55     
56     respond_to do |format|
57       format.html { render :layout => false } # show.html.erb
58     end
59   end
60   
61   def new
62     # use @item, @original_picture
63     respond_to do |format|
64       format.html
65     end
66   end
67   
68   def create
69     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
70     @imager = PettanImager.load @original_picture.restore
71     jsn = nil
72     if params[:json]
73       jsn = JSON.parse_no_except(params[:json])
74     end
75     @prm = if params[:resource_picture] == nil or params[:resource_picture].empty?
76        jsn
77     else
78        params[:resource_picture]
79     end
80     @item = @original_picture.resource_picture || ResourcePicture.new
81     @item.attributes = @prm
82     @item.overwrite @original_picture
83     @item.boosts 'post'
84     
85     respond_to do |format|
86       if @item.store(@imager)
87         format.html { redirect_to @item }
88         format.json { render json: @item.to_json, status: :created, location: @item }
89       else
90         format.html { render action: "new" }
91         format.json { render json: @item.errors, status: :unprocessable_entity }
92       end
93     end
94   end
95   
96   def destroy
97     @resource_picture = ResourcePicture.edit(params[:id], @operators)
98
99     respond_to do |format|
100       if @resource_picture.unpublish
101         format.html { redirect_to :controller => '/home', :action => :resource_pictures }
102         format.json { head :ok }
103       else
104         format.html { redirect_to resource_picture_path(@resource_picture) }
105         format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
106       end
107     end
108   end
109   
110   def count
111     @resource_picture = {:count => ResourcePicture.visible_count}
112     respond_to do |format|
113       format.json { render json: @resource_picture.to_json }
114     end
115   end
116   
117 end