OSDN Git Service

add editor
[pettanr/pettanr.git] / app / controllers / original_pictures_controller.rb
1 #原画
2 class OriginalPicturesController < ApplicationController
3   before_filter :authenticate_reader, :only => [:show, :history]
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     public_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 new
45     @original_picture = OriginalPicture.new
46     @original_picture.supply_default
47
48     respond_to do |format|
49       format.html
50       format.js
51       format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt) }
52     end
53   end
54
55   def edit
56     @original_picture = OriginalPicture.edit(params[:id], @operators)
57     respond_to do |format|
58       format.html
59       format.js
60     end
61   end
62
63   def create
64     @imager = if params[:original_picture]
65       PettanImager.load set_image params[:original_picture][:file]
66     else
67       nil
68     end
69     @original_picture = OriginalPicture.new
70     @original_picture.supply_default
71     @original_picture.overwrite @operators
72
73     respond_to do |format|
74       if @original_picture.store(@imager)
75         flash[:notice] = I18n.t('flash.notice.created', :model => OriginalPicture.model_name.human)
76         format.html { redirect_to @original_picture }
77         format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture }
78       else
79         flash[:notice] = I18n.t('flash.notice.not_created', :model => OriginalPicture.model_name.human)
80         format.html { render action: "new" }
81         format.json { render json: @original_picture.errors, status: :unprocessable_entity }
82       end
83     end
84   end
85
86   def update
87     @imager = if params[:original_picture]
88       PettanImager.load set_image params[:original_picture][:file]
89     else
90       nil
91     end
92     @original_picture = OriginalPicture.edit(params[:id], @operators)
93     @original_picture.overwrite @operators
94
95     respond_to do |format|
96       if @original_picture.store(@imager)
97         flash[:notice] = I18n.t('flash.notice.updated', :model => OriginalPicture.model_name.human)
98         format.html { redirect_to @original_picture }
99         format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture }
100       else
101         flash[:notice] = I18n.t('flash.notice.not_updated', :model => OriginalPicture.model_name.human)
102         format.html { render action: "edit" }
103         format.json { render json: @original_picture.errors, status: :unprocessable_entity }
104       end
105     end
106   end
107
108   def destroy
109     @original_picture = OriginalPicture.edit(params[:id], @operators)
110     
111     respond_to do |format|
112       if @original_picture.destroy_with_resource_picture
113         format.html { redirect_to original_pictures_url }
114         format.json { head :ok }
115       else
116         format.html { redirect_to original_picture_path(@original_picture) }
117         format.json { render json: @original_picture.errors, status: :unprocessable_entity }
118       end
119     end
120   end
121 end