X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;ds=sidebyside;f=app%2Fcontrollers%2Foriginal_pictures_controller.rb;h=8246a634e913a889b714f4cdc6df972fa28549c9;hb=d7c8065be895b67dc453b0e11ad0f259f1ca6706;hp=6b39ad03127610d44ead7250eef002aca3a8d747;hpb=20ba1e939ba583f314b9fd95121870dd7f66a6c2;p=pettanr%2Fpettanr.git diff --git a/app/controllers/original_pictures_controller.rb b/app/controllers/original_pictures_controller.rb index 6b39ad03..8246a634 100644 --- a/app/controllers/original_pictures_controller.rb +++ b/app/controllers/original_pictures_controller.rb @@ -1,144 +1,113 @@ #原画 class OriginalPicturesController < ApplicationController - layout 'test' if MagicNumber['test_layout'] - before_filter :authenticate_user!, :only => [:index, :show, :history, :new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:index, :show, :history, :new, :edit, :create, :update, :destroy] - before_filter :authenticate_admin!, :only => [:list, :browse] - before_filter :authenticate_artist, :only => [:index, :show, :history, :new, :edit, :create, :update, :destroy] + before_action :authenticate_reader, :only => [:show, :history] + before_action :authenticate_user, :only => [:index, :new, :edit, :create, :update, :destroy] + before_action :authenticate_artist, :only => [:index, :new, :edit, :create, :update, :destroy] - # 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.mylist(@artist.id, @page, @page_size) - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @original_pictures.to_json(OriginalPicture.list_json_opt) } - end + filer_list param: @operators end - # GET /original_pictures/1 - # GET /original_pictures/1.json + def show_html_format format + format.html { + #ライセンス付与のために原画ライセンスグループ作成準備 + @original_picture_license_group = OriginalPictureLicenseGroup.new :original_picture_id => @item.id + render + } + end + + def show_json_format format + format.json { render json: @item.to_json( + {:include => {:resource_picture => {}} } + )} + end + def show - @original_picture = OriginalPicture.show(params[:id], @admin || @artist) - + set_show 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 { - #ライセンス付与のために原画ライセンスグループ作成準備 - @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)} + opt = {:type => @item.mime_type, :disposition=>"inline"} + format.png { send_data(@item.restore(params[:subdir]), opt ) } + format.gif { send_data(@item.restore(params[:subdir]), opt ) } + format.jpeg { send_data(@item.restore(params[:subdir]), opt ) } + show_html_format format + show_prof_format format + show_json_format format end end - + def history - @original_picture = OriginalPicture.show(params[:id], @artist) - @history = @original_picture.history + set_show + @finder = @my_action.finder(param: params[:id]).page(1).per(-1) respond_to do |format| - format.html # index.html.erb - format.json { render json: @history.to_json } + format.html + list_json_format @finder, format end end - def list - @original_pictures = OriginalPicture.all - - respond_to do |format| - format.html { render layout: 'system' } - format.json { render json: @original_pictures } - end - end - - def browse - @original_picture = OriginalPicture.find(params[:id]) - - respond_to do |format| - format.html { render layout: 'system' } - format.json { render json: @original_picture } - end - end - def new - @original_picture = OriginalPicture.new - @original_picture.supply_default - + set_new respond_to do |format| - format.html # new.html.erb - format.js - format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt) } + format.html + format.json { render json: @item.to_json } end end - + def edit - @original_picture = OriginalPicture.edit(params[:id], @artist) + set_edit respond_to do |format| format.html - format.js + format.json { render json: @item.to_json } end end - + def create + set_model @imager = if params[:original_picture] PettanImager.load set_image params[:original_picture][:file] else nil end - @original_picture = OriginalPicture.new - @original_picture.supply_default - @original_picture.overwrite @artist - + @item = OriginalPicture.new + @item.supply_default + @item.overwrite @operators + respond_to do |format| - 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 } + if @item.store(@imager) + created_html_format format + created_json_format format else - format.html { render action: "new" } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } + not_created_html_format format + not_created_json_format format end end end - + def update + set_model @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 - + @item = OriginalPicture.edit(params[:id], @operators) + @item.overwrite @operators + respond_to do |format| - 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 } + if @item.store(@imager) + updated_html_format format + updated_json_format format else - format.html { render action: "edit" } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } + not_updated_html_format format + not_updated_json_format format end end end - + def destroy - @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 - end + set_model + @item = @my_model_class.edit(params[:id], @operators) + render_destroy_by 'destroy_with_resource_picture', original_pictures_url end + end