OSDN Git Service

t#:
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
index 8d31b6d..e75fc0b 100644 (file)
@@ -1,39 +1,40 @@
 class ResourcePicturesController < ApplicationController
-  layout 'test' if Pettanr::TestLayout
-  before_filter :authenticate_user!, :only => [:index, :show, :credit, :new, :create, :update]
-  before_filter :authenticate_admin!, :only => [:list, :browse]
-  before_filter :authenticate_artist, :only => [:new, :create]
+  layout 'test' if MagicNumber['test_layout']
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
+    before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
+  else
+    before_filter :authenticate_resource_reader, :only => [:index, :show, :credit]
+    before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
+    before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
+  end
 
-  # GET /resource_pictures
-  # GET /resource_pictures.json
+  def self.model
+    ResourcePicture
+  end
+  
   def index
-    @page = ResourcePicture.page params[:page]
-    @page_size = ResourcePicture.page_size params[:page_size]
-    @resource_pictures = ResourcePicture.list(@page, @page_size)
-
-    respond_to do |format|
-      format.html # index.html.erb
-      format.json { render :json => @resource_pictures.to_json(ResourcePicture.list_json_opt) }
-    end
+    public_list
   end
 
-  # GET /resource_pictures/1
-  # GET /resource_pictures/1.json
   def show
-    @resource_picture = ResourcePicture.show(params[:id], @author)
+    @item = ResourcePicture.show(params[:id], @operators)
 
     respond_to do |format|
-      opt = {:type => @resource_picture.mime_type, :disposition=>"inline"}
-      format.png { send_data(@resource_picture.restore(params[:subdir]), opt ) }
-      format.gif { send_data(@resource_picture.restore(params[:subdir]), opt ) }
-      format.jpeg { send_data(@resource_picture.restore(params[:subdir]), opt ) }
-      format.html # show.html.erb
-      format.json { render :json => @resource_picture.to_json(ResourcePicture.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 ) }
+      format.html {
+        @resource_picture = @item
+      }
+      format_prof format
+      format.json { render :json => @item.to_json(ResourcePicture.show_json_opt)}
     end
   end
   
   def credit
-    @resource_picture = ResourcePicture.show(params[:id], @author)
+    @resource_picture = ResourcePicture.show(params[:id], @operators)
 
     respond_to do |format|
       format.html { render :layout => false } # show.html.erb
@@ -42,7 +43,7 @@ class ResourcePicturesController < ApplicationController
   end
   
   def new
-    @original_picture = OriginalPicture.edit params[:original_picture_id], @artist
+    @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
     @imager = PettanImager.load @original_picture.restore
     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
@@ -62,7 +63,7 @@ class ResourcePicturesController < ApplicationController
   end
   
   def create
-    @original_picture = OriginalPicture.edit params[:original_picture_id], @artist
+    @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
     @imager = PettanImager.load @original_picture.restore
     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
@@ -86,29 +87,25 @@ class ResourcePicturesController < ApplicationController
     end
   end
   
-  def count
-    @resource_picture = {:count => ResourcePicture.visible_count}
-    respond_to do |format|
-      format.json { render json: @resource_picture.to_json }
-    end
-  end
-  
-  def list
-    @resource_pictures = ResourcePicture.all
+  def destroy
+    @resource_picture = ResourcePicture.edit(params[:id], @operators)
 
     respond_to do |format|
-      format.html { render layout: 'system' }
-      format.json { render json: @resource_pictures }
+      if @resource_picture.unpublish
+        format.html { redirect_to :controller => '/home', :action => :resource_picture }
+        format.json { head :ok }
+      else
+        format.html { redirect_to resource_picture_path(@resource_picture) }
+        format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
+      end
     end
   end
-
-  def browse
-    @resource_picture = ResourcePicture.find(params[:id])
-
+  
+  def count
+    @resource_picture = {:count => ResourcePicture.visible_count}
     respond_to do |format|
-      format.html { render layout: 'system' }
-      format.json { render json: @resource_picture }
+      format.json { render json: @resource_picture.to_json }
     end
   end
-
+  
 end