Class: Admin::ResourcesController
Constant Summary
collapse
- Whitelist =
[:edit, :update, :destroy, :toggle]
Instance Method Summary
collapse
#headless_mode?, included
included
Instance Method Details
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/controllers/admin/resources_controller.rb', line 45
def create
item_params = params[:resource] || {}
item_params.merge!(params[@object_name])
@item = @resource.new
@item.assign_attributes(item_params, :as => current_role)
set_attributes_on_create
respond_to do |format|
if @item.save
format.html { redirect_on_success }
format.json { render :json => @item, :status => :created, :location => @item }
else
format.html { render :action => "new" }
format.json { render :json => @item.errors, :status => :unprocessable_entity }
end
end
end
|
106
107
108
109
110
111
112
113
|
# File 'app/controllers/admin/resources_controller.rb', line 106
def destroy
if @item.destroy
notice = Typus::I18n.t("%{model} successfully removed.", :model => @resource.model_name.human)
else
alert = @item.errors.full_messages
end
redirect_to :back, :notice => notice, :alert => alert
end
|
67
68
69
70
71
|
# File 'app/controllers/admin/resources_controller.rb', line 67
def edit
custom_actions_for(:edit).each do |action|
prepend_resources_action(action.titleize, {:action => action, :id => @item})
end
end
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/admin/resources_controller.rb', line 16
def index
get_objects
custom_actions_for(:index).each do |action|
prepend_resources_action(action.titleize, {:action => action, :id => nil})
end
respond_to do |format|
format.html do
set_default_action
add_resource_action("Trash", {:action => "destroy"}, {:confirm => "#{Typus::I18n.t("Trash")}?", :method => 'delete'})
generate_html
end
format.csv { generate_csv }
format.json { export(:json) }
format.xml { export(:xml) }
end
end
|
36
37
38
39
40
41
42
43
|
# File 'app/controllers/admin/resources_controller.rb', line 36
def new
@item = @resource.new(params[:resource])
respond_to do |format|
format.html
format.json { render :json => @item }
end
end
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'app/controllers/admin/resources_controller.rb', line 73
def show
check_resource_ownership if @resource.typus_options_for(:only_user_items)
if admin_user.can?('edit', @resource)
prepend_resources_action("Edit", {:action => 'edit', :id => @item})
end
custom_actions_for(:show).each do |action|
prepend_resources_action(action.titleize, {:action => action, :id => @item})
end
respond_to do |format|
format.html
format.xml { render :xml => @item }
format.json { render :json => @item }
end
end
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/admin/resources_controller.rb', line 115
def toggle
@item.toggle(params[:field])
respond_to do |format|
if @item.save
format.html do
notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
redirect_to :back, :notice => notice
end
format.json { render :json => @item }
else
format.html { render :edit }
format.json { render :json => @item.errors, :status => :unprocessable_entity }
end
end
end
|
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'app/controllers/admin/resources_controller.rb', line 91
def update
attributes = params[:_nullify] ? { params[:_nullify] => nil } : params[@object_name]
respond_to do |format|
if @item.update_attributes(attributes, :as => current_role)
set_attributes_on_update
format.html { redirect_on_success }
format.json { render :json => @item }
else
format.html { render :edit }
format.json { render :json => @item.errors, :status => :unprocessable_entity }
end
end
end
|