ransack_ui 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,2 @@
1
1
  //= require ransack/predicates
2
- //= require ransack_ui_jquery/search_form
3
- //= require ransack_ui_jquery/search_tabs
2
+ //= require ransack_ui_jquery/search_form
@@ -8,7 +8,6 @@
8
8
  el.on 'click', '.remove_fields', $.proxy(this.remove_fields, this)
9
9
  el.on 'change', 'select.ransack_predicate', $.proxy(this.predicate_changed, this)
10
10
  el.on 'change', 'select.ransack_attribute', $.proxy(this.attribute_changed, this)
11
- el.on 'click focus', 'input.ransack_query', $.proxy(this.query_focus, this)
12
11
 
13
12
  # Set up Select2 on select lists in .filters
14
13
  this.init_select2(this.element.find('.filters'))
@@ -47,8 +46,8 @@
47
46
  predicate_select2 = this.element.find('#s2id_' + base_id + 'p')
48
47
  query_input = $('input#' + base_id + "v_0_value")
49
48
 
50
- # Clear any datepicker from query input
51
- query_input.datepicker('destroy')
49
+ # Initialize datepicker if column is date/datetime/time
50
+ $.proxy(this.init_datetimepicker, this)(base_id)
52
51
 
53
52
  if selected.data('ajax-url') and Select2?
54
53
  controller = selected.data('controller')
@@ -108,31 +107,6 @@
108
107
 
109
108
  return true
110
109
 
111
- query_focus: (e) ->
112
- if $.ui?.timepicker?
113
- target = $(e.currentTarget)
114
- base_id = target.attr('id').slice(0, -9)
115
- query_input = $('input#' + base_id + "v_0_value")
116
-
117
- # Only set up new datepicker if not already initialized
118
- if query_input.not('.hasDatePicker')
119
- selected_attr = this.element.find('select#' + base_id + 'a_0_name option:selected')
120
-
121
- datepicker_options =
122
- changeMonth: true
123
- constrainInput: false
124
- dateFormat: 'yy-mm-dd'
125
- # Always prefer custom input text over selected date
126
- onClose: (date) -> $(this).val(date)
127
-
128
- switch selected_attr.data('type')
129
- when "date"
130
- query_input.datepicker(datepicker_options)
131
- when "datetime"
132
- query_input.datetimepicker(datepicker_options)
133
- when "time"
134
- query_input.datetimepicker $.extend(datepicker_options, {timeOnly: true})
135
-
136
110
  # Attempts to find a predicate translation for the specific column type,
137
111
  # or returns the default label.
138
112
  # For example, 'lt' on an integer column will be translated to 'is less than',
@@ -195,7 +169,7 @@
195
169
  container.find('select.ransack_predicate').select2
196
170
  width: '130px'
197
171
  formatNoMatches: (term) ->
198
- "No predicates found"
172
+ "Select a field first"
199
173
 
200
174
  container.find('select.ransack_attribute').select2
201
175
  width: '220px'
@@ -212,4 +186,33 @@
212
186
  object.text
213
187
  else
214
188
  $(object.element).parent().attr('label') + ': ' + object.text
189
+
190
+
191
+
192
+ init_datetimepicker: (base_id) ->
193
+ if $.ui?.timepicker?
194
+ query_input = this.element.find('input#' + base_id + "v_0_value")
195
+ selected_attr = this.element.find('select#' + base_id + 'a_0_name option:selected')
196
+
197
+ # Clear any datepicker from query input first
198
+ query_input.datepicker('destroy')
199
+
200
+ datepicker_options =
201
+ changeMonth: true
202
+ constrainInput: false
203
+ dateFormat: 'yy-mm-dd'
204
+ buttonImage: "<%= asset_path('ransack_ui/calendar.png') %>"
205
+ buttonImageOnly: true
206
+ showOn: 'button'
207
+ # Always prefer custom input text over selected date
208
+ onClose: (date) -> $(this).val(date)
209
+
210
+ # Show datepicker button for dates
211
+ switch selected_attr.data('type')
212
+ when "date"
213
+ query_input.datepicker(datepicker_options)
214
+ when "datetime"
215
+ query_input.datetimepicker(datepicker_options)
216
+ when "time"
217
+ query_input.datetimepicker $.extend(datepicker_options, {timeOnly: true})
215
218
  ) jQuery
