+#原画
class OriginalPicturesController < ApplicationController
- before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
+ layout 'test' if MagicNumber['test_layout']
+ before_filter :authenticate_reader, :only => [:show, :history]
+ before_filter :authenticate_user, :only => [:index, :new, :edit, :create, :update, :destroy]
+ before_filter :authenticate_artist, :only => [:index, :new, :edit, :create, :update, :destroy]
before_filter :authenticate_admin!, :only => [:list, :browse]
- before_filter :authenticate_artist, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
-
- private
-
- def set_image(file)
- if file.respond_to?(:read)
- file.read
- else
- Base64.decode64(file.to_s.gsub(' ', '+')) #rubyのバグ?+でデコードされるべきキャラがスペースになる
- end
- end
-
- def authenticate_artist
- if @author.artist?
- true
- else
- respond_to do |format|
- format.html { redirect_to new_artist_path, :status => :found }
- format.js { render "artists/new" }
- format.json {
- raise ActiveRecord::Forbidden
- }
- end
- false
- end
- end
-
- public
# GET /original_pictures
# GET /original_pictures.json
def index
@page = OriginalPicture.page params[:page]
@page_size = OriginalPicture.page_size params[:page_size]
- @original_pictures = OriginalPicture.list(@artist.id, {}, @page, @page_size)
+ @original_pictures = OriginalPicture.mylist(@artist.id, @page, @page_size)
respond_to do |format|
format.html # index.html.erb
# GET /original_pictures/1
# GET /original_pictures/1.json
def show
- @original_picture = OriginalPicture.show(params[:id], @author)
-# if params[:subdir] == 'refresh'
-# refresh
-# return
-# end
-
+ @original_picture = OriginalPicture.show(params[:id], [@artist, @admin])
+
respond_to do |format|
opt = {:type => @original_picture.mime_type, :disposition=>"inline"}
format.png { send_data(@original_picture.restore, opt ) }
format.gif { send_data(@original_picture.restore, opt ) }
format.jpeg { send_data(@original_picture.restore, opt ) }
- format.html # show.html.erb
- format.json { render json: @original_picture}
+ format.html {
+ #ライセンス付与のために原画ライセンスグループ作成準備
+ @original_picture_license_group = OriginalPictureLicenseGroup.new :original_picture_id => @original_picture.id
+ render
+ }
+ format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt)}
end
end
+ def history
+ @original_picture = OriginalPicture.show(params[:id], [@artist, @admin])
+ @history = @original_picture.history
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @history.to_json }
+ end
+ end
+
def list
@original_pictures = OriginalPicture.all
end
end
- def refresh
- @original_picture = OriginalPicture.find(params[:id])
- img = Magick::Image.from_blob(@original_picture.restore).shift
- @original_picture.store img
- respond_to do |format|
- format.html { redirect_to original_pictures_url }
- end
- end
-
- # GET /original_pictures/new
- # GET /original_pictures/new.json
def new
@original_picture = OriginalPicture.new
- @original_picture.supply_default @artist
+ @original_picture.supply_default
respond_to do |format|
format.html # new.html.erb
format.js
- format.json { render json: @original_picture }
+ format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt) }
end
end
- # GET /original_pictures/1/edit
def edit
- @original_picture = OriginalPicture.show(params[:id], @author)
+ @original_picture = OriginalPicture.edit(params[:id], @artist)
respond_to do |format|
format.html
format.js
end
end
- # POST /original_pictures
- # POST /original_pictures.json
def create
- @picture_data = set_image params[:original_picture][:file]
+ @imager = if params[:original_picture]
+ PettanImager.load set_image params[:original_picture][:file]
+ else
+ nil
+ end
@original_picture = OriginalPicture.new
- @original_picture.supply_default @artist
+ @original_picture.supply_default
+ @original_picture.overwrite @artist
respond_to do |format|
- if @original_picture.store(@picture_data, @artist, params[:original_picture][:license_id])
- format.html { redirect_to @original_picture, notice: 'Original picture was successfully created.' }
- format.json { render json: @original_picture, status: :created, location: @original_picture }
+ if @original_picture.store(@imager)
+ flash[:notice] = I18n.t('flash.notice.created', :model => OriginalPicture.model_name.human)
+ format.html { redirect_to @original_picture }
+ format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture }
else
format.html { render action: "new" }
format.json { render json: @original_picture.errors, status: :unprocessable_entity }
end
end
- # PUT /original_pictures/1
- # PUT /original_pictures/1.json
def update
- @picture_data = set_image params[:original_picture][:file]
- @original_picture = OriginalPicture.show(params[:id], @author)
- @original_picture.supply_default @artist
+ @imager = if params[:original_picture]
+ PettanImager.load set_image params[:original_picture][:file]
+ else
+ nil
+ end
+ @original_picture = OriginalPicture.edit(params[:id], @artist)
+ @original_picture.overwrite @artist
respond_to do |format|
- if @original_picture.store(@picture_data, @artist, params[:original_picture][:license_id])
- format.html { redirect_to @original_picture, notice: 'Original picture was successfully created.' }
- format.json { render json: @original_picture, status: :created, location: @original_picture }
+ if @original_picture.store(@imager)
+ flash[:notice] = I18n.t('flash.notice.updated', :model => OriginalPicture.model_name.human)
+ format.html { redirect_to @original_picture }
+ format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture }
else
- format.html { render action: "new" }
+ format.html { render action: "edit" }
format.json { render json: @original_picture.errors, status: :unprocessable_entity }
end
end
end
- # DELETE /original_pictures/1
- # DELETE /original_pictures/1.json
def destroy
- @original_picture = OriginalPicture.find(params[:id], @author)
- OriginalPicture.transaction do
- @original_picture.destroy
- end
+ @original_picture = OriginalPicture.edit(params[:id], @artist)
respond_to do |format|
- format.html { redirect_to original_pictures_url }
- format.json { head :ok }
+ if @original_picture.destroy_with_resource_picture
+ format.html { redirect_to original_pictures_url }
+ format.json { head :ok }
+ else
+ format.html { redirect_to original_picture_path(@original_picture) }
+ format.json { render json: @original_picture.errors, status: :unprocessable_entity }
+ end
end
end
end