+#原画
class OriginalPicturesController < ApplicationController
- before_filter :authenticate_author!, :except => [:index, :show]
-
- private
+ 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]
- def set_image(prm)
- img = nil
- if (f = prm[:original_picture][:file]).respond_to?(:read)
- if f.size > 1000000
- @original_picture.width = 0
- @original_picture.height = 0
- @original_picture.ext = 'none'
- @original_picture.filesize = 1.megabytes
- else
- img = Magick::Image.from_blob(f.read).shift
- @original_picture.width = img.columns
- @original_picture.height = img.rows
- @original_picture.ext = img.format.downcase
- @original_picture.filesize = f.size
- end
- else
- dat = Base64.decode64(prm[:original_picture][:file].to_s.gsub(' ', '+')) #rubyのバグ?+でデコードされるべきキャラがスペースになる
- img = Magick::Image.from_blob(dat).shift
- @original_picture.width = img.columns
- @original_picture.height = img.rows
- @original_picture.ext = img.format.downcase
- @original_picture.filesize = 1000
- end
- img
+ def self.model
+ OriginalPicture
+ end
+ def self.controller
+ Pettanr::Application::manifest.controller_managers[self.model.item_name]
+ end
+ def self.profiler_manager
+ Pettanr::Application::manifest.profiler_managers[self.model.item_name]
end
- public
-
- # GET /original_pictures
- # GET /original_pictures.json
def index
- @original_pictures = OriginalPicture.all
-
+ action_name = params[:action]
+ @action = self.class.controller.open(action_name, params, @operators)
+ @items = @action.items
respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @original_pictures }
+ format.html {
+ @filer = @action.filer
+ render :template => 'system/filer', :locals => {
+ :filer => @filer
+ }
+ }
+ format.json { render json: @items.to_json(self.class.model.list_json_opt) }
+ format.atom
+ format.rss
end
end
- # GET /original_pictures/1
- # GET /original_pictures/1.json
def show
- @original_picture = OriginalPicture.find(params[:id])
-# if params[:subdir] == 'refresh'
-# refresh
-# return
-# end
+ @item = OriginalPicture.show(params[:id], @operators)
+
+ respond_to do |format|
+ opt = {:type => @item.mime_type, :disposition=>"inline"}
+ format.png { send_data(@item.restore, opt ) }
+ format.gif { send_data(@item.restore, opt ) }
+ format.jpeg { send_data(@item.restore, opt ) }
+ format.html {
+ @original_picture = @item
+ #ライセンス付与のために原画ライセンスグループ作成準備
+ @original_picture_license_group = OriginalPictureLicenseGroup.new :original_picture_id => @item.id
+ render
+ }
+ format_prof format
+ format.json { render json: @item.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
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 { render layout: 'system' }
+ format.json { render json: @original_pictures }
end
end
- def refresh
+ def browse
@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 }
+ format.html { render layout: 'system' }
+ format.json { render json: @original_picture }
end
end
-
- # GET /original_pictures/new
- # GET /original_pictures/new.json
+
def new
@original_picture = OriginalPicture.new
+ @original_picture.supply_default
respond_to do |format|
format.html # new.html.erb
- format.json { render json: @original_picture }
+ format.js
+ format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt) }
end
end
- # GET /original_pictures/1/edit
def edit
- @original_picture = OriginalPicture.find(params[:id])
+ @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
- unless @artist
- respond_to do |format|
- format.html { redirect_to @original_picture, notice: 'Failed! author does not artist.' }
- format.json { render json: @original_picture.errors, status: :unprocessable_entity }
- end
- return
+ @imager = if params[:original_picture]
+ PettanImager.load set_image params[:original_picture][:file]
+ else
+ nil
end
@original_picture = OriginalPicture.new
- img = set_image params
- @original_picture.artist_id = current_author.artist.id
+ @original_picture.supply_default
+ @original_picture.overwrite @artist
respond_to do |format|
- OriginalPicture.transaction do
- if @original_picture.save
- if @original_picture.store(img)
- format.html { redirect_to @original_picture, notice: 'Original picture was successfully created.' }
- format.json { render json: @original_picture, status: :created, location: @original_picture }
- else
- format.html { redirect_to @original_picture, notice: 'Failed! Original picture was NOT created.' }
- format.json { render json: @original_picture.errors, status: :unprocessable_entity }
- end
- else
- format.html { render action: "new" }
- format.json { render json: @original_picture.errors, status: :unprocessable_entity }
- end
+ 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
+ flash[:notice] = I18n.t('flash.notice.not_created', :model => OriginalPicture.model_name.human)
+ format.html { render action: "new" }
+ format.json { render json: @original_picture.errors, status: :unprocessable_entity }
end
end
end
- # PUT /original_pictures/1
- # PUT /original_pictures/1.json
def update
- unless @artist
- respond_to do |format|
- format.html { redirect_to @original_picture, notice: 'Failed! author does not artist.' }
- format.json { render json: @original_picture.errors, status: :unprocessable_entity }
- end
- return
- end
- @original_picture = OriginalPicture.find(params[:id])
- unless @original_picture.own? current_author
- respond_to do |format|
- format.html { redirect_to @original_picture, notice: 'Failed! ' }
- format.json { render json: @original_picture.errors, status: :unprocessable_entity }
- end
- return
+ @imager = if params[:original_picture]
+ PettanImager.load set_image params[:original_picture][:file]
+ else
+ nil
end
- img = set_image params
+ @original_picture = OriginalPicture.edit(params[:id], @artist)
+ @original_picture.overwrite @artist
respond_to do |format|
- OriginalPicture.transaction do
- if @original_picture.save
- if @original_picture.store(img)
- format.html { redirect_to @original_picture, notice: 'Original picture was successfully updated.' }
- format.json { head :ok }
- else
- format.html { redirect_to @original_picture, notice: 'Failed! Original picture was NOT created.' }
- format.json { render json: @original_picture.errors, status: :unprocessable_entity }
- end
- else
- format.html { render action: "edit" }
- format.json { render json: @original_picture.errors, status: :unprocessable_entity }
- end
+ 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
+ flash[:notice] = I18n.t('flash.notice.not_updated', :model => OriginalPicture.model_name.human)
+ 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
- unless @artist
- respond_to do |format|
- format.html { redirect_to @original_picture, notice: 'Failed! author does not artist.' }
- format.json { render json: @original_picture.errors, status: :unprocessable_entity }
- end
- return
- end
- @original_picture = OriginalPicture.find(params[:id])
- unless @original_picture.own? current_author
- respond_to do |format|
- format.html { redirect_to @original_picture, notice: 'Failed! ' }
+ @original_picture = OriginalPicture.edit(params[:id], @artist)
+
+ respond_to do |format|
+ 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
- return
- end
- @original_picture.destroy
-
- respond_to do |format|
- format.html { redirect_to original_pictures_url }
- format.json { head :ok }
end
end
end