class ResourcePicturesController < ApplicationController
- before_filter :authenticate_author!, :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, :by_artist, :count, :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
- @resource_pictures = ResourcePicture.find(:all,
- :include => {:original_picture => [:artist, :license]}, :order => 'updated_at', :limit => 20
- )
-
+ filer_list
+ end
+
+ def by_license
+ filer_list
+ end
+
+ def by_artist
+ filer_list
+ end
+
+ def show_html_format format
+ format.html {
+ @resource_picture = @item
+ }
+ end
+
+ def show
+ set_show
respond_to do |format|
- format.html # index.html.erb
- format.json { render :json => @resource_pictures.to_json(
- :include => [:original_picture, :artist, :license]
- ) }
+ 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.find(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}
+ format.html { render :layout => false } # show.html.erb
+ format.json { render :json => @resource_picture.to_json(ResourcePicture.show_json_opt)}
end
end
-
- def list
- @resource_pictures = ResourcePicture.all
-
+
+ def count
+ list_count
+ end
+
+ def count_by_license
+ list_count
+ end
+
+ def count_by_artist
+ list_count
+ end
+
+ def new
+ @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
+ @resource_picture = @original_picture.resource_picture
+ unless @resource_picture
+ @resource_picture = ResourcePicture.new
+ @resource_picture.supply_default
+ end
+ @resource_picture.attributes = params[:resource_picture]
+ @resource_picture.overwrite @original_picture
+ @license = @resource_picture.license
+
respond_to do |format|
- format.html { render layout: 'system' }
- format.json { render json: @resource_pictures }
+ format.html # new.html.erb
+ format.js
end
end
-
- def browse
- @resource_picture = ResourcePicture.find(params[:id])
+
+ def create
+ @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, @operators
+ @resource_picture = @original_picture.resource_picture
+ unless @resource_picture
+ @resource_picture = ResourcePicture.new
+ @resource_picture.supply_default
+ end
+ @resource_picture.attributes = params[:resource_picture]
+ @resource_picture.overwrite @original_picture
+ @license = @resource_picture.license
respond_to do |format|
- format.html { render layout: 'system' }
- format.json { render json: @resource_picture }
+ if @resource_picture.store(@imager)
+ format.html { redirect_to @resource_picture }
+ format.json { render json: @resource_picture.to_json(ResourcePicture.show_json_opt), status: :created, location: @resource_picture }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
+ end
end
end
+
+ def destroy
+ @resource_picture = ResourcePicture.edit(params[:id], @operators)
+ respond_to do |format|
+ 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