1 class CommonLicensesController < ApplicationController
2 layout 'test' if Pettanr::TestLayout
3 before_filter :authenticate_user!, :only => [:index, :show]
4 before_filter :authenticate_admin!, :only => [:list, :browse, :import, :destroy]
9 if file.respond_to?(:read)
18 # GET /common_licenses
19 # GET /common_licenses.json
21 @page = CommonLicense.page params[:page]
22 @page_size = CommonLicense.page_size params[:page_size]
23 @common_licenses = CommonLicense.list({}, @page, @page_size)
25 respond_to do |format|
26 format.html # index.html.erb
27 format.json { render json: @common_licenses.to_json(CommonLicense.list_json_opt) }
31 # GET /common_licenses/1
32 # GET /common_licenses/1.json
34 @common_license = CommonLicense.show(params[:id])
36 respond_to do |format|
37 format.html # show.html.erb
38 format.json { render json: @common_license.to_json(CommonLicense.show_json_include_opt) }
43 @common_licenses = CommonLicense.all
45 respond_to do |format|
46 format.html { render layout: 'system' }
47 format.json { render json: @common_licenses }
52 @common_license = CommonLicense.find(params[:id])
54 respond_to do |format|
55 format.html { render layout: 'system' }
56 format.json { render json: @common_license }
60 # POST /common_licenses
61 # POST /common_licenses.json
63 @data = set_data params[:file]
64 respond_to do |format|
65 @errors = CommonLicense.import @data
66 if @errors and @errors.empty?
67 format.html { redirect_to :action => :list }
68 format.json { render text: 'ok', status: :created }
70 format.html { render action: "result" }
71 format.json { render json: @errors, status: :unprocessable_entity }
76 # DELETE /common_licenses/1
77 # DELETE /common_licenses/1.json
79 @common_license = CommonLicense.find(params[:id])
80 @common_license.destroy
82 respond_to do |format|
83 format.html { redirect_to common_licenses_url }
84 format.json { head :ok }