Skip to content

Commit 847ce2c

Browse files
tomselect fixes (#1938)
* tomselect fixes * bump nokogiri
1 parent c01f6ed commit 847ce2c

File tree

13 files changed

+45
-26
lines changed

13 files changed

+45
-26
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ GEM
488488
net-protocol
489489
netstring (0.0.3)
490490
nio4r (2.5.9)
491-
nokogiri (1.18.9)
491+
nokogiri (1.19.1)
492492
mini_portile2 (~> 2.8.2)
493493
racc (~> 1.4)
494494
oj (3.11.2)

app/admin/cdr/cdr_exports.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def build_new_resource
306306
input_html: {
307307
class: 'tom-select-ajax',
308308
data: {
309-
path: '/customers_auths/search_with_return_external_id?q[ordered_by]=name&q[external_id_null]=false'
309+
path: '/customers_auths/search_with_return_external_id?q[external_id_null]=false'
310310
}
311311
},
312312
collection: if ff.object.customer_auth_external_id_in.present?

app/admin/cdr/cdrs.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def try_cdr_replica(&)
112112
},
113113
input_html: {
114114
class: 'tom-select-ajax',
115-
'data-path': '/gateways/search?q[allow_origination_eq]=true&q[ordered_by]=name'
115+
'data-path': '/gateways/search?q[allow_origination_eq]=true'
116116
}
117117

118118
filter :term_gw_id_eq,
@@ -124,7 +124,7 @@ def try_cdr_replica(&)
124124
},
125125
input_html: {
126126
class: 'tom-select-ajax',
127-
'data-path': '/gateways/search?q[allow_termination_eq]=true&q[ordered_by]=name'
127+
'data-path': '/gateways/search?q[allow_termination_eq]=true'
128128
}
129129

130130
filter :routing_plan, collection: proc { Routing::RoutingPlan.select(%i[id name]) }, input_html: { class: 'tom-select' }

app/admin/reports/interval_data.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040

4141
contractor_filter :customer_id,
4242
label: 'Customer',
43-
path_params: { q: { customer_eq: true, ordered_by: :name } },
43+
path_params: { q: { customer_eq: true } },
4444
if: proc { parent.group_by.include?('customer_id') }
4545
contractor_filter :vendor_id,
4646
label: 'Vendor',
47-
path_params: { q: { vendor_eq: true, ordered_by: :name } },
47+
path_params: { q: { vendor_eq: true } },
4848
if: proc { parent.group_by.include?('vendor_id') }
4949

5050
with_options as: :select, input_html: { class: 'tom-select' } do |f|

app/admin/reports/realtime/origination_performances.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
collection: Report::Realtime::Base::INTERVALS,
1515
input_html: { class: 'tom-select' }, include_blank: false
1616

17-
contractor_filter :customer_id_eq, label: 'Customer', path_params: { q: { customer_eq: true, ordered_by: :name } }
17+
contractor_filter :customer_id_eq, label: 'Customer', path_params: { q: { customer_eq: true } }
1818

1919
with_default_realtime_interval
2020

app/admin/reports/realtime/termination_distributions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
collection: Report::Realtime::Base::INTERVALS,
1515
input_html: { class: 'tom-select' }, include_blank: false
1616

17-
contractor_filter :customer_id_eq, label: 'Customer', path_params: { q: { customer_eq: true, ordered_by: :name } }
17+
contractor_filter :customer_id_eq, label: 'Customer', path_params: { q: { customer_eq: true } }
1818

1919
with_default_realtime_interval
2020

app/admin/system/api_accesses.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
includes :customer, :provision_gateway, :customer_portal_access_profile
2222

2323
filter :id
24-
contractor_filter :customer_id_eq, label: 'Customer', path_params: { q: { customer_eq: true, ordered_by: :name } }
24+
contractor_filter :customer_id_eq, label: 'Customer', path_params: { q: { customer_eq: true } }
2525
filter :login
2626
filter :provision_gateway,
2727
input_html: { class: 'tom-select-ajax', 'data-path': '/gateways/search' },

