OSDN Git Service

fix: local manifest/add helper
[pettanr/pettanr.git] / app / controllers / original_pictures_controller.rb
index 7bf19cc..c902cf9 100644 (file)
@@ -1,39 +1,43 @@
 #原画
 class OriginalPicturesController < ApplicationController
-  before_filter :authenticate_reader, :only => [:show, :history, :count]
+  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]
   
-  def self.model
-    OriginalPicture
-  end
-  
   def index
     filer_list
   end
 
+  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
-    @item = OriginalPicture.show(params[:id], @operators)
-    
+    set_show
     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)}
+      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], @operators)
-    @history = @original_picture.history
+    set_show
+    @history = @item.history
     
     respond_to do |format|
       format.html
@@ -41,84 +45,76 @@ class OriginalPicturesController < ApplicationController
     end
   end
   
-  def count
-    list_count
-  end
-  
   def new
-    @original_picture = OriginalPicture.new
-    @original_picture.supply_default
-
+    set_new
     respond_to do |format|
       format.html
-      format.js
-      format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt) }
+      format.json { render json: @item.to_json }
     end
   end
-
+  
   def edit
-    @original_picture = OriginalPicture.edit(params[:id], @operators)
+    set_edit
     respond_to do |format|
       format.html
-      format.js
+      format.json { render json: @item.to_json }
     end
   end
-
+  
   def create
+    set_model
+    p  params[: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
-    @original_picture.overwrite @operators
-
+    @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
-        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 }
+        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], @operators)
-    @original_picture.overwrite @operators
-
+    @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
-        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 }
+        not_updated_html_format format
+        not_updated_json_format format
       end
     end
   end
-
+  
   def destroy
-    @original_picture = OriginalPicture.edit(params[:id], @operators)
+    @item = OriginalPicture.edit(params[:id], @operators)
     
     respond_to do |format|
-      if @original_picture.destroy_with_resource_picture
+      if @item.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 }
+        format.html { redirect_to original_picture_path(@item) }
+        format.json { render json: @item.errors, status: :unprocessable_entity }
       end
     end
   end