OSDN Git Service

fix form extend
[pettanr/pettanr.git] / app / controllers / licenses_controller.rb
1 class LicensesController < ApplicationController
2   before_filter :authenticate_resource_reader, :only => [
3     :by_license_group, :by_system_picture, :count_by_license_group, :count_by_system_picture
4   ]
5   before_filter :authenticate_admin, :only => [:new, :create, :edit, :update, :destroy]
6
7   def self.model
8     License
9   end
10   
11   def index
12     filer_list
13   end
14   
15   def by_license_group
16     filer_list
17   end
18   
19   def by_system_picture
20     filer_list
21   end
22   
23   def show_html_format format
24     format.html {
25       @license = @item
26     }
27   end
28   
29   def show
30     set_show
31     respond_to do |format|
32       show_html_format format
33       show_prof_format format
34       show_json_format format
35     end
36   end
37
38   def search
39     @licenses = License.list_by_name(params[:name])
40     
41     respond_to do |format|
42       format.html
43       format.json { render json: @licenses.to_json }
44     end
45   end
46   
47   def count
48     list_count
49   end
50   
51   def count_by_license_group
52     list_count
53   end
54   
55   def count_by_system_picture
56     list_count
57   end
58   
59   def new
60     form_new
61   end
62   
63   def edit
64     form_edit
65   end
66   
67   def create
68     @item = self.class.model.new
69     @item.supply_default 
70     @item.attributes = params[:license]
71     @item.overwrite @operators
72
73     if @item.save
74       respond_to do |format|
75         flash[:notice] = I18n.t('flash.notice.created', :model => self.class.model.model_name.human)
76         format.html { redirect_to @item }
77         format.json { render json: @item.to_json(self.class.model.show_json_opt), status: :created, location: @item }
78       end
79     else
80       flash[:notice] = I18n.t('flash.notice.not_created', :model => self.class.model.model_name.human)
81       render_new
82         format.html { render action: "new" }
83         format.json { render json: @item.errors, status: :unprocessable_entity }
84     end
85   end
86
87   def update
88     @item = self.class.model.edit(params[:id], @operators)
89     self.class.model.fold_extend_settings params
90     @item.attributes = params[:license]
91     @item.overwrite 
92     respond_to do |format|
93       if @item.save
94         flash[:notice] = I18n.t('flash.notice.updated', :model => self.class.model.model_name.human)
95         format.html { redirect_to @item }
96         format.json { head :ok }
97       else
98         flash[:notice] = I18n.t('flash.notice.not_updated', :model => self.class.model.model_name.human)
99         format.html { render action: "edit" }
100         format.json { render json: @item.errors, status: :unprocessable_entity }
101       end
102     end
103   end
104
105   def destroy
106     @item = self.class.model.edit(params[:id], @operators)
107     respond_to do |format|
108         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => self.class.model.model_name.human)
109         format.html { redirect_to @item }
110         format.json { render json: @item.errors, status: :unprocessable_entity }
111     end
112   end
113 end