OSDN Git Service

change editor
[pettanr/pettanr.git] / app / controllers / system_pictures_controller.rb
index 71708b7..3917ca6 100644 (file)
 class SystemPicturesController < ApplicationController
-  before_filter :authenticate_admin!, :except => [:index, :show]
-
-  private
+  if Manifest.manifest.magic_numbers['run_mode'] == 0
+    before_filter :authenticate_user, :only => []
+    before_filter :authenticate_author, :only => []
+  else
+    before_filter :authenticate_resource_reader, :only => [:index, :show]
+    before_filter :authenticate_user, :only => []
+    before_filter :authenticate_author, :only => []
+  end
+  before_filter :authenticate_admin!, :only => []
   
-  def set_image(prm)
-    img = nil
-    if (f = prm[:system_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 index
+    filer_list
   end
   
-  # GET /system_pictures
-  # GET /system_pictures.json
-  def index
-    @system_pictures = SystemPicture.all
-
-    respond_to do |format|
-      format.html # index.html.erb
-      format.json { render json: @system_pictures }
-    end
+  def show_html_format format
+    format.html {
+    }
   end
-
-  # GET /system_pictures/1
-  # GET /system_pictures/1.json
+  
   def show
-    @system_picture = SystemPicture.find(params[:id])
-
-    respond_to do |format|
-      format.html # show.html.erb
-      format.json { render json: @system_picture }
-    end
-  end
-
-  # GET /system_pictures/new
-  # GET /system_pictures/new.json
-  def new
-    @system_picture = SystemPicture.new
-
-    respond_to do |format|
-      format.html # new.html.erb
-      format.json { render json: @system_picture }
-    end
-  end
-
-  # GET /system_pictures/1/edit
-  def edit
-    @system_picture = SystemPicture.find(params[:id])
-  end
-
-  # POST /system_pictures
-  # POST /system_pictures.json
-  def create
-    @original_picture = OriginalPicture.new
-    img = set_image params
-
-    respond_to do |format|
-      SystemPicture.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
-      end
-    end
-    @system_picture = SystemPicture.new(params[:system_picture])
-
+    set_show
     respond_to do |format|
-      if @system_picture.save
-        format.html { redirect_to @system_picture, notice: 'System picture was successfully created.' }
-        format.json { render json: @system_picture, status: :created, location: @system_picture }
-      else
-        format.html { render action: "new" }
-        format.json { render json: @system_picture.errors, status: :unprocessable_entity }
-      end
+      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 ) }
+      show_html_format format
+      show_prof_format format
+      show_json_format format
     end
   end
-
-  # PUT /system_pictures/1
-  # PUT /system_pictures/1.json
-  def update
-    @system_picture = SystemPicture.find(params[:id])
-
-    respond_to do |format|
-      if @system_picture.update_attributes(params[:system_picture])
-        format.html { redirect_to @system_picture, notice: 'System picture was successfully updated.' }
-        format.json { head :ok }
-      else
-        format.html { render action: "edit" }
-        format.json { render json: @system_picture.errors, status: :unprocessable_entity }
-      end
-    end
-  end
-
-  # DELETE /system_pictures/1
-  # DELETE /system_pictures/1.json
-  def destroy
-    @system_picture = SystemPicture.find(params[:id])
-    @system_picture.destroy
-
-    respond_to do |format|
-      format.html { redirect_to system_pictures_url }
-      format.json { head :ok }
-    end
+  
+  def count
+    list_count
   end
+  
 end