OSDN Git Service

rename model name
[pettanr/pettanr.git] / app / controllers / original_picture_license_groups_controller.rb
index 8897d16..457c5a4 100644 (file)
@@ -1,55 +1,50 @@
 class OriginalPictureLicenseGroupsController < ApplicationController
-  layout 'test' if Pettanr::TestLayout
-  before_filter :authenticate_user!, :only => [:new, :create]
+  before_filter :authenticate_user, :only => [:new, :create]
   before_filter :authenticate_artist, :only => [:new, :create]
   
-  private
-  
-  def authenticate_artist
-    if @author.artist?
-      true
-    else
-      respond_to do |format|
-        format.html { redirect_to new_artist_path, :status => :found }
-        format.js { render "artists/new" }
-        format.json { 
-          raise ActiveRecord::Forbidden
-        }
-      end
-      false
-    end
-  end
-  
-  public
-  
-  # GET /original_picture_license_groups/new
-  # GET /original_picture_license_groups/new.js
   def new
-    @original_picture = OriginalPicture.show params[:original_picture_id], @artist
-    @original_picture_license_group = OriginalPictureLicenseGroup.new()
-    @original_picture_license_group.supply_default @original_picture.id
-
+    @original_picture = OriginalPicture.show params[:original_picture_id], @operators
+    @item = OriginalPictureLicenseGroup.new()
+    @item.supply_default @original_picture.id
+    
     respond_to do |format|
-      format.html # new.html.erb
-      format.js
+      format.html {
+        @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
+      }
+      format.json { render json: @item.to_json }
     end
   end
-
-  # POST /original_picture_license_groups
-  # POST /original_picture_license_groups.js
+  
   def create
-    @original_picture = OriginalPicture.show params[:original_picture_id], @artist
-    @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
-    @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
-    @ctl = @license_group.classname.tableize
-
-    respond_to do |format|
-      if @original_picture_license_group.valid?
-        format.html { render :template => "#{@ctl}/new" }
-        format.js { render :template => "#{@ctl}/new" }
-      else
-        format.html { render action: "new" }
-        format.js { render action: "new" }
+    @my_model_class = OriginalPictureLicenseGroup
+    
+    @item = @my_model_class.new
+    @my_model_class.fold_extend_settings params[@my_model_class.item_name]
+    @item.attributes = params[@my_model_class.item_name]
+    @item.overwrite 
+    @original_picture = OriginalPicture.show @item.original_picture, @operators
+    
+    if @item.valid?
+      # switch my_model_class
+      @item = OriginalPictureLicenseGroup.build_original_picture_license @item, nil, @operators
+      respond_to do |format|
+        format.html {
+          @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
+          render :template => @item.path_name + '/new'
+        }
+        format.json {
+          render json: @item.to_json(), status: :created, location: @item
+        }
+      end
+    else
+      respond_to do |format|
+        format.html {
+          @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
+          render action: "new"
+        }
+        format.json {
+          render json: @item.errors, status: :unprocessable_entity
+        }
       end
     end
   end