active_scaffold 3.1.20 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/jquery/active_scaffold.js +4 -1
- data/app/assets/javascripts/prototype/active_scaffold.js +4 -1
- data/app/assets/stylesheets/{active_scaffold.scss~ → active_scaffold.css.scss} +5 -2
- data/app/assets/stylesheets/{active_scaffold_colors.scss → active_scaffold_colors.css.scss} +4 -0
- data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -0
- data/app/assets/stylesheets/active_scaffold_images.css.scss +43 -0
- data/lib/active_scaffold/actions/core.rb +1 -0
- data/lib/active_scaffold/actions/nested.rb +0 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
- data/lib/active_scaffold/helpers/form_column_helpers.rb +1 -0
- data/lib/active_scaffold/version.rb +2 -2
- data/test/mock_app/.gitignore +2 -0
- metadata +86 -164
- data/app/assets/javascripts/active_scaffold.js.erb~ +0 -16
- data/app/assets/javascripts/jquery/active_scaffold.js~ +0 -1053
- data/app/assets/javascripts/jquery/draggable_lists.js~ +0 -27
- data/app/assets/javascripts/prototype/active_scaffold.js~ +0 -1037
- data/app/assets/stylesheets/active_scaffold.css.erb +0 -11
- data/app/assets/stylesheets/active_scaffold.css.erb~ +0 -11
- data/app/assets/stylesheets/active_scaffold.css.scss.erb~ +0 -1120
- data/app/assets/stylesheets/active_scaffold.css.scss~ +0 -11
- data/app/assets/stylesheets/active_scaffold.css~ +0 -11
- data/app/assets/stylesheets/active_scaffold_colors.css +0 -244
- data/app/assets/stylesheets/active_scaffold_colors.css.scss~ +0 -481
- data/app/assets/stylesheets/active_scaffold_default.css.erb +0 -47
- data/app/assets/stylesheets/active_scaffold_default.css.erb~ +0 -57
- data/app/assets/stylesheets/active_scaffold_default.css.scss~ +0 -1092
- data/app/assets/stylesheets/active_scaffold_default.css~ +0 -923
- data/app/assets/stylesheets/active_scaffold_layout.css~ +0 -922
- data/app/assets/stylesheets/blue-theme.css~ +0 -1150
- data/config/locales/es.yml~ +0 -120
- data/frontends/default/views/_action_group.html.erb~ +0 -24
- data/frontends/default/views/_base_form.html.erb~ +0 -42
- data/frontends/default/views/_form.html.erb~ +0 -26
- data/frontends/default/views/_form_association.html.erb~ +0 -19
- data/frontends/default/views/_form_association_footer.html.erb~ +0 -48
- data/frontends/default/views/_horizontal_subform.html.erb~ +0 -32
- data/frontends/default/views/_horizontal_subform_header.html.erb~ +0 -11
- data/frontends/default/views/_horizontal_subform_record.html.erb~ +0 -38
- data/frontends/default/views/_list_actions.html.erb~ +0 -15
- data/frontends/default/views/_list_inline_adapter.html.erb~ +0 -10
- data/frontends/default/views/_list_messages.html.erb~ +0 -30
- data/frontends/default/views/_list_pagination.html.erb~ +0 -11
- data/frontends/default/views/_list_pagination_links.html.erb~ +0 -0
- data/frontends/default/views/_list_with_header.html.erb~ +0 -36
- data/frontends/default/views/_render_field.js.erb~ +0 -23
- data/frontends/default/views/_row.html.erb~ +0 -6
- data/frontends/default/views/_show.html.erb~ +0 -8
- data/frontends/default/views/_update_form.html.erb~ +0 -6
- data/frontends/default/views/_vertical_subform.html.erb~ +0 -12
- data/frontends/default/views/add_existing.js.erb~ +0 -18
- data/frontends/default/views/add_existing_form.html.erb~ +0 -5
- data/frontends/default/views/create.html.erb~ +0 -5
- data/frontends/default/views/edit_associated.js.erb~ +0 -13
- data/frontends/default/views/on_create.js.erb~ +0 -45
- data/frontends/default/views/on_update.js.erb~ +0 -31
- data/frontends/default/views/render_field.js.erb~ +0 -1
- data/frontends/default/views/search.html.erb~ +0 -5
- data/frontends/default/views/show.html.erb~ +0 -5
- data/frontends/default/views/update.html.erb~ +0 -8
- data/frontends/default/views/update_column.js.erb~ +0 -16
- data/lib/active_scaffold.rb~ +0 -373
- data/lib/active_scaffold/actions/core.rb~ +0 -203
- data/lib/active_scaffold/actions/create.rb~ +0 -148
- data/lib/active_scaffold/actions/list.rb~ +0 -196
- data/lib/active_scaffold/actions/nested.rb~ +0 -247
- data/lib/active_scaffold/actions/search.rb~ +0 -49
- data/lib/active_scaffold/actions/subform.rb~ +0 -27
- data/lib/active_scaffold/actions/update.rb~ +0 -150
- data/lib/active_scaffold/attribute_params.rb~ +0 -203
- data/lib/active_scaffold/bridges/date_picker/helper.rb~ +0 -180
- data/lib/active_scaffold/bridges/record_select/helpers.rb~ +0 -86
- data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +0 -209
- data/lib/active_scaffold/config/base.rb~ +0 -72
- data/lib/active_scaffold/config/list.rb~ +0 -195
- data/lib/active_scaffold/config/nested.rb~ +0 -41
- data/lib/active_scaffold/config/search.rb~ +0 -74
- data/lib/active_scaffold/constraints.rb~ +0 -186
- data/lib/active_scaffold/data_structures/action_columns.rb~ +0 -140
- data/lib/active_scaffold/data_structures/action_link.rb~ +0 -179
- data/lib/active_scaffold/data_structures/nested_info.rb~ +0 -147
- data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +0 -22
- data/lib/active_scaffold/extensions/action_view_rendering.rb~ +0 -120
- data/lib/active_scaffold/extensions/active_association_reflection.rb~ +0 -22
- data/lib/active_scaffold/extensions/cache_association.rb~ +0 -12
- data/lib/active_scaffold/extensions/reverse_associations.rb~ +0 -64
- data/lib/active_scaffold/extensions/routing_mapper.rb~ +0 -48
- data/lib/active_scaffold/extensions/unsaved_associated.rb~ +0 -62
- data/lib/active_scaffold/finder.rb~ +0 -370
- data/lib/active_scaffold/helpers/controller_helpers.rb~ +0 -92
- data/lib/active_scaffold/helpers/form_column_helpers.rb~ +0 -320
- data/lib/active_scaffold/helpers/id_helpers.rb~ +0 -123
- data/lib/active_scaffold/helpers/list_column_helpers.rb~ +0 -370
- data/lib/active_scaffold/helpers/search_column_helpers.rb~ +0 -263
- data/lib/active_scaffold/helpers/view_helpers.rb~ +0 -350
@@ -1,263 +0,0 @@
|
|
1
|
-
module ActiveScaffold
|
2
|
-
module Helpers
|
3
|
-
# Helpers that assist with the rendering of a Form Column
|
4
|
-
module SearchColumnHelpers
|
5
|
-
# This method decides which input to use for the given column.
|
6
|
-
# It does not do any rendering. It only decides which method is responsible for rendering.
|
7
|
-
def active_scaffold_search_for(column)
|
8
|
-
options = active_scaffold_search_options(column)
|
9
|
-
|
10
|
-
# first, check if the dev has created an override for this specific field for search
|
11
|
-
if override_search_field?(column)
|
12
|
-
send(override_search_field(column), @record, options)
|
13
|
-
|
14
|
-
# second, check if the dev has specified a valid search_ui for this column, using specific ui for searches
|
15
|
-
elsif column.search_ui and override_search?(column.search_ui)
|
16
|
-
send(override_search(column.search_ui), column, options)
|
17
|
-
|
18
|
-
# third, check if the dev has specified a valid search_ui for this column, using generic ui for forms
|
19
|
-
elsif column.search_ui and override_input?(column.search_ui)
|
20
|
-
send(override_input(column.search_ui), column, options)
|
21
|
-
|
22
|
-
# fourth, check if the dev has created an override for this specific field
|
23
|
-
elsif override_form_field?(column)
|
24
|
-
send(override_form_field(column), @record, options)
|
25
|
-
|
26
|
-
# fallback: we get to make the decision
|
27
|
-
else
|
28
|
-
if column.association or column.virtual?
|
29
|
-
active_scaffold_search_text(column, options)
|
30
|
-
|
31
|
-
else # regular model attribute column
|
32
|
-
# if we (or someone else) have created a custom render option for the column type, use that
|
33
|
-
if override_search?(column.column.type)
|
34
|
-
send(override_search(column.column.type), column, options)
|
35
|
-
# if we (or someone else) have created a custom render option for the column type, use that
|
36
|
-
elsif override_input?(column.column.type)
|
37
|
-
send(override_input(column.column.type), column, options)
|
38
|
-
# final ultimate fallback: use rails' generic input method
|
39
|
-
else
|
40
|
-
# for textual fields we pass different options
|
41
|
-
text_types = [:text, :string, :integer, :float, :decimal]
|
42
|
-
options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type)
|
43
|
-
text_field(:record, column.name, options.merge(column.options))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# the standard active scaffold options used for class, name and scope
|
50
|
-
def active_scaffold_search_options(column)
|
51
|
-
{ :name => "search[#{column.name}]", :class => "#{column.name}-input", :id => "search_#{column.name}", :value => field_search_params[column.name] }
|
52
|
-
end
|
53
|
-
|
54
|
-
##
|
55
|
-
## Search input methods
|
56
|
-
##
|
57
|
-
|
58
|
-
def active_scaffold_search_multi_select(column, options)
|
59
|
-
associated = options.delete :value
|
60
|
-
associated = [associated].compact unless associated.is_a? Array
|
61
|
-
associated.collect!(&:to_i)
|
62
|
-
|
63
|
-
if column.association
|
64
|
-
select_options = options_for_association(column.association, false)
|
65
|
-
else
|
66
|
-
select_options = Array(column.options[:options])
|
67
|
-
end
|
68
|
-
return as_(:no_options) if select_options.empty?
|
69
|
-
|
70
|
-
active_scaffold_checkbox_list(column, select_options, associated, options)
|
71
|
-
end
|
72
|
-
|
73
|
-
def active_scaffold_search_select(column, html_options)
|
74
|
-
associated = html_options.delete :value
|
75
|
-
if column.association
|
76
|
-
associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil?
|
77
|
-
method = column.association.macro == :belongs_to ? column.association.foreign_key : column.name
|
78
|
-
select_options = options_for_association(column.association, true)
|
79
|
-
else
|
80
|
-
method = column.name
|
81
|
-
select_options = Array(column.options[:options])
|
82
|
-
end
|
83
|
-
|
84
|
-
options = { :selected => associated }.merge! column.options
|
85
|
-
html_options.merge! column.options[:html_options] || {}
|
86
|
-
if html_options[:multiple]
|
87
|
-
html_options[:name] += '[]'
|
88
|
-
else
|
89
|
-
options[:include_blank] ||= as_(:_select_)
|
90
|
-
end
|
91
|
-
select(:record, method, select_options, options, html_options)
|
92
|
-
end
|
93
|
-
|
94
|
-
def active_scaffold_search_text(column, options)
|
95
|
-
text_field :record, column.name, active_scaffold_input_text_options(options)
|
96
|
-
end
|
97
|
-
|
98
|
-
# we can't use active_scaffold_input_boolean because we need to have a nil value even when column can't be null
|
99
|
-
# to decide whether search for this field or not
|
100
|
-
def active_scaffold_search_boolean(column, options)
|
101
|
-
select_options = []
|
102
|
-
select_options << [as_(:_select_), nil]
|
103
|
-
select_options << [as_(:true), true]
|
104
|
-
select_options << [as_(:false), false]
|
105
|
-
|
106
|
-
select_tag(options[:name], options_for_select(select_options, column.column.type_cast(field_search_params[column.name])))
|
107
|
-
end
|
108
|
-
# we can't use checkbox ui because it's not possible to decide whether search for this field or not
|
109
|
-
alias_method :active_scaffold_search_checkbox, :active_scaffold_search_boolean
|
110
|
-
|
111
|
-
def active_scaffold_search_null(column, options)
|
112
|
-
select_options = []
|
113
|
-
select_options << [as_(:_select_), nil]
|
114
|
-
select_options.concat ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp), comp]}
|
115
|
-
select_tag(options[:name], options_for_select(select_options, field_search_params[column.name]))
|
116
|
-
end
|
117
|
-
|
118
|
-
def field_search_params_range_values(column)
|
119
|
-
values = field_search_params[column.name]
|
120
|
-
return nil if values.nil?
|
121
|
-
return values[:opt], (values[:from].blank? ? nil : values[:from]), (values[:to].blank? ? nil : values[:to])
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
def active_scaffold_search_range_string?(column)
|
126
|
-
(column.column && column.column.text?) || column.search_ui == :string
|
127
|
-
end
|
128
|
-
|
129
|
-
def include_null_comparators?(column)
|
130
|
-
return column.options[:null_comparators] if column.options.has_key? :null_comparators
|
131
|
-
if column.association
|
132
|
-
column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.primary_key_name].column.try(:null)
|
133
|
-
else
|
134
|
-
column.column.try(:null)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def active_scaffold_search_range_comparator_options(column)
|
139
|
-
select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
|
140
|
-
if active_scaffold_search_range_string?(column)
|
141
|
-
select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]}
|
142
|
-
end
|
143
|
-
if include_null_comparators? column
|
144
|
-
select_options += ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp), comp]}
|
145
|
-
end
|
146
|
-
select_options
|
147
|
-
end
|
148
|
-
|
149
|
-
def include_null_comparators?(column)
|
150
|
-
return column.options[:null_comparators] if column.options.has_key? :null_comparators
|
151
|
-
if column.association
|
152
|
-
column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.primary_key_name].column.try(:null)
|
153
|
-
else
|
154
|
-
column.column.try(:null)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def active_scaffold_search_range(column, options)
|
159
|
-
opt_value, from_value, to_value = field_search_params_range_values(column)
|
160
|
-
|
161
|
-
select_options = active_scaffold_search_range_comparator_options(column)
|
162
|
-
if active_scaffold_search_range_string?(column)
|
163
|
-
text_field_size = 15
|
164
|
-
opt_value ||= '%?%'
|
165
|
-
else
|
166
|
-
text_field_size = 10
|
167
|
-
opt_value ||= '='
|
168
|
-
end
|
169
|
-
|
170
|
-
from_value = controller.class.condition_value_for_numeric(column, from_value)
|
171
|
-
to_value = controller.class.condition_value_for_numeric(column, to_value)
|
172
|
-
from_value = format_number_value(from_value, column.options) if from_value.is_a?(Numeric)
|
173
|
-
to_value = format_number_value(to_value, column.options) if to_value.is_a?(Numeric)
|
174
|
-
html = select_tag("#{options[:name]}[opt]",
|
175
|
-
options_for_select(select_options, opt_value),
|
176
|
-
:id => "#{options[:id]}_opt",
|
177
|
-
:class => "as_search_range_option")
|
178
|
-
html << ' ' << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => text_field_size))
|
179
|
-
html << ' ' << content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value,
|
180
|
-
active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => text_field_size))).html_safe,
|
181
|
-
:id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:#{(opt_value == 'BETWEEN') ? '' : 'none'}")
|
182
|
-
content_tag :span, html, :class => 'search_range'
|
183
|
-
end
|
184
|
-
alias_method :active_scaffold_search_integer, :active_scaffold_search_range
|
185
|
-
alias_method :active_scaffold_search_decimal, :active_scaffold_search_range
|
186
|
-
alias_method :active_scaffold_search_float, :active_scaffold_search_range
|
187
|
-
alias_method :active_scaffold_search_string, :active_scaffold_search_range
|
188
|
-
|
189
|
-
def field_search_datetime_value(value)
|
190
|
-
DateTime.new(value[:year].to_i, value[:month].to_i, value[:day].to_i, value[:hour].to_i, value[:minute].to_i, value[:second].to_i) unless value.nil? || value[:year].blank?
|
191
|
-
end
|
192
|
-
|
193
|
-
def active_scaffold_search_datetime(column, options)
|
194
|
-
opt_value, from_value, to_value = field_search_params_range_values(column)
|
195
|
-
options = column.options.merge(options)
|
196
|
-
helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}"
|
197
|
-
|
198
|
-
send(helper, field_search_datetime_value(from_value), {:include_blank => true, :prefix => "#{options[:name]}[from]"}.merge(options)) <<
|
199
|
-
' - '.html_safe << send(helper, field_search_datetime_value(to_value), {:include_blank => true, :prefix => "#{options[:name]}[to]"}.merge(options))
|
200
|
-
end
|
201
|
-
|
202
|
-
def active_scaffold_search_date(column, options)
|
203
|
-
active_scaffold_search_datetime(column, options.merge!(:discard_time => true))
|
204
|
-
end
|
205
|
-
def active_scaffold_search_time(column, options)
|
206
|
-
active_scaffold_search_datetime(column, options.merge!(:discard_date => true))
|
207
|
-
end
|
208
|
-
alias_method :active_scaffold_search_timestamp, :active_scaffold_search_datetime
|
209
|
-
|
210
|
-
##
|
211
|
-
## Search column override signatures
|
212
|
-
##
|
213
|
-
|
214
|
-
def override_search_field(column)
|
215
|
-
method_with_class = override_search_field_name(column, true)
|
216
|
-
return method_with_class if respond_to?(method_with_class)
|
217
|
-
method = override_search_field_name(column)
|
218
|
-
method if respond_to?(method)
|
219
|
-
end
|
220
|
-
alias_method :override_search_field?, :override_search_field
|
221
|
-
|
222
|
-
# the naming convention for overriding form fields with helpers
|
223
|
-
def override_search_field_name(column, class_prefix = false)
|
224
|
-
"#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_search_column"
|
225
|
-
end
|
226
|
-
|
227
|
-
def override_search?(search_ui)
|
228
|
-
respond_to?(override_search(search_ui))
|
229
|
-
end
|
230
|
-
|
231
|
-
# the naming convention for overriding search input types with helpers
|
232
|
-
def override_search(form_ui)
|
233
|
-
"active_scaffold_search_#{form_ui}"
|
234
|
-
end
|
235
|
-
|
236
|
-
def visibles_and_hiddens(search_config)
|
237
|
-
visibles = []
|
238
|
-
hiddens = []
|
239
|
-
search_config.columns.each do |column|
|
240
|
-
next unless column.search_sql
|
241
|
-
if search_config.optional_columns.include?(column.name) && !searched_by?(column)
|
242
|
-
hiddens << column
|
243
|
-
else
|
244
|
-
visibles << column
|
245
|
-
end
|
246
|
-
end
|
247
|
-
return visibles, hiddens
|
248
|
-
end
|
249
|
-
|
250
|
-
def searched_by?(column)
|
251
|
-
value = field_search_params[column.name]
|
252
|
-
case value
|
253
|
-
when Hash
|
254
|
-
!value['from'].blank?
|
255
|
-
when String
|
256
|
-
!value.blank?
|
257
|
-
else
|
258
|
-
false
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
@@ -1,350 +0,0 @@
|
|
1
|
-
module ActiveScaffold
|
2
|
-
module Helpers
|
3
|
-
# All extra helpers that should be included in the View.
|
4
|
-
# Also a dumping ground for uncategorized helpers.
|
5
|
-
module ViewHelpers
|
6
|
-
include ActiveScaffold::Helpers::IdHelpers
|
7
|
-
include ActiveScaffold::Helpers::AssociationHelpers
|
8
|
-
include ActiveScaffold::Helpers::PaginationHelpers
|
9
|
-
include ActiveScaffold::Helpers::ListColumnHelpers
|
10
|
-
include ActiveScaffold::Helpers::ShowColumnHelpers
|
11
|
-
include ActiveScaffold::Helpers::FormColumnHelpers
|
12
|
-
include ActiveScaffold::Helpers::SearchColumnHelpers
|
13
|
-
include ActiveScaffold::Helpers::HumanConditionHelpers
|
14
|
-
|
15
|
-
##
|
16
|
-
## Delegates
|
17
|
-
##
|
18
|
-
|
19
|
-
# access to the configuration variable
|
20
|
-
def active_scaffold_config
|
21
|
-
controller.class.active_scaffold_config
|
22
|
-
end
|
23
|
-
|
24
|
-
def active_scaffold_config_for(*args)
|
25
|
-
controller.class.active_scaffold_config_for(*args)
|
26
|
-
end
|
27
|
-
|
28
|
-
def active_scaffold_controller_for(*args)
|
29
|
-
controller.class.active_scaffold_controller_for(*args)
|
30
|
-
end
|
31
|
-
|
32
|
-
##
|
33
|
-
## Uncategorized
|
34
|
-
##
|
35
|
-
|
36
|
-
def controller_path_for_activerecord(klass)
|
37
|
-
begin
|
38
|
-
controller = active_scaffold_controller_for(klass)
|
39
|
-
controller.controller_path
|
40
|
-
rescue ActiveScaffold::ControllerNotFound
|
41
|
-
controller = nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# This is the template finder logic, keep it updated with however we find stuff in rails
|
46
|
-
# currently this very similar to the logic in ActionBase::Base.render for options file
|
47
|
-
def template_exists?(template_name, partial = false)
|
48
|
-
lookup_context.exists? template_name, '', partial
|
49
|
-
end
|
50
|
-
|
51
|
-
def generate_temporary_id
|
52
|
-
(Time.now.to_f*1000).to_i.to_s
|
53
|
-
end
|
54
|
-
|
55
|
-
# Turns [[label, value]] into <option> tags
|
56
|
-
# Takes optional parameter of :include_blank
|
57
|
-
def option_tags_for(select_options, options = {})
|
58
|
-
select_options.insert(0,[as_(:_select_),nil]) if options[:include_blank]
|
59
|
-
select_options.collect do |option|
|
60
|
-
label, value = option[0], option[1]
|
61
|
-
value.nil? ? "<option value="">#{label}</option>" : "<option value=\"#{value}\">#{label}</option>"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Should this column be displayed in the subform?
|
66
|
-
def in_subform?(column, parent_record)
|
67
|
-
return true unless column.association
|
68
|
-
|
69
|
-
# Polymorphic associations can't appear because they *might* be the reverse association, and because you generally don't assign an association from the polymorphic side ... I think.
|
70
|
-
return false if column.polymorphic_association?
|
71
|
-
|
72
|
-
# A column shouldn't be in the subform if it's the reverse association to the parent
|
73
|
-
return false if column.association.inverse_for?(parent_record.class)
|
74
|
-
|
75
|
-
return true
|
76
|
-
end
|
77
|
-
|
78
|
-
def form_remote_upload_tag(url_for_options = {}, options = {})
|
79
|
-
options[:target] = action_iframe_id(url_for_options)
|
80
|
-
options[:multipart] ||= true
|
81
|
-
options[:class] = "#{options[:class]} as_remote_upload".strip
|
82
|
-
output=""
|
83
|
-
output << form_tag(url_for_options, options)
|
84
|
-
(output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>").html_safe
|
85
|
-
end
|
86
|
-
|
87
|
-
# a general-use loading indicator (the "stuff is happening, please wait" feedback)
|
88
|
-
def loading_indicator_tag(options)
|
89
|
-
image_tag "indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator"
|
90
|
-
end
|
91
|
-
|
92
|
-
# Creates a javascript-based link that toggles the visibility of some element on the page.
|
93
|
-
# By default, it toggles the visibility of the sibling after the one it's nested in. You may pass custom javascript logic in options[:of] to change that, though. For example, you could say :of => '$("my_div_id")'.
|
94
|
-
# You may also flag whether the other element is visible by default or not, and the initial text will adjust accordingly.
|
95
|
-
def link_to_visibility_toggle(id, options = {})
|
96
|
-
options[:default_visible] = true if options[:default_visible].nil?
|
97
|
-
options[:hide_label] = as_(:hide)
|
98
|
-
options[:show_label] = as_(:show)
|
99
|
-
javascript_tag("ActiveScaffold.create_visibility_toggle('#{id}', #{options.to_json});")
|
100
|
-
end
|
101
|
-
|
102
|
-
def skip_action_link(link, *args)
|
103
|
-
(!link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args))
|
104
|
-
end
|
105
|
-
|
106
|
-
def render_action_link(link, url_options, record = nil, html_options = {})
|
107
|
-
url_options = action_link_url_options(link, url_options, record)
|
108
|
-
html_options = action_link_html_options(link, url_options, record, html_options)
|
109
|
-
action_link_html(link, url_options, html_options, record)
|
110
|
-
end
|
111
|
-
|
112
|
-
def render_group_action_link(link, url_options, options, record = nil)
|
113
|
-
if link.type == :member && !options[:authorized]
|
114
|
-
action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}, record)
|
115
|
-
else
|
116
|
-
render_action_link(link, url_options, record)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def action_link_url_options(link, url_options, record, options = {})
|
121
|
-
url_options = url_options.clone
|
122
|
-
url_options[:action] = link.action
|
123
|
-
url_options[:controller] = link.controller.to_s if link.controller
|
124
|
-
url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller]
|
125
|
-
url_options.merge! link.parameters if link.parameters
|
126
|
-
@link_record = record
|
127
|
-
url_options.merge! self.instance_eval(&(link.dynamic_parameters)) if link.dynamic_parameters.is_a?(Proc)
|
128
|
-
@link_record = nil
|
129
|
-
url_options_for_nested_link(link.column, record, link, url_options, options) if link.nested_link?
|
130
|
-
url_options_for_sti_link(link.column, record, link, url_options, options) unless record.nil? || active_scaffold_config.sti_children.nil?
|
131
|
-
url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get
|
132
|
-
url_options
|
133
|
-
end
|
134
|
-
|
135
|
-
def action_link_html_options(link, url_options, record, html_options)
|
136
|
-
link_id = get_action_link_id(url_options, record, link.column)
|
137
|
-
html_options.reverse_merge! link.html_options.merge(:class => link.action.to_s)
|
138
|
-
|
139
|
-
# Needs to be in html_options to as the adding _method to the url is no longer supported by Rails
|
140
|
-
html_options[:method] = link.method if link.method != :get
|
141
|
-
|
142
|
-
html_options[:class] += ' as_action' if link.inline?
|
143
|
-
html_options[:data] = {}
|
144
|
-
html_options[:data][:confirm] = link.confirm(record.try(:to_label)) if link.confirm?
|
145
|
-
html_options[:data][:position] = link.position if link.position and link.inline?
|
146
|
-
html_options[:data][:action] = link.action if link.inline?
|
147
|
-
if link.popup?
|
148
|
-
html_options[:data][:popup] = true
|
149
|
-
html_options[:target] = '_blank'
|
150
|
-
end
|
151
|
-
html_options[:id] = link_id
|
152
|
-
html_options[:remote] = true unless link.page? || link.popup?
|
153
|
-
if link.dhtml_confirm?
|
154
|
-
html_options[:class] += ' as_action' if !link.inline?
|
155
|
-
html_options[:page_link] = 'true' if !link.inline?
|
156
|
-
html_options[:dhtml_confirm] = link.dhtml_confirm.value
|
157
|
-
html_options[:onclick] = link.dhtml_confirm.onclick_function(controller, link_id)
|
158
|
-
end
|
159
|
-
html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank?
|
160
|
-
html_options
|
161
|
-
end
|
162
|
-
|
163
|
-
def get_action_link_id(url_options, record = nil, column = nil)
|
164
|
-
id = url_options[:id] || url_options[:parent_id]
|
165
|
-
id = "#{column.association.name}-#{record.id}" if column && column.plural_association?
|
166
|
-
if record.try(column.association.name.to_sym).present?
|
167
|
-
id = "#{column.association.name}-#{record.send(column.association.name).id}-#{record.id}"
|
168
|
-
else
|
169
|
-
id = "#{column.association.name}-#{record.id}" unless record.nil?
|
170
|
-
end if column && column.singular_association?
|
171
|
-
id = "#{id}-#{url_options[:batch_scope].downcase}" if url_options[:batch_scope]
|
172
|
-
action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}"
|
173
|
-
action_link_id(action_id, id)
|
174
|
-
end
|
175
|
-
|
176
|
-
def action_link_html(link, url, html_options, record)
|
177
|
-
# issue 260, use url_options[:link] if it exists. This prevents DB data from being localized.
|
178
|
-
label = url.delete(:link) if url.is_a?(Hash)
|
179
|
-
label ||= link.label
|
180
|
-
if link.image.nil?
|
181
|
-
html = link_to(label, url, html_options)
|
182
|
-
else
|
183
|
-
html = link_to(image_tag(link.image[:name] , :size => link.image[:size], :alt => label), url, html_options)
|
184
|
-
end
|
185
|
-
# if url is nil we would like to generate an anchor without href attribute
|
186
|
-
url.nil? ? html.sub(/href=".*?"/, '').html_safe : html.html_safe
|
187
|
-
end
|
188
|
-
|
189
|
-
def url_options_for_nested_link(column, record, link, url_options, options = {})
|
190
|
-
if column && column.association
|
191
|
-
url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id)
|
192
|
-
url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present?
|
193
|
-
elsif link.parameters && link.parameters[:named_scope]
|
194
|
-
index = url_options[:parent_scaffold] ? url_options[:parent_scaffold].camelize.singularize.foreign_key.to_sym : :assoc_id
|
195
|
-
url_options[index] = url_options.delete(:id)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
def url_options_for_sti_link(column, record, link, url_options, options = {})
|
200
|
-
#need to find out controller of current record type
|
201
|
-
#and set parameters
|
202
|
-
# its quite difficult to detect an sti link
|
203
|
-
# if link.column.nil? we are sure that it is nt an singular association inline autolink
|
204
|
-
# howver that will not work if a sti parent is an singular association inline autolink
|
205
|
-
if link.column.nil?
|
206
|
-
sti_controller_path = controller_path_for_activerecord(record.class)
|
207
|
-
if sti_controller_path
|
208
|
-
url_options[:controller] = sti_controller_path
|
209
|
-
url_options[:parent_sti] = controller_path
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def column_class(column, column_value, record)
|
215
|
-
classes = []
|
216
|
-
classes << "#{column.name}-column"
|
217
|
-
if column.css_class.is_a?(Proc)
|
218
|
-
css_class = column.css_class.call(column_value, record)
|
219
|
-
classes << css_class unless css_class.nil?
|
220
|
-
else
|
221
|
-
classes << column.css_class
|
222
|
-
end unless column.css_class.nil?
|
223
|
-
|
224
|
-
classes << 'empty' if column_empty? column_value
|
225
|
-
classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column)
|
226
|
-
classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type)
|
227
|
-
classes.join(' ').rstrip
|
228
|
-
end
|
229
|
-
|
230
|
-
def column_heading_class(column, sorting)
|
231
|
-
classes = []
|
232
|
-
classes << "#{column.name}-column_heading"
|
233
|
-
classes << "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column
|
234
|
-
classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc)
|
235
|
-
classes.join(' ')
|
236
|
-
end
|
237
|
-
|
238
|
-
def as_main_div_class
|
239
|
-
classes = ["active-scaffold", "active-scaffold-#{controller_id}", "#{id_from_controller params[:controller]}-view", "#{active_scaffold_config.theme}-theme"]
|
240
|
-
classes << "as_touch" if touch_device?
|
241
|
-
classes.join(' ')
|
242
|
-
end
|
243
|
-
|
244
|
-
def column_empty?(column_value)
|
245
|
-
empty = column_value.nil?
|
246
|
-
empty ||= column_value.blank? if column_value.respond_to? :blank?
|
247
|
-
empty ||= [' ', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value
|
248
|
-
return empty
|
249
|
-
end
|
250
|
-
|
251
|
-
def column_calculation(column)
|
252
|
-
unless column.calculate.instance_of? Proc
|
253
|
-
conditions = controller.send(:all_conditions)
|
254
|
-
includes = active_scaffold_config.list.count_includes
|
255
|
-
includes ||= controller.send(:active_scaffold_includes) unless conditions.nil?
|
256
|
-
calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions,
|
257
|
-
:joins => controller.send(:joins_for_collection), :include => includes)
|
258
|
-
else
|
259
|
-
column.calculate.call(@records)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
def render_column_calculation(column)
|
264
|
-
calculation = column_calculation(column)
|
265
|
-
override_formatter = "render_#{column.name}_#{column.calculate.is_a?(Proc) ? :calculate : column.calculate}"
|
266
|
-
calculation = send(override_formatter, calculation) if respond_to? override_formatter
|
267
|
-
|
268
|
-
"#{"#{as_(column.calculate)}: " unless column.calculate.is_a? Proc}#{format_column_value nil, column, calculation}"
|
269
|
-
end
|
270
|
-
|
271
|
-
def column_show_add_existing(column)
|
272
|
-
(column.allow_add_existing and options_for_association_count(column.association) > 0)
|
273
|
-
end
|
274
|
-
|
275
|
-
def column_show_add_new(column, associated, record)
|
276
|
-
value = (column.plural_association? && !column.readonly_association?) || (column.singular_association? and not associated.empty?)
|
277
|
-
value = false unless column.association.klass.authorized_for?(:crud_type => :create)
|
278
|
-
value
|
279
|
-
end
|
280
|
-
|
281
|
-
def clean_column_name(name)
|
282
|
-
name.to_s.gsub('?', '')
|
283
|
-
end
|
284
|
-
|
285
|
-
def clean_class_name(name)
|
286
|
-
name.underscore.gsub('/', '_')
|
287
|
-
end
|
288
|
-
|
289
|
-
def active_scaffold_error_messages_for(*params)
|
290
|
-
options = params.extract_options!.symbolize_keys
|
291
|
-
options.reverse_merge!(:container_tag => :div, :list_type => :ul)
|
292
|
-
|
293
|
-
objects = Array.wrap(options.delete(:object) || params).map do |object|
|
294
|
-
object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model)
|
295
|
-
object = convert_to_model(object)
|
296
|
-
|
297
|
-
if object.class.respond_to?(:model_name)
|
298
|
-
options[:object_name] ||= object.class.model_name.human.downcase
|
299
|
-
end
|
300
|
-
|
301
|
-
object
|
302
|
-
end
|
303
|
-
|
304
|
-
objects.compact!
|
305
|
-
count = objects.inject(0) {|sum, object| sum + object.errors.count }
|
306
|
-
|
307
|
-
unless count.zero?
|
308
|
-
html = {}
|
309
|
-
[:id, :class].each do |key|
|
310
|
-
if options.include?(key)
|
311
|
-
value = options[key]
|
312
|
-
html[key] = value unless value.blank?
|
313
|
-
else
|
314
|
-
html[key] = 'errorExplanation'
|
315
|
-
end
|
316
|
-
end
|
317
|
-
options[:object_name] ||= params.first
|
318
|
-
|
319
|
-
header_message = if options.include?(:header_message)
|
320
|
-
options[:header_message]
|
321
|
-
else
|
322
|
-
as_('errors.template.header', :count => count, :model => options[:object_name].to_s.gsub('_', ' '))
|
323
|
-
end
|
324
|
-
|
325
|
-
message = options.include?(:message) ? options[:message] : as_('errors.template.body')
|
326
|
-
|
327
|
-
error_messages = objects.sum do |object|
|
328
|
-
object.errors.full_messages.map do |msg|
|
329
|
-
options[:list_type] != :br ? content_tag(:li, msg) : msg
|
330
|
-
end
|
331
|
-
end
|
332
|
-
error_messages = if options[:list_type] == :br
|
333
|
-
error_messages.join('<br/>').html_safe
|
334
|
-
else
|
335
|
-
content_tag(options[:list_type], error_messages.join.html_safe)
|
336
|
-
end
|
337
|
-
|
338
|
-
contents = []
|
339
|
-
contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
|
340
|
-
contents << content_tag(:p, message) unless message.blank?
|
341
|
-
contents << error_messages
|
342
|
-
contents = contents.join.html_safe
|
343
|
-
options[:container_tag] ? content_tag(options[:container_tag], contents, html) : contents
|
344
|
-
else
|
345
|
-
''
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
350
|
-
end
|