OSDN Git Service

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