@@ -6,7 +6,7 @@
6
6
  .filters
7
7
  - f.object.build_condition unless f.object.conditions.any?
8
8
  = f.condition_fields do |c|
9
- = render 'ransack/condition_fields', :f => c
9
+ = render 'ransack_ui/condition_fields', :f => c
10
10
 
11
11
  %p
12
12
  = link_to_add_fields t(:advanced_search_add_condition), f, :condition
@@ -1,11 +1,11 @@
1
- = search_form_for search, :url => url_for(:action => :index), :html => {:method => :get, :class => "advanced_search"}, :remote => true do |f|
1
+ = search_form_for @ransack_search, :url => url_for(:action => :index), :html => {:method => :get, :class => "ransack_search"}, :remote => true do |f|
2
2
 
3
3
  :javascript
4
4
  if (window.Ransack == null) { window.Ransack = {}; }
5
5
  Ransack.alt_predicates_i18n = #{I18n.translate(:"ransack.predicates.alt", :default => {}).to_json}
6
6
 
7
7
  = f.grouping_fields do |g|
8
- = render 'ransack/grouping_fields', :f => g
8
+ = render 'ransack_ui/grouping_fields', :f => g
9
9
 
10
10
  %p
11
11
  = link_to_add_fields t(:advanced_search_add_group), f, :grouping
@@ -0,0 +1,14 @@
1
+ module RansackUI
2
+ module ControllerHelpers
3
+ # Builds @ransack_search object from params[:q]
4
+ # Infers model class from controller name.
5
+ #
6
+ # Should be used as a before_filter, e.g.:
7
+ # before_filter :load_ransack_search, :only => :index
8
+ def load_ransack_search
9
+ klass = controller_name.classify.constantize
10
+ @ransack_search = klass.search(params[:q])
11
+ @ransack_search.build_grouping unless @ransack_search.groupings.any?
12
+ end
13
+ end
14
+ end
@@ -1,4 +1,5 @@
1
1
  require 'ransack_ui/view_helpers'
2
+ require 'ransack_ui/controller_helpers'
2
3
 
3
4
  module RansackUI
4
5
  module Rails
@@ -7,8 +8,13 @@ module RansackUI
7
8
  ActionView::Base.send :include, ViewHelpers
8
9
  end
9
10
 
11
+ initializer "ransack_ui.controller_helpers" do
12
+ ActionController::Base.send :include, ControllerHelpers
13
+ end
14
+
10
15
  initializer :assets do
11
- ::Rails.application.config.assets.precompile += %w( delete.png )
16
+ # Add images to be precompiled
17
+ ::Rails.application.config.assets.precompile += %w(ransack_ui/delete.png ransack_ui/calendar.png)
12
18
  end
13
19
  end
14
20
  end
@@ -1,3 +1,3 @@
1
1
  module RansackUI
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,19 +1,19 @@
1
1
  module RansackUI
2
2
  module ViewHelpers
3
- def ransack_search_form
4
- render 'ransack/search'
3
+ def ransack_ui_search
4
+ render 'ransack_ui/search'
5
5
  end
6
6
 
7
7
  def link_to_add_fields(name, f, type)
8
8
  new_object = f.object.send "build_#{type}"
9
9
  fields = f.send("#{type}_fields", new_object, :child_index => "new_#{type}") do |builder|
10
- render "ransack/#{type.to_s}_fields", :f => builder
10
+ render "ransack_ui/#{type.to_s}_fields", :f => builder
11
11
  end
12
12
  link_to name, nil, :class => "add_fields", "data-field-type" => type, "data-content" => "#{fields}"
13
13
  end
14
14
 
15
15
  def link_to_remove_fields(name, f)
16
- link_to image_tag('delete.png', :size => '16x16', :alt => name), nil, :class => "remove_fields"
16
+ link_to image_tag('ransack_ui/delete.png', :size => '16x16', :alt => name), nil, :class => "remove_fields"
17
17
  end
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-12 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chronic
@@ -39,20 +39,19 @@ files:
39
39
  - LICENSE.txt
