cck_forms 3.1.3 → 3.2.2

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: 5885969f4592d28cbe4d4d18cdf8b3cca99dbc50
4
- data.tar.gz: e28ae670e596ba61fda2d37fef00f82ce55d0f4e
3
+ metadata.gz: 13d92b9f74221a1651abc8c15bfe35743bc11bd0
4
+ data.tar.gz: 643415c319917544c8902187f8bd007d083a53a8
5
5
  SHA512:
6
- metadata.gz: 4d277ea14c0bfa3ab0fb220758845301c62878e8cc96f226b9c4bc2ee3d5a78bc2a8b7016d7ace1da5083b04f0dc24598b38b58db5399e1388aba53ae8e592cc
7
- data.tar.gz: c3b13d9108fec8637998616cc8c798dc3e32c7d2af4932a946f4b1bfc5f471d15e22f8e7cfef721b913b7e32996ba2cf15cfa3f3d81802065a0ca5543b0eecfb
6
+ metadata.gz: 50a1ed167f097b57f7e94f1dc0dad6d4d2fa185d07f5fb458ae4edc8a39c3030542c2d0228a7973736671c5b596cdb9fd3a139bca7c737bc352cecc598b6ac67
7
+ data.tar.gz: f4220e7b29a787d7686733b531f8243b3219249a76bdbdb855ede70f676f59f91da253a60def0f4e2c107f997058ef927ecfce151d9d995df45fad73f1bb5038
data/README.md CHANGED
@@ -238,6 +238,9 @@ config.cck_forms.phones.prefix = '+7'
238
238
 
239
239
  # the glue for concatenating phone number parts: 111[glue]22[glue]33
240
240
  config.cck_forms.phones.number_parts_glue = '-'