app/assets/javascripts/tom-select-ajax-fillable.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
window.initTomSelectAjaxFillable = function(el) {
55
var $el = $(el)
66
var path = $el.attr('data-path')
7-
if (path.includes('?') && path.indexOf('?') === -1) path += '&'
8-
if (!path.includes('?') && path.indexOf('?') === -1) path += '?'
7+
path += path.includes('?') ? '&' : '?'
98
var pathParams = $el.data('pathParams')
109
var requiredParam = $el.attr('data-required-param')
1110
var fillOnInit = $el.attr('data-fill-on-init')
@@ -18,7 +17,7 @@
1817
searchField: 'text',
1918
allowEmptyOption: true,
2019
maxOptions: null,
21-
controlInput: null, // add search box only for tom-select-ajax
20+
controlInput: null,
2221
render: {
2322
no_results: tomSelectRenderNoResultsFunc,
2423
item: tomSelectRenderItemFunc

app/assets/javascripts/tom-select-ajax.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
window.initTomSelectAjax = function (el) {
55
var $el = $(el)
66
var path = $el.attr('data-path')
7-
if (path.includes('?') && path.indexOf('?') === -1) path += '&'
8-
if (!path.includes('?') && path.indexOf('?') === -1) path += '?'
7+
path += path.includes('?') ? '&' : '?'
98
var pathParams = $el.data('pathParams')
109
var requiredParam = $el.attr('data-required-param')
1110
var key = 'k-' + Math.random().toString(36).substr(2, 9)

app/assets/javascripts/tom-select.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ function initTomSelect(parent) {
3434

3535
var plugins = []
3636
var $el = $(this)
37-
if ($el.attr('multiple')) plugins.push('remove_button')
37+
var isMultiple = !!$el.attr('multiple')
38+
if (!isMultiple) plugins.push('dropdown_input')
39+
if (isMultiple) plugins.push('remove_button')
3840
if (hasBlankOption(this)) plugins.push('clear_button')
3941
if (hasBlankOption(this) && !$el.data('allow-empty-option')) {
4042
// delete empty option from original select to avoid duplication
@@ -43,10 +45,10 @@ function initTomSelect(parent) {
4345
new TomSelect(this, {
4446
plugins: plugins,
4547
allowEmptyOption: hasBlankOption(this),
46-
// add search box only for tom-select-ajax
47-
controlInput: null,
48-
// we need to display all if we remove search input
48+
controlInput: isMultiple ? undefined : null,
4949
maxOptions: null,
50+
loadThrottle: 0,
51+
refreshThrottle: 0,
5052
onInitialize: function () {
5153
// avoid selecting first option by default
5254
if (!hasSelectedOption(this.input)) this.clear()
@@ -57,7 +59,7 @@ function initTomSelect(parent) {
5759
})
5860
})
5961

60-
// Sortable: .tom-select-sortable
62+
// Sortable: .tom-select-sortable (always multiple)
6163
parent.find('select.tom-select-sortable').each(function () {
6264
if (this.tomselect) return
6365

@@ -67,13 +69,11 @@ function initTomSelect(parent) {
6769
// delete empty option from original select to avoid duplication
6870
$el.find('option[value=""]').remove()
6971
}
70-
if ($el.data('with-search')) plugins.push('dropdown_input')
7172
new TomSelect(this, {
7273
plugins: plugins,
73-
// add search box only for tom-select-ajax
74-
controlInput: null,
75-
// we need to display all if we remove search input
7674
maxOptions: null,
75+
loadThrottle: 0,
76+
refreshThrottle: 0,
7777
onInitialize: function () {
7878
// avoid selecting first option by default
7979
if (!hasSelectedOption(this.input)) this.clear()
@@ -98,11 +98,15 @@ function initTomSelect(parent) {
9898
initTomSelectAjaxFillable(this)
9999
})
100100

101-
// Filter form selects (disable search)
101+
// Filter form selects
102102
parent.find('form.filter_form div.select_and_search > select').each(function () {
103103
if (this.tomselect) return
104104
new TomSelect(this, {
105+
plugins: ['dropdown_input'],
105106
controlInput: null,
107+
maxOptions: null,
108+
loadThrottle: 0,
109+
refreshThrottle: 0,
106110
render: {
107111
item: tomSelectRenderItemFunc
108112
}

0 commit comments

Comments
 (0)