OSDN Git Service

e6b36f548729d96eb9f346222902aa574e5fd636
[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_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_license
22     filer_list
23   end
24   
25   def by_artist
26     filer_list
27   end
28   
29   def show_html_format format
30     format.html {
31       @item.boosts 'post'
32     }
33   end
34   
35   def show
36     set_show
37     respond_to do |format|
38       opt = {:type => @item.mime_type, :disposition=>"inline"}
39       format.png { send_data(@item.restore(params[:subdir]), opt ) }
40       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
41       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
42       show_html_format format
43       show_prof_format format
44       show_json_format format
45     end
46   end
47   
48   def credit
49     @resource_picture = ResourcePicture.show(params[:id], @operators)
50     
51     respond_to do |format|
52       format.html { render :layout => false } # show.html.erb
53     end
54   end
55   
56   def count
57     list_count
58   end
59   
60   def count_by_license
61     list_count
62   end
63   
64   def count_by_artist
65     list_count
66   end
67   
68   def new
69     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
70     @imager = PettanImager.load @original_picture.restore
71     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
72     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
73     @resource_picture = @original_picture.resource_picture
74     unless @resource_picture
75       @resource_picture = ResourcePicture.new
76       @resource_picture.supply_default
77     end
78     @resource_picture.attributes = params[:resource_picture]
79     @resource_picture.overwrite @original_picture
80     @license = @resource_picture.license
81     
82     respond_to do |format|
83       format.html # new.html.erb
84       format.js
85     end
86   end
87   
88   def create
89     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
90     @imager = PettanImager.load @original_picture.restore
91     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
92     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id, @operators
93     @resource_picture = @original_picture.resource_picture
94     unless @resource_picture
95       @resource_picture = ResourcePicture.new
96       @resource_picture.supply_default
97     end
98     @resource_picture.attributes = params[:resource_picture]
99     @resource_picture.overwrite @original_picture
100     @resource_picture.boosts 'post'
101     @license = @resource_picture.license
102
103     respond_to do |format|
104       if @resource_picture.store(@imager)
105         format.html { redirect_to @resource_picture }
106         format.json { render json: @resource_picture.to_json(ResourcePicture.show_json_opt), status: :created, location: @resource_picture }
107       else
108         format.html { render action: "new" }
109         format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
110       end
111     end
112   end
113   
114   def destroy
115     @resource_picture = ResourcePicture.edit(params[:id], @operators)
116
117     respond_to do |format|
118       if @resource_picture.unpublish
119         format.html { redirect_to :controller => '/home', :action => :resource_pictures }
120         format.json { head :ok }
121       else
122         format.html { redirect_to resource_picture_path(@resource_picture) }
123         format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
124       end
125     end
126   end
127   
128   def count
129     @resource_picture = {:count => ResourcePicture.visible_count}
130     respond_to do |format|
131       format.json { render json: @resource_picture.to_json }
132     end
133   end
134   
135 end