OSDN Git Service

add Picture
[pettanr/pettanr.git] / app / controllers / standard_licenses_controller.rb
1 class StandardLicensesController < ApplicationController
2   layout 'test' if Pettanr::TestLayout
3   before_filter :authenticate_user!, :only => [:new, :create]
4   before_filter :authenticate_artist, :only => [:new, :create]
5   
6   private
7   
8   def authenticate_artist
9     if @author.artist?
10       true
11     else
12       respond_to do |format|
13         format.html { redirect_to new_artist_path, :status => :found }
14         format.js { render "artists/new" }
15         format.json { 
16           raise ActiveRecord::Forbidden
17         }
18       end
19       false
20     end
21   end
22   
23   public
24   
25   # GET /standard_licenses/new
26   # GET /standard_licenses/new.js
27   def new
28     @original_picture = OriginalPicture.show params[:original_picture_id], @artist
29     @original_picture_license_group = OriginalPictureLicenseGroup.new(params[:original_picture_license_group])
30     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
31     @standard_license = StandardLicense.new
32     @standard_license.supply_default @artist
33
34     respond_to do |format|
35       format.html # new.html.erb
36       format.js
37     end
38   end
39
40   # POST /standard_licenses
41   # POST /standard_licenses.js
42   def create
43     @original_picture = OriginalPicture.show params[:original_picture_id], @artist
44     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
45     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
46     @standard_license = StandardLicense.new params[:standard_license]
47     @license = License.show @standard_license.license_id
48     @resource_picture = ResourcePicture.new :original_picture_id => @original_picture.id, 
49       :license_id => @license.id, :artist_name => @standard_license.artist_name, 
50       :credit => @standard_license.credit, :settings => @license.settings
51
52     respond_to do |format|
53       if @standard_license.valid?
54         format.html { render :template => "resource_pictures/new" }
55         format.js { render :template => "resource_pictures/new" }
56       else
57         format.html { render action: "new" }
58         format.js { render action: "new" }
59       end
60     end
61   end
62
63 end