record_collection 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/record_collection/multi_select.js.coffee +21 -5
- data/app/assets/javascripts/record_collection/optionals.js.coffee +7 -0
- data/lib/record_collection/base.rb +1 -1
- data/lib/record_collection/version.rb +1 -1
- data/spec/base/accessors_spec.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4abda6b9b06f53f8caacf070513cfe5b3f7fa4be
|
4
|
+
data.tar.gz: beec42bfc69c04587a0baa1f722c6e0dd99ea6db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94846e1eb01ff6e90afd9b3f58d9d34bfc21d697b9a8e5f57c15883549201226dd3edb6aa537df4425f5eabbcab74bc2001190cfa01e8339d36c2cf886b5583f
|
7
|
+
data.tar.gz: c0b027639f916a9475a769f0c151c48e28d6a30f5ba1080202640866eedcda28f03c12e76a26debd9842e2b8ba6fed4e11763c986047c0a502d83418ab687955
|
@@ -1,8 +1,19 @@
|
|
1
1
|
class MultiSelect
|
2
|
-
|
2
|
+
callbacks: {}
|
3
|
+
on: (event, callback) ->
|
4
|
+
@callbacks[event] ||= []
|
5
|
+
@callbacks[event].push callback
|
6
|
+
trigger: (event)->
|
7
|
+
return unless @callbacks[event]
|
8
|
+
for callback in @callbacks[event]
|
9
|
+
callback.call(@)
|
10
|
+
setup: (table, options) ->
|
3
11
|
return unless table and table.length
|
12
|
+
selector = @
|
4
13
|
table.data 'multi_select', @
|
5
14
|
@set 'table', table
|
15
|
+
@options = options
|
16
|
+
@on 'changed', options.changed if options.changed
|
6
17
|
|
7
18
|
@set 'resource', table.data('resource')
|
8
19
|
# Add an extra th to all header rows
|
@@ -20,6 +31,7 @@ class MultiSelect
|
|
20
31
|
else
|
21
32
|
table.find('td.selection .checker').removeClass('unchecked').addClass('checked')
|
22
33
|
$(this).removeClass('unchecked').addClass('checked')
|
34
|
+
selector.trigger 'changed'
|
23
35
|
table.find('thead tr:last th:first').append toggle_all
|
24
36
|
|
25
37
|
# Create a toggle/checkbox for all records and add it to the row
|
@@ -29,6 +41,7 @@ class MultiSelect
|
|
29
41
|
$(this).removeClass('checked').addClass('unchecked')
|
30
42
|
else
|
31
43
|
$(this).removeClass('unchecked').addClass('checked')
|
44
|
+
selector.trigger 'changed'
|
32
45
|
record_td = $('<td></td>').addClass('selection').append(record_toggle)
|
33
46
|
table.find('tbody tr').prepend record_td
|
34
47
|
|
@@ -41,19 +54,22 @@ class MultiSelect
|
|
41
54
|
set: (path, value) -> @[path] = value
|
42
55
|
get: (path) -> @[path]
|
43
56
|
|
57
|
+
selected_count: -> @table.find('td.selection .checked').length
|
58
|
+
total_count: -> @table.find('td.selection .checker').length
|
59
|
+
|
44
60
|
#selected_records: -> @table.find("td.selection input:checked").map( -> $(this).parents('tr').data('record') )
|
45
61
|
selected_records: -> @table.find("td.selection .checked").map( -> $(this).parents('tr').data('record') )
|
46
|
-
selected_ids: -> @selected_records().map( ->
|
62
|
+
selected_ids: -> @selected_records().map( -> @id ).toArray()
|
47
63
|
root = @
|
48
64
|
root.MultiSelect = new MultiSelect()
|
49
|
-
$.fn.multi_select = ->
|
65
|
+
$.fn.multi_select = (options = {})->
|
50
66
|
if @.hasClass('with-selection') or @.prop('tagName') is 'TABLE'
|
51
67
|
select = new MultiSelect()
|
52
68
|
root.MultiSelect = select
|
53
|
-
select.setup
|
69
|
+
select.setup @, options
|
54
70
|
else
|
55
71
|
@.find('table.with-selection').each (i, el)->
|
56
72
|
select = new MultiSelect()
|
57
73
|
root.MultiSelect = select
|
58
|
-
select.setup $(el)
|
74
|
+
select.setup $(el), options
|
59
75
|
select
|
@@ -82,6 +82,13 @@ class Optionals
|
|
82
82
|
#value_toggle.hide()
|
83
83
|
container.removeClass('active').addClass('inactive')
|
84
84
|
activator_label = $('<span></span>').addClass('optional-input-activator-label').text label_text
|
85
|
+
activator_label.click ->
|
86
|
+
if activator_container.hasClass('active')
|
87
|
+
# Focus on element
|
88
|
+
value_field.focus()
|
89
|
+
else
|
90
|
+
# Activate the optional
|
91
|
+
activator_toggle.click()
|
85
92
|
activator_container.append activator_toggle
|
86
93
|
activator_container.append activator_label
|
87
94
|
|
data/spec/base/accessors_spec.rb
CHANGED
@@ -8,6 +8,11 @@ RSpec.describe RecordCollection::Base do
|
|
8
8
|
described_class.new([employee]).ids.should eq [employee.id]
|
9
9
|
end
|
10
10
|
|
11
|
+
it 'Filters out nil records' do
|
12
|
+
employee = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
13
|
+
described_class.new([employee, nil]).ids.should eq [employee.id]
|
14
|
+
end
|
15
|
+
|
11
16
|
it 'returns an empty array for an empty collection' do
|
12
17
|
described_class.new.ids.should be_empty
|
13
18
|
end
|