OSDN Git Service

update license test
[pettanr/pettanr.git] / app / controllers / original_licenses_controller.rb
index a6bf378..41a320e 100644 (file)
@@ -1,6 +1,19 @@
 class OriginalLicensesController < ApplicationController
-  before_filter :authenticate_admin!, :only => [:list, :browse, :new, :edit, :create, :update, :destroy]
+  layout 'test' if Pettanr::TestLayout
+  before_filter :authenticate_admin!, :only => [:list, :browse, :new, :edit, :create, :update, :destroy, :import]
 
+  private
+  
+  def set_data(file)
+    if file.respond_to?(:read)
+      file.read
+    else
+      file
+    end
+  end
+  
+  public
+  
   # GET /original_licenses
   # GET /original_licenses.json
   def index
@@ -109,4 +122,19 @@ class OriginalLicensesController < ApplicationController
       format.json { head :ok }
     end
   end
+  
+  def import
+    @data = set_data params[:file]
+    respond_to do |format|
+      @errors = OriginalLicense.import @data
+      if @errors and @errors.empty?
+        format.html { redirect_to :action => :list }
+        format.json { render text: 'ok', status: :created }
+      else
+        format.html { render action: "result" }
+        format.json { render json: @errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
 end