2 class CommonLicensesController < ApplicationController
3 layout 'test' if Pettanr::TestLayout
4 before_filter :authenticate_user!, :only => [:index, :show]
5 before_filter :authenticate_admin!, :only => [:list, :browse, :import, :destroy]
10 if file.respond_to?(:read)
19 # GET /common_licenses
20 # GET /common_licenses.json
22 @page = CommonLicense.page params[:page]
23 @page_size = CommonLicense.page_size params[:page_size]
24 @common_licenses = CommonLicense.list({}, @page, @page_size)
26 respond_to do |format|
27 format.html # index.html.erb
28 format.json { render json: @common_licenses.to_json(CommonLicense.list_json_opt) }
32 # GET /common_licenses/1
33 # GET /common_licenses/1.json
35 @common_license = CommonLicense.show(params[:id])
37 respond_to do |format|
38 format.html # show.html.erb
39 format.json { render json: @common_license.to_json(CommonLicense.show_json_include_opt) }
44 @common_licenses = CommonLicense.all
46 respond_to do |format|
47 format.html { render layout: 'system' }
48 format.json { render json: @common_licenses }
53 @common_license = CommonLicense.find(params[:id])
55 respond_to do |format|
56 format.html { render layout: 'system' }
57 format.json { render json: @common_license }
61 # POST /common_licenses
62 # POST /common_licenses.json
64 @data = set_data params[:file]
65 respond_to do |format|
66 @errors = CommonLicense.import @data
67 if @errors and @errors.empty?
68 format.html { redirect_to :action => :list }
69 format.json { render text: 'ok', status: :created }
71 #@errorsがNILならJson展開できない全体異常
72 format.html { render action: "result" }
73 format.json { render json: @errors, status: :unprocessable_entity }
78 # DELETE /common_licenses/1
79 # DELETE /common_licenses/1.json
81 @common_license = CommonLicense.find(params[:id])
82 @common_license.destroy
84 respond_to do |format|
85 format.html { redirect_to common_licenses_url }
86 format.json { head :ok }