OSDN Git Service

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