241
+
242
+ # the default map provider; if not specified, google is the default
243
+ config.cck_forms.maps.default_type = 'yandex'.freeze
241
244
  ```
242
245
 
243
246
 
@@ -19,5 +19,8 @@ module CckForms
19
19
  config.cck_forms.phones.mobile_codes = %w{ 777 705 771 701 702 775 778 700 707 }
20
20
  config.cck_forms.phones.prefix = '+7'
21
21
  config.cck_forms.phones.number_parts_glue = '-'
22
+
23
+ # maps
24
+ config.cck_forms.maps = ActiveSupport::OrderedOptions.new
22
25
  end
23
26
  end
@@ -95,9 +95,10 @@ HTML
95
95
  # Returns a collection of 64x64 IMGs
96
96
  def to_diff_value(options = {})
97
97
  view_context = options[:view_context]
98
- images_html_list = []
99
- value.each do |image_id|
100
- images_html_list << "<img style='width: 64px; height: 64px;' src='#{view_context.neofiles_image_path(id: image_id, format: '64x64', crop: 1)}'>"
98
+
99
+ images_html_list = (value || []).map(&:presence).compact.map do
100
+ id = elem.is_a?(BSON::Document) ? elem['_id'] : elem
101
+ "<img style='width: 64px; height: 64px;' src='#{view_context.neofiles_image_path(id: id, format: '64x64', crop: 1)}'>"
101
102
  end
102
103
 
103
104
  images_html_list.join.html_safe if images_html_list.any?
@@ -28,10 +28,14 @@ class CckForms::ParameterTypeClass::Checkboxes
28
28
  value.present? or return {}
29
29
 
30
30
  valid_values = parameter_type_class.try!(:valid_values) || value.map { |x| [x, nil] }
31
- valid_values.reduce({}) do |r, (key, _)|
31
+ valid_values = valid_values.reduce({}) do |r, (key, _)|
32
32
  r[key] = value.include?(key) ? '1' : '0'
33
33
  r
34
34
  end
35
+
36
+ valid_values = valid_values.dup
37
+ priority_values = valid_values.extract!(*(value.respond_to?(:keys) ? value.keys : value))
38
+ priority_values.merge valid_values
35
39
  end
36
40
 
37
41
  # Comma-separated list of checked entries. Options:
@@ -150,33 +154,31 @@ class CckForms::ParameterTypeClass::Checkboxes
150
154
  set_value_in_hash options
151
155
  val = options[:value]
152
156
 
153
- result = ''
154
- if valid_values.is_a? Array
155
- method = :each_with_index
156
- elsif valid_values.is_a? Hash
157
- method = :each_pair
158
- end
159
-
160
- valid_values.send(method) do |k, v|
161
- if !options[:only] || options[:only] == k || options[:only].try(:include?, k)
162
- result += form_builder.fields_for :value do |ff|
157
+ result = ''
158
+ valid_values = self.valid_values.dup
159
+ valid_values = valid_values.is_a?(Hash) ? valid_values : valid_values.zip([])
160
+ priority_values = valid_values.extract!(*(value.respond_to?(:keys) ? value.keys : value))
163
161
 
164
- begin
165
- checked = ! val.try(:[], k).to_i.zero?
166
- rescue
167
- checked = false
168
- end
162
+ priority_values.merge(valid_values).each_pair do |k, v|
163
+ next if options[:only] && options[:only] != k && !options[:only].try(:include?, k)
169
164
 
170
- v = options[:map][v] || v
165
+ result += form_builder.fields_for :value do |ff|
171
166
 
172
- # skip `required` since form will not be submitted unless a user checks all the checkboxes
173
- data = options[:data] ? extract_data_for_key(k, options[:data]) : nil
174
- sprintf(options[:block], ff.check_box(k.to_sym, {checked: checked}, '1', options[:for] == :search ? nil : '0'), ff.label(k.to_sym, v, data: data)).html_safe
167
+ begin
168
+ checked = !val.try(:[], k).to_i.zero?
169
+ rescue
170
+ checked = false
175
171
  end
172
+
173
+ v = options[:map][v] || v
174
+
175
+ # skip `required` since form will not be submitted unless a user checks all the checkboxes
176
+ data = options[:data] ? extract_data_for_key(k, options[:data]) : nil
177
+ sprintf(options[:block], ff.check_box(k.to_sym, {checked: checked}, '1', options[:for] == :search ? nil : '0'), ff.label(k.to_sym, v, data: data)).html_safe
176
178
  end
177
179
  end
178
180
 
179
- result
181
+ sprintf '<div class="checkboxes" id="%1$s">%2$s</div><script type="text/javascript">$(function() {$("#%1$s").checkboxes()})</script>', form_builder_name_to_id(form_builder), result
180
182
  end
181
183
 
182
184
 
@@ -12,6 +12,10 @@ class CckForms::ParameterTypeClass::Image < CckForms::ParameterTypeClass::File
12
12
  # Returns a 64x64 IMG
13
13
  def to_diff_value(options = {})
14
14
  view_context = options[:view_context]
15
- "<img style='width: 64px; height: 64px;' src='#{view_context.neofiles_image_path(id: value, format: '64x64', crop: 1)}'>".html_safe
15
+
16
+ if value.present?
17
+ id = value.is_a?(BSON::Document) ? value['_id'] : value
18
+ "<img style='width: 64px; height: 64px;' src='#{view_context.neofiles_image_path(id: id, format: '64x64', crop: 1)}'>".html_safe
19
+ end
16
20
  end
17
21
  end
@@ -5,7 +5,7 @@ class CckForms::ParameterTypeClass::Map
5
5
 
6
6
  MAP_TYPE_GOOGLE = 'google'.freeze
7
7
  MAP_TYPE_YANDEX = 'yandex'.freeze
8
- DEFAULT_MAP_TYPE = MAP_TYPE_GOOGLE
8
+ DEFAULT_MAP_TYPE = Rails.application.config.cck_forms.maps.default_type || MAP_TYPE_GOOGLE
9
9
 
10
10
  mattr_accessor :map_providers
11
11
  @@map_providers = [MAP_TYPE_YANDEX, MAP_TYPE_GOOGLE]
@@ -1,3 +1,3 @@
1
1
  module CckForms
2
- VERSION = '3.1.3'
2
+ VERSION = '3.2.2'
3
3
  end
@@ -1,2 +1,3 @@
1
+ //= require ./jquery.checkboxes
1
2
  //= require ./jquery.workhours
2
- //= require ./map
3
+ //= require ./map
@@ -0,0 +1,42 @@
1
+ $ ->
2
+
3
+ #
4
+ # Helper widget to allow sorting of checkboxes, if jquery.sortable is available
5
+ #
6
+ $.widget "cck.checkboxes",
7
+
8
+ _create: ->
9
+ @_checkBoxBlockSelector = ".form_check_box_block"
10
+
11
+ @_ensureSortableIsAvailable =>
12
+ @_initStickies()
13
+ @_bind()
14
+
15
+ _ensureSortableIsAvailable: (callback)->
16
+ callback() if $(document).sortable
17
+
18
+ _initStickies: ->
19
+ @element.find("input:checked").each (_i, checkbox)=>
20
+ $(checkbox).closest(@_checkBoxBlockSelector).addClass("sticky")
21
+
22
+ @element.sortable
23
+ items: ".sticky"
24
+
25
+ _bind: ->
26
+ @element.on "change", "#{@_checkBoxBlockSelector} input:checkbox", (e)=>
27
+ @_checkboxChange($(e.target))
28
+
29
+ _checkboxChange: ($checkbox)->
30
+ $container = $checkbox.closest(@_checkBoxBlockSelector)
31
+
32
+ $container.removeClass("sticky") unless $checkbox.is(":checked")
33
+
34
+ $lastSticky = @element.find(".sticky").last()
35
+
36
+ if $container.prev(@_checkBoxBlockSelector).get(0) != $lastSticky.get(0)
37
+ if $lastSticky.size() == 0
38
+ @element.prepend($container)
39
+ else
40
+ $container.insertAfter($lastSticky)
41
+
42
+ $container.addClass("sticky") if $checkbox.is(":checked")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cck_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Konanykhin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-13 00:00:00.000000000 Z
11
+ date: 2017-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -91,6 +91,7 @@ files:
91
91
  - lib/cck_forms/parameter_type_class/work_hours.rb
92
92
  - lib/cck_forms/version.rb
93
93
  - vendor/assets/javascripts/cck_forms/index.js
94
+ - vendor/assets/javascripts/cck_forms/jquery.checkboxes.coffee
94
95
  - vendor/assets/javascripts/cck_forms/jquery.workhours.js
95
96
  - vendor/assets/javascripts/cck_forms/map.js.coffee
96
97
  homepage: http://github.com/ilya-konanykhin/cck_forms
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  version: '0'
114
115
  requirements: []
115
116
  rubyforge_project:
116
- rubygems_version: 2.5.1
117
+ rubygems_version: 2.6.12
117
118
  signing_key:
118
119
  specification_version: 4
119
120
  summary: Content Construction Kit Forms