OSDN Git Service

add folder
[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, :by_original_picture, :by_license, :by_artist, :count, :count_by_license, :count_by_artist
8     ]
9     before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
10     before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
11   end
12
13   def self.model
14     ResourcePicture
15   end
16   
17   def index
18     filer_list
19   end
20   
21   def by_original_picture
22     filer_list
23   end
24   
25   def by_license
26     filer_list
27   end
28   
29   def by_artist
30     filer_list
31   end
32   
33   def show_html_format format
34     format.html {
35       @item.boosts 'post'
36       @resource_picture = @item
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       format.json { render :json => @resource_picture.to_json(ResourcePicture.show_json_opt)}
59     end
60   end
61   
62   def count
63     list_count
64   end
65   
66   def count_by_license
67     list_count
68   end
69   
70   def count_by_artist
71     list_count
72   end
73   
74   def new
75     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
76     @imager = PettanImager.load @original_picture.restore
77     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
78     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
79     @resource_picture = @original_picture.resource_picture
80     unless @resource_picture
81       @resource_picture = ResourcePicture.new
82       @resource_picture.supply_default
83     end
84     @resource_picture.attributes = params[:resource_picture]
85     @resource_picture.overwrite @original_picture
86     @license = @resource_picture.license
87     
88     respond_to do |format|
89       format.html # new.html.erb
90       format.js
91     end
92   end
93   
94   def create
95     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
96     @imager = PettanImager.load @original_picture.restore
97     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
98     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id, @operators
99     @resource_picture = @original_picture.resource_picture
100     unless @resource_picture
101       @resource_picture = ResourcePicture.new
102       @resource_picture.supply_default
103     end
104     @resource_picture.attributes = params[:resource_picture]
105     @resource_picture.overwrite @original_picture
106     @resource_picture.boosts 'post'
107     @license = @resource_picture.license
108
109     respond_to do |format|
110       if @resource_picture.store(@imager)
111         format.html { redirect_to @resource_picture }
112         format.json { render json: @resource_picture.to_json(ResourcePicture.show_json_opt), status: :created, location: @resource_picture }
113       else
114         format.html { render action: "new" }
115         format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
116       end
117     end
118   end
119   
120   def destroy
121     @resource_picture = ResourcePicture.edit(params[:id], @operators)
122
123     respond_to do |format|
124       if @resource_picture.unpublish
125         format.html { redirect_to :controller => '/home', :action => :resource_pictures }
126         format.json { head :ok }
127       else
128         format.html { redirect_to resource_picture_path(@resource_picture) }
129         format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
130       end
131     end
132   end
133   
134   def count
135     @resource_picture = {:count => ResourcePicture.visible_count}
136     respond_to do |format|
137       format.json { render json: @resource_picture.to_json }
138     end
139   end
140   
141 end