OSDN Git Service

add folder
[pettanr/pettanr.git] / app / controllers / original_pictures_controller.rb
1 #原画
2 class OriginalPicturesController < ApplicationController
3   before_filter :authenticate_reader, :only => [:show, :history, :count]
4   before_filter :authenticate_user, :only => [:index, :new, :edit, :create, :update, :destroy]
5   before_filter :authenticate_artist, :only => [:index, :new, :edit, :create, :update, :destroy]
6   
7   def self.model
8     OriginalPicture
9   end
10   
11   def index
12     filer_list
13   end
14
15   def show_html_format format
16     format.html {
17       @item.boosts 'post'
18       @original_picture = @item
19       #ライセンス付与のために原画ライセンスグループ作成準備
20       @original_picture_license_group  = OriginalPictureLicenseGroup.new :original_picture_id => @item.id
21       render
22     }
23   end
24   
25   def show
26     set_show
27     respond_to do |format|
28       opt = {:type => @item.mime_type, :disposition=>"inline"}
29       format.png { send_data(@item.restore(params[:subdir]), opt ) }
30       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
31       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
32       show_html_format format
33       show_prof_format format
34       show_json_format format
35     end
36   end
37
38   def history
39     @original_picture = OriginalPicture.show(params[:id], @operators)
40     @history = @original_picture.history
41     
42     respond_to do |format|
43       format.html
44       format.json { render json: @history.to_json }
45     end
46   end
47   
48   def count
49     list_count
50   end
51   
52   def new
53     @original_picture = OriginalPicture.new
54     @original_picture.supply_default
55
56     respond_to do |format|
57       format.html
58       format.js
59       format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt) }
60     end
61   end
62
63   def edit
64     @original_picture = OriginalPicture.edit(params[:id], @operators)
65     respond_to do |format|
66       format.html
67       format.js
68     end
69   end
70
71   def create
72     @imager = if params[:original_picture]
73       PettanImager.load set_image params[:original_picture][:file]
74     else
75       nil
76     end
77     @original_picture = OriginalPicture.new
78     @original_picture.supply_default
79     @original_picture.overwrite @operators
80
81     respond_to do |format|
82       if @original_picture.store(@imager)
83         flash[:notice] = I18n.t('flash.notice.created', :model => OriginalPicture.model_name.human)
84         format.html { redirect_to @original_picture }
85         format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture }
86       else
87         flash[:notice] = I18n.t('flash.notice.not_created', :model => OriginalPicture.model_name.human)
88         format.html { render action: "new" }
89         format.json { render json: @original_picture.errors, status: :unprocessable_entity }
90       end
91     end
92   end
93
94   def update
95     @imager = if params[:original_picture]
96       PettanImager.load set_image params[:original_picture][:file]
97     else
98       nil
99     end
100     @original_picture = OriginalPicture.edit(params[:id], @operators)
101     @original_picture.overwrite @operators
102
103     respond_to do |format|
104       if @original_picture.store(@imager)
105         flash[:notice] = I18n.t('flash.notice.updated', :model => OriginalPicture.model_name.human)
106         format.html { redirect_to @original_picture }
107         format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture }
108       else
109         flash[:notice] = I18n.t('flash.notice.not_updated', :model => OriginalPicture.model_name.human)
110         format.html { render action: "edit" }
111         format.json { render json: @original_picture.errors, status: :unprocessable_entity }
112       end
113     end
114   end
115
116   def destroy
117     @original_picture = OriginalPicture.edit(params[:id], @operators)
118     
119     respond_to do |format|
120       if @original_picture.destroy_with_resource_picture
121         format.html { redirect_to original_pictures_url }
122         format.json { head :ok }
123       else
124         format.html { redirect_to original_picture_path(@original_picture) }
125         format.json { render json: @original_picture.errors, status: :unprocessable_entity }
126       end
127     end
128   end
129 end