40
40
  - README.md
41
41
  - Rakefile
42
- - app/assets/images/delete.png
42
+ - app/assets/images/ransack_ui/calendar.png
43
+ - app/assets/images/ransack_ui/delete.png
43
44
  - app/assets/javascripts/ransack/predicates.js.coffee
44
45
  - app/assets/javascripts/ransack_ui_jquery.js
45
- - app/assets/javascripts/ransack_ui_jquery/search_form.js.coffee
46
- - app/assets/javascripts/ransack_ui_jquery/search_tabs.js.coffee
47
- - app/views/ransack/_advanced_search.html.haml
48
- - app/views/ransack/_basic_search.html.haml
49
- - app/views/ransack/_condition_fields.html.haml
50
- - app/views/ransack/_grouping_fields.html.haml
51
- - app/views/ransack/_search.html.haml
46
+ - app/assets/javascripts/ransack_ui_jquery/search_form.js.coffee.erb
47
+ - app/views/ransack_ui/_condition_fields.html.haml
48
+ - app/views/ransack_ui/_grouping_fields.html.haml
49
+ - app/views/ransack_ui/_search.html.haml
52
50
  - config/locales/en-US.yml
53
51
  - config/locales/en.yml
54
52
  - lib/core_ext/enumerable.rb
55
53
  - lib/ransack_ui.rb
54
+ - lib/ransack_ui/controller_helpers.rb
56
55
  - lib/ransack_ui/rails/engine.rb
57
56
  - lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb
58
57
  - lib/ransack_ui/ransack_overrides/configuration.rb
@@ -77,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
76
  version: '0'
78
77
  segments:
79
78
  - 0
80
- hash: 4598873639471933372
79
+ hash: -2183248768965735638
81
80
  required_rubygems_version: !ruby/object:Gem::Requirement
82
81
  none: false
83
82
  requirements:
@@ -86,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
85
  version: '0'
87
86
  segments:
88
87
  - 0
89
- hash: 4598873639471933372
88
+ hash: -2183248768965735638
90
89
  requirements: []
91
90
  rubyforge_project:
92
91
  rubygems_version: 1.8.24
@@ -1,31 +0,0 @@
1
- (($) ->
2
- $ ->
3
- # Search tabs
4
- # -----------------------------------------------------
5
- activate_search_form = (search_form) ->
6
- # Hide all
7
- $('#search .search_form').hide()
8
- $('#search .tabs li a').removeClass('active')
9
- # Show selected
10
- $('#' + search_form).show()
11
- $('a[data-search-form=' + search_form + ']').addClass('active')
12
- # Run search for current query
13
- switch search_form
14
- when 'basic_search'
15
- query_input = $('#basic_search input#query')
16
- if !query_input.is('.defaultTextActive')
17
- value = query_input.val()
18
- else
19
- value = ""
20
- crm.search(value, window.controller)
21
- $('#filters').enable() # Enable filters panel (if present)
22
-
23
- when 'advanced_search'
24
- $("#advanced_search form input:submit").click()
25
- $('#filters').disable() # Disable filters panel (if present)
26
-
27
- return
28
- $("#search .tabs a").click ->
29
- activate_search_form($(this).data('search-form'))
30
-
31
- ) jQuery
@@ -1,2 +0,0 @@
1
- %div{ :style => "margin: 0px 0px 6px 0px" }
2
- = text_field_tag('query', @current_query, :size => 32, :placeholder => "Search #{controller_name}")
@@ -1,13 +0,0 @@
1
- #search
2
- .tabs
3
- %ul
4
- %li
5
- = link_to 'Basic Search', '#', :"data-search-form" => "basic_search", :class => (params[:q] ? "" : " active")
6
- %li
7
- = link_to 'Advanced Search', '#', :"data-search-form" => "advanced_search", :class => (!params[:q] ? "" : " active")
8
-
9
- .search_form#basic_search{ :style => (params[:q] ? 'display: none;' : '') }
10
- = render "ransack/basic_search"
11
-
12
- .search_form#advanced_search{ :style => (!params[:q] ? 'display: none;' : '') }
13
- = render "ransack/advanced_search"