record_collection 0.5.3 → 0.6.0

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: 4abda6b9b06f53f8caacf070513cfe5b3f7fa4be
4
- data.tar.gz: beec42bfc69c04587a0baa1f722c6e0dd99ea6db
3
+ metadata.gz: 9ee07c5d52e0e54488e931828ea1e6fa5fcfcf11
4
+ data.tar.gz: 287f65ae03ea2093b1f8bfa8fecde2d5acb3d9c4
5
5
  SHA512:
6
- metadata.gz: 94846e1eb01ff6e90afd9b3f58d9d34bfc21d697b9a8e5f57c15883549201226dd3edb6aa537df4425f5eabbcab74bc2001190cfa01e8339d36c2cf886b5583f
7
- data.tar.gz: c0b027639f916a9475a769f0c151c48e28d6a30f5ba1080202640866eedcda28f03c12e76a26debd9842e2b8ba6fed4e11763c986047c0a502d83418ab687955
6
+ metadata.gz: af0f6e48b22e6456ceb5b74f3c8989df45e0cf8b19f67650aea3bcd2ed8d99aa15b9a7cbbaccafe7ba47ac1fd3be00c99937e138511ca0550e8d14e0e3293de1
7
+ data.tar.gz: 302c8acc483678b28be818e928d6f5ad193c8a71f36ce1c3c94fb270f83bb90916701aed6c7f2ad8a75dc185bd17d7cbf13544ffd404f68f434da3084f7ab8ea
@@ -16,12 +16,13 @@ class Optionals
16
16
  check_box = container.find('input')
17
17
  initially_checked = check_box.is(':checked')
18
18
  field_name = check_box.attr('name')
19
+ one = container.data('one')
19
20
 
20
21
  label_text = container.find('label').text()
21
22
 
22
23
  value_field = $('<input>').attr('type', 'hidden').val(0)
23
24
  # Set name based on activated state
24
- if container.hasClass('active')
25
+ if one or container.hasClass('active')
25
26
  value_field.attr 'name', field_name
26
27
  else
27
28
  value_field.attr 'name', "disabled_#{field_name}"
@@ -29,8 +30,6 @@ class Optionals
29
30
  # Clear the container and initialize to inactive
30
31
  container.html('')
31
32
 
32
- label = $('<span></span>').addClass('optional-boolean-label').text label_text
33
-
34
33
  activator_toggle = $('<span></span>').addClass('optional-boolean-activator-toggle').click ->
35
34
  container.toggleClass('active').toggleClass('inactive')
36
35
  if container.hasClass('active')
@@ -38,6 +37,11 @@ class Optionals
38
37
  else
39
38
  value_field.attr 'name', "disabled_#{value_field.attr('name')}"
40
39
 
40
+ label = $('<span></span>').addClass('optional-boolean-label').text label_text
41
+ label.click ->
42
+ if container.hasClass('inactive')
43
+ activator_toggle.click()
44
+
41
45
  value_toggle = $('<span></span>').addClass('optional-boolean-toggle').click ->
42
46
  return if container.hasClass('inactive')
43
47
  if $(@).hasClass('active')
@@ -57,12 +61,14 @@ class Optionals
57
61
  container.append label
58
62
  container.append value_toggle
59
63
  container.append value_field
64
+ activator_toggle.hide() if one
60
65
 
61
66
  prependActivator: (container)->
62
67
  value_field = container.find('select,input')
63
68
  # INITIAL STATE IS DISABLED, Activation by triggering click if needed
64
69
  value_field.attr 'name', "disabled_#{value_field.attr('name')}"
65
70
  container.addClass('inactive')
71
+ one = container.data('one')
66
72
 
67
73
  label_text = container.find('label').text()
68
74
 
@@ -97,6 +103,7 @@ class Optionals
97
103
  container.find('label').remove()
98
104
 
99
105
  activator_toggle.click() if container.hasClass('active')
106
+ activator_toggle.hide() if one
100
107
 
101
108
  root = @
102
109
  root.Optionals = new Optionals()
@@ -47,7 +47,7 @@ class <%= controller_class_name %>Controller < ApplicationController
47
47
  # DELETE <%= route_url %>/1
48
48
  def destroy
49
49
  @<%= orm_instance.destroy %>
50
- redirect_to <%= index_helper %>_url, notice: t('action.destroy.successful', model: <%= class_name %>.model_name.human)
50
+ redirect_to <%= index_helper %>_path, notice: t('action.destroy.successful', model: <%= class_name %>.model_name.human)
51
51
  end
52
52
 
53
53
  # GET <%= route_url %>/collection_edit
@@ -59,25 +59,26 @@ class <%= controller_class_name %>Controller < ApplicationController
59
59
  def collection_update
