advanced_select 0.1.1 → 0.1.2
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/views/advanced_select/_options.html.erb +3 -1
- data/lib/advanced_select/helper.rb +59 -1
- data/lib/advanced_select/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8acafe10e284da26e61bec53737160926b3b6f43e51aa4d2a690e9a9b5a47367
|
|
4
|
+
data.tar.gz: c2465e1a792dc86ece9747b18fe2dcb3e077d706aed3e178515fe1376308067b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d9a0cefc246959a5f8f5910e91e648f5654c55eee8bbb63ae78232c5abd9b7ab0b307eb04744f70016d5e23ab54cc3b7c9a6973c18b5d2ea3b885255a54e8c5a
|
|
7
|
+
data.tar.gz: 4e4143bb1da3fb3e50f5aa6fda9cce40f3631c6f7d0ba5b2185a5f06ca4cb9f0b16938932aca365206cf0391ac5b8151335ae1e32e1e5c9abd4a26447e383617
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
aria-busy="false"
|
|
5
5
|
<% if local_assigns[:multiple] %>aria-multiselectable="true"<% end %>
|
|
6
6
|
role="listbox">
|
|
7
|
+
<% selected_option_ids = advanced_select_selected_option_ids(selected_options) %>
|
|
8
|
+
|
|
7
9
|
<% advanced_select_option_groups(options).each do |group| %>
|
|
8
10
|
<% if group[:label].present? %>
|
|
9
11
|
<div class="<%= advanced_select_class(class_map, :group_label) %>"><%= group.fetch(:label) %></div>
|
|
10
12
|
<% end %>
|
|
11
13
|
|
|
12
14
|
<% group.fetch(:options).each do |option| %>
|
|
13
|
-
<%=
|
|
15
|
+
<%= advanced_select_option_tag(option, selected_options, option_content_partial, class_map, selected_option_ids: selected_option_ids) %>
|
|
14
16
|
<% end %>
|
|
15
17
|
<% end %>
|
|
16
18
|
|
|
@@ -60,6 +60,56 @@ module AdvancedSelect
|
|
|
60
60
|
end.to_json
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
+
def advanced_select_option_tag(option, selected_options, option_content_partial, class_map, selected_option_ids: nil)
|
|
64
|
+
selected = advanced_select_option_selected?(option, selected_options, selected_option_ids)
|
|
65
|
+
|
|
66
|
+
tag.button(
|
|
67
|
+
type: "button",
|
|
68
|
+
class: advanced_select_class(class_map, :option, (:option_selected if selected)),
|
|
69
|
+
role: "option",
|
|
70
|
+
aria: { selected: selected },
|
|
71
|
+
data: {
|
|
72
|
+
advanced_select_option: "",
|
|
73
|
+
action: "mouseenter->advanced-select#activateOption mousedown->advanced-select#choose",
|
|
74
|
+
advanced_select_value_param: option.fetch(:id),
|
|
75
|
+
advanced_select_submit_value_param: advanced_select_option_value(option),
|
|
76
|
+
advanced_select_label_param: advanced_select_option_label(option),
|
|
77
|
+
advanced_select_display_label_param: advanced_select_option_display_label(option)
|
|
78
|
+
}
|
|
79
|
+
) do
|
|
80
|
+
safe_join([
|
|
81
|
+
tag.span(
|
|
82
|
+
(selected ? "\u2713" : ""),
|
|
83
|
+
class: advanced_select_class(class_map, :option_check),
|
|
84
|
+
data: { advanced_select_option_check: "" }
|
|
85
|
+
),
|
|
86
|
+
advanced_select_option_content_tag(option, option_content_partial, class_map)
|
|
87
|
+
])
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def advanced_select_option_content_tag(option, option_content_partial, class_map)
|
|
92
|
+
if option_content_partial.present?
|
|
93
|
+
render partial: option_content_partial, locals: { option: option }
|
|
94
|
+
else
|
|
95
|
+
advanced_select_default_option_content_tag(option, class_map)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def advanced_select_default_option_content_tag(option, class_map)
|
|
100
|
+
description = advanced_select_option_description(option)
|
|
101
|
+
content = [tag.span(advanced_select_option_label(option))]
|
|
102
|
+
|
|
103
|
+
if description.present?
|
|
104
|
+
content << tag.span(
|
|
105
|
+
description,
|
|
106
|
+
class: advanced_select_class(class_map, :option_description)
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
tag.span(safe_join(content), class: advanced_select_class(class_map, :option_content))
|
|
111
|
+
end
|
|
112
|
+
|
|
63
113
|
def advanced_select_options_for_render(options, selected_options, searchable)
|
|
64
114
|
searchable ? selected_options.presence || options : options
|
|
65
115
|
end
|
|
@@ -83,7 +133,15 @@ module AdvancedSelect
|
|
|
83
133
|
end
|
|
84
134
|
end
|
|
85
135
|
|
|
86
|
-
def
|
|
136
|
+
def advanced_select_selected_option_ids(selected_options)
|
|
137
|
+
selected_options.each_with_object({}) do |selected_option, selected_option_ids|
|
|
138
|
+
selected_option_ids[selected_option.fetch(:id).to_s] = true
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def advanced_select_option_selected?(option, selected_options, selected_option_ids = nil)
|
|
143
|
+
return selected_option_ids.key?(option.fetch(:id).to_s) if selected_option_ids
|
|
144
|
+
|
|
87
145
|
selected_options.any? { |selected_option| selected_option.fetch(:id).to_s == option.fetch(:id).to_s }
|
|
88
146
|
end
|
|
89
147
|
|
metadata
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: advanced_select
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mehmet Celik
|
|
8
8
|
- Tankut Ozbeyendir
|
|
9
|
+
- Emre ULUSOY
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
12
|
date: 1980-01-01 00:00:00.000000000 Z
|
|
@@ -86,6 +87,7 @@ description: AdvancedSelect provides helper-rendered Rails partials, Stimulus dr
|
|
|
86
87
|
email:
|
|
87
88
|
- mehmetcelik4@gmail.com
|
|
88
89
|
- tankutozbeyendir@gmail.com
|
|
90
|
+
- ulsyemr@gmail.com
|
|
89
91
|
executables: []
|
|
90
92
|
extensions: []
|
|
91
93
|
extra_rdoc_files: []
|