OSDN Git Service

change page status for offset
[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, :count, 
8       :by_original_picture, :by_license_group, :by_license, :by_artist, 
9       :count_by_original_picture, :count_by_license_group, :count_by_license, :count_by_artist
10     ]
11     before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
12     before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
13   end
14   
15   def index
16     filer_list
17   end
18   
19   def by_original_picture
20     filer_list
21   end
22   
23   def by_license_group
24     filer_list
25   end
26   
27   def by_license
28     filer_list
29   end
30   
31   def by_artist
32     filer_list
33   end
34   
35   def show_html_format format
36     format.html {
37       @item.boosts 'post'
38     }
39   end
40   
41   def show
42     set_show
43     respond_to do |format|
44       opt = {:type => @item.mime_type, :disposition=>"inline"}
45       format.png { send_data(@item.restore(params[:subdir]), opt ) }
46       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
47       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
48       show_html_format format
49       show_prof_format format
50       show_json_format format
51     end
52   end
53   
54   def credit
55     @resource_picture = ResourcePicture.show(params[:id], @operators)
56     
57     respond_to do |format|
58       format.html { render :layout => false } # show.html.erb
59     end
60   end
61   
62   def count
63     list_count
64   end
65   
66   def count_by_original_picture
67     list_count
68   end
69   
70   def count_by_license_group
71     list_count
72   end
73   
74   def count_by_license
75     list_count
76   end
77   
78   def count_by_artist
79     list_count
80   end
81   
82   def new
83     # use @item, @original_picture
84     respond_to do |format|
85       format.html
86     end
87   end
88   
89   def create
90     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
91     @imager = PettanImager.load @original_picture.restore
92     jsn = nil
93     if params[:json]
94       jsn = JSON.parse_no_except(params[:json])
95     end
96     @prm = if params[:resource_picture] == nil or params[:resource_picture].empty?
97        jsn
98     else
99        params[:resource_picture]
100     end
101     @item = @original_picture.resource_picture || ResourcePicture.new
102     @item.attributes = @prm
103     @item.overwrite @original_picture
104     @item.boosts 'post'
105     
106     respond_to do |format|
107       if @item.store(@imager)
108         format.html { redirect_to @item }
109         format.json { render json: @item.to_json, status: :created, location: @item }
110       else
111         format.html { render action: "new" }
112         format.json { render json: @item.errors, status: :unprocessable_entity }
113       end
114     end
115   end
116   
117   def destroy
118     @resource_picture = ResourcePicture.edit(params[:id], @operators)
119
120     respond_to do |format|
121       if @resource_picture.unpublish
122         format.html { redirect_to :controller => '/home', :action => :resource_pictures }
123         format.json { head :ok }
124       else
125         format.html { redirect_to resource_picture_path(@resource_picture) }
126         format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
127       end
128     end
129   end
130   
131   def count
132     @resource_picture = {:count => ResourcePicture.visible_count}
133     respond_to do |format|
134       format.json { render json: @resource_picture.to_json }
135     end
136   end
137   
138 end