60
60
  @collection = <%= class_name %>::Collection.find(params[:ids])
61
61
  if @collection.update params[:collection]
62
- redirect_to <%= index_helper %>_url, notice: t('action.collection_update.successful', model: <%= class_name %>.model_name.human)
62
+ redirect_to <%= index_helper %>_path, notice: t('action.collection_update.successful', model: <%= class_name %>.model_name.human)
63
63
  else
64
64
  render :collection_edit
65
65
  end
66
66
  end
67
67
 
68
68
  private
69
- # Use callbacks to share common setup or constraints between actions.
70
- def set_<%= singular_table_name %>
71
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
72
- end
73
69
 
74
- # Only allow a trusted parameter "white list" through.
75
- def <%= "#{singular_table_name}_params" %>
76
- <%- if attributes_names.empty? -%>
77
- params[:<%= singular_table_name %>]
78
- <%- else -%>
79
- params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
80
- <%- end -%>
81
- end
70
+ # Use callbacks to share common setup or constraints between actions.
71
+ def set_<%= singular_table_name %>
72
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
73
+ end
74
+
75
+ # Only allow a trusted parameter "white list" through.
76
+ def <%= "#{singular_table_name}_params" %>
77
+ <%- if attributes_names.empty? -%>
78
+ params[:<%= singular_table_name %>]
79
+ <%- else -%>
80
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
81
+ <%- end -%>
82
+ end
82
83
  end
83
84
  <% end -%>
@@ -91,6 +91,11 @@ module RecordCollection
91
91
  self
92
92
  end
93
93
 
94
+ # Return a hash of the changed attributes of the collection:
95
+ # {
96
+ # name: 'Ben',
97
+ # ....etc...
98
+ # }
94
99
  def changed_attributes
95
100
  @changed_attributes ||= attributes.reject{|attr, val| val.nil? }
96
101
  end
@@ -19,7 +19,7 @@ class ActionView::Helpers::FormBuilder
19
19
  classes = get_optional_classes(attr, base_class: 'optional-boolean')
20
20
  label_tag = label(attr, options[:label])
21
21
  check_box_tag = check_box(attr, options)
22
- add_collection_ids @template.content_tag(:div, label_tag + check_box_tag , class: classes, data: { attribute: attr })
22
+ add_collection_ids @template.content_tag(:div, label_tag + check_box_tag , class: classes, data: get_data_attributes(attr))
23
23
  end
24
24
 
25
25
  def optional_check_box(attr)
@@ -28,17 +28,22 @@ class ActionView::Helpers::FormBuilder
28
28
 
29
29
  def optional_input(attr, options = {})
30
30
  classes = get_optional_classes(attr, base_class: 'optional-input')
31
- add_collection_ids @template.content_tag(:div, input(attr, options), class: classes, data: { attribute: attr })
31
+ add_collection_ids @template.content_tag(:div, input(attr, options), class: classes, data: get_data_attributes(attr))
32
32
  end
33
33
 
34
34
  def optional_text_field(attr, options={})
35
35
  classes = get_optional_classes(attr, base_class: 'optional-text-field')
36
- add_collection_ids @template.content_tag(:div, label(attr, options[:label]) + text_field(attr, options), class: classes, data: { attribute: attr })
36
+ add_collection_ids @template.content_tag(:div, label(attr, options[:label]) + text_field(attr, options), class: classes, data: get_data_attributes(attr))
37
37
  end
38
38
 
39
39
  def optional_text_area(attr, options={})
40
40
  classes = get_optional_classes(attr, base_class: 'optional-text-area')
41
- add_collection_ids @template.content_tag(:div, label(attr, options[:label]) + text_area(attr, options), class: classes, data: { attribute: attr })
41
+ add_collection_ids @template.content_tag(:div, label(attr, options[:label]) + text_area(attr, options), class: classes, data: get_data_attributes(attr))
42
+ end
43
+
44
+ def get_data_attributes(attr, options = {})
45
+ one = object.respond_to?(:one?) && object.one?
46
+ {attribute: attr, one: one}
42
47
  end
43
48
 
44
49
  def get_optional_classes(attr, options = {})
@@ -51,6 +56,7 @@ class ActionView::Helpers::FormBuilder
51
56
  active = true unless object.public_send(attr).nil? # Activate if collection attribute is not nil
52
57
  classes = [options[:base_class] || 'optional-input', 'optional-attribute-container', attr]
53
58
  classes << (active ? 'active' : 'inactive')
59
+ classes << 'one' if object.respond_to?(:one?) and object.one?
54
60
  classes << 'error' if object.errors[attr].present?
55
61
  classes
56
62
  end
@@ -1,3 +1,3 @@
1
1
  module RecordCollection
2
- VERSION = "0.5.3"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record_collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin ter Kuile
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler