active_scaffold 3.4.36 → 3.4.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83c0925aecdf8e8cb67457796ee92dda1238e643
4
- data.tar.gz: ca9244cc82582adb62affbd49e316d5b4a5bafd4
3
+ metadata.gz: a4cba196e4425cbbb6fbf33eb6e53865030e87cf
4
+ data.tar.gz: ebf4fdae5434832d4c412c9d67f58a9d13aca510
5
5
  SHA512:
6
- metadata.gz: 5bf876c309a71dd8a954782e51ce23ff8a20dc937f5562a110cd9814909f9bdd16c0da239cd40c2b79045895235194638d7b0383d68853e031e537b713892ef8
7
- data.tar.gz: d7aef2c46b06c3a13a980ae5faf7f1df628802921643a9a92784f4b55066406f7b7da2a99e25c40c5307a0c7ad324d37dc8cd408d7166bf3d037eb7b4ee3e3a1
6
+ metadata.gz: dfc1186e00611b378bd728334cb52c9279df90bd02572abb27b31a3b39957181cd9aaae180397c186fa75850cbc8b44357b8f69797371ffc026ca833991a5776
7
+ data.tar.gz: 9a1ab9e777c2703f022c36e6d031a16a7af211af985cd37aad4e22286814603782eccb881e61b96c022ff80f870c1e2b82844c6e6569cf973f6cc81a0da17ab2
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ = 3.4.37
2
+ - return valid css class for subgroups, e.g. when name with dot is used for translation scopes
3
+ - check permissions for add existing and delete existing, use nested parent record authorized for update nested association column
4
+ - TinyMCE bridge integrate better with the tinymce-rails (thanks to @subfusc)
5
+ - Remove own country_select helpers and convert into bridge for country_select gem (now it will save country code instead of country name, migrate data or restore old behaviour setting columns[:col].options[:format] = :old)
6
+
1
7
  = 3.4.36
2
8
  - Fix tableless for rails >= 4.1 for associations with table
3
9
  - use number_with_precision for non-integer numbers with i18n_number format, so strip_insignificant_zeros and precision can be used
