recordselect 3.10.5 → 3.10.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README +1 -1
- data/app/assets/javascripts/jquery/record_select.js +3 -0
- data/app/assets/stylesheets/record_select.css.scss +4 -0
- data/app/views/record_select/_browse.html.erb +3 -3
- data/app/views/record_select/_list.html.erb +19 -13
- data/app/views/record_select/_search.html.erb +5 -4
- data/app/views/record_select/browse.js.erb +2 -2
- data/config/locales/en.yml +2 -0
- data/config/locales/es.yml +2 -0
- data/lib/record_select/conditions.rb +7 -2
- data/lib/record_select/config.rb +5 -0
- data/lib/record_select/engine.rb +16 -1
- data/lib/record_select/helpers/record_select_helper.rb +5 -1
- data/lib/record_select/version.rb +1 -1
- data/lib/recordselect.rb +0 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc773464f9b5721d1a6e205ab3cb7ae67f746fb9fb53747dcf0ddffe0b5cfd58
|
4
|
+
data.tar.gz: c4571682e737bf1ddc478f1c1ab78519856751d47a28990a3dc3614f1cc49f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9051ef714a6ce7eb6f52a8cf1b88ae90ad1cbbc1f5988c1873efd448f840a55bb18f1691fd9e205ca6b27744e33185b798edab0679cef8233eb1ad4bbf1a313
|
7
|
+
data.tar.gz: 115b9546c262baff6f6d27b1ab0b83ff129d0664e4450334b89d38290983868ee3c2e7426a08a2a7f7911cbef3186d7a905d20d31b0ec3159c2ea93761d6313f
|
data/README
CHANGED
@@ -5,7 +5,7 @@ RecordSelect
|
|
5
5
|
|
6
6
|
RecordSelect is a Rails widget to help you pick one record out of many. I designed it as a more usable and performant alternative to generating a massive dropdown list. It relies on AJAX for the cooler uses (all the provided view helpers rely on JavaScript?) but can also function in a pure-http fashion (although multi-select support is provided in a pure-JavaScript implementation).
|
7
7
|
|
8
|
-
Please see the ActionView::Helpers::RecordSelectHelpers for the most common API. More documentation (and HOWTOs) can be found online at
|
8
|
+
Please see the ActionView::Helpers::RecordSelectHelpers for the most common API. More documentation (and HOWTOs) can be found online at the wiki.
|
9
9
|
|
10
10
|
= DEPENDENCIES
|
11
11
|
This depends on the excellent Paginator gem by Bruce Williams. This simple gem is available at paginator.rubyforge.org.
|
@@ -143,6 +143,9 @@ jQuery(document).ready(function() {
|
|
143
143
|
if (jQuery(event.target).val()) $clear_button.addClass('enabled');
|
144
144
|
else $clear_button.removeClass('enabled');
|
145
145
|
});
|
146
|
+
jQuery(document).on('ajax:beforeSend', 'a.rs-mode', function() {
|
147
|
+
$(this).closest('.record-select').find('form input[name="rs_mode"]').val($(this).data('value'));
|
148
|
+
});
|
146
149
|
});
|
147
150
|
|
148
151
|
var RecordSelect = new Object();
|
@@ -3,9 +3,9 @@ controller ||= params[:controller]
|
|
3
3
|
record_select_id = record_select_id(controller)
|
4
4
|
-%>
|
5
5
|
<div class="record-select" id="<%= record_select_id -%>">
|
6
|
-
<%= render_record_select :
|
7
|
-
<%= render_record_select :
|
6
|
+
<%= render_record_select partial: 'search', locals: {controller: controller, record_select_id: record_select_id} %>
|
7
|
+
<%= render_record_select partial: 'list', locals: {controller: controller, page: @page, record_select_id: record_select_id} %>
|
8
8
|
</div>
|
9
9
|
<%= javascript_tag do %>
|
10
|
-
<%= render_record_select(:
|
10
|
+
<%= render_record_select(partial: 'highlight', formats: [:js]) %>
|
11
11
|
<% end %>
|
@@ -2,19 +2,26 @@
|
|
2
2
|
controller ||= params[:controller]
|
3
3
|
|
4
4
|
permit_fields = [:search] + (permit_rs_browse_params || [])
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
permit_fields << :rs_mode if record_select_config.toggle_search_mode?
|
6
|
+
pagination_url_params = params.permit(*permit_fields).merge(controller: controller, action: :browse, search: params[:search], update: 1)
|
7
|
+
prev_url = url_for(pagination_url_params.merge(page: page.prev.number)) if page.prev?
|
8
|
+
next_url = url_for(pagination_url_params.merge(page: page.next.number)) if page.next?
|
8
9
|
-%>
|
9
|
-
<%= content_tag :ol, :
|
10
|
-
<%= content_tag :li,
|
11
|
-
|
10
|
+
<%= content_tag :ol, class: ('scrollable' unless record_select_config.pagination?) do %>
|
11
|
+
<%= content_tag :li, class: 'found', data: {searching: rs_(:searching)} do %>
|
12
|
+
<%= rs_(:records_found,
|
13
|
+
count: page.pager.count,
|
14
|
+
model: record_select_config.model.model_name.human(:count => page.pager.count).downcase) %>
|
15
|
+
<% if record_select_config.toggle_search_mode? %>
|
16
|
+
<% rs_mode = full_text_search? ? 'begins' : 'contains' %>
|
17
|
+
<%= link_to rs_(rs_mode), pagination_url_params.merge(rs_mode: rs_mode),
|
18
|
+
class: 'rs-mode', method: :get, remote: true, data: {value: rs_mode} %>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
12
21
|
<% if page.prev? -%>
|
13
22
|
<li class="pagination previous">
|
14
|
-
<%= link_to image_tag('record_select/previous.gif', :
|
15
|
-
:
|
16
|
-
{:url => prev_url},
|
17
|
-
{:href => prev_url, :method => :get, :remote => true} %>
|
23
|
+
<%= link_to image_tag('record_select/previous.gif', alt: rs_(:previous)) + " " + rs_(:previous_items, count: page.pager.per_page),
|
24
|
+
prev_url, method: :get, remote: true %>
|
18
25
|
</li>
|
19
26
|
<% end -%>
|
20
27
|
<% page.items.each do |record| -%>
|
@@ -24,9 +31,8 @@ next_url = url_for(pagination_url_params.merge(:page => page.next.number)) if pa
|
|
24
31
|
<% end -%>
|
25
32
|
<% if record_select_config.pagination? && page.next? -%>
|
26
33
|
<li class="pagination next">
|
27
|
-
<%= link_to (rs_(:next_items, :
|
28
|
-
|
29
|
-
{:href => next_url, :method => :get, :remote => true} %>
|
34
|
+
<%= link_to safe_join([rs_(:next_items, count: page.pager.per_page), image_tag('record_select/next.gif', alt: rs_(:next))], ' '),
|
35
|
+
next_url, method: :get, remote: true %>
|
30
36
|
</li>
|
31
37
|
<% end -%>
|
32
38
|
<% end %>
|
@@ -1,8 +1,9 @@
|
|
1
1
|
<%
|
2
2
|
permit_fields = [:search] + (permit_rs_browse_params || [])
|
3
|
-
url_options = params.permit(*permit_fields).merge(:
|
3
|
+
url_options = params.permit(*permit_fields).merge(controller: controller, action: :browse, page: 1, update: 1)
|
4
4
|
-%>
|
5
|
-
<%= form_tag url_options, {:
|
6
|
-
<%= text_field_tag 'search', params[:search], :
|
7
|
-
<%=
|
5
|
+
<%= form_tag url_options, {method: :get, remote: true, id: record_select_search_id} -%>
|
6
|
+
<%= text_field_tag 'search', params[:search], autocomplete: 'off', class: 'text-input' %>
|
7
|
+
<%= hidden_field_tag 'rs_mode', params[:rs_mode] %>
|
8
|
+
<%= submit_tag 'search', class: "search_submit" %>
|
8
9
|
</form>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
RecordSelect.render_page('<%= record_select_id %>', '<%= escape_javascript(render_record_select(:
|
2
|
-
<%= render_record_select(:
|
1
|
+
RecordSelect.render_page('<%= record_select_id %>', '<%= escape_javascript(render_record_select(partial: 'list', locals: {page: @page})) %>');
|
2
|
+
<%= render_record_select(partial: 'highlight', formats: [:js]) %>
|
data/config/locales/en.yml
CHANGED
data/config/locales/es.yml
CHANGED
@@ -38,15 +38,20 @@ module RecordSelect
|
|
38
38
|
# override this if you want to customize the search routine
|
39
39
|
def record_select_conditions_from_search
|
40
40
|
if params[:search] && !params[:search].strip.empty?
|
41
|
-
if
|
41
|
+
if full_text_search?
|
42
42
|
tokens = params[:search].strip.split(' ')
|
43
|
+
search_pattern = '%?%'
|
43
44
|
else
|
44
45
|
tokens = [params[:search].strip]
|
46
|
+
search_pattern = '?%'
|
45
47
|
end
|
46
|
-
search_pattern = record_select_config.full_text_search? ? '%?%' : '?%'
|
47
48
|
build_record_select_conditions(tokens, record_select_like_operator, search_pattern)
|
48
49
|
end
|
49
50
|
end
|
51
|
+
|
52
|
+
def full_text_search?
|
53
|
+
record_select_config.full_text_search? && params[:rs_mode].blank? || params[:rs_mode] == 'contains'
|
54
|
+
end
|
50
55
|
|
51
56
|
def build_record_select_conditions(tokens, operator, search_pattern)
|
52
57
|
where_clauses = record_select_config.search_on.collect { |sql| "#{sql} #{operator} ?" }
|
data/lib/record_select/config.rb
CHANGED
@@ -11,6 +11,7 @@ module RecordSelect
|
|
11
11
|
@label = options[:label]
|
12
12
|
@include = options[:include]
|
13
13
|
@pagination = options.include?(:pagination) ? options[:pagination] : true
|
14
|
+
@toggle_search_mode = options[:toggle_search_mode]
|
14
15
|
end
|
15
16
|
|
16
17
|
def self.js_framework=(framework)
|
@@ -59,6 +60,10 @@ module RecordSelect
|
|
59
60
|
@full_text_search ? true : false
|
60
61
|
end
|
61
62
|
|
63
|
+
def toggle_search_mode?
|
64
|
+
@toggle_search_mode ? true : false
|
65
|
+
end
|
66
|
+
|
62
67
|
def include
|
63
68
|
@include
|
64
69
|
end
|
data/lib/record_select/engine.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
module RecordSelect
|
2
2
|
class Engine < Rails::Engine
|
3
|
-
|
3
|
+
initializer 'active_scaffold.action_controller' do
|
4
|
+
ActiveSupport.on_load :action_controller do
|
5
|
+
include RecordSelect
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer 'record_select.action_view' do
|
10
|
+
ActiveSupport.on_load :action_view do
|
11
|
+
include RecordSelectHelper
|
12
|
+
ActionView::Helpers::FormBuilder.send(:include, RecordSelect::FormBuilder)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer 'record_select.assets' do
|
17
|
+
config.assets.precompile << 'record_select/next.gif' << 'record_select/previous.gif'
|
18
|
+
end
|
4
19
|
end
|
5
20
|
end
|
@@ -61,7 +61,7 @@ module RecordSelectHelper
|
|
61
61
|
record_select_options.merge! options[:rs] if options[:rs]
|
62
62
|
|
63
63
|
html = text_field_tag(name, nil, options.merge(:autocomplete => 'off', :onfocus => "this.focused=true", :onblur => "this.focused=false"))
|
64
|
-
html << button_tag('x', type: :
|
64
|
+
html << button_tag('x', type: :button, class: clear_button_class, aria_label: 'Clear input', title: 'Clear input') if options[:clear_button]
|
65
65
|
url = url_for({:action => :browse, :controller => controller.controller_path}.merge(params))
|
66
66
|
html << javascript_tag("new RecordSelect.Single(#{options[:id].to_json}, #{url.to_json}, #{record_select_options.to_json});")
|
67
67
|
|
@@ -148,6 +148,10 @@ module RecordSelectHelper
|
|
148
148
|
controller.send :record_select_config
|
149
149
|
end
|
150
150
|
|
151
|
+
def full_text_search?
|
152
|
+
controller.send :full_text_search?
|
153
|
+
end
|
154
|
+
|
151
155
|
# The id of the RecordSelect widget for the given controller.
|
152
156
|
def record_select_id(controller = nil) #:nodoc:
|
153
157
|
controller ||= params[:controller]
|
data/lib/recordselect.rb
CHANGED
@@ -8,7 +8,3 @@ require 'record_select/config'
|
|
8
8
|
require 'record_select/form_builder'
|
9
9
|
require 'record_select/helpers/record_select_helper'
|
10
10
|
require 'record_select/engine'
|
11
|
-
|
12
|
-
ActionController::Base.send(:include, RecordSelect)
|
13
|
-
ActionView::Base.send(:include, RecordSelectHelper)
|
14
|
-
ActionView::Helpers::FormBuilder.send(:include, RecordSelect::FormBuilder)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recordselect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.10.
|
4
|
+
version: 3.10.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Cambra
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-
|
13
|
+
date: 2024-04-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|