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   def self.controller
13     Pettanr::Application::manifest.controller_managers[self.model.item_name]
14   end
15   def self.profiler_manager
16     Pettanr::Application::manifest.profiler_managers[self.model.item_name]
17   end
18   
19   def index
20     action_name = params[:action]
21     @action = self.class.controller.open(action_name, params, @operators)
22     @items = @action.items 
23     respond_to do |format|
24       format.html {
25         @filer = @action.filer
26         render :template => 'system/filer', :locals => {
27           :filer => @filer
28         }
29       }
30       format.json { render json: @items.to_json(self.class.model.list_json_opt) }
31       format.atom 
32       format.rss
33     end
34   end
35
36   def show
37     @item = OriginalPicture.show(params[:id], @operators)
38     
39     respond_to do |format|
40       opt = {:type => @item.mime_type, :disposition=>"inline"}
41       format.png { send_data(@item.restore, opt ) }
42       format.gif { send_data(@item.restore, opt ) }
43       format.jpeg { send_data(@item.restore, opt ) }
44       format.html {
45         @original_picture = @item
46         #ライセンス付与のために原画ライセンスグループ作成準備
47         @original_picture_license_group  = OriginalPictureLicenseGroup.new :original_picture_id => @item.id
48         render
49       }
50       format_prof format
51       format.json { render json: @item.to_json(OriginalPicture.show_json_opt)}
52     end
53   end
54
55   def history
56     @original_picture = OriginalPicture.show(params[:id], [@artist, @admin])
57     @history = @original_picture.history
58     
59     respond_to do |format|
60       format.html # index.html.erb
61       format.json { render json: @history.to_json }
62     end
63   end
64   
65   def list
66     @original_pictures = OriginalPicture.all
67
68     respond_to do |format|
69       format.html { render layout: 'system' }
70       format.json { render json: @original_pictures }
71     end
72   end
73
74   def browse
75     @original_picture = OriginalPicture.find(params[:id])
76
77     respond_to do |format|
78       format.html { render layout: 'system' }
79       format.json { render json: @original_picture }
80     end
81   end
82
83   def new
84     @original_picture = OriginalPicture.new
85     @original_picture.supply_default
86
87     respond_to do |format|
88       format.html # new.html.erb
89       format.js
90       format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt) }
91     end
92   end
93
94   def edit
95     @original_picture = OriginalPicture.edit(params[:id], @artist)
96     respond_to do |format|
97       format.html
98       format.js
99     end
100   end
101
102   def create
103     @imager = if params[:original_picture]
104       PettanImager.load set_image params[:original_picture][:file]
105     else
106       nil
107     end
108     @original_picture = OriginalPicture.new
109     @original_picture.supply_default
110     @original_picture.overwrite @artist
111
112     respond_to do |format|
113       if @original_picture.store(@imager)
114         flash[:notice] = I18n.t('flash.notice.created', :model => OriginalPicture.model_name.human)
115         format.html { redirect_to @original_picture }
116         format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture }
117       else
118         flash[:notice] = I18n.t('flash.notice.not_created', :model => OriginalPicture.model_name.human)
119         format.html { render action: "new" }
120         format.json { render json: @original_picture.errors, status: :unprocessable_entity }
121       end
122     end
123   end
124
125   def update
126     @imager = if params[:original_picture]
127       PettanImager.load set_image params[:original_picture][:file]
128     else
129       nil
130     end
131     @original_picture = OriginalPicture.edit(params[:id], @artist)
132     @original_picture.overwrite @artist
133
134     respond_to do |format|
135       if @original_picture.store(@imager)
136         flash[:notice] = I18n.t('flash.notice.updated', :model => OriginalPicture.model_name.human)
137         format.html { redirect_to @original_picture }
138         format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture }
139       else
140         flash[:notice] = I18n.t('flash.notice.not_updated', :model => OriginalPicture.model_name.human)
141         format.html { render action: "edit" }
142         format.json { render json: @original_picture.errors, status: :unprocessable_entity }
143       end
144     end
145   end
146
147   def destroy
148     @original_picture = OriginalPicture.edit(params[:id], @artist)
149     
150     respond_to do |format|
151       if @original_picture.destroy_with_resource_picture
152         format.html { redirect_to original_pictures_url }
153         format.json { head :ok }
154       else
155         format.html { redirect_to original_picture_path(@original_picture) }
156         format.json { render json: @original_picture.errors, status: :unprocessable_entity }
157       end
158     end
159   end
160 end