recordselect 3.10.6 → 3.10.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a803f4cce0feb7095d6ab279c96c7c21c000c4793a18ecf31ba853201d7a657e
4
- data.tar.gz: '09a46eba1ccd474a57f85fc5898a8bb189933921ad966fc0c13f82ec8b30dab5'
3
+ metadata.gz: bc773464f9b5721d1a6e205ab3cb7ae67f746fb9fb53747dcf0ddffe0b5cfd58
4
+ data.tar.gz: c4571682e737bf1ddc478f1c1ab78519856751d47a28990a3dc3614f1cc49f2d
5
5
  SHA512:
6
- metadata.gz: b71316cb9333e52790f6f73ef953c356254ccaa2cb92a8b18efa1a34fbb644e507d41b325687e6d71cae3386673f44520db16a29fee5d7007cf163c72e25f785
7
- data.tar.gz: 0dff189b2e67a6a41c03946513ada59ffa901dfd48192c68b0c590e89b82fca3005ae4a50f9040169894be3b3103e2baa39290311ab2d060ea442e9c338fb87c
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 http://code.google.com/p/recordselect, and a demo application is available at http://recordselect.googlecode.com/svn/demo.
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();
@@ -55,6 +55,10 @@
55
55
  padding: 2px 4px;
56
56
  }
57
57
 
58
+ .record-select ol a.rs-mode {
59
+ display: inline;
60
+ }
61
+
58
62
  .record-select ol .even {
59
63
  background-color: #ffffff;
60
64
  }
@@ -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 :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} %>
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(:partial => 'highlight', :formats => [:js]) %>
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
- pagination_url_params = params.permit(*permit_fields).merge(:controller => controller, :action => :browse, :search => params[:search], :update => 1)
6
- prev_url = url_for(pagination_url_params.merge(:page => page.prev.number)) if page.prev?
7
- next_url = url_for(pagination_url_params.merge(:page => page.next.number)) if page.next?
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, :class => ('scrollable' unless record_select_config.pagination?) do %>
10
- <%= content_tag :li, rs_(:records_found, :count => page.pager.count,
11
- :model => record_select_config.model.model_name.human(:count => page.pager.count).downcase), class: 'found', data: {searching: rs_(:searching)} %>
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', :alt => rs_(:previous)) + " " + rs_(:previous_items,
15
- :count => page.pager.per_page),
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, :count => page.pager.per_page) + " " + image_tag('record_select/next.gif', :alt => rs_(:next))).html_safe,
28
- {:url => next_url},
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(:controller => controller, :action => :browse, :page => 1, :update => 1)
3
+ url_options = params.permit(*permit_fields).merge(controller: controller, action: :browse, page: 1, update: 1)
4
4
  -%>
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
- <%= submit_tag 'search', :class => "search_submit" %>
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(:partial => 'list', :locals => {:page => @page})) %>');
2
- <%= render_record_select(:partial => 'highlight', :formats => [:js]) %>
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]) %>
@@ -8,3 +8,5 @@ en:
8
8
  records_found:
9
9
  one: "1 %{model} found"
10
10
  other: "%{count} %{model} found"
11
+ contains: "Contains search"
12
+ begins: "Begins search"
@@ -12,3 +12,5 @@ es:
12
12
  records_found:
13
13
  one: "1 %{model} encontrado"
14
14
  other: "%{count} %{model} encontrados"
15
+ contains: "Buscar contiene"
16
+ begins: "Buscar empieza por"
@@ -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 record_select_config.full_text_search?
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} ?" }
@@ -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
@@ -1,5 +1,20 @@
1
1
  module RecordSelect
2
2
  class Engine < Rails::Engine
3
- config.assets.precompile << 'record_select/next.gif' << 'record_select/previous.gif' if Rails::VERSION::MAJOR >= 4
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
@@ -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]
@@ -2,7 +2,7 @@ module RecordSelect
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 10
5
- PATCH = 6
5
+ PATCH = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
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.6
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-03-21 00:00:00.000000000 Z
13
+ date: 2024-04-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler