X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fresource_pictures_controller.rb;h=a0847fe5821d39157e26215eb523a60864b7067d;hb=69b61b39006c1951fc8c08746e884e63e50233b3;hp=a68cd7c801f26e0a73095ee9881249de9f2e6da0;hpb=e238f6a0e79f30d8a9fca5f9af3a1fa6317f401a;p=pettanr%2Fpettanr.git diff --git a/app/controllers/resource_pictures_controller.rb b/app/controllers/resource_pictures_controller.rb index a68cd7c8..a0847fe5 100644 --- a/app/controllers/resource_pictures_controller.rb +++ b/app/controllers/resource_pictures_controller.rb @@ -1,58 +1,132 @@ class ResourcePicturesController < ApplicationController - before_filter :authenticate_user!, :only => [:index, :show] - before_filter :authenticate_admin!, :only => [:list, :browse] + if Manifest.manifest.magic_numbers['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, :by_license_group, :by_license, :by_artist, :count, :count_by_license_group, :count_by_license, :count_by_artist + ] + 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) - + filer_list + end + + def by_license_group + filer_list + end + + def by_license + filer_list + end + + def by_artist + filer_list + end + + def show_html_format format + format.html { + @item.boosts 'post' + } + end + + def show + set_show respond_to do |format| - format.html # index.html.erb - format.json { render :json => @resource_pictures.to_json(ResourcePicture.list_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 - - # GET /resource_pictures/1 - # GET /resource_pictures/1.json - def show - @resource_picture = ResourcePicture.show(params[:id]) - + + def credit + @resource_picture = 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.list_json_opt)} + format.html { render :layout => false } # show.html.erb end end - + def count - @resource_picture = {:count => ResourcePicture.visible_count} + list_count + end + + def count_by_license_group + list_count + end + + def count_by_license + list_count + end + + def count_by_artist + list_count + end + + def new + # use @item, @original_picture respond_to do |format| - format.json { render json: @resource_picture.to_json } + format.html end end - def list - @resource_pictures = ResourcePicture.all - + def create + @original_picture = OriginalPicture.edit params[:original_picture_id], @operators + @imager = PettanImager.load @original_picture.restore + jsn = nil + if params[:json] + jsn = JSON.parse_no_except(params[:json]) + end + @prm = if params[:resource_picture] == nil or params[:resource_picture].empty? + jsn + else + params[:resource_picture] + end + @item = @original_picture.resource_picture || ResourcePicture.new + @item.attributes = @prm + @item.overwrite @original_picture + @item.boosts 'post' + respond_to do |format| - format.html { render layout: 'system' } - format.json { render json: @resource_pictures } + if @item.store(@imager) + format.html { redirect_to @item } + format.json { render json: @item.to_json, status: :created, location: @item } + else + format.html { render action: "new" } + format.json { render json: @item.errors, status: :unprocessable_entity } + end end end - - def browse - @resource_picture = ResourcePicture.find(params[:id]) + + def destroy + @resource_picture = ResourcePicture.edit(params[:id], @operators) respond_to do |format| - format.html { render layout: 'system' } - format.json { render json: @resource_picture } + if @resource_picture.unpublish + format.html { redirect_to :controller => '/home', :action => :resource_pictures } + 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 count + @resource_picture = {:count => ResourcePicture.visible_count} + respond_to do |format| + format.json { render json: @resource_picture.to_json } + end + end + end