OSDN Git Service

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