OSDN Git Service

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