OSDN Git Service

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