OSDN Git Service

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