data/README.md CHANGED
@@ -6,6 +6,7 @@ Overview
6
6
  [![Dependency Status](https://gemnasium.com/activescaffold/active_scaffold.svg)](https://gemnasium.com/activescaffold/active_scaffold)
7
7
  [![Gem Version](https://badge.fury.io/rb/active_scaffold.svg)](https://badge.fury.io/rb/active_scaffold)
8
8
  [![Inline docs](https://inch-ci.org/github/activescaffold/active_scaffold.svg?branch=master)](https://inch-ci.org/github/activescaffold/active_scaffold)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
10
 
10
11
  ActiveScaffold provides a quick and powerful user interfaces for CRUD (create, read, update, delete) operations for Rails applications. It offers additonal features including searching, pagination & layout control. Rails 3.2 and 4.x are supported, ruby >= 1.9 required. For rails 4 is recommended >= 4.0.5.
11
12
 
@@ -52,11 +52,11 @@ module ActiveScaffold::Actions
52
52
  # The default security delegates to ActiveRecordPermissions.
53
53
  # You may override the method to customize.
54
54
  def delete_authorized?(record = nil)
55
- (!nested? || !nested.readonly?) && (record || self).send(:authorized_for?, :crud_type => :delete)
55
+ (!nested? || !nested.readonly?) && (record || self).authorized_for?(:crud_type => :delete)
56
56
  end
57
57
 
58
58
  def delete_ignore?(record = nil)
59
- (nested? && nested.readonly?) || !send(:authorized_for?, :crud_type => :delete)
59
+ (nested? && nested.readonly?) || !self.authorized_for?(:crud_type => :delete)
60
60
  end
61
61
 
62
62
  private
@@ -207,11 +207,11 @@ module ActiveScaffold::Actions::Nested
207
207
  end
208
208
 
209
209
  def add_existing_authorized?(record = nil)
210
- true
210
+ nested_parent_record.authorized_for?(:crud_type => :update, :column => nested.association.try(:name))
211
211
  end
212
212
 
213
213
  def delete_existing_authorized?(record = nil)
214
- true
214
+ nested_parent_record.authorized_for?(:crud_type => :update, :column => nested.association.try(:name))
215
215
  end
216
216
 
217
217
  def after_create_save(record)
@@ -0,0 +1,38 @@
1
+ module ActiveScaffold::Bridges
2
+ class CountrySelect
3
+ module FormColumnHelpers
4
+ def active_scaffold_input_country(column, options)
5
+ select_options = {:prompt => as_(:_select_), :priority_countries => column.options[:priority] || [:us], :format => column.options[:format]}
6
+ select_options.merge!(options)
7
+ options.reverse_merge!(column.options).except!(:prompt, :priority, :format)
8
+ options[:name] += '[]' if options[:multiple]
9
+ country_select(:record, column.name, select_options, options.except(:object))
10
+ end
11
+ end
12
+
13
+ module ListColumnHelpers
14
+ def active_scaffold_column_country(record, column)
15
+ country_code = record.send(column.name)
16
+ return if country_code.blank?
17
+ country = ISO3166::Country[country_code]
18
+ return country_code unless country
19
+ country.translations[I18n.locale.to_s] || country.name
20
+ end
21
+ end
22
+
23
+ module SearchColumnHelpers
24
+ def active_scaffold_search_country(column, options)
25
+ active_scaffold_input_country(column, options.merge!(:selected => options.delete(:value)))
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ # To use old way, saving country name instead of CountrySelect default of country code
32
+ CountrySelect::FORMATS[:old] = lambda { |country| [country.translations[I18n.locale.to_s] || country.name, country.name] }
33
+
34
+ ActionView::Base.class_eval do
35
+ include ActiveScaffold::Bridges::CountrySelect::FormColumnHelpers
36
+ include ActiveScaffold::Bridges::CountrySelect::ListColumnHelpers
37
+ include ActiveScaffold::Bridges::CountrySelect::SearchColumnHelpers
38
+ end
@@ -0,0 +1,5 @@
1
+ class ActiveScaffold::Bridges::CountrySelect < ActiveScaffold::DataStructures::Bridge
2
+ def self.install
3
+ require File.join(File.dirname(__FILE__), 'country_select/country_select_bridge_helper.rb')
4
+ end
5
+ end
@@ -12,10 +12,18 @@ class ActiveScaffold::Bridges::TinyMce
12
12
  base.alias_method_chain :onsubmit, :tiny_mce
13
13
  end
14
14
 
15
+ # The two column options that can be set specifically for the text_editor input
16
+ # is :tinymce, which overrides single values in the tinymce config.
17
+ # E.g. column[:foo].options[:tinymce] = {theme: 'other'} will change the theme
18
+ # but not the plugins, toolbars etc.
19
+ # The other one is :tinymce_config, which selects the config to use from tinymce.yml.
20
+ # See the tinymce-rails gem documentation for usage.
15
21
  def active_scaffold_input_text_editor(column, options)
16
22
  options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip
17
23
 
18
- settings = {:theme => 'modern'}.merge(column.options[:tinymce] || {})
24
+ settings = tinymce_configuration(column.options[:tinymce_config] || :default).options.
25
+ reject{|k,v| k =='selector'}.
26
+ merge(column.options[:tinymce] || {})
19
27
  settings = settings.to_json
20
28
  settings = "tinyMCE.settings = #{settings};"
21
29
 
@@ -34,6 +42,10 @@ class ActiveScaffold::Bridges::TinyMce
34
42
  end
35
43
  [onsubmit_without_tiny_mce, submit_js].compact.join ';'
36
44
  end
45
+
46
+ # The implementation is very tinymce specific, so it makes sense allowing :form_ui
47
+ # to be :tinymce as well
48
+ alias_method :active_scaffold_input_tinymce, :active_scaffold_input_text_editor
37
49
  end
38
50
 
39
51
  module SearchColumnHelpers
@@ -0,0 +1,84 @@
1
+ module ActiveScaffold::Bridges
2
+ class UsaStateSelect
3
+ module UsaStateSelectHelpers
4
+ def usa_state_select_options(options)
5
+ # TODO remove when rails 3.2 support is dropped
6
+ defined?(ActionView::Helpers::InstanceTag) ? options[:object] : options
7
+ end
8
+
9
+ def usa_state_select(object, method, priority_states = nil, options = {}, html_options = {})
10
+ ActionView::Helpers::Tags::UsaStateSelect.new(object, method, self, usa_state_select_options(options)).to_usa_state_select_tag(priority_states, options, html_options)
11
+ end
12
+ end
13
+
14
+ module UsaStateSelectOptionsHelpers
15
+ # Returns a string of option tags for the states in the United States. Supply a state name as +selected to
16
+ # have it marked as the selected option tag. Included also is the option to set a couple of +priority_states+
17
+ # in case you want to highligh a local area
18
+ # NOTE: Only the option tags are returned from this method, wrap it in a <select>
19
+ def usa_state_options_for_select(selected = nil, priority_states = nil)
20
+ if priority_states
21
+ state_options = options_for_select(priority_states + [['-------------', '']], :selected => selected, :disabled => '')
22
+ else
23
+ state_options = options_for_select([])
24
+ end
25
+
26
+ if priority_states && priority_states.include?(selected)
27
+ state_options += options_for_select(USASTATES - priority_states, :selected => selected)
28
+ else
29
+ state_options += options_for_select(USASTATES, :selected => selected)
30
+ end
31
+
32
+ state_options
33
+ end
34
+
35
+ USASTATES = [%w(Alabama AL), %w(Alaska AK), %w(Arizona AZ), %w(Arkansas AR), %w(California CA), %w(Colorado CO), %w(Connecticut CT), %w(Delaware DE), ['District of Columbia', 'DC'], %w(Florida FL), %w(Georgia GA), %w(Hawaii HI), %w(Idaho ID), %w(Illinois IL), %w(Indiana IN), %w(Iowa IA), %w(Kansas KS), %w(Kentucky KY), %w(Louisiana LA), %w(Maine ME), %w(Maryland MD), %w(Massachusetts MA), %w(Michigan MI), %w(Minnesota MN), %w(Mississippi MS), %w(Missouri MO), %w(Montana MT), %w(Nebraska NE), %w(Nevada NV), ['New Hampshire', 'NH'], ['New Jersey', 'NJ'], ['New Mexico', 'NM'], ['New York', 'NY'], ['North Carolina', 'NC'], ['North Dakota', 'ND'], %w(Ohio OH), %w(Oklahoma OK), %w(Oregon OR), %w(Pennsylvania PA), ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], %w(Tennessee TN), %w(Texas TX), %w(Utah UT), %w(Vermont VT), %w(Virginia VA), %w(Washington WA), %w(Wisconsin WI), ['West Virginia', 'WV'], %w(Wyoming WY)] unless const_defined?('USASTATES')
36
+ end
37
+
38
+ module InstanceTagMethods
39
+ def to_usa_state_select_tag(priority_states, options, html_options)
40
+ html_options = html_options.stringify_keys
41
+ add_default_name_and_id(html_options)
42
+ value = value(object)
43
+ selected_value = options.key?(:selected) ? options[:selected] : value
44
+ content_tag('select', add_options(usa_state_options_for_select(selected_value, priority_states), options, selected_value), html_options)
45
+ end
46
+ end
47
+
48
+ module FormColumnHelpers
49
+ def active_scaffold_input_usa_state(column, options)
50
+ select_options = {:prompt => as_(:_select_)}
51
+ select_options.merge!(options)
52
+ options.reverse_merge!(column.options).except!(:prompt, :priority)
53
+ options[:name] += '[]' if options[:multiple]
54
+ usa_state_select(:record, column.name, column.options[:priority], select_options, options.except(:object))
55
+ end
56
+ end
57
+
58
+ module SearchColumnHelpers
59
+ def active_scaffold_search_usa_state(column, options)
60
+ active_scaffold_input_usa_state(column, options.merge!(:selected => options.delete(:value)))
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ ActionView::Base.class_eval do
67
+ include ActiveScaffold::Bridges::UsaStateSelect::UsaStateSelectHelpers
68
+ include ActiveScaffold::Bridges::UsaStateSelect::UsaStateSelectOptionsHelpers
69
+ include ActiveScaffold::Bridges::UsaStateSelect::FormColumnHelpers
70
+ include ActiveScaffold::Bridges::UsaStateSelect::SearchColumnHelpers
71
+ end
72
+ if defined? ActionView::Helpers::InstanceTag # TODO remove when rails 3.2 support is dropped
73
+ module ActionView::Helpers::Tags
74
+ class UsaStateSelect < ActionView::Helpers::InstanceTag
75
+ include ActiveScaffold::Bridges::UsaStateSelect::UsaStateSelectOptionsHelpers
76
+ include ActiveScaffold::Bridges::UsaStateSelect::InstanceTagMethods
77
+ end
78
+ end
79
+ else
80
+ class ActionView::Helpers::Tags::UsaStateSelect < ActionView::Helpers::Tags::Base #:nodoc:
81
+ include ActiveScaffold::Bridges::UsaStateSelect::UsaStateSelectOptionsHelpers
82
+ include ActiveScaffold::Bridges::UsaStateSelect::InstanceTagMethods
83
+ end
84
+ end
@@ -0,0 +1,9 @@
1
+ class ActiveScaffold::Bridges::UsaStateSelect < ActiveScaffold::DataStructures::Bridge
2
+ def self.install
3
+ require File.join(File.dirname(__FILE__), 'usa_state_select/usa_state_select_helper.rb')
4
+ end
5
+
6
+ def self.install?
7
+ true
8
+ end
9
+ end
@@ -18,7 +18,7 @@ module ActiveScaffold::DataStructures
18
18
  end
19
19
 
20
20
  def css_class
21
- @label.to_s.underscore
21
+ @label.to_s.underscore.gsub /[^-_0-9a-zA-Z]/, '-'
22
22
  end
23
23
 
24
24
  # this is so that array.delete and array.include?, etc., will work by column name
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 4
5
- PATCH = 36
5
+ PATCH = 37
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -4,6 +4,27 @@ class TinyMceTest < ActionView::TestCase
4
4
  include ActiveScaffold::Helpers::ViewHelpers
5
5
  include ActiveScaffold::Bridges::TinyMce::Helpers
6
6
 
7
+ # Mimic the behaviour of the tinymce-rails plugin function[1] to get
8
+ # configuration options from tinymce.yml
9
+ #
10
+ # [1]: https://github.com/spohlenz/tinymce-rails/blob/master/lib/tinymce/rails/helper.rb#L37
11
+ def tinymce_configuration(config=:default)
12
+ return case config
13
+ when :default
14
+ Class.new do
15
+ def options
16
+ {theme: 'modern'}
17
+ end
18
+ end.new
19
+ when :alternate
20
+ Class.new do
21
+ def options
22
+ {theme: 'alternate', toolbar: 'undo redo | format'}
23
+ end
24
+ end.new
25
+ end
26
+ end
27
+
7
28
  def test_includes
8
29
  ActiveScaffold::Bridges::TinyMce.expects(:install?).returns(true)
9
30
  ActiveScaffold.js_framework = :jquery
@@ -18,6 +39,15 @@ class TinyMceTest < ActionView::TestCase
18
39
  assert_dom_equal %{<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\">\n</textarea>\n<script#{' type="text/javascript"' if Rails::VERSION::MAJOR < 4}>\n//<![CDATA[\ntinyMCE.settings = {\"theme\":\"modern\"};tinyMCE.execCommand('mceAddEditor', false, 'record_name');\n//]]>\n</script>}, active_scaffold_input_text_editor(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input', :object => record)
19
40
  end
20
41
 
42
+ def test_form_ui_alternate
43
+ config = ActiveScaffold::Config::Core.new(:company)
44
+ record = Company.new
45
+ expects(:request).returns(stub(:xhr? => true))
46
+ config.columns[:name].options[:tinymce_config] = :alternate
47
+
48
+ assert_dom_equal %{<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\">\n</textarea>\n<script#{' type="text/javascript"' if Rails::VERSION::MAJOR < 4}>\n//<![CDATA[\ntinyMCE.settings = {\"theme\":\"alternate\",\"toolbar\":\"undo redo | format\"};tinyMCE.execCommand('mceAddEditor', false, 'record_name');\n//]]>\n</script>}, active_scaffold_input_tinymce(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input', :object => record)
49
+ end
50
+
21
51
  protected
22
52
 
23
53
  def include_tiny_mce_if_needed; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.36
4
+ version: 3.4.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -233,8 +233,8 @@ files:
233
233
  - lib/active_scaffold/bridges/carrierwave/list_ui.rb
234
234
  - lib/active_scaffold/bridges/chosen.rb
235
235
  - lib/active_scaffold/bridges/chosen/helpers.rb
236
- - lib/active_scaffold/bridges/country_helper.rb
237
- - lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb
236
+ - lib/active_scaffold/bridges/country_select.rb
237
+ - lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
238
238
  - lib/active_scaffold/bridges/date_picker.rb
239
239
  - lib/active_scaffold/bridges/date_picker/ext.rb
240
240
  - lib/active_scaffold/bridges/date_picker/helper.rb
@@ -268,6 +268,8 @@ files:
268
268
  - lib/active_scaffold/bridges/shared/date_bridge.rb
269
269
  - lib/active_scaffold/bridges/tiny_mce.rb
270
270
  - lib/active_scaffold/bridges/tiny_mce/helpers.rb
271
+ - lib/active_scaffold/bridges/usa_state_select.rb
272
+ - lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb
271
273
  - lib/active_scaffold/config/base.rb
272
274
  - lib/active_scaffold/config/core.rb
273
275
  - lib/active_scaffold/config/create.rb
@@ -1,380 +0,0 @@
1
- module ActiveScaffold::Bridges
2
- class CountryHelper
3
- module CountryHelpers
4
- def country_select_class
5
- # TODO remove when rails 3.2 support is dropped
6
- defined?(ActionView::Helpers::InstanceTag) ? ActionView::Helpers::InstanceTag : ActionView::Helpers::Tags::CountrySelect
7
- end
8
-
9
- def country_select_options(options)
10
- # TODO remove when rails 3.2 support is dropped
11
- defined?(ActionView::Helpers::InstanceTag) ? options[:object] : options
12
- end
13
-
14
- # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
15
- def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
16
- country_select_class.new(object, method, self, country_select_options(options)).to_country_select_tag(priority_countries, options, html_options)
17
- end
18
-
19
- def usa_state_select(object, method, priority_states = nil, options = {}, html_options = {})
20
- country_select_class.new(object, method, self, country_select_options(options)).to_usa_state_select_tag(priority_states, options, html_options)
21
- end
22
- end
23
-
24
- module CountryOptionsHelpers
25
- # Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to
26
- # have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so
27
- # that they will be listed above the rest of the (long) list.
28
- #
29
- # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
30
- def country_options_for_select(selected = nil, priority_countries = nil)
31
- if priority_countries
32
- country_options = options_for_select(priority_countries.collect { |country| [I18n.t("countries.#{country}", :default => country.to_s.titleize), country.to_s] } + [['-------------', '']], :selected => selected, :disabled => '')
33
- else
34
- country_options = options_for_select([])
35
- end
36
-
37
- country_options + options_for_select(COUNTRIES.collect { |country| [I18n.t("countries.#{country}", :default => country.to_s.titleize), country.to_s] }, :selected => selected)
38
- end
39
-
40
- # Returns a string of option tags for the states in the United States. Supply a state name as +selected to
41
- # have it marked as the selected option tag. Included also is the option to set a couple of +priority_states+
42
- # in case you want to highligh a local area
43
- # NOTE: Only the option tags are returned from this method, wrap it in a <select>
44
- def usa_state_options_for_select(selected = nil, priority_states = nil)
45
- if priority_states
46
- state_options = options_for_select(priority_states + [['-------------', '']], :selected => selected, :disabled => '')
47
- else
48
- state_options = options_for_select([])
49
- end
50
-
51
- if priority_states && priority_states.include?(selected)
52
- state_options += options_for_select(USASTATES - priority_states, :selected => selected)
53
- else
54
- state_options += options_for_select(USASTATES, :selected => selected)
55
- end
56
-
57
- state_options
58
- end
59
- # All the countries included in the country_options output.
60
- COUNTRIES = [
61
- :afghanistan,
62
- :aland_islands,
63
- :albania,
64
- :algeria,
65
- :american_samoa,
66
- :andorra,
67
- :angola,
68
- :anguilla,
69
- :antarctica,
70
- :antigua_and_barbuda,
71
- :argentina,
72
- :armenia,
73
- :aruba,
74
- :australia,
75
- :austria,
76
- :azerbaijan,
77
- :bahamas,
78
- :bahrain,
79
- :bangladesh,
80
- :barbados,
81
- :belarus,
82
- :belgium,
83
- :belize,
84
- :benin,
85
- :bermuda,
86
- :bhutan,
87
- :bolivia,
88
- :bosnia_and_herzegowina,
89
- :botswana,
90
- :bouvet_island,
91
- :brazil,
92
- :british_indian_ocean_territory,
93
- :brunei_darussalam,
94
- :bulgaria,
95
- :burkina_faso,
96
- :burundi,
97
- :cambodia,
98
- :cameroon,
99
- :canada,
100
- :cape_verde,
101
- :cayman_islands,
102
- :central_african_republic,
103
- :chad,
104
- :chile,
105
- :china,
106
- :christmas_island,
107
- :cocos_keeling_islands,
108
- :colombia,
109
- :comoros,
110
- :congo,
111
- :congo_the_democratic_republic_of_the,
112
- :cook_islands,
113
- :costa_rica,
114
- :cote_divoire,
115
- :croatia,
116
- :cuba,
117
- :cyprus,
118
- :czech_republic,
119
- :denmark,
120
- :djibouti,
121
- :dominica,
122
- :dominican_republic,
123
- :ecuador,
124
- :egypt,
125
- :el_salvador,
126
- :equatorial_guinea,
127
- :eritrea,
128
- :estonia,
129
- :ethiopia,
130
- :falkland_islands_malvinas,
131
- :faroe_islands,
132
- :fiji,
133
- :finland,
134
- :france,
135
- :french_guiana,
136
- :french_polynesia,
137
- :french_southern_territories,
138
- :gabon,
139
- :gambia,
140
- :georgia,
141
- :germany,
142
- :ghana,
143
- :gibraltar,
144
- :greece,
145
- :greenland,
146
- :grenada,
147
- :guadeloupe,
148
- :guam,
149
- :guatemala,
150
- :guernsey,
151
- :guinea,
152
- :guinea_bissau,
153
- :guyana,
154
- :haiti,
155
- :heard_and_mcdonald_islands,
156
- :holy_see_vatican_city_state,
157
- :honduras,
158
- :hong_kong,
159
- :hungary,
160
- :iceland,
161
- :india,
162
- :indonesia,
163
- :iran_islamic_republic_of,
164
- :iraq,
165
- :ireland,
166
- :isle_of_man,
167
- :israel,
168
- :italy,
169
- :jamaica,
170
- :japan,
171
- :jersey,
172
- :jordan,
173
- :kazakhstan,
174
- :kenya,
175
- :kiribati,
176
- :korea_democratic_peoples_republic_of,
177
- :korea_republic_of,
178
- :kuwait,
179
- :kyrgyzstan,
180
- :lao_peoples_democratic_republic,
181
- :latvia,
182
- :lebanon,
183
- :lesotho,
184
- :liberia,
185
- :libyan_arab_jamahiriya,
186
- :liechtenstein,
187
- :lithuania,
188
- :luxembourg,
189
- :macao,
190
- :macedonia_the_former_yugoslav_republic_of,
191
- :madagascar,
192
- :malawi,
193
- :malaysia,
194
- :maldives,
195
- :mali,
196
- :malta,
197
- :marshall_islands,
198
- :martinique,
199
- :mauritania,
200
- :mauritius,
201
- :mayotte,
202
- :mexico,
203
- :micronesia_federated_states_of,
204
- :moldova_republic_of,
205
- :monaco,
206
- :mongolia,
207
- :montenegro,
208
- :montserrat,
209
- :morocco,
210
- :mozambique,
211
- :myanmar,
212
- :namibia,
213
- :nauru,
214
- :nepal,
215
- :netherlands,
216
- :netherlands_antilles,
217
- :new_caledonia,
218
- :new_zealand,
219
- :nicaragua,
220
- :niger,
221
- :nigeria,
222
- :niue,
223
- :norfolk_island,
224
- :northern_mariana_islands,
225
- :norway,
226
- :oman,
227
- :pakistan,
228
- :palau,
229
- :palestinian_territory_occupied,
230
- :panama,
231
- :papua_new_guinea,
232
- :paraguay,
233
- :peru,
234
- :philippines,
235
- :pitcairn,
236
- :poland,
237
- :portugal,
238
- :puerto_rico,
239
- :qatar,
240
- :reunion,
241
- :romania,
242
- :russian_federation,
243
- :rwanda,
244
- :saint_barthelemy,
245
- :saint_helena,
246
- :saint_kitts_and_nevis,
247
- :saint_lucia,
248
- :saint_pierre_and_miquelon,
249
- :saint_vincent_and_the_grenadines,
250
- :samoa,
251
- :san_marino,
252
- :sao_tome_and_principe,
253
- :saudi_arabia,
254
- :senegal,
255
- :serbia,
256
- :seychelles,
257
- :sierra_leone,
258
- :singapore,
259
- :slovakia,
260
- :slovenia,
261
- :solomon_islands,
262
- :somalia,
263
- :south_africa,
264
- :south_georgia_and_the_south_sandwich_islands,
265
- :spain,
266
- :sri_lanka,
267
- :sudan,
268
- :suriname,
269
- :svalbard_and_jan_mayen,
270
- :swaziland,
271
- :sweden,
272
- :switzerland,
273
- :syrian_arab_republic,
274
- :taiwan_province_of_china,
275
- :tajikistan,
276
- :tanzania_united_republic_of,
277
- :thailand,
278
- :timor_leste,
279
- :togo,
280
- :tokelau,
281
- :tonga,
282
- :trinidad_and_tobago,
283
- :tunisia,
284
- :turkey,
285
- :turkmenistan,
286
- :turks_and_caicos_islands,
287
- :tuvalu,
288
- :uganda,
289
- :ukraine,
290
- :united_arab_emirates,
291
- :united_kingdom,
292
- :united_states,
293
- :united_states_minor_outlying_islands,
294
- :uruguay,
295
- :uzbekistan,
296
- :vanuatu,
297
- :venezuela,
298
- :viet_nam,
299
- :virgin_islands_british,
300
- :virgin_islands_us,
301
- :wallis_and_futuna,
302
- :western_sahara,
303
- :yemen,
304
- :zambia,
305
- :zimbabwe] unless const_defined?('COUNTRIES')
306
-
307
- USASTATES = [%w(Alabama AL), %w(Alaska AK), %w(Arizona AZ), %w(Arkansas AR), %w(California CA), %w(Colorado CO), %w(Connecticut CT), %w(Delaware DE), ['District of Columbia', 'DC'], %w(Florida FL), %w(Georgia GA), %w(Hawaii HI), %w(Idaho ID), %w(Illinois IL), %w(Indiana IN), %w(Iowa IA), %w(Kansas KS), %w(Kentucky KY), %w(Louisiana LA), %w(Maine ME), %w(Maryland MD), %w(Massachusetts MA), %w(Michigan MI), %w(Minnesota MN), %w(Mississippi MS), %w(Missouri MO), %w(Montana MT), %w(Nebraska NE), %w(Nevada NV), ['New Hampshire', 'NH'], ['New Jersey', 'NJ'], ['New Mexico', 'NM'], ['New York', 'NY'], ['North Carolina', 'NC'], ['North Dakota', 'ND'], %w(Ohio OH), %w(Oklahoma OK), %w(Oregon OR), %w(Pennsylvania PA), ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], %w(Tennessee TN), %w(Texas TX), %w(Utah UT), %w(Vermont VT), %w(Virginia VA), %w(Washington WA), %w(Wisconsin WI), ['West Virginia', 'WV'], %w(Wyoming WY)] unless const_defined?('USASTATES')
308
- end
309
-
310
- module InstanceTagMethods
311
- def to_country_select_tag(priority_countries, options, html_options)
312
- html_options = html_options.stringify_keys
313
- add_default_name_and_id(html_options)
314
- value = value(object)
315
- selected_value = options.key?(:selected) ? options[:selected] : value
316
- content_tag(
317
- 'select',
318
- add_options(
319
- country_options_for_select(selected_value, priority_countries),
320
- options, selected_value
321
- ), html_options
322
- )
323
- end
324
-
325
- def to_usa_state_select_tag(priority_states, options, html_options)
326
- html_options = html_options.stringify_keys
327
- add_default_name_and_id(html_options)
328
- value = value(object)
329
- selected_value = options.key?(:selected) ? options[:selected] : value
330
- content_tag('select', add_options(usa_state_options_for_select(selected_value, priority_states), options, selected_value), html_options)
331
- end
332
- end
333
-
334
- module FormColumnHelpers
335
- def active_scaffold_input_country(column, options)
336
- select_options = {:prompt => as_(:_select_)}
337
- select_options.merge!(options)
338
- options.reverse_merge!(column.options).except!(:prompt, :priority)
339
- options[:name] += '[]' if options[:multiple]
340
- country_select(:record, column.name, column.options[:priority] || [:united_states], select_options, options)
341
- end
342
-
343
- def active_scaffold_input_usa_state(column, options)
344
- select_options = {:prompt => as_(:_select_)}
345
- select_options.merge!(options)
346
- options.reverse_merge!(column.options).except!(:prompt, :priority)
347
- options[:name] += '[]' if options[:multiple]
348
- usa_state_select(:record, column.name, column.options[:priority], select_options, options)
349
- end
350
- end
351
-
352
- module SearchColumnHelpers
353
- def active_scaffold_search_country(column, options)
354
- active_scaffold_input_country(column, options.merge!(:selected => options.delete(:value)))
355
- end
356
-
357
- def active_scaffold_search_usa_state(column, options)
358
- active_scaffold_input_usa_state(column, options.merge!(:selected => options.delete(:value)))
359
- end
360
- end
361
- end
362
- end
363
-
364
- ActionView::Base.class_eval do
365
- include ActiveScaffold::Bridges::CountryHelper::CountryHelpers
366
- include ActiveScaffold::Bridges::CountryHelper::CountryOptionsHelpers
367
- include ActiveScaffold::Bridges::CountryHelper::FormColumnHelpers
368
- include ActiveScaffold::Bridges::CountryHelper::SearchColumnHelpers
369
- end
370
- if defined? ActionView::Helpers::InstanceTag # TODO remove when rails 3.2 support is dropped
371
- ActionView::Helpers::InstanceTag.class_eval do
372
- include ActiveScaffold::Bridges::CountryHelper::CountryOptionsHelpers
373
- include ActiveScaffold::Bridges::CountryHelper::InstanceTagMethods
374
- end
375
- else
376
- class ActionView::Helpers::Tags::CountrySelect < ActionView::Helpers::Tags::Base #:nodoc:
377
- include ActiveScaffold::Bridges::CountryHelper::CountryOptionsHelpers
378
- include ActiveScaffold::Bridges::CountryHelper::InstanceTagMethods
379
- end
380
- end
@@ -1,9 +0,0 @@
1
- class ActiveScaffold::Bridges::CountryHelper < ActiveScaffold::DataStructures::Bridge
2
- def self.install
3
- require File.join(File.dirname(__FILE__), 'country_helper/country_helper_bridge.rb')
4
- end
5
-
6
- def self.install?
7
- true
8
- end
9
- end