OSDN Git Service

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