effective_bootstrap 0.3.0 → 0.3.1

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: 8ef5c490c21c811d0bab4b33f68d2b45a49e71e5
4
- data.tar.gz: fd13c727e25be05f6dd021fa0fa3165562dcf7f8
3
+ metadata.gz: 4253e5912bdb4bd1ee2046f404c40a108d6baf41
4
+ data.tar.gz: e1acfb6e5c27e969801f47bb3989a8eb796744d7
5
5
  SHA512:
6
- metadata.gz: 365573317df114f67454c6331f58fdc869b89c7b5f13ced477098a2b87582395dbfca0d34683805162dfb49b4499cb9a8769fa9afd100ba905d69f2878942efd
7
- data.tar.gz: c857d13f1b2e978f363eab1514c2a2936560b802d87418143da60a4d41e1f0f0446061c4dd151cd2fe50fdc92c1986d49834fbaf20a04ef3b9ec67b9cea3bbe4
6
+ metadata.gz: a4682dab51bfb9812ca8afee9dc146b324e776dedc31e1902e3017c8ec62d9978eac8ed070e3572866ad03752605ca365b011565ddaeaa51c149c06acb5b385b
7
+ data.tar.gz: 2351f437787f0bbf3e8969076299acac707dc7756883cda27e1cfca8ad4c86047d6c701bd5eaa408b6f91aae7fbacc8624d6cd7014e7e1b843f1a951967d1933
@@ -21,14 +21,20 @@
21
21
 
22
22
  if content_mode == 'code'
23
23
  quill.formatText(0, quill.getLength(), 'code-block', true)
24
- quill.on 'text-change', -> $element.val(quill.getText())
24
+
25
+ quill.on 'text-change', ->
26
+ $element.val(quill.getText())
27
+ $element.trigger('change')
25
28
  else if content_mode == 'html'
26
29
  quill.on 'text-change', ->
27
30
  html = $(editor).children('.ql-editor').html()
28
31
  html = '' if html == '<p><br></p>' || html == '<p></p>'
29
32
  $element.val(html)
33
+ $element.trigger('change')
30
34
  else
31
- quill.on 'text-change', -> $element.val(JSON.stringify(quill.getContents()))
35
+ quill.on 'text-change', ->
36
+ $element.val(JSON.stringify(quill.getContents()))
37
+ $element.trigger('change')
32
38
 
33
39
  $element.on 'quill:focus', (event) -> quill.focus()
34
40
 
@@ -36,8 +36,8 @@ module Effective
36
36
  include_blank = options[:input].delete(:include_blank)
37
37
 
38
38
  @collection_options = {
39
- checked: (checked || selected || passed_value || polymorphic_value || value),
40
- selected: (selected || checked || passed_value || polymorphic_value || value),
39
+ checked: [checked, selected, passed_value, polymorphic_value, value].find { |value| value != nil },
40
+ selected: [selected, checked, passed_value, polymorphic_value, value].find { |value| value != nil },
41
41
  include_blank: include_blank
42
42
  }.compact
43
43
  end
@@ -78,14 +78,10 @@ module Effective
78
78
  # This is a grouped polymorphic collection
79
79
  # [["Clinics", [["Clinc 50", "Clinic_50"], ["Clinic 43", "Clinic_43"]]], ["Contacts", [["Contact 544", "Contact_544"]]]]
80
80
  def assign_options_collection!
81
- collection = options[:input].delete(:collection)
81
+ collection = options[:input].delete(:collection) || raise('Please include a collection')
82
82
 
83
83
  grouped = collection.kind_of?(Hash) && collection.values.first.respond_to?(:to_a)
84
84
 
85
- if collection.nil?
86
- raise "Please include a collection"
87
- end
88
-
89
85
  if grouped? && !grouped && collection.present?
90
86
  raise "Grouped collection expecting a Hash {'Posts' => Post.all, 'Events' => Event.all} or a Hash {'Posts' => [['Post A', 1], ['Post B', 2]], 'Events' => [['Event A', 1], ['Event B', 2]]}"
91
87
  end
@@ -96,15 +92,27 @@ module Effective
96
92
 
97
93
  @options_collection = (
98
94
  if polymorphic?
99
- collection.inject({}) { |h, (k, group)| h[k] = group.map { |obj| [obj.to_s, "#{obj.class.model_name}_#{obj.id}"] }; h }
95
+ collection.inject({}) { |h, (k, group)| h[k] = translate(group).map { |obj| [obj.to_s, "#{obj.class.model_name}_#{obj.id}"] }; h }
100
96
  elsif grouped
101
- collection.inject({}) { |h, (k, group)| h[k] = group.map { |obj| obj }; h }
97
+ collection.inject({}) { |h, (k, group)| h[k] = translate(group).map { |obj| obj }; h }
102
98
  else
103
- collection.map { |obj| obj }
99
+ translate(collection).map { |obj| obj }
104
100
  end
105
101
  )
106
102
  end
107
103
 
104
+ # Apply ActsAsArchived behavior. That's all for now.
105
+ def translate(collection)
106
+ return collection unless object.respond_to?(:new_record?)
107
+ return collection unless collection.respond_to?(:klass) && collection.klass.respond_to?(:acts_as_archived?)
108
+
109
+ if object.new_record?
110
+ collection.unarchived
111
+ else
112
+ collection.unarchived.or(collection.archived.where(collection.klass.primary_key => value))
113
+ end
114
+ end
115
+
108
116
  def assign_options_collection_methods!
109
117
  options[:input].reverse_merge!(
110
118
  if polymorphic?
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-02 00:00:00.000000000 Z
11
+ date: 2018-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails