OSDN Git Service

rename model name
[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 index
14     filer_list
15   end
16   
17   def by_license_group
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_group
61     list_count
62   end
63   
64   def count_by_license
65     list_count
66   end
67   
68   def count_by_artist
69     list_count
70   end
71   
72   def new
73     # use @item, @original_picture
74     respond_to do |format|
75       format.html
76     end
77   end
78   
79   def create
80     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
81     @imager = PettanImager.load @original_picture.restore
82     jsn = nil
83     if params[:json]
84       jsn = JSON.parse_no_except(params[:json])
85     end
86     @prm = if params[:resource_picture] == nil or params[:resource_picture].empty?
87        jsn
88     else
89        params[:resource_picture]
90     end
91     @item = @original_picture.resource_picture || ResourcePicture.new
92     @item.attributes = @prm
93     @item.overwrite @original_picture
94     @item.boosts 'post'
95     
96     respond_to do |format|
97       if @item.store(@imager)
98         format.html { redirect_to @item }
99         format.json { render json: @item.to_json, status: :created, location: @item }
100       else
101         format.html { render action: "new" }
102         format.json { render json: @item.errors, status: :unprocessable_entity }
103       end
104     end
105   end
106   
107   def destroy
108     @resource_picture = ResourcePicture.edit(params[:id], @operators)
109
110     respond_to do |format|
111       if @resource_picture.unpublish
112         format.html { redirect_to :controller => '/home', :action => :resource_pictures }
113         format.json { head :ok }
114       else
115         format.html { redirect_to resource_picture_path(@resource_picture) }
116         format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
117       end
118     end
119   end
120   
121   def count
122     @resource_picture = {:count => ResourcePicture.visible_count}
123     respond_to do |format|
124       format.json { render json: @resource_picture.to_json }
125     end
126   end
127   
128 end