OSDN Git Service

add lg_id in resource picture
[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_group, :by_license, :by_artist, :count, :count_by_license_group, :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_group
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     }
37   end
38   
39   def show
40     set_show
41     respond_to do |format|
42       opt = {:type => @item.mime_type, :disposition=>"inline"}
43       format.png { send_data(@item.restore(params[:subdir]), opt ) }
44       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
45       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
46       show_html_format format
47       show_prof_format format
48       show_json_format format
49     end
50   end
51   
52   def credit
53     @resource_picture = ResourcePicture.show(params[:id], @operators)
54     
55     respond_to do |format|
56       format.html { render :layout => false } # show.html.erb
57     end
58   end
59   
60   def count
61     list_count
62   end
63   
64   def count_by_license_group
65     list_count
66   end
67   
68   def count_by_license
69     list_count
70   end
71   
72   def count_by_artist
73     list_count
74   end
75   
76   def new
77     # use @item, @original_picture
78     respond_to do |format|
79       format.html
80     end
81   end
82   
83   def create
84     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
85     @imager = PettanImager.load @original_picture.restore
86     jsn = nil
87     if params[:json]
88       jsn = JSON.parse_no_except(params[:json])
89     end
90     @prm = if params[:resource_picture] == nil or params[:resource_picture].empty?
91        jsn
92     else
93        params[:resource_picture]
94     end
95     @item = @original_picture.resource_picture || ResourcePicture.new
96     @item.attributes = @prm
97     @item.overwrite @original_picture
98     @item.boosts 'post'
99     
100     respond_to do |format|
101       if @item.store(@imager)
102         format.html { redirect_to @item }
103         format.json { render json: @item.to_json, status: :created, location: @item }
104       else
105         format.html { render action: "new" }
106         format.json { render json: @item.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