active_scaffold-sequel 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/stylesheets/active_scaffold_images.css.scss +3 -6
- data/app/assets/stylesheets/active_scaffold_layout.css +1 -4
- data/frontends/default/views/_field_search.html.erb +1 -1
- data/frontends/default/views/_form_association.html.erb +1 -1
- data/frontends/default/views/_form_attribute.html.erb +1 -1
- data/frontends/default/views/_search.html.erb +1 -1
- data/lib/active_scaffold/actions/core.rb +20 -8
- data/lib/active_scaffold/actions/create.rb +11 -22
- data/lib/active_scaffold/actions/list.rb +3 -4
- data/lib/active_scaffold/actions/nested.rb +26 -15
- data/lib/active_scaffold/actions/update.rb +11 -18
- data/lib/active_scaffold/attribute_params.rb +6 -6
- data/lib/active_scaffold/config/nested.rb +0 -7
- data/lib/active_scaffold/data_structures/action_link.rb +1 -8
- data/lib/active_scaffold/data_structures/column.rb +8 -0
- data/lib/active_scaffold/data_structures/nested_info.rb +10 -62
- data/lib/active_scaffold/extensions/routing_mapper.rb +0 -7
- data/lib/active_scaffold/finder.rb +1 -1
- data/lib/active_scaffold/helpers/form_column_helpers.rb +3 -2
- data/lib/active_scaffold/helpers/list_column_helpers.rb +4 -3
- data/lib/active_scaffold/helpers/search_column_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/view_helpers.rb +6 -8
- data/lib/active_scaffold/version.rb +1 -1
- data/lib/active_scaffold.rb +0 -8
- metadata +4 -24
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +0 -39
- data/lib/active_scaffold/bridges/ancestry.rb +0 -5
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +0 -48
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +0 -57
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +0 -34
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +0 -26
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +0 -43
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +0 -9
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +0 -15
- data/lib/active_scaffold/bridges/file_column.rb +0 -11
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +0 -27
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +0 -16
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +0 -36
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +0 -24
- data/lib/active_scaffold/bridges/paperclip.rb +0 -12
- data/lib/active_scaffold/bridges/record_select/helpers.rb +0 -86
- data/lib/active_scaffold/bridges/record_select.rb +0 -11
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +0 -20
- data/lib/active_scaffold/bridges/semantic_attributes.rb +0 -5
- data/lib/active_scaffold/extensions/cache_association.rb +0 -16
@@ -15,18 +15,15 @@ background-image: image-url('active_scaffold/add.gif');
|
|
15
15
|
background-image: image-url('active_scaffold/magnifier.png');
|
16
16
|
}
|
17
17
|
|
18
|
-
.active-scaffold th.asc a
|
19
|
-
.active-scaffold th.asc a:hover {
|
18
|
+
.active-scaffold th.asc a {
|
20
19
|
background-image: image-url('active_scaffold/arrow_up.gif');
|
21
20
|
}
|
22
21
|
|
23
|
-
.active-scaffold th.desc a
|
24
|
-
.active-scaffold th.desc a:hover {
|
22
|
+
.active-scaffold th.desc a {
|
25
23
|
background-image: image-url('active_scaffold/arrow_down.gif');
|
26
24
|
}
|
27
25
|
|
28
|
-
.active-scaffold th.loading a
|
29
|
-
.active-scaffold th.loading a:hover {
|
26
|
+
.active-scaffold th.loading a {
|
30
27
|
background-image: image-url('active_scaffold/indicator-small.gif');
|
31
28
|
}
|
32
29
|
|
@@ -172,11 +172,8 @@ padding-right: 18px;
|
|
172
172
|
}
|
173
173
|
|
174
174
|
.active-scaffold th.asc a,
|
175
|
-
.active-scaffold th.asc a:hover,
|
176
175
|
.active-scaffold th.desc a,
|
177
|
-
.active-scaffold th.
|
178
|
-
.active-scaffold th.loading a,
|
179
|
-
.active-scaffold th.loading a:hover {
|
176
|
+
.active-scaffold th.loading a {
|
180
177
|
background: right 50% no-repeat;
|
181
178
|
}
|
182
179
|
|
@@ -25,7 +25,7 @@ form_tag url_options, options %>
|
|
25
25
|
</ol>
|
26
26
|
<p class="form-footer">
|
27
27
|
<%= submit_tag as_(:search), :class => "submit" %>
|
28
|
-
<%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true %>
|
28
|
+
<%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true, :data => {:refresh => true} %>
|
29
29
|
<%= loading_indicator_tag(:action => :search) %>
|
30
30
|
</p>
|
31
31
|
</form>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%
|
2
2
|
parent_record = @record
|
3
3
|
associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a
|
4
|
-
associated = associated.sort_by {|r| r.new? ? 99999999999 : r.id} unless
|
4
|
+
associated = associated.sort_by {|r| r.new? ? 99999999999 : r.id} unless column.association[:order]
|
5
5
|
if show_blank_record = column.show_blank_record?(associated)
|
6
6
|
associated << build_associated(column, parent_record)
|
7
7
|
end
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<%=raw active_scaffold_input_for column, scope %>
|
9
9
|
<% else %>
|
10
10
|
<%= get_column_value(@record, column) %>
|
11
|
-
<%= hidden_field :record, column.association ? column.association.
|
11
|
+
<%= hidden_field :record, column.association ? (column.association[:key] || column.association[:left_key]) : column.name, active_scaffold_input_options(column, scope) -%>
|
12
12
|
<% end %>
|
13
13
|
<% if column.update_columns -%>
|
14
14
|
<%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %>
|
@@ -9,7 +9,7 @@ options['data-loading'] = true unless live_search
|
|
9
9
|
form_tag url_options, options %>
|
10
10
|
<%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocomplete => :off %>
|
11
11
|
<%= submit_tag as_(:search), :class => "submit" %>
|
12
|
-
<%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true %>
|
12
|
+
<%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true, :data => {:refresh => true} %>
|
13
13
|
<%= loading_indicator_tag(:action => :search) %>
|
14
14
|
</form>
|
15
15
|
|
@@ -139,11 +139,21 @@ module ActiveScaffold::Actions
|
|
139
139
|
{}
|
140
140
|
end
|
141
141
|
|
142
|
-
#Overide this method on your controller to provide model with named scopes
|
142
|
+
# Overide this method on your controller to provide model with named scopes
|
143
|
+
# This method returns a model class or a dataset.
|
143
144
|
def beginning_of_chain
|
144
145
|
active_scaffold_config.model
|
145
146
|
end
|
146
|
-
|
147
|
+
|
148
|
+
# This method returns a model class.
|
149
|
+
def origin_class
|
150
|
+
active_scaffold_config.model
|
151
|
+
end
|
152
|
+
|
153
|
+
def origin_class_with_build_options
|
154
|
+
[origin_class, {}]
|
155
|
+
end
|
156
|
+
|
147
157
|
# Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5".
|
148
158
|
def conditions_from_params
|
149
159
|
conditions = nil
|
@@ -155,15 +165,17 @@ module ActiveScaffold::Actions
|
|
155
165
|
end
|
156
166
|
|
157
167
|
def new_model
|
158
|
-
model =
|
168
|
+
model, build_options = origin_class_with_build_options
|
159
169
|
if model.respond_to?(:sti_key)
|
160
|
-
build_options
|
170
|
+
build_options[model.sti_key] = active_scaffold_config.model_id if nested? && nested.association && nested.association.collection?
|
161
171
|
sti_key = model.sti_key.to_s
|
162
|
-
|
163
|
-
|
164
|
-
|
172
|
+
if params[sti_key] # in new action sti_key must be in params
|
173
|
+
model = params[sti_key].constantize
|
174
|
+
elsif params[:record] and params[:record][sti_key] # in create action must be inside record key
|
175
|
+
model = params[:record][sti_key].constantize
|
176
|
+
end
|
165
177
|
end
|
166
|
-
model.
|
178
|
+
model.new(build_options)
|
167
179
|
end
|
168
180
|
|
169
181
|
private
|
@@ -83,7 +83,6 @@ module ActiveScaffold::Actions
|
|
83
83
|
@record = new_model
|
84
84
|
apply_constraints_to_record(@record)
|
85
85
|
if nested?
|
86
|
-
create_association_with_parent(@record)
|
87
86
|
register_constraints_with_action_columns(nested.constrained_fields)
|
88
87
|
end
|
89
88
|
@record
|
@@ -92,28 +91,18 @@ module ActiveScaffold::Actions
|
|
92
91
|
# A somewhat complex method to actually create a new record. The complexity is from support for subforms and associated records.
|
93
92
|
# If you want to customize this behavior, consider using the +before_create_save+ and +after_create_save+ callbacks.
|
94
93
|
def do_create
|
95
|
-
|
96
|
-
active_scaffold_config.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
create_save
|
104
|
-
end
|
105
|
-
rescue ActiveRecord::RecordInvalid
|
106
|
-
flash[:error] = $!.message
|
107
|
-
self.successful = false
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def create_save
|
112
|
-
before_create_save(@record)
|
113
|
-
self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit
|
114
|
-
if successful?
|
115
|
-
@record.save! and @record.save_associated!
|
94
|
+
active_scaffold_config.model.db.transaction do
|
95
|
+
@record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record])
|
96
|
+
apply_constraints_to_record(@record, :allow_autosave => true)
|
97
|
+
before_create_save(@record)
|
98
|
+
@record.raise_on_save_failure = false
|
99
|
+
self.successful = @record.save
|
100
|
+
raise Sequel::Rollback unless successful?
|
116
101
|
after_create_save(@record)
|
102
|
+
if nested?
|
103
|
+
create_association_with_parent(@record)
|
104
|
+
register_constraints_with_action_columns(nested.constrained_fields)
|
105
|
+
end
|
117
106
|
end
|
118
107
|
end
|
119
108
|
|
@@ -92,13 +92,12 @@ module ActiveScaffold::Actions
|
|
92
92
|
|
93
93
|
def each_record_in_scope
|
94
94
|
do_search if respond_to? :do_search
|
95
|
-
finder_options = {
|
95
|
+
finder_options = {:order => "#{active_scaffold_config.model.table_name}__#{active_scaffold_config.model.primary_key}".to_sym,
|
96
96
|
:conditions => all_conditions,
|
97
97
|
:joins => joins_for_finder}
|
98
98
|
finder_options.merge! custom_finder_options
|
99
|
-
finder_options.merge! :
|
100
|
-
|
101
|
-
klass.all(finder_options).each {|record| yield record}
|
99
|
+
finder_options.merge! :includes => (active_scaffold_includes.blank? ? nil : active_scaffold_includes)
|
100
|
+
append_to_query(beginning_of_chain.dataset, finder_options).all.each {|record| yield record}
|
102
101
|
end
|
103
102
|
|
104
103
|
# The default security delegates to ModelPermissions.
|
@@ -24,7 +24,7 @@ module ActiveScaffold::Actions
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def set_nested
|
27
|
-
if params[:parent_scaffold] &&
|
27
|
+
if params[:parent_scaffold] && params[:association]
|
28
28
|
@nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params)
|
29
29
|
unless @nested.nil?
|
30
30
|
active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to?
|
@@ -76,19 +76,33 @@ module ActiveScaffold::Actions
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def beginning_of_chain
|
79
|
-
if nested? && nested.association && !nested.association
|
80
|
-
if nested.association.
|
81
|
-
nested.parent_scope.send(nested.association[:name])
|
82
|
-
elsif nested.child_association
|
83
|
-
active_scaffold_config.model.where(nested.child_association.
|
79
|
+
if nested? && nested.association && !(nested.association[:type] == :many_to_one)
|
80
|
+
if nested.association.returns_array?
|
81
|
+
nested.parent_scope.send("#{nested.association[:name]}_dataset")
|
82
|
+
elsif nested.child_association[:type] == :many_to_one
|
83
|
+
active_scaffold_config.model.where((nested.child_association[:key] || nested.child_association[:left_key]) => nested.parent_id)
|
84
84
|
end
|
85
|
-
elsif nested? && nested.scope
|
86
|
-
nested.parent_scope.send(nested.scope)
|
87
85
|
else
|
88
86
|
active_scaffold_config.model
|
89
87
|
end
|
90
88
|
end
|
91
89
|
|
90
|
+
def origin_class
|
91
|
+
origin_class_with_build_options[0]
|
92
|
+
end
|
93
|
+
|
94
|
+
def origin_class_with_build_options
|
95
|
+
if nested? && nested.association && !(nested.association[:type] == :many_to_one)
|
96
|
+
if nested.association.returns_array?
|
97
|
+
[nested.association.associated_class, {nested.association.reciprocal => nested.parent_scope}]
|
98
|
+
elsif nested.child_association[:type] == :many_to_one
|
99
|
+
[active_scaffold_config.model, {(nested.child_association[:key] || nested.child_association[:left_key]) => nested.parent_id}]
|
100
|
+
end
|
101
|
+
else
|
102
|
+
[active_scaffold_config.model, {}]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
92
106
|
def nested_parent_record(crud = :read)
|
93
107
|
@nested_parent_record ||= find_if_allowed(nested.parent_id, crud, nested.parent_model)
|
94
108
|
end
|
@@ -203,7 +217,7 @@ module ActiveScaffold::Actions::Nested
|
|
203
217
|
end
|
204
218
|
|
205
219
|
def after_create_save(record)
|
206
|
-
if
|
220
|
+
if nested and nested.habtm?
|
207
221
|
params[:associated_id] = record
|
208
222
|
do_add_existing
|
209
223
|
end
|
@@ -212,10 +226,9 @@ module ActiveScaffold::Actions::Nested
|
|
212
226
|
# The actual "add_existing" algorithm
|
213
227
|
def do_add_existing
|
214
228
|
parent_record = nested_parent_record(:update)
|
215
|
-
@record = active_scaffold_config.model
|
229
|
+
@record = active_scaffold_config.model[params[:associated_id]]
|
216
230
|
if parent_record && @record
|
217
|
-
parent_record.send(nested.association[:name]
|
218
|
-
parent_record.save
|
231
|
+
parent_record.send("add_#{nested.association[:name].to_s.singularize}", @record)
|
219
232
|
else
|
220
233
|
false
|
221
234
|
end
|
@@ -224,9 +237,7 @@ module ActiveScaffold::Actions::Nested
|
|
224
237
|
def do_destroy_existing
|
225
238
|
if active_scaffold_config.nested.shallow_delete
|
226
239
|
@record = nested_parent_record(:update)
|
227
|
-
|
228
|
-
assoc_record = collection.find(params[:id])
|
229
|
-
collection.delete(assoc_record)
|
240
|
+
@record.send("remove_#{nested.association[:name].to_s.singularize}", params[:id])
|
230
241
|
else
|
231
242
|
do_destroy
|
232
243
|
end
|
@@ -81,25 +81,18 @@ module ActiveScaffold::Actions
|
|
81
81
|
active_scaffold_config.model.db.transaction do
|
82
82
|
@record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) unless options[:no_record_param_update]
|
83
83
|
before_update_save(@record)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
@record.raise_on_save_failure = false
|
85
|
+
self.successful = @record.save
|
86
|
+
raise Sequel::Rollback unless successful?
|
87
|
+
after_update_save(@record)
|
88
|
+
end
|
89
|
+
rescue Sequel::Error => err
|
90
|
+
if Sequel::Plugins.const_defined?(:OptimisticLocking) and err.kind_of?(Sequel::Plugins::OptimisticLocking::Error)
|
91
|
+
@record.errors.add(:base, as_(:version_inconsistency))
|
92
|
+
self.successful = false
|
93
|
+
else
|
94
|
+
raise err
|
93
95
|
end
|
94
|
-
rescue ActiveRecord::RecordInvalid
|
95
|
-
flash[:error] = $!.message
|
96
|
-
self.successful = false
|
97
|
-
rescue ActiveRecord::StaleObjectError
|
98
|
-
@record.errors.add(:base, as_(:version_inconsistency))
|
99
|
-
self.successful = false
|
100
|
-
rescue ActiveRecord::RecordNotSaved
|
101
|
-
@record.errors.add(:base, as_(:record_not_saved)) if @record.errors.empty?
|
102
|
-
self.successful = false
|
103
96
|
end
|
104
97
|
end
|
105
98
|
|
@@ -55,12 +55,12 @@ module ActiveScaffold
|
|
55
55
|
|
56
56
|
if multi_parameter_attributes.has_key? column.name
|
57
57
|
parent_record.send(:assign_multiparameter_attributes, multi_parameter_attributes[column.name])
|
58
|
-
elsif attributes.has_key? column.
|
59
|
-
|
60
|
-
|
58
|
+
elsif column.nested and attributes.has_key? column.nested_attribute_name
|
59
|
+
parent_record.send("#{column.nested_attribute_name}=", attributes[column.nested_attribute_name])
|
60
|
+
elsif attributes.has_key? column.name.to_s
|
61
|
+
value = column_value_from_param_value(parent_record, column, attributes[column.name.to_s])
|
61
62
|
# we avoid assigning a value that already exists because otherwise has_one associations will break (AR bug in has_one_association.rb#replace)
|
62
63
|
parent_record.send("#{column.name}=", value) unless parent_record.send(column.name) == value
|
63
|
-
|
64
64
|
elsif column.plural_association? and not parent_record.new?
|
65
65
|
parent_record.send("remove_all_#{column.name}")
|
66
66
|
end
|
@@ -80,7 +80,7 @@ module ActiveScaffold
|
|
80
80
|
|
81
81
|
parent_record
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def manage_nested_record_from_params(parent_record, column, attributes)
|
85
85
|
record = find_or_create_for_params(attributes, column, parent_record)
|
86
86
|
if record
|
@@ -157,7 +157,7 @@ module ActiveScaffold
|
|
157
157
|
def find_or_create_for_params(params, parent_column, parent_record)
|
158
158
|
current = parent_record.send(parent_column.name)
|
159
159
|
klass = parent_column.association.associated_class
|
160
|
-
pk = klass.primary_key
|
160
|
+
pk = klass.primary_key
|
161
161
|
return nil if parent_column.show_blank_record?(current) and attributes_hash_is_empty?(params, klass)
|
162
162
|
|
163
163
|
if params.has_key? pk
|
@@ -26,15 +26,8 @@ module ActiveScaffold::Config
|
|
26
26
|
action_link = @core.link_for_association(column, options)
|
27
27
|
action_link.action ||= :index
|
28
28
|
@core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
|
29
|
-
else
|
30
|
-
|
31
29
|
end
|
32
30
|
end
|
33
|
-
|
34
|
-
def add_scoped_link(named_scope, options = {})
|
35
|
-
action_link = @core.link_for_association_as_scope(named_scope.to_sym, options)
|
36
|
-
@core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
|
37
|
-
end
|
38
31
|
|
39
32
|
# the label for this Nested action. used for the header.
|
40
33
|
attr_writer :label
|
@@ -165,15 +165,8 @@ module ActiveScaffold::DataStructures
|
|
165
165
|
|
166
166
|
# nested action_links are referencing a column
|
167
167
|
attr_accessor :column
|
168
|
-
|
169
|
-
# indicates that this a nested_link
|
170
|
-
def nested_link?
|
171
|
-
@column || (parameters && parameters[:named_scope])
|
172
|
-
end
|
173
|
-
|
168
|
+
|
174
169
|
# Internal use: generated eid for this action_link
|
175
170
|
attr_accessor :eid
|
176
|
-
|
177
|
-
|
178
171
|
end
|
179
172
|
end
|
@@ -220,6 +220,13 @@ module ActiveScaffold::DataStructures
|
|
220
220
|
cattr_accessor :association_form_ui
|
221
221
|
@@association_form_ui = nil
|
222
222
|
|
223
|
+
# boolean: true if the column is for a nested association, otherwise nil
|
224
|
+
attr_accessor :nested
|
225
|
+
|
226
|
+
def nested_attribute_name
|
227
|
+
@nested_attribute_name ||= "#{name}_attributes"
|
228
|
+
end
|
229
|
+
|
223
230
|
# ----------------------------------------------------------------- #
|
224
231
|
# the below functionality is intended for internal consumption only #
|
225
232
|
# ----------------------------------------------------------------- #
|
@@ -270,6 +277,7 @@ module ActiveScaffold::DataStructures
|
|
270
277
|
self.name = name
|
271
278
|
@column = active_record_class.db_schema[name]
|
272
279
|
@association = active_record_class.association_reflection(name)
|
280
|
+
@nested = true if @association and @association[:nested_attributes]
|
273
281
|
@autolink = !@association.nil?
|
274
282
|
@active_record_class = active_record_class
|
275
283
|
@table = active_record_class.table_name
|
@@ -3,72 +3,40 @@ module ActiveScaffold::DataStructures
|
|
3
3
|
def self.get(model, params)
|
4
4
|
nested_info = {}
|
5
5
|
begin
|
6
|
-
nested_info[:name] =
|
6
|
+
nested_info[:name] = params[:association].to_sym
|
7
7
|
nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize
|
8
8
|
nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model
|
9
9
|
nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key]
|
10
10
|
if nested_info[:parent_id]
|
11
|
-
|
12
|
-
ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info)
|
13
|
-
else
|
14
|
-
ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info)
|
15
|
-
end
|
11
|
+
ActiveScaffold::DataStructures::NestedInfo.new(model, nested_info)
|
16
12
|
end
|
17
13
|
rescue ActiveScaffold::ControllerNotFound
|
18
14
|
nil
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
22
|
-
attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields
|
18
|
+
attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields
|
23
19
|
|
24
20
|
def initialize(model, nested_info)
|
25
21
|
@parent_model = nested_info[:parent_model]
|
26
22
|
@parent_id = nested_info[:parent_id]
|
27
23
|
@parent_scaffold = nested_info[:parent_scaffold]
|
24
|
+
@association = @parent_model.association_reflection(nested_info[:name])
|
25
|
+
iterate_model_associations(model)
|
28
26
|
end
|
29
27
|
|
30
28
|
def to_params
|
31
|
-
{:parent_scaffold => parent_scaffold.controller_path}
|
32
|
-
end
|
33
|
-
|
34
|
-
def new_instance?
|
35
|
-
result = @new_instance.nil?
|
36
|
-
@new_instance = false
|
37
|
-
result
|
29
|
+
{:parent_scaffold => parent_scaffold.controller_path, :association => association[:name], :assoc_id => parent_id}
|
38
30
|
end
|
39
|
-
|
31
|
+
|
40
32
|
def parent_scope
|
41
|
-
parent_model
|
42
|
-
end
|
43
|
-
|
44
|
-
def habtm?
|
45
|
-
false
|
46
|
-
end
|
47
|
-
|
48
|
-
def belongs_to?
|
49
|
-
false
|
33
|
+
parent_model[parent_id]
|
50
34
|
end
|
51
35
|
|
52
|
-
def has_one?
|
53
|
-
false
|
54
|
-
end
|
55
|
-
|
56
|
-
def sorted?
|
57
|
-
false
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class NestedInfoAssociation < NestedInfo
|
62
|
-
def initialize(model, nested_info)
|
63
|
-
super(model, nested_info)
|
64
|
-
@association = parent_model.association_reflection(nested_info[:name])
|
65
|
-
iterate_model_associations(model)
|
66
|
-
end
|
67
|
-
|
68
36
|
def name
|
69
|
-
|
37
|
+
association[:name]
|
70
38
|
end
|
71
|
-
|
39
|
+
|
72
40
|
def habtm?
|
73
41
|
association[:type] == :many_to_many
|
74
42
|
end
|
@@ -89,10 +57,6 @@ module ActiveScaffold::DataStructures
|
|
89
57
|
association[:order]
|
90
58
|
end
|
91
59
|
|
92
|
-
def to_params
|
93
|
-
super.merge(:association => @association[:name], :assoc_id => parent_id)
|
94
|
-
end
|
95
|
-
|
96
60
|
protected
|
97
61
|
|
98
62
|
def iterate_model_associations(model)
|
@@ -111,20 +75,4 @@ module ActiveScaffold::DataStructures
|
|
111
75
|
end
|
112
76
|
end
|
113
77
|
end
|
114
|
-
|
115
|
-
class NestedInfoScope < NestedInfo
|
116
|
-
def initialize(model, nested_info)
|
117
|
-
super(model, nested_info)
|
118
|
-
@scope = nested_info[:name]
|
119
|
-
@constrained_fields = []
|
120
|
-
end
|
121
|
-
|
122
|
-
def to_params
|
123
|
-
super.merge(:named_scope => @scope)
|
124
|
-
end
|
125
|
-
|
126
|
-
def name
|
127
|
-
self.scope
|
128
|
-
end
|
129
|
-
end
|
130
78
|
end
|
@@ -35,13 +35,6 @@ module ActionDispatch
|
|
35
35
|
resources(resource, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :association => resource)) { yield if block_given? }
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
39
|
-
def as_scoped_routes(*scopes)
|
40
|
-
options = scopes.extract_options!
|
41
|
-
scopes.each do |scope|
|
42
|
-
resources(scope, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :named_scope => scope, :controller => parent_resource.plural)) { yield if block_given? }
|
43
|
-
end
|
44
|
-
end
|
45
38
|
end
|
46
39
|
end
|
47
40
|
end
|
@@ -240,7 +240,7 @@ module ActiveScaffold
|
|
240
240
|
# returns a single record (the given id) but only if it's allowed for the specified action.
|
241
241
|
# accomplishes this by checking model.#{action}_authorized?
|
242
242
|
# TODO: this should reside on the model, not the controller
|
243
|
-
def find_if_allowed(id, crud_type, klass =
|
243
|
+
def find_if_allowed(id, crud_type, klass = origin_class)
|
244
244
|
record = klass[id]
|
245
245
|
raise ActiveScaffold::RecordNotAllowed, "#{klass} with id = #{id}" unless record.authorized_for?(:crud_type => crud_type.to_sym)
|
246
246
|
return record
|
@@ -289,10 +289,11 @@ module ActiveScaffold
|
|
289
289
|
end
|
290
290
|
|
291
291
|
def column_scope(column)
|
292
|
+
name = column.nested ? column.nested_attribute_name : column.name
|
292
293
|
if column.plural_association?
|
293
|
-
"[#{
|
294
|
+
"[#{name}][#{@record.id || generate_temporary_id}]"
|
294
295
|
else
|
295
|
-
"[#{
|
296
|
+
"[#{name}]"
|
296
297
|
end
|
297
298
|
end
|
298
299
|
|
@@ -33,7 +33,7 @@ module ActiveScaffold
|
|
33
33
|
def render_list_column(text, column, record)
|
34
34
|
if column.link
|
35
35
|
link = column.link
|
36
|
-
associated = record.send(column.association[:name])
|
36
|
+
associated = column.association ? record.send(column.association[:name]) : nil
|
37
37
|
url_options = params_for(:action => nil, :id => record.id)
|
38
38
|
|
39
39
|
# setup automatic link
|
@@ -49,8 +49,9 @@ module ActiveScaffold
|
|
49
49
|
else
|
50
50
|
"<a class='disabled'>#{text}</a>".html_safe
|
51
51
|
end
|
52
|
+
elsif inplace_edit?(record, column)
|
53
|
+
active_scaffold_inplace_edit(record, column, {:formatted_column => text})
|
52
54
|
else
|
53
|
-
text = active_scaffold_inplace_edit(record, column, {:formatted_column => text}) if inplace_edit?(record, column)
|
54
55
|
text
|
55
56
|
end
|
56
57
|
end
|
@@ -325,7 +326,7 @@ module ActiveScaffold
|
|
325
326
|
def render_nested_view(action_links, url_options, record)
|
326
327
|
rendered = []
|
327
328
|
action_links.member.each do |link|
|
328
|
-
if link.
|
329
|
+
if link.column && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && controller.respond_to?(:render_component_into_view)
|
329
330
|
link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, url_options, record, options = {:reuse_eid => true}))
|
330
331
|
link_id = get_action_link_id(link_url_options, record, link.column)
|
331
332
|
rendered << (controller.send(:render_component_into_view, link_url_options) + javascript_tag("ActiveScaffold.ActionLink.get('#{link_id}').set_opened();"))
|
@@ -133,7 +133,7 @@ module ActiveScaffold
|
|
133
133
|
def include_null_comparators?(column)
|
134
134
|
return column.options[:null_comparators] if column.options.has_key? :null_comparators
|
135
135
|
if column.association
|
136
|
-
column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.
|
136
|
+
column.association.macro != :belongs_to || active_scaffold_config.columns[column.association[:key] || column.association[:left_key]].column.try(:null)
|
137
137
|
else
|
138
138
|
column.column.try(:null)
|
139
139
|
end
|
@@ -153,7 +153,7 @@ module ActiveScaffold
|
|
153
153
|
def include_null_comparators?(column)
|
154
154
|
return column.options[:null_comparators] if column.options.has_key? :null_comparators
|
155
155
|
if column.association
|
156
|
-
column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.
|
156
|
+
column.association.macro != :belongs_to || active_scaffold_config.columns[column.association[:key] || column.association[:left_key]].column.try(:null)
|
157
157
|
else
|
158
158
|
column.column.try(:null)
|
159
159
|
end
|
@@ -119,7 +119,7 @@ module ActiveScaffold
|
|
119
119
|
@link_record = record
|
120
120
|
url_options.merge! self.instance_eval(&(link.dynamic_parameters)) if link.dynamic_parameters.is_a?(Proc)
|
121
121
|
@link_record = nil
|
122
|
-
url_options_for_nested_link(link.column, record, link, url_options, options) if link.
|
122
|
+
url_options_for_nested_link(link.column, record, link, url_options, options) if link.column
|
123
123
|
url_options_for_sti_link(link.column, record, link, url_options, options) unless record.nil? || active_scaffold_config.sti_children.nil?
|
124
124
|
url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get
|
125
125
|
url_options
|
@@ -183,8 +183,6 @@ module ActiveScaffold
|
|
183
183
|
if column && column.association
|
184
184
|
url_options[column.association[:model].name.foreign_key.to_sym] = url_options.delete(:id)
|
185
185
|
url_options[:id] = record.send(column.association[:name]).id if column.singular_association? && record.send(column.association[:name]).present?
|
186
|
-
elsif link.parameters && link.parameters[:named_scope]
|
187
|
-
url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id)
|
188
186
|
end
|
189
187
|
end
|
190
188
|
|
@@ -241,14 +239,14 @@ module ActiveScaffold
|
|
241
239
|
end
|
242
240
|
|
243
241
|
def column_calculation(column)
|
244
|
-
|
242
|
+
if column.calculate.instance_of? Proc
|
243
|
+
column.calculate.call(@records)
|
244
|
+
else
|
245
245
|
conditions = controller.send(:all_conditions)
|
246
246
|
includes = active_scaffold_config.list.count_includes
|
247
247
|
includes ||= controller.send(:active_scaffold_includes) unless conditions.nil?
|
248
|
-
|
249
|
-
|
250
|
-
else
|
251
|
-
column.calculate.call(@records)
|
248
|
+
controller.send(:append_to_query, beginning_of_chain.dataset, :where => conditions, :includes => includes,
|
249
|
+
:joins => controller.send(:joins_for_collection)).get(column.calculate.sql_function(column.name))
|
252
250
|
end
|
253
251
|
end
|
254
252
|
|