OSDN Git Service

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