OSDN Git Service

Merge branch 'v04' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v04
[pettanr/pettanr.git] / app / controllers / common_licenses_controller.rb
1 #コモンライセンス
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]
6
7   private
8   
9   def set_data(file)
10     if file.respond_to?(:read)
11       file.read
12     else
13       file
14     end
15   end
16   
17   public
18   
19   # GET /common_licenses
20   # GET /common_licenses.json
21   def index
22     @page = CommonLicense.page params[:page]
23     @page_size = CommonLicense.page_size params[:page_size]
24     @common_licenses = CommonLicense.list({}, @page, @page_size)
25
26     respond_to do |format|
27       format.html # index.html.erb
28       format.json { render json: @common_licenses.to_json(CommonLicense.list_json_opt) }
29     end
30   end
31
32   # GET /common_licenses/1
33   # GET /common_licenses/1.json
34   def show
35     @common_license = CommonLicense.show(params[:id])
36
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) }
40     end
41   end
42
43   def list
44     @common_licenses = CommonLicense.all
45
46     respond_to do |format|
47       format.html { render layout: 'system' }
48       format.json { render json: @common_licenses }
49     end
50   end
51
52   def browse
53     @common_license = CommonLicense.find(params[:id])
54
55     respond_to do |format|
56       format.html { render layout: 'system' }
57       format.json { render json: @common_license }
58     end
59   end
60
61   # POST /common_licenses
62   # POST /common_licenses.json
63   def import
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 }
70       else
71         #@errorsがNILならJson展開できない全体異常
72         format.html { render action: "result" }
73         format.json { render json: @errors, status: :unprocessable_entity }
74       end
75     end
76   end
77
78   # DELETE /common_licenses/1
79   # DELETE /common_licenses/1.json
80   def destroy
81     @common_license = CommonLicense.find(params[:id])
82     @common_license.destroy
83
84     respond_to do |format|
85       format.html { redirect_to common_licenses_url }
86       format.json { head :ok }
87     end
88   end
89 end