china_region_fu 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -5
- data/.rspec +2 -1
- data/.rubocop.yml +101 -0
- data/.travis.yml +4 -2
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +10 -4
- data/LICENSE.txt +21 -0
- data/README.en.md +212 -0
- data/README.md +103 -68
- data/Rakefile +1 -1
- data/app/controllers/china_region_fu/fetch_options_controller.rb +64 -28
- data/app/models/city.rb +1 -11
- data/app/models/district.rb +1 -11
- data/app/models/province.rb +4 -4
- data/bin/console +14 -0
- data/bin/rspec +17 -0
- data/bin/setup +8 -0
- data/china_region_fu.gemspec +20 -19
- data/db/migrate/20111111111111_create_china_region_tables.rb +19 -17
- data/lib/china_region_fu.rb +4 -3
- data/lib/china_region_fu/engine.rb +11 -9
- data/lib/china_region_fu/errors.rb +5 -0
- data/lib/china_region_fu/helpers/formtastic.rb +4 -6
- data/lib/china_region_fu/helpers/helpers.rb +44 -53
- data/lib/china_region_fu/helpers/simple_form.rb +15 -14
- data/lib/china_region_fu/helpers/utils.rb +82 -0
- data/lib/china_region_fu/version.rb +1 -1
- data/lib/generators/china_region_fu/models/USAGE +1 -1
- data/lib/generators/china_region_fu/models/models_generator.rb +3 -3
- data/lib/tasks/{region.rake → china_region_fu_tasks.rake} +8 -14
- data/spec/china_region_fu_spec.rb +3 -7
- data/spec/helpers/helpers_spec.rb +113 -0
- data/spec/helpers/utils_spec.rb +87 -0
- data/spec/spec_helper.rb +6 -1
- data/spec/support/models.rb +39 -0
- metadata +50 -61
- data/LICENSE +0 -22
- data/lib/china_region_fu/exceptions.rb +0 -7
- data/lib/china_region_fu/helpers/utilities.rb +0 -54
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Xuhao
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module ChinaRegionFu
|
2
|
-
module Utilities
|
3
|
-
def js_for_region_ajax
|
4
|
-
js = <<-JAVASCRIPT
|
5
|
-
<script type="text/javascript">
|
6
|
-
//<![CDATA[
|
7
|
-
$(function(){
|
8
|
-
$('body').on('change', '.region_select', function(event) {
|
9
|
-
var self, $targetDom;
|
10
|
-
self = $(event.currentTarget);
|
11
|
-
$targetDom = $('#' + self.data('region-target'));
|
12
|
-
if ($targetDom.size() > 0) {
|
13
|
-
$.getJSON('/china_region_fu/fetch_options', {klass: self.data('region-target-kalss'), parent_klass: self.data('region-klass'), parent_id: self.val()}, function(data) {
|
14
|
-
var options = [];
|
15
|
-
$('option[value!=""]', $targetDom).remove();
|
16
|
-
$.each(data, function(index, value) {
|
17
|
-
options.push("<option value='" + value.id + "'>" + value.name + "</option>");
|
18
|
-
});
|
19
|
-
$targetDom.append(options.join(''));
|
20
|
-
});
|
21
|
-
}
|
22
|
-
});
|
23
|
-
});
|
24
|
-
//]]>
|
25
|
-
</script>
|
26
|
-
JAVASCRIPT
|
27
|
-
js.html_safe
|
28
|
-
end
|
29
|
-
|
30
|
-
def set_html_options(object, method, html_options, next_region)
|
31
|
-
region_klass_name = method.to_s#.sub(/_id\Z/, '')
|
32
|
-
next_region_klass_name = next_region.to_s#.sub(/_id\Z/, '')
|
33
|
-
html_options[:data] ? (html_options[:data][:region_klass] = region_klass_name) : (html_options[:data] = { region_klass: region_klass_name })
|
34
|
-
if next_region
|
35
|
-
region_target = object ? "#{object}_#{next_region.to_s}" : next_region.to_s
|
36
|
-
html_options[:data].merge!(region_target: region_target, region_target_kalss: next_region_klass_name)
|
37
|
-
else
|
38
|
-
html_options[:data].delete(:region_target)
|
39
|
-
html_options[:data].delete(:region_target_kalss)
|
40
|
-
end
|
41
|
-
html_options
|
42
|
-
end
|
43
|
-
|
44
|
-
def to_class(str_name)
|
45
|
-
return nil if str_name.blank?
|
46
|
-
str_name.to_s.sub(/_id\Z/, '').classify.safe_constantize
|
47
|
-
end
|
48
|
-
|
49
|
-
def append_region_class(options)
|
50
|
-
options[:class] ? (options[:class].prepend('region_select ')) : (options[:class] = 'region_select')
|
51
|
-
options
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|