active_scaffold 3.2.11 → 3.2.12
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +23 -2
- data/app/assets/javascripts/jquery/active_scaffold.js +55 -46
- data/app/assets/javascripts/prototype/active_scaffold.js +54 -35
- data/app/assets/stylesheets/active_scaffold_layout.css +4 -0
- data/config/locales/de.yml +5 -0
- data/config/locales/en.yml +5 -0
- data/config/locales/es.yml +5 -0
- data/config/locales/fr.yml +5 -0
- data/config/locales/hu.yml +5 -0
- data/config/locales/ja.yml +5 -0
- data/config/locales/ru.yml +5 -0
- data/frontends/default/views/_form_association.html.erb +2 -2
- data/frontends/default/views/_form_association_footer.html.erb +2 -2
- data/frontends/default/views/_horizontal_subform.html.erb +3 -3
- data/frontends/default/views/_list_inline_adapter.html.erb +7 -4
- data/frontends/default/views/_list_messages.html.erb +2 -1
- data/frontends/default/views/_messages.html.erb +1 -1
- data/frontends/default/views/_row.html.erb +1 -6
- data/frontends/default/views/_vertical_subform.html.erb +2 -2
- data/frontends/default/views/add_existing.js.erb +1 -1
- data/frontends/default/views/destroy.js.erb +2 -2
- data/frontends/default/views/on_action_update.js.erb +1 -1
- data/frontends/default/views/on_create.js.erb +3 -17
- data/frontends/default/views/on_mark.js.erb +6 -0
- data/frontends/default/views/on_update.js.erb +4 -13
- data/frontends/default/views/row.js.erb +1 -0
- data/lib/active_scaffold.rb +1 -0
- data/lib/active_scaffold/actions/core.rb +9 -7
- data/lib/active_scaffold/actions/create.rb +1 -1
- data/lib/active_scaffold/actions/delete.rb +1 -1
- data/lib/active_scaffold/actions/list.rb +11 -4
- data/lib/active_scaffold/actions/mark.rb +35 -24
- data/lib/active_scaffold/actions/nested.rb +3 -1
- data/lib/active_scaffold/actions/subform.rb +2 -2
- data/lib/active_scaffold/config/core.rb +17 -1
- data/lib/active_scaffold/config/form.rb +1 -1
- data/lib/active_scaffold/config/list.rb +0 -8
- data/lib/active_scaffold/config/mark.rb +7 -12
- data/lib/active_scaffold/data_structures/action_columns.rb +19 -15
- data/lib/active_scaffold/data_structures/nested_info.rb +27 -7
- data/lib/active_scaffold/extensions/routing_mapper.rb +2 -2
- data/lib/active_scaffold/finder.rb +12 -11
- data/lib/active_scaffold/helpers/controller_helpers.rb +5 -9
- data/lib/active_scaffold/helpers/form_column_helpers.rb +3 -3
- data/lib/active_scaffold/helpers/id_helpers.rb +5 -1
- data/lib/active_scaffold/helpers/list_column_helpers.rb +55 -40
- data/lib/active_scaffold/helpers/view_helpers.rb +22 -6
- data/lib/active_scaffold/marked_model.rb +4 -4
- data/lib/active_scaffold/tableless.rb +18 -0
- data/lib/active_scaffold/version.rb +1 -1
- data/test/config/list_test.rb +0 -6
- metadata +18 -18
- data/frontends/default/views/on_mark_all.js.erb +0 -12
@@ -76,13 +76,15 @@ module ActiveScaffold::Actions
|
|
76
76
|
if nested? && nested.association && !nested.association.belongs_to?
|
77
77
|
if nested.association.collection?
|
78
78
|
nested.parent_scope.send(nested.association.name)
|
79
|
+
elsif nested.association.options[:through] # has_one :through doesn't need conditions
|
80
|
+
active_scaffold_config.model
|
79
81
|
elsif nested.child_association.belongs_to?
|
80
82
|
active_scaffold_config.model.where(nested.child_association.foreign_key => nested.parent_scope)
|
81
83
|
end
|
82
84
|
elsif nested? && nested.scope
|
83
85
|
nested.parent_scope.send(nested.scope)
|
84
86
|
else
|
85
|
-
|
87
|
+
active_scaffold_config.model
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
@@ -9,13 +9,13 @@ module ActiveScaffold::Actions
|
|
9
9
|
|
10
10
|
def do_edit_associated
|
11
11
|
@parent_record = params[:id].nil? ? new_model : find_if_allowed(params[:id], :update)
|
12
|
-
@column = active_scaffold_config.columns[params[:
|
12
|
+
@column = active_scaffold_config.columns[params[:child_association]]
|
13
13
|
|
14
14
|
# NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all.
|
15
15
|
@record = @column.association.klass.find(params[:associated_id]) if params[:associated_id]
|
16
16
|
@record ||= build_associated(@column, @parent_record)
|
17
17
|
|
18
|
-
@scope = "[#{@column.name}]"
|
18
|
+
@scope = "#{params[:scope]}[#{@column.name}]"
|
19
19
|
@scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association?
|
20
20
|
end
|
21
21
|
|
@@ -60,6 +60,14 @@ module ActiveScaffold::Config
|
|
60
60
|
cattr_accessor :sti_create_links
|
61
61
|
@@sti_create_links = true
|
62
62
|
|
63
|
+
# prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used
|
64
|
+
cattr_accessor :timestamped_messages
|
65
|
+
@@timestamped_messages = false
|
66
|
+
|
67
|
+
# a hash of string (or array of strings) and highlighter string to highlight words in messages. It will use highlight rails helper
|
68
|
+
cattr_accessor :highlight_messages
|
69
|
+
@@highlight_messages = nil
|
70
|
+
|
63
71
|
# instance-level configuration
|
64
72
|
# ----------------------------
|
65
73
|
|
@@ -101,6 +109,12 @@ module ActiveScaffold::Config
|
|
101
109
|
# STI children models, use an array of model names
|
102
110
|
attr_accessor :sti_children
|
103
111
|
|
112
|
+
# prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used
|
113
|
+
attr_accessor :timestamped_messages
|
114
|
+
|
115
|
+
# a hash of string (or array of strings) and highlighter string to highlight words in messages. It will use highlight rails helper
|
116
|
+
attr_accessor :highlight_messages
|
117
|
+
|
104
118
|
##
|
105
119
|
## internal usage only below this point
|
106
120
|
## ------------------------------------
|
@@ -129,11 +143,13 @@ module ActiveScaffold::Config
|
|
129
143
|
|
130
144
|
# inherit from the global set of action links
|
131
145
|
@action_links = self.class.action_links.clone
|
146
|
+
@timestamped_messages = self.class.timestamped_messages
|
147
|
+
@highlight_messages = self.class.highlight_messages
|
132
148
|
end
|
133
149
|
|
134
150
|
# To be called after your finished configuration
|
135
151
|
def _load_action_columns
|
136
|
-
ActiveScaffold::DataStructures::ActionColumns.class_eval {include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration}
|
152
|
+
#ActiveScaffold::DataStructures::ActionColumns.class_eval {include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration}
|
137
153
|
|
138
154
|
# then, register the column objects
|
139
155
|
self.actions.each do |action_name|
|
@@ -47,7 +47,7 @@ module ActiveScaffold::Config
|
|
47
47
|
def columns
|
48
48
|
unless @columns # lazy evaluation
|
49
49
|
self.columns = @core.columns._inheritable
|
50
|
-
self.columns.exclude :created_on, :created_at, :updated_on, :updated_at, :
|
50
|
+
self.columns.exclude :created_on, :created_at, :updated_on, :updated_at, :as_marked
|
51
51
|
self.columns.exclude *@core.columns.collect{|c| c.name if c.polymorphic_association?}.compact
|
52
52
|
end
|
53
53
|
@columns
|
@@ -20,7 +20,6 @@ module ActiveScaffold::Config
|
|
20
20
|
@pagination = self.class.pagination
|
21
21
|
@show_search_reset = self.class.show_search_reset
|
22
22
|
@reset_link = self.class.reset_link.clone
|
23
|
-
@mark_records = self.class.mark_records
|
24
23
|
@wrap_tag = self.class.wrap_tag
|
25
24
|
@always_show_search = self.class.always_show_search
|
26
25
|
@always_show_create = self.class.always_show_create
|
@@ -62,10 +61,6 @@ module ActiveScaffold::Config
|
|
62
61
|
cattr_accessor :pagination
|
63
62
|
@@pagination = true
|
64
63
|
|
65
|
-
# Add a checkbox in front of each record to mark them and use them with a batch action later
|
66
|
-
cattr_accessor :mark_records
|
67
|
-
@@mark_records = false
|
68
|
-
|
69
64
|
# show a link to reset the search next to filtered message
|
70
65
|
cattr_accessor :show_search_reset
|
71
66
|
@@show_search_reset = true
|
@@ -130,9 +125,6 @@ module ActiveScaffold::Config
|
|
130
125
|
# the ActionLink to reset search
|
131
126
|
attr_reader :reset_link
|
132
127
|
|
133
|
-
# Add a checkbox in front of each record to mark them and use them with a batch action later
|
134
|
-
attr_accessor :mark_records
|
135
|
-
|
136
128
|
# the default sorting. should be an array of hashes of {column_name => direction}, e.g. [{:a => 'desc'}, {:b => 'asc'}]. to just sort on one column, you can simply provide a hash, though, e.g. {:a => 'desc'}.
|
137
129
|
def sorting=(val)
|
138
130
|
val = [val] if val.is_a? Hash
|
@@ -13,23 +13,18 @@ module ActiveScaffold::Config
|
|
13
13
|
def initialize(core_config)
|
14
14
|
@core = core_config
|
15
15
|
@mark_all_mode = self.class.mark_all_mode
|
16
|
-
|
17
|
-
|
18
|
-
add_mark_column
|
19
|
-
else
|
20
|
-
raise "Mark action requires update action in controller for model: #{core_config.model.to_s}"
|
21
|
-
end
|
16
|
+
@core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model < ActiveScaffold::MarkedModel
|
17
|
+
add_mark_column
|
22
18
|
end
|
23
19
|
|
24
20
|
protected
|
25
21
|
|
26
22
|
def add_mark_column
|
27
|
-
@core.columns.add :
|
28
|
-
@core.columns[:
|
29
|
-
@core.columns[:
|
30
|
-
@core.columns[:
|
31
|
-
@core.columns[:
|
32
|
-
@core.list.columns = [:marked] + @core.list.columns.names_without_auth_check unless @core.list.columns.include? :marked
|
23
|
+
@core.columns.add :as_marked
|
24
|
+
@core.columns[:as_marked].label = 'M'
|
25
|
+
@core.columns[:as_marked].list_ui = :marked
|
26
|
+
@core.columns[:as_marked].sort = false
|
27
|
+
@core.list.columns = [:as_marked] + @core.list.columns.names_without_auth_check unless @core.list.columns.include? :as_marked
|
33
28
|
end
|
34
29
|
end
|
35
30
|
end
|
@@ -38,27 +38,20 @@ module ActiveScaffold::DataStructures
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def names
|
41
|
-
|
41
|
+
if @columns
|
42
|
+
self.collect(&:name)
|
43
|
+
else
|
44
|
+
names_without_auth_check
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
44
48
|
def names_without_auth_check
|
45
49
|
Array(@set)
|
46
50
|
end
|
47
51
|
|
48
|
-
protected
|
49
|
-
|
50
|
-
def collect_columns
|
51
|
-
@set.collect {|col| col.is_a?(ActiveScaffold::DataStructures::ActionColumns) ? col.collect_columns : col}
|
52
|
-
end
|
53
|
-
|
54
|
-
# called during clone or dup. makes the clone/dup deeper.
|
55
|
-
def initialize_copy(from)
|
56
|
-
@set = from.instance_variable_get('@set').clone
|
57
|
-
end
|
58
|
-
|
59
52
|
# A package of stuff to add after the configuration block. This is an attempt at making a certain level of functionality inaccessible during configuration, to reduce possible breakage from misuse.
|
60
53
|
# The bulk of the package is a means of connecting the referential column set (ActionColumns) with the actual column objects (Columns). This lets us iterate over the set and yield real column objects.
|
61
|
-
module AfterConfiguration
|
54
|
+
#module AfterConfiguration
|
62
55
|
# Redefine the each method to yield actual Column objects.
|
63
56
|
# It will skip constrained and unauthorized columns.
|
64
57
|
#
|
@@ -66,10 +59,10 @@ module ActiveScaffold::DataStructures
|
|
66
59
|
# * :flatten - whether to recursively iterate on nested sets. default is false.
|
67
60
|
# * :for - the record (or class) being iterated over. used for column-level security. default is the class.
|
68
61
|
def each(options = {}, &proc)
|
69
|
-
options[:for] ||= @columns.active_record_class
|
62
|
+
options[:for] ||= @columns.active_record_class unless @columns.nil?
|
70
63
|
self.unauthorized_columns = []
|
71
64
|
@set.each do |item|
|
72
|
-
unless item.is_a?
|
65
|
+
unless item.is_a?(ActiveScaffold::DataStructures::ActionColumns) || @columns.nil?
|
73
66
|
item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class))
|
74
67
|
next if self.skip_column?(item, options)
|
75
68
|
end
|
@@ -133,6 +126,17 @@ module ActiveScaffold::DataStructures
|
|
133
126
|
def length
|
134
127
|
((@set - self.constraint_columns) - self.unauthorized_columns).length
|
135
128
|
end
|
129
|
+
#end
|
130
|
+
|
131
|
+
protected
|
132
|
+
|
133
|
+
def collect_columns
|
134
|
+
@set.collect {|col| col.is_a?(ActiveScaffold::DataStructures::ActionColumns) ? col.collect_columns : col}
|
135
|
+
end
|
136
|
+
|
137
|
+
# called during clone or dup. makes the clone/dup deeper.
|
138
|
+
def initialize_copy(from)
|
139
|
+
@set = from.instance_variable_get('@set').clone
|
136
140
|
end
|
137
141
|
end
|
138
142
|
end
|
@@ -38,13 +38,17 @@ module ActiveScaffold::DataStructures
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def parent_scope
|
41
|
-
parent_model.find(parent_id)
|
41
|
+
@parent_scope ||= parent_model.find(parent_id)
|
42
42
|
end
|
43
43
|
|
44
44
|
def habtm?
|
45
45
|
false
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
|
+
def has_many?
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
48
52
|
def belongs_to?
|
49
53
|
false
|
50
54
|
end
|
@@ -52,6 +56,18 @@ module ActiveScaffold::DataStructures
|
|
52
56
|
def has_one?
|
53
57
|
false
|
54
58
|
end
|
59
|
+
|
60
|
+
def singular_association?
|
61
|
+
belongs_to? || has_one?
|
62
|
+
end
|
63
|
+
|
64
|
+
def plural_association?
|
65
|
+
has_many? || habtm?
|
66
|
+
end
|
67
|
+
|
68
|
+
def through_association?
|
69
|
+
false
|
70
|
+
end
|
55
71
|
|
56
72
|
def readonly?
|
57
73
|
false
|
@@ -73,6 +89,10 @@ module ActiveScaffold::DataStructures
|
|
73
89
|
self.association.name
|
74
90
|
end
|
75
91
|
|
92
|
+
def has_many?
|
93
|
+
association.macro == :has_many
|
94
|
+
end
|
95
|
+
|
76
96
|
def habtm?
|
77
97
|
association.macro == :has_and_belongs_to_many
|
78
98
|
end
|
@@ -85,12 +105,12 @@ module ActiveScaffold::DataStructures
|
|
85
105
|
association.macro == :has_one
|
86
106
|
end
|
87
107
|
|
108
|
+
def through_association?
|
109
|
+
association.options[:through]
|
110
|
+
end
|
111
|
+
|
88
112
|
def readonly?
|
89
|
-
|
90
|
-
association.options[:readonly]
|
91
|
-
else
|
92
|
-
association.options.has_key? :through
|
93
|
-
end
|
113
|
+
association.options[:readonly]
|
94
114
|
end
|
95
115
|
|
96
116
|
def sorted?
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module ActionDispatch
|
2
2
|
module Routing
|
3
3
|
ACTIVE_SCAFFOLD_CORE_ROUTING = {
|
4
|
-
:collection => {:show_search => :get, :render_field => :get},
|
5
|
-
:member => {:row => :get, :update_column => :post, :render_field => :get}
|
4
|
+
:collection => {:show_search => :get, :render_field => :get, :mark => :post},
|
5
|
+
:member => {:row => :get, :update_column => :post, :render_field => :get, :mark => :post}
|
6
6
|
}
|
7
7
|
ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = {
|
8
8
|
:collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post},
|
@@ -281,13 +281,19 @@ module ActiveScaffold
|
|
281
281
|
finder_options
|
282
282
|
end
|
283
283
|
|
284
|
-
|
285
|
-
# See finder_options for valid options
|
286
|
-
def count_options(find_options = {}, count_includes = nil)
|
284
|
+
def count_items(find_options = {}, count_includes = nil)
|
287
285
|
count_includes ||= find_options[:includes] unless find_options[:conditions].nil?
|
288
286
|
options = find_options.reject{|k,v| [:select, :reorder].include? k}
|
289
287
|
options[:includes] = count_includes
|
290
|
-
|
288
|
+
|
289
|
+
# NOTE: we must use :include in the count query, because some conditions may reference other tables
|
290
|
+
count_query = append_to_query(beginning_of_chain, options)
|
291
|
+
count = count_query.count
|
292
|
+
|
293
|
+
# Converts count to an integer if ActiveRecord returned an OrderedHash
|
294
|
+
# that happens when find_options contains a :group key
|
295
|
+
count = count.length if count.is_a? ActiveSupport::OrderedHash
|
296
|
+
count
|
291
297
|
end
|
292
298
|
|
293
299
|
# returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters
|
@@ -298,18 +304,13 @@ module ActiveScaffold
|
|
298
304
|
options[:page] ||= 1
|
299
305
|
|
300
306
|
find_options = finder_options(options)
|
301
|
-
klass = beginning_of_chain
|
302
307
|
|
303
308
|
# NOTE: we must use :include in the count query, because some conditions may reference other tables
|
304
309
|
if options[:pagination] && options[:pagination] != :infinite
|
305
|
-
|
306
|
-
count = count_query.count unless options[:pagination] == :infinite
|
310
|
+
count = count_items(find_options, options[:count_includes])
|
307
311
|
end
|
308
|
-
|
309
|
-
# Converts count to an integer if ActiveRecord returned an OrderedHash
|
310
|
-
# that happens when find_options contains a :group key
|
311
|
-
count = count.length if count.is_a? ActiveSupport::OrderedHash
|
312
312
|
|
313
|
+
klass = beginning_of_chain
|
313
314
|
# we build the paginator differently for method- and sql-based sorting
|
314
315
|
if options[:sorting] and options[:sorting].sorts_by_method?
|
315
316
|
pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
|
@@ -2,10 +2,14 @@ module ActiveScaffold
|
|
2
2
|
module Helpers
|
3
3
|
module ControllerHelpers
|
4
4
|
def self.included(controller)
|
5
|
-
controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated}
|
5
|
+
controller.class_eval { helper_method :params_for, :params_conditions, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated}
|
6
6
|
end
|
7
7
|
|
8
8
|
include ActiveScaffold::Helpers::IdHelpers
|
9
|
+
|
10
|
+
def params_conditions
|
11
|
+
conditions_from_params.keys
|
12
|
+
end
|
9
13
|
|
10
14
|
def params_for(options = {})
|
11
15
|
# :adapter and :position are one-use rendering arguments. they should not propagate.
|
@@ -81,14 +85,6 @@ module ActiveScaffold
|
|
81
85
|
end if @parent_action.nil?
|
82
86
|
@parent_action
|
83
87
|
end
|
84
|
-
|
85
|
-
def render_parent_controller
|
86
|
-
if nested_singular_association?
|
87
|
-
nested.parent_scaffold.controller_path
|
88
|
-
else
|
89
|
-
params[:parent_sti]
|
90
|
-
end
|
91
|
-
end
|
92
88
|
|
93
89
|
def build_associated(column, record)
|
94
90
|
if column.singular_association?
|
@@ -278,11 +278,11 @@ module ActiveScaffold
|
|
278
278
|
end
|
279
279
|
end
|
280
280
|
|
281
|
-
def column_scope(column)
|
281
|
+
def column_scope(column, scope = nil)
|
282
282
|
if column.plural_association?
|
283
|
-
"[#{column.name}][#{@record.id || generate_temporary_id}]"
|
283
|
+
"#{scope}[#{column.name}][#{@record.id || generate_temporary_id}]"
|
284
284
|
else
|
285
|
-
"[#{column.name}]"
|
285
|
+
"#{scope}[#{column.name}]"
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
@@ -6,10 +6,14 @@ module ActiveScaffold
|
|
6
6
|
controller.to_s.gsub("/", "__").html_safe
|
7
7
|
end
|
8
8
|
|
9
|
-
def controller_id(controller = (params[:eid] || params[:parent_controller] || params[:controller]))
|
9
|
+
def controller_id(controller = (params[:eid] || nested_id || params[:parent_controller] || params[:controller]))
|
10
10
|
controller_id ||= 'as_' + id_from_controller(controller)
|
11
11
|
end
|
12
12
|
|
13
|
+
def nested_id
|
14
|
+
"#{nested.parent_scaffold.controller_path}-#{nested.parent_id}-#{params[:controller]}" if nested?
|
15
|
+
end
|
16
|
+
|
13
17
|
def active_scaffold_id
|
14
18
|
"#{controller_id}-active-scaffold"
|
15
19
|
end
|
@@ -92,10 +92,11 @@ module ActiveScaffold
|
|
92
92
|
|
93
93
|
def column_link_authorized?(link, column, record, associated)
|
94
94
|
if column.association
|
95
|
-
associated_for_authorized = if associated.nil? || (associated.respond_to?(:blank?) && associated.blank?)
|
95
|
+
associated_for_authorized = if associated.nil? || (column.plural_association? && !associated.loaded?) || (associated.respond_to?(:blank?) && associated.blank?)
|
96
96
|
column.association.klass
|
97
97
|
elsif [:has_many, :has_and_belongs_to_many].include? column.association.macro
|
98
|
-
|
98
|
+
# may be cached with [] or [nil] to avoid some queries
|
99
|
+
associated.first || column.association.klass
|
99
100
|
else
|
100
101
|
associated
|
101
102
|
end
|
@@ -125,6 +126,11 @@ module ActiveScaffold
|
|
125
126
|
clean_column_value(truncate(record.send(column.name), :length => column.options[:truncate] || 50))
|
126
127
|
end
|
127
128
|
|
129
|
+
def active_scaffold_column_marked(column, record)
|
130
|
+
options = {:id => nil, :object => record}
|
131
|
+
content_tag(:span, check_box(:record, column.name, options), :class => 'in_place_editor_field', :data => {:ie_id => record.id.to_s})
|
132
|
+
end
|
133
|
+
|
128
134
|
def active_scaffold_column_checkbox(column, record)
|
129
135
|
options = {:disabled => true, :id => nil, :object => record}
|
130
136
|
options.delete(:disabled) if inplace_edit?(record, column)
|
@@ -150,7 +156,7 @@ module ActiveScaffold
|
|
150
156
|
value ||= record.send(column.name) unless record.nil?
|
151
157
|
if value && column.association # cache association size before calling column_empty?
|
152
158
|
associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association
|
153
|
-
cache_association(value, column) if column.plural_association?
|
159
|
+
cache_association(value, column, associated_size) if column.plural_association?
|
154
160
|
end
|
155
161
|
if column.association.nil? or column_empty?(value)
|
156
162
|
if column.form_ui == :select && column.options[:options]
|
@@ -222,14 +228,16 @@ module ActiveScaffold
|
|
222
228
|
clean_column_value(value)
|
223
229
|
end
|
224
230
|
|
225
|
-
def cache_association(value, column)
|
231
|
+
def cache_association(value, column, size)
|
226
232
|
# we are not using eager loading, cache firsts records in order not to query the database in a future
|
227
233
|
unless value.loaded?
|
228
|
-
# load at least one record, is needed
|
234
|
+
# load at least one record, is needed to display '...'
|
229
235
|
if column.associated_limit.nil?
|
230
236
|
Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries"
|
231
|
-
|
237
|
+
elsif column.associated_limit > 0
|
232
238
|
value.target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns)
|
239
|
+
else
|
240
|
+
value.target = size.to_i.zero? ? [] : [nil]
|
233
241
|
end
|
234
242
|
end
|
235
243
|
end
|
@@ -254,9 +262,9 @@ module ActiveScaffold
|
|
254
262
|
formatted_column = options[:formatted_column] || format_column_value(record, column)
|
255
263
|
id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s}
|
256
264
|
tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field",
|
257
|
-
:title => as_(:click_to_edit),
|
265
|
+
:title => as_(:click_to_edit), :data => {:ie_id => record.id.to_s}}
|
258
266
|
|
259
|
-
content_tag(:span, as_(:
|
267
|
+
content_tag(:span, as_(:inplace_edit_handle), :class => 'handle') <<
|
260
268
|
content_tag(:span, formatted_column, tag_options)
|
261
269
|
end
|
262
270
|
|
@@ -276,54 +284,65 @@ module ActiveScaffold
|
|
276
284
|
"as_inplace_pattern"
|
277
285
|
end
|
278
286
|
|
279
|
-
def
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
287
|
+
def inplace_edit_data(column)
|
288
|
+
data = {}
|
289
|
+
data[:ie_url] = url_for({:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => '__id__'})
|
290
|
+
data[:ie_cancel_text] = column.options[:cancel_text] || as_(:cancel)
|
291
|
+
data[:ie_loading_text] = column.options[:loading_text] || as_(:loading)
|
292
|
+
data[:ie_save_text] = column.options[:save_text] || as_(:update)
|
293
|
+
data[:ie_saving_text] = column.options[:saving_text] || as_(:saving)
|
294
|
+
data[:ie_rows] = column.options[:rows] || 5 if column.column.try(:type) == :text
|
295
|
+
data[:ie_cols] = column.options[:cols] if column.options[:cols]
|
296
|
+
data[:ie_size] = column.options[:size] if column.options[:size]
|
289
297
|
|
290
298
|
if column.list_ui == :checkbox
|
291
|
-
|
299
|
+
data[:ie_mode] = :inline_checkbox
|
292
300
|
elsif inplace_edit_cloning?(column)
|
293
|
-
|
301
|
+
data[:ie_mode] = :clone
|
294
302
|
elsif column.inplace_edit == :ajax
|
295
303
|
url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :column => column.name, :update_column => column.name, :in_place_editing => true)
|
296
304
|
plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui)
|
297
|
-
|
298
|
-
|
299
|
-
|
305
|
+
data[:ie_render_url] = url
|
306
|
+
data[:ie_mode] = :ajax
|
307
|
+
data[:ie_plural] = plural
|
300
308
|
end
|
301
|
-
|
309
|
+
data
|
302
310
|
end
|
303
311
|
|
304
|
-
def
|
305
|
-
if active_scaffold_config.mark.mark_all_mode == :page
|
306
|
-
all_marked =
|
307
|
-
@page.items.each do |record|
|
308
|
-
all_marked = false if !marked_records.entries.include?(record.id)
|
309
|
-
end
|
312
|
+
def all_marked?
|
313
|
+
if active_scaffold_config.mark.mark_all_mode == :page
|
314
|
+
all_marked = @page.items.detect { |record| !marked_records.include?(record.id) }.nil?
|
310
315
|
else
|
311
316
|
all_marked = (marked_records.length >= @page.pager.count)
|
312
317
|
end
|
313
|
-
|
314
|
-
|
315
|
-
|
318
|
+
end
|
319
|
+
|
320
|
+
def mark_column_heading
|
321
|
+
tag_options = {
|
322
|
+
:id => "#{controller_id}_mark_heading",
|
323
|
+
:class => "mark_heading in_place_editor_field",
|
324
|
+
}
|
325
|
+
content_tag(:span, check_box_tag("#{controller_id}_mark_heading_span_input", '1', all_marked?), tag_options)
|
316
326
|
end
|
317
327
|
|
318
328
|
def render_column_heading(column, sorting, sort_direction)
|
319
329
|
tag_options = {:id => active_scaffold_column_header_id(column), :class => column_heading_class(column, sorting), :title => column.description}
|
320
|
-
|
330
|
+
if column.name == :as_marked
|
331
|
+
tag_options[:data] = {
|
332
|
+
:ie_mode => :inline_checkbox,
|
333
|
+
:ie_url => url_for(:controller => params_for[:controller], :action => 'mark', :id => '__id__', :eid => params[:eid])
|
334
|
+
}
|
335
|
+
else
|
336
|
+
tag_options[:data] = inplace_edit_data(column) if column.inplace_edit
|
337
|
+
end
|
321
338
|
content_tag(:th, column_heading_value(column, sorting, sort_direction) + inplace_edit_control(column), tag_options)
|
322
339
|
end
|
323
340
|
|
324
341
|
|
325
342
|
def column_heading_value(column, sorting, sort_direction)
|
326
|
-
if column.
|
343
|
+
if column.name == :as_marked
|
344
|
+
mark_column_heading
|
345
|
+
elsif column.sortable?
|
327
346
|
options = {:id => nil, :class => "as_sort",
|
328
347
|
'data-page-history' => controller_id,
|
329
348
|
:remote => true, :method => :get}
|
@@ -331,11 +350,7 @@ module ActiveScaffold
|
|
331
350
|
:sort => column.name, :sort_direction => sort_direction)
|
332
351
|
link_to column.label, url_options, options
|
333
352
|
else
|
334
|
-
|
335
|
-
content_tag(:p, column.label)
|
336
|
-
else
|
337
|
-
mark_column_heading
|
338
|
-
end
|
353
|
+
content_tag(:p, column.label)
|
339
354
|
end
|
340
355
|
end
|
341
356
|
|