admin_assistant 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/README +3 -28
  2. data/Rakefile +18 -10
  3. data/init.rb +1 -0
  4. data/install.rb +5 -1
  5. data/lib/admin_assistant/active_record_column.rb +211 -0
  6. data/lib/admin_assistant/association_target.rb +35 -0
  7. data/lib/admin_assistant/belongs_to_column.rb +186 -0
  8. data/lib/admin_assistant/builder.rb +222 -35
  9. data/lib/admin_assistant/column.rb +266 -297
  10. data/lib/admin_assistant/default_search_column.rb +41 -0
  11. data/lib/admin_assistant/file_column_column.rb +73 -0
  12. data/lib/admin_assistant/form_view.rb +7 -68
  13. data/lib/admin_assistant/helper.rb +4 -2
  14. data/lib/admin_assistant/index.rb +101 -81
  15. data/lib/admin_assistant/paperclip_column.rb +45 -0
  16. data/lib/admin_assistant/polymorphic_belongs_to_column.rb +102 -0
  17. data/lib/admin_assistant/request/autocomplete.rb +47 -0
  18. data/lib/admin_assistant/request/base.rb +176 -0
  19. data/lib/admin_assistant/request/create.rb +27 -0
  20. data/lib/admin_assistant/request/destroy.rb +15 -0
  21. data/lib/admin_assistant/request/edit.rb +11 -0
  22. data/lib/admin_assistant/request/index.rb +26 -0
  23. data/lib/admin_assistant/request/new.rb +19 -0
  24. data/lib/admin_assistant/request/show.rb +24 -0
  25. data/lib/admin_assistant/request/update.rb +44 -0
  26. data/lib/admin_assistant/search.rb +82 -0
  27. data/lib/admin_assistant/show_view.rb +20 -0
  28. data/lib/admin_assistant/virtual_column.rb +61 -0
  29. data/lib/admin_assistant.rb +190 -85
  30. data/lib/javascripts/admin_assistant.js +253 -0
  31. data/lib/stylesheets/activescaffold.css +219 -0
  32. data/lib/stylesheets/default.css +119 -0
  33. data/lib/views/_polymorphic_field_search.html.erb +89 -0
  34. data/lib/views/_restricted_autocompleter.html.erb +53 -0
  35. data/lib/views/autocomplete.html.erb +11 -0
  36. data/lib/views/form.html.erb +6 -3
  37. data/lib/views/index.html.erb +53 -46
  38. data/lib/views/show.html.erb +19 -0
  39. data/vendor/ar_query/MIT-LICENSE +20 -0
  40. data/vendor/ar_query/README +0 -0
  41. data/vendor/ar_query/init.rb +1 -0
  42. data/vendor/ar_query/install.rb +1 -0
  43. data/vendor/ar_query/lib/ar_query.rb +137 -0
  44. data/vendor/ar_query/spec/ar_query_spec.rb +253 -0
  45. data/vendor/ar_query/tasks/ar_query_tasks.rake +0 -0
  46. data/vendor/ar_query/uninstall.rb +1 -0
  47. metadata +39 -16
  48. data/lib/admin_assistant/request.rb +0 -183
  49. data/lib/stylesheets/admin_assistant.css +0 -75
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
@@ -0,0 +1 @@
1
+ # Include hook code here
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,137 @@
1
+ class ARQuery
2
+ attr_reader :joins
3
+
4
+ def initialize(simple_values={})
5
+ @simple_values = simple_values
6
+ @base_condition = Condition.new self
7
+ @joins = UniqueArray.new simple_values[:joins]
8
+ end
9
+
10
+ def method_missing(sym, *args)
11
+ if sym == :total_entries=
12
+ @simple_values[:total_entries] = args.first
13
+ elsif [:has_conditions?, :boolean_join=].include?(sym)
14
+ @base_condition.send(sym, *args)
15
+ else
16
+ super
17
+ end
18
+ end
19
+
20
+ def add_condition(&block)
21
+ if @base_condition.has_conditions?
22
+ @base_condition.add_condition do |nested|
23
+ block.call nested
24
+ end
25
+ else
26
+ block.call @base_condition
27
+ end
28
+ end
29
+
30
+ def condition_bind_vars
31
+ @base_condition.bind_vars
32
+ end
33
+
34
+ def condition_bind_vars=(arg)
35
+ @base_condition.bind_vars = arg
36
+ end
37
+
38
+ def condition_sqls
39
+ @base_condition.sqls
40
+ end
41
+
42
+ def to_hash
43
+ hash = @simple_values.dup
44
+ hash[:conditions] = @base_condition.to_conditions if has_conditions?
45
+ joins = @joins
46
+ if includes = @simple_values[:include]
47
+ if includes.is_a?(Array)
48
+ joins = joins.reject { |join|
49
+ includes.any? { |inc| inc.to_sym == join.to_sym }
50
+ }
51
+ else
52
+ joins = joins.reject { |join| includes.to_sym == join.to_sym }
53
+ end
54
+ end
55
+ hash[:joins] = joins unless joins.empty?
56
+ hash
57
+ end
58
+
59
+ class Condition
60
+ attr_accessor :bind_vars, :boolean_join
61
+ attr_reader :ar_query, :sqls
62
+
63
+ def initialize(ar_query)
64
+ @ar_query = ar_query
65
+ @bind_vars = []
66
+ @sqls = SQLs.new
67
+ @boolean_join = :and
68
+ @children = []
69
+ end
70
+
71
+ def has_conditions?
72
+ !@sqls.empty?
73
+ end
74
+
75
+ def add_condition(&block)
76
+ if has_conditions?
77
+ @children << Condition.new(@ar_query)
78
+ yield @children.last
79
+ else
80
+ yield self
81
+ end
82
+ end
83
+
84
+ def to_conditions
85
+ join_str = @boolean_join == :and ? ' AND ' : ' OR '
86
+ binds = @bind_vars.dup || []
87
+ condition_sql_fragments = @sqls.map { |c_sql| "(#{c_sql})" }
88
+ @children.each do |child|
89
+ sub_conditions = child.to_conditions
90
+ if sub_conditions
91
+ if sub_conditions.is_a?(Array)
92
+ sql = sub_conditions.first
93
+ sub_binds = sub_conditions[1..-1]
94
+ condition_sql_fragments << "(#{sql})"
95
+ binds.concat sub_binds
96
+ else
97
+ condition_sql_fragments << "(#{sub_conditions})"
98
+ end
99
+ end
100
+ end
101
+ condition_sql = condition_sql_fragments.join(join_str)
102
+ if binds.empty?
103
+ condition_sql unless condition_sql == ''
104
+ else
105
+ [ condition_sql, *binds ]
106
+ end
107
+ end
108
+
109
+ class SQLs < Array
110
+ def <<(elt)
111
+ if elt.is_a?(String)
112
+ super
113
+ else
114
+ raise(
115
+ ArgumentError,
116
+ "Tried appending #{elt.inspect} to ARQuery::Condition::SQLs: Only strings are allowed"
117
+ )
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ class UniqueArray < Array
124
+ def initialize(values)
125
+ super()
126
+ if values
127
+ values = [values] unless values.is_a?(Array)
128
+ values.each do |value| self << value; end
129
+ end
130
+ end
131
+
132
+ def <<(value)
133
+ super
134
+ uniq!
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,253 @@
1
+ require File.dirname(__FILE__) + '/../lib/ar_query'
2
+
3
+ describe ARQuery do
4
+ describe '#initialize with no values' do
5
+ before :all do
6
+ ar_query = ARQuery.new
7
+ @hash = ar_query.to_hash
8
+ end
9
+
10
+ it 'should not have conditions' do
11
+ @hash[:conditions].should be_nil
12
+ end
13
+
14
+ it 'should not have joins' do
15
+ @hash[:joins].should be_nil
16
+ end
17
+
18
+ it 'should not let you assign like a hash' do
19
+ lambda {
20
+ @ar_query[:conditions] = "foo = 'bar'"
21
+ }.should raise_error(NoMethodError)
22
+ lambda {
23
+ @ar_query[:joins] = "foo = 'bar'"
24
+ }.should raise_error(NoMethodError)
25
+ end
26
+ end
27
+
28
+ describe '#initialize with values' do
29
+ before :all do
30
+ @ar_query = ARQuery.new(:order => 'id desc', :limit => 25)
31
+ @hash = @ar_query.to_hash
32
+ end
33
+
34
+ it 'should have those values in the hash' do
35
+ @hash[:order].should == 'id desc'
36
+ @hash[:limit].should == 25
37
+ end
38
+
39
+ it 'should not have other values in the hash' do
40
+ @hash[:conditions].should be_nil
41
+ end
42
+ end
43
+
44
+ describe "#condition_sqls <<" do
45
+ before :all do
46
+ @ar_query = ARQuery.new
47
+ @ar_query.condition_sqls << "fname is not null"
48
+ @ar_query.condition_sqls << "lname is not null"
49
+ end
50
+
51
+ it 'should join the conditions with an AND' do
52
+ @ar_query.to_hash[:conditions].should ==
53
+ "(fname is not null) AND (lname is not null)"
54
+ end
55
+
56
+ it "should prevent you from appending nil" do
57
+ lambda { @ar_query.condition_sqls << nil }.should raise_error(
58
+ ArgumentError,
59
+ "Tried appending nil to ARQuery::Condition::SQLs: Only strings are allowed"
60
+ )
61
+ end
62
+
63
+ it "should prevent you from appending a value besides a string" do
64
+ lambda { @ar_query.condition_sqls << 55 }.should raise_error(
65
+ ArgumentError,
66
+ "Tried appending 55 to ARQuery::Condition::SQLs: Only strings are allowed"
67
+ )
68
+ end
69
+ end
70
+
71
+ describe '#condition_sqls << with OR as the boolean join' do
72
+ before :all do
73
+ @ar_query = ARQuery.new
74
+ @ar_query.boolean_join = :or
75
+ @ar_query.condition_sqls << "fname is not null"
76
+ @ar_query.condition_sqls << "lname is not null"
77
+ end
78
+
79
+ it 'should join the conditions with an OR' do
80
+ @ar_query.to_hash[:conditions].should ==
81
+ "(fname is not null) OR (lname is not null)"
82
+ end
83
+ end
84
+
85
+ describe '[:conditions]' do
86
+ describe 'with bind vars' do
87
+ before :all do
88
+ @ar_query = ARQuery.new
89
+ @ar_query.condition_sqls << "fname = ?"
90
+ @ar_query.condition_sqls << "lname = ?"
91
+ end
92
+
93
+ describe 'using appends' do
94
+ before :all do
95
+ @ar_query.condition_bind_vars << 'Francis'
96
+ @ar_query.condition_bind_vars << 'Hwang'
97
+ end
98
+
99
+ it 'should put the bind_vars at the end of the conditions array' do
100
+ @ar_query.to_hash[:conditions].should ==
101
+ [ "(fname = ?) AND (lname = ?)", 'Francis', 'Hwang' ]
102
+ end
103
+ end
104
+
105
+ describe 'using assignment' do
106
+ before :all do
107
+ @ar_query.condition_bind_vars = %w( Francis Hwang )
108
+ end
109
+
110
+ it 'should put the bind_vars at the end of the conditions array' do
111
+ @ar_query.to_hash[:conditions].should ==
112
+ [ "(fname = ?) AND (lname = ?)", 'Francis', 'Hwang' ]
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ describe 'with a nested condition' do
119
+ before :all do
120
+ @ar_query = ARQuery.new
121
+ @ar_query.condition_sqls << "fname = ?"
122
+ @ar_query.condition_bind_vars << 'Francis'
123
+ @ar_query.add_condition do |cond|
124
+ cond.boolean_join = :or
125
+ cond.sqls << 'lname = ?'
126
+ cond.sqls << 'lname = ?'
127
+ cond.bind_vars << 'Hwang'
128
+ cond.bind_vars << 'Bacon'
129
+ cond.ar_query.should == @ar_query
130
+ end
131
+ end
132
+
133
+ it 'should generate nested conditions in SQL' do
134
+ @ar_query.to_hash[:conditions].should == [
135
+ "(fname = ?) AND ((lname = ?) OR (lname = ?))",
136
+ 'Francis', 'Hwang', 'Bacon'
137
+ ]
138
+ end
139
+ end
140
+
141
+ describe "when using the nested condition syntax even though the query isn't nested" do
142
+ before :all do
143
+ @ar_query = ARQuery.new
144
+ @ar_query.add_condition do |cond|
145
+ cond.boolean_join = :or
146
+ cond.sqls << "fname = ?"
147
+ cond.bind_vars << 'Chunky'
148
+ end
149
+ end
150
+
151
+ it 'should generate the non-nested condition in SQL' do
152
+ @ar_query.to_hash[:conditions].should == ["(fname = ?)", 'Chunky']
153
+ end
154
+ end
155
+
156
+ describe 'when nesting the nested condition unnecessarily' do
157
+ before :all do
158
+ @ar_query = ARQuery.new
159
+ @ar_query.add_condition do |cond|
160
+ cond.add_condition do |subcond|
161
+ subcond.boolean_join = :or
162
+ subcond.sqls << "fname = ?"
163
+ subcond.bind_vars << 'Chunky'
164
+ end
165
+ end
166
+ end
167
+
168
+ it 'should generate the non-nested condition in SQL' do
169
+ @ar_query.to_hash[:conditions].should == ["(fname = ?)", 'Chunky']
170
+ end
171
+ end
172
+
173
+ describe 'when calling an empty #add_condition after already adding to condition_sqls' do
174
+ before :all do
175
+ @ar_query = ARQuery.new
176
+ @ar_query.condition_sqls << "published = true"
177
+ @ar_query.add_condition do |cond|
178
+ end
179
+ end
180
+
181
+ it 'should not appending anything to the condition' do
182
+ @ar_query.to_hash[:conditions].should == '(published = true)'
183
+ end
184
+ end
185
+
186
+ describe '#joins <<' do
187
+ describe 'when there are no joins to start' do
188
+ before :all do
189
+ @ar_query = ARQuery.new
190
+ @ar_query.joins << :user
191
+ end
192
+
193
+ it 'should result in an array of 1 join' do
194
+ @ar_query.to_hash[:joins].should == [:user]
195
+ end
196
+ end
197
+
198
+ describe 'when it was initialized with one join' do
199
+ before :all do
200
+ @ar_query = ARQuery.new :joins => :user
201
+ @ar_query.joins << :tags
202
+ end
203
+
204
+ it 'should result in an array of 2 joins' do
205
+ @ar_query.to_hash[:joins].should == [:user, :tags]
206
+ end
207
+ end
208
+
209
+ describe 'when there are already two joins' do
210
+ before :all do
211
+ @ar_query = ARQuery.new :joins => [:user, :tags]
212
+ @ar_query.joins << :images
213
+ end
214
+
215
+ it 'should result in 3 joins' do
216
+ @ar_query.to_hash[:joins].should == [:user, :tags, :images]
217
+ end
218
+ end
219
+
220
+ describe 'when a duplicate join is being appended' do
221
+ before :all do
222
+ @ar_query = ARQuery.new :joins => [:user, :tags]
223
+ @ar_query.joins << :user
224
+ end
225
+
226
+ it 'should not keep the array of joins unique' do
227
+ @ar_query.to_hash[:joins].should == [:user, :tags]
228
+ end
229
+ end
230
+
231
+ describe 'when the same association has already been :included' do
232
+ before :all do
233
+ @ar_query = ARQuery.new :include => 'user'
234
+ @ar_query.joins << :user
235
+ end
236
+
237
+ it 'should not include the association in the join' do
238
+ @ar_query.to_hash[:joins].should be_nil
239
+ end
240
+ end
241
+ end
242
+
243
+ describe '#total_entries =' do
244
+ before :all do
245
+ @ar_query = ARQuery.new
246
+ @ar_query.total_entries = 25
247
+ end
248
+
249
+ it 'should set [:total_entries]' do
250
+ @ar_query.to_hash[:total_entries].should == 25
251
+ end
252
+ end
253
+ end
File without changes
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admin_assistant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Hwang
@@ -9,19 +9,9 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-19 00:00:00 -05:00
12
+ date: 2009-08-02 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: ar_query
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
15
  - !ruby/object:Gem::Dependency
26
16
  name: mislav-will_paginate
27
17
  type: :runtime
@@ -32,7 +22,7 @@ dependencies:
32
22
  - !ruby/object:Gem::Version
33
23
  version: "0"
34
24
  version:
35
- description: ""
25
+ description: admin_assistant is a Rails plugin that automates a lot of features typically needed in admin interfaces.
36
26
  email: sera@fhwang.net
37
27
  executables: []
38
28
 
@@ -43,22 +33,55 @@ extra_rdoc_files: []
43
33
  files:
44
34
  - MIT-LICENSE
45
35
  - README
36
+ - init.rb
46
37
  - install.rb
47
38
  - uninstall.rb
48
39
  - Rakefile
49
40
  - lib/admin_assistant.rb
41
+ - lib/admin_assistant/active_record_column.rb
42
+ - lib/admin_assistant/association_target.rb
43
+ - lib/admin_assistant/belongs_to_column.rb
50
44
  - lib/admin_assistant/builder.rb
51
45
  - lib/admin_assistant/column.rb
46
+ - lib/admin_assistant/default_search_column.rb
47
+ - lib/admin_assistant/file_column_column.rb
52
48
  - lib/admin_assistant/form_view.rb
53
49
  - lib/admin_assistant/helper.rb
54
50
  - lib/admin_assistant/index.rb
55
- - lib/admin_assistant/request.rb
51
+ - lib/admin_assistant/paperclip_column.rb
52
+ - lib/admin_assistant/polymorphic_belongs_to_column.rb
53
+ - lib/admin_assistant/search.rb
54
+ - lib/admin_assistant/show_view.rb
55
+ - lib/admin_assistant/virtual_column.rb
56
+ - lib/admin_assistant/request/autocomplete.rb
57
+ - lib/admin_assistant/request/base.rb
58
+ - lib/admin_assistant/request/create.rb
59
+ - lib/admin_assistant/request/destroy.rb
60
+ - lib/admin_assistant/request/edit.rb
61
+ - lib/admin_assistant/request/index.rb
62
+ - lib/admin_assistant/request/new.rb
63
+ - lib/admin_assistant/request/show.rb
64
+ - lib/admin_assistant/request/update.rb
56
65
  - lib/images/sort-asc.png
57
66
  - lib/images/sort-desc.png
58
- - lib/stylesheets/admin_assistant.css
67
+ - lib/javascripts/admin_assistant.js
68
+ - lib/stylesheets/activescaffold.css
69
+ - lib/stylesheets/default.css
70
+ - lib/views/_polymorphic_field_search.html.erb
71
+ - lib/views/_restricted_autocompleter.html.erb
72
+ - lib/views/autocomplete.html.erb
59
73
  - lib/views/form.html.erb
60
74
  - lib/views/index.html.erb
75
+ - lib/views/show.html.erb
61
76
  - tasks/admin_assistant_tasks.rake
77
+ - vendor/ar_query/MIT-LICENSE
78
+ - vendor/ar_query/README
79
+ - vendor/ar_query/init.rb
80
+ - vendor/ar_query/install.rb
81
+ - vendor/ar_query/uninstall.rb
82
+ - vendor/ar_query/lib/ar_query.rb
83
+ - vendor/ar_query/spec/ar_query_spec.rb
84
+ - vendor/ar_query/tasks/ar_query_tasks.rake
62
85
  has_rdoc: false
63
86
  homepage: http://github.com/fhwang/admin_assistant/tree/master
64
87
  post_install_message:
@@ -84,6 +107,6 @@ rubyforge_project:
84
107
  rubygems_version: 1.3.1
85
108
  signing_key:
86
109
  specification_version: 2
87
- summary: ""
110
+ summary: admin_assistant is a Rails plugin that automates a lot of features typically needed in admin interfaces.
88
111
  test_files: []
89
112
 
@@ -1,183 +0,0 @@
1
- class AdminAssistant
2
- module Request
3
- class Base
4
- def initialize(admin_assistant, controller)
5
- @admin_assistant, @controller = admin_assistant, controller
6
- end
7
-
8
- def action
9
- @controller.action_name
10
- end
11
-
12
- def after_form_html_template
13
- File.join(
14
- RAILS_ROOT, 'app/views/', @controller.controller_path,
15
- '_after_form.html.erb'
16
- )
17
- end
18
-
19
- def after_form_html_template_exists?
20
- File.exist? after_form_html_template
21
- end
22
-
23
- def model_class
24
- @admin_assistant.model_class
25
- end
26
-
27
- def model_class_symbol
28
- model_class.name.underscore.to_sym
29
- end
30
-
31
- def params_for_save
32
- params = {}
33
- split_params = {}
34
- whole_params = {}
35
- @controller.params[model_class_symbol].each do |k, v|
36
- k =~ /\([0-9]+i\)$/ ? (split_params[k] = v) : (whole_params[k] = v)
37
- end
38
- bases = split_params.map{ |k, v| k.gsub(/\([0-9]+i\)$/, '') }.uniq
39
- bases.each do |b|
40
- h = {}
41
- split_params.each{ |k, v| h[k] = split_params.delete(k) if k =~ /#{b}\([0-9]+i\)$/ }
42
- from_form_method = "#{b}_from_form".to_sym
43
- if @controller.respond_to?(from_form_method)
44
- params[b] = @controller.send(from_form_method, h)
45
- elsif @record.respond_to?("#{b}=")
46
- params.merge! h
47
- end
48
- end
49
- whole_params.each do |k, v|
50
- from_form_method = "#{k}_from_form".to_sym
51
- if @controller.respond_to?(from_form_method)
52
- params[k] = @controller.send(from_form_method, v)
53
- elsif @record.respond_to?("#{k}=")
54
- params[k] = v
55
- end
56
- end
57
- params
58
- end
59
-
60
- def redirect_after_save
61
- url_params = if @controller.respond_to?(:destination_after_save)
62
- @controller.send(
63
- :destination_after_save, @record, @controller.params
64
- )
65
- end
66
- url_params ||= {:action => 'index'}
67
- @controller.send :redirect_to, url_params
68
- end
69
-
70
- def render_after_form
71
- @controller.send(
72
- :render_to_string,
73
- :file => after_form_html_template, :layout => false
74
- )
75
- end
76
-
77
- def render_form
78
- html = @controller.send(
79
- :render_to_string, :file => template_file('form'), :layout => true
80
- )
81
- html << render_after_form if after_form_html_template_exists?
82
- @controller.send :render, :text => html
83
- end
84
-
85
- def render_template_file(template_name = action, options_plus = {})
86
- options = {:file => template_file(template_name), :layout => true}
87
- options = options.merge options_plus
88
- @controller.send(:render, options)
89
- end
90
-
91
- def save
92
- if @controller.respond_to?(:before_save)
93
- @controller.send(:before_save, @record)
94
- end
95
- @record.save
96
- end
97
-
98
- def template_file(template_name = action)
99
- "#{File.dirname(__FILE__)}/../views/#{template_name}.html.erb"
100
- end
101
- end
102
-
103
- class Create < Base
104
- def call
105
- @record = model_class.new
106
- @record.attributes = params_for_save
107
- if save
108
- redirect_after_save
109
- else
110
- @controller.instance_variable_set :@record, @record
111
- render_form
112
- end
113
- end
114
-
115
- def save
116
- if @controller.respond_to?(:before_create)
117
- @controller.send(:before_create, @record)
118
- end
119
- result = super
120
- if @controller.respond_to?(:after_create)
121
- @controller.send(:after_create, @record)
122
- end
123
- result
124
- end
125
- end
126
-
127
- class Destroy < Base
128
- def call
129
- @record = model_class.find @controller.params[:id]
130
- @record.destroy
131
- @controller.send :render, :text => ''
132
- end
133
- end
134
-
135
- class Edit < Base
136
- def call
137
- @record = model_class.find @controller.params[:id]
138
- @controller.instance_variable_set :@record, @record
139
- render_form
140
- end
141
- end
142
-
143
- class Index < Base
144
- def call
145
- index = AdminAssistant::Index.new(@admin_assistant, @controller.params)
146
- @controller.instance_variable_set :@index, index
147
- render_template_file
148
- end
149
-
150
- def columns
151
- @admin_assistant.index_settings.columns
152
- end
153
- end
154
-
155
- class New < Base
156
- def call
157
- @record = model_class.new
158
- @controller.instance_variable_set :@record, @record
159
- render_form
160
- end
161
- end
162
-
163
- class Update < Base
164
- def call
165
- @record = model_class.find @controller.params[:id]
166
- @record.attributes = params_for_save
167
- if save
168
- redirect_after_save
169
- else
170
- @controller.instance_variable_set :@record, @record
171
- render_form
172
- end
173
- end
174
-
175
- def save
176
- if @controller.respond_to?(:before_update)
177
- @controller.send(:before_update, @record)
178
- end
179
- super
180
- end
181
- end
182
- end
183
- end