searchgasm 0.9.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v1.0.0. Major changes in the helpers, they were completely re-engineered. Much nicer and cleaner now. I established a pattern between all helpers giving you complete flexibility as to how they are used. All helpers are called differently now (see documentation).
2
+
1
3
  v0.9.10. Hardened more tests, fixed bug with setting the per_page configuration to only take effect on protected searches, thus staying out of the way of normal searching.
2
4
 
3
5
  v0.9.9. Fixed setting per_page to nil, false, or ''. This is done to "show all" results.
data/Manifest CHANGED
@@ -22,9 +22,16 @@ lib/searchgasm/condition/tree.rb
22
22
  lib/searchgasm/conditions/base.rb
23
23
  lib/searchgasm/conditions/protection.rb
24
24
  lib/searchgasm/config.rb
25
- lib/searchgasm/helpers/form_helper.rb
26
- lib/searchgasm/helpers/search_helper.rb
27
- lib/searchgasm/helpers/utilities_helper.rb
25
+ lib/searchgasm/helpers/control_types/link.rb
26
+ lib/searchgasm/helpers/control_types/links.rb
27
+ lib/searchgasm/helpers/control_types/remote_link.rb
28
+ lib/searchgasm/helpers/control_types/remote_links.rb
29
+ lib/searchgasm/helpers/control_types/remote_select.rb
30
+ lib/searchgasm/helpers/control_types/select.rb
31
+ lib/searchgasm/helpers/control_types.rb
32
+ lib/searchgasm/helpers/form.rb
33
+ lib/searchgasm/helpers/utilities.rb
34
+ lib/searchgasm/helpers.rb
28
35
  lib/searchgasm/search/base.rb
29
36
  lib/searchgasm/search/conditions.rb
30
37
  lib/searchgasm/search/ordering.rb
data/README.rdoc CHANGED
@@ -84,19 +84,21 @@ Your view:
84
84
 
85
85
  %table
86
86
  %tr
87
- %th= order_by :first_name
88
- %th= order_by :last_name
89
- %th= order_by :email
87
+ %th= order_by_link :account => :name
88
+ %th= order_by_link :first_name
89
+ %th= order_by_link :last_name
90
+ %th= order_by_link :email
90
91
  - @users.each do |user|
91
- %tr
92
- %td= user.first_name
93
- %td= user.last_name
94
- %td= user.email
92
+ %tr
93
+ %td= user.account? ? user.account.name : "-"
94
+ %td= user.first_name
95
+ %td= user.last_name
96
+ %td= user.email
95
97
 
96
98
  Per page:
97
- = per_page
99
+ = per_page_select
98
100
  Page:
99
- = pages
101
+ = page_select
100
102
 
101
103
  <b>{See my tutorial on this example}(http://www.binarylogic.com/2008/9/7/tutorial-pagination-ordering-and-searching-with-searchgasm)</b>
102
104
 
@@ -253,6 +255,8 @@ If there is one thing we all know, it's to always use protection against SQL inj
253
255
  search = Account.new_search!(params[:search])
254
256
  conditions = Account.new_conditions!(params[:conditions])
255
257
 
258
+ I'm sure you already knew this, but it's tempting to do this when you can pass the params hash right into these methods.
259
+
256
260
  Lesson learned: use new\_search and new\_conditions when passing in params as *ANY* of the options.
257
261
 
258
262
  == Available Conditions
@@ -43,31 +43,6 @@ module Searchgasm
43
43
  @desc_indicator = value
44
44
  end
45
45
 
46
- def pages_text # :nodoc:
47
- @set_pages_text ? @pages_text : "Page %p"
48
- end
49
-
50
- # The default value for the :text options in the pages helper.
51
- #
52
- # * <tt>Default:</tt> "Page %p"
53
- # * <tt>Accepts:</tt> "Your string %p": where %p is replaced by the page number, or a block: Proc.new { |p| "Page #{p}" }
54
- def pages_text=(value)
55
- @set_pages_text = true
56
- @pages_text
57
- end
58
-
59
- def pages_type # :nodoc:
60
- @pages_type ||= :select
61
- end
62
-
63
- # The default value for the :type option in the pages helper.
64
- #
65
- # * <tt>Default:</tt> :select
66
- # * <tt>Accepts:</tt> :select, :links
67
- def pages_type=(value)
68
- @pages_type = value.to_sym
69
- end
70
-
71
46
  def per_page # :nodoc:
72
47
  @per_page
73
48
  end
@@ -95,69 +70,17 @@ module Searchgasm
95
70
  @per_page_choices = value
96
71
  end
97
72
 
98
- def per_page_type # :nodoc:
99
- @per_page_type ||= :select
100
- end
101
-
102
- # The default value for the :type option in the per_page helper.
103
- #
104
- # * <tt>Default:</tt> :select
105
- # * <tt>Accepts:</tt> :select, :links
106
- def per_page_type=(value)
107
- @per_page_type = value.to_sym
108
- end
109
-
110
73
  def hidden_fields # :nodoc:
111
74
  @hidden_fields ||= (Search::Base::SPECIAL_FIND_OPTIONS - [:page])
112
75
  end
113
76
 
114
- # Which hidden fields to automatically include when creating a form with a Searchgasm object. See Searchgasm::Helpers::FormHelper for more info.
77
+ # Which hidden fields to automatically include when creating a form with a Searchgasm object. See Searchgasm::Helpers::Form for more info.
115
78
  #
116
79
  # * <tt>Default:</tt> [:order_by, :order_as, :per_page]
117
80
  # * <tt>Accepts:</tt> Array, nil, false
118
81
  def hidden_fields=(value)
119
82
  @hidden_fields = value
120
83
  end
121
-
122
- def remote_helpers # :nodoc:
123
- @remote_helpers ||= false
124
- end
125
-
126
- # Tells all helpers to default to using remote links (AJAX) instead of normal links.
127
- #
128
- # * <tt>Default:</tt> false
129
- # * <tt>Accepts:</tt> Boolean
130
- #
131
- # nil means "Show all"
132
- def remote_helpers=(value)
133
- @remote_helpers = value
134
- end
135
-
136
- def remote_helpers? # :nodoc:
137
- remote_helpers == true
138
- end
139
-
140
- def search_scope # :nodoc:
141
-
142
- end
143
-
144
- def search_obj_name # :nodoc:
145
- @search_obj_name ||= :@search
146
- end
147
-
148
- # The instance variable name you use to assign your search to. This allows the helpers to grab your Searchgasm object without having
149
- # to specify it everywhere.
150
- #
151
- # * <tt>Default:</tt> :@search
152
- # * <tt>Accepts:</tt> String or Symbol.
153
- #
154
- # === Examples
155
- #
156
- # config.search_obj_name = :@search
157
- # config.search_obj_name = "@search"
158
- def search_obj_name=(value)
159
- @search_obj_name = value
160
- end
161
84
  end
162
85
  end
163
86
  end
@@ -0,0 +1,198 @@
1
+ module Searchgasm
2
+ module Helpers
3
+ module ControlTypes
4
+ # = Link Control Types
5
+ #
6
+ # These helpers make ordering and paginating your data a breeze in your view. They only produce links.
7
+ module Link
8
+ # Creates a link for ordering data by a column or columns
9
+ #
10
+ # === Example uses for a User class that has many orders
11
+ #
12
+ # order_by_link(:first_name)
13
+ # order_by_link([:first_name, :last_name])
14
+ # order_by_link({:orders => :total})
15
+ # order_by_link([{:orders => :total}, :first_name])
16
+ # order_by_link(:id, :text => "Order Number", :html => {:class => "order_number"})
17
+ #
18
+ # What's nifty about this is that the value gets "serialized", if it is not a string or a symbol, so that it can be passed via a param in the url. Searchgasm will automatically try to "unserializes" this value and use it. This allows you
19
+ # to pass complex objects besides strings and symbols, such as arrays and hashes. All of the hard work is done for you.
20
+ #
21
+ # Another thing to keep in mind is that this will alternate between "asc" and "desc" each time it is clicked.
22
+ #
23
+ # === Options
24
+ # * <tt>:text</tt> -- default: column_name.to_s.humanize, text for the link
25
+ # * <tt>:desc_indicator</tt> -- default: &nbsp;&#9660;, the indicator that this column is descending
26
+ # * <tt>:asc_indicator</tt> -- default: &nbsp;&#9650;, the indicator that this column is ascending
27
+ # * <tt>:html</tt> -- html arrtributes for the <a> tag.
28
+ #
29
+ # === Advanced Options
30
+ # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base leve in params such as params[:page], params[:per_page], etc, then set this to nil.
31
+ # * <tt>:search_obj</tt> -- default: @#{params_scope}, this is your search object, everything revolves around this. It will try to infer the name from your params_scope. If your params_scope is :search it will try to get @search, etc. If it can not be inferred by this, you need to pass the object itself.
32
+ def order_by_link(order_by, options = {})
33
+ order_by = deep_stringify(order_by)
34
+ add_order_by_link_defaults!(order_by, options)
35
+ html = searchgasm_state_for(:order_by, options) + searchgasm_state_for(:order_as, options)
36
+
37
+ if !options[:is_remote]
38
+ html += link_to(options[:text], options[:url], options[:html])
39
+ else
40
+ html += link_to_remote(options[:text], options[:remote].merge(:url => options[:url]), options[:html])
41
+ end
42
+
43
+ html
44
+ end
45
+
46
+ # Creates a link for ascending or descending data, pretty self e
47
+ #
48
+ # === Example uses
49
+ #
50
+ # order_as_link("asc")
51
+ # order_as_link("desc")
52
+ # order_as_link("asc", :text => "Ascending", :html => {:class => "ascending"})
53
+ #
54
+ # === Options
55
+ # * <tt>:text</tt> -- default: column_name.to_s.humanize, text for the link
56
+ # * <tt>:html</tt> -- html arrtributes for the <a> tag.
57
+ #
58
+ # === Advanced Options
59
+ # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base leve in params such as params[:page], params[:per_page], etc, then set this to nil.
60
+ # * <tt>:search_obj</tt> -- default: @#{params_scope}, this is your search object, everything revolves around this. It will try to infer the name from your params_scope. If your params_scope is :search it will try to get @search, etc. If it can not be inferred by this, you need to pass the object itself.
61
+ def order_as_link(order_as, options = {})
62
+ add_order_as_link_defaults!(order_as, options)
63
+ html = searchgasm_state_for(:order_as, options)
64
+
65
+ if !options[:is_remote]
66
+ html += link_to(options[:text], options[:url], options[:html])
67
+ else
68
+ html += link_to_remote(options[:text], options[:remote].merge(:url => options[:url]), options[:html])
69
+ end
70
+
71
+ html
72
+ end
73
+
74
+ # Creates a link for limiting how many items are on each page
75
+ #
76
+ # === Example uses
77
+ #
78
+ # per_page_link(200)
79
+ # per_page_link(nil) # => Show all
80
+ # per_page_link(nil, :text => "All", :html => {:class => "show_all"})
81
+ #
82
+ # As you can see above, passing nil means "show all" and the text will automatically revert to "show all"
83
+ #
84
+ # === Options
85
+ # * <tt>:text</tt> -- default: column_name.to_s.humanize, text for the link
86
+ # * <tt>:html</tt> -- html arrtributes for the <a> tag.
87
+ #
88
+ # === Advanced Options
89
+ # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base leve in params such as params[:page], params[:per_page], etc, then set this to nil.
90
+ # * <tt>:search_obj</tt> -- default: @#{params_scope}, this is your search object, everything revolves around this. It will try to infer the name from your params_scope. If your params_scope is :search it will try to get @search, etc. If it can not be inferred by this, you need to pass the object itself.
91
+ def per_page_link(per_page, options = {})
92
+ add_per_page_link_defaults!(per_page, options)
93
+ html = searchgasm_state_for(:per_page, options)
94
+
95
+ if !options[:is_remote]
96
+ html += link_to(options[:text], options[:url], options[:html])
97
+ else
98
+ html += link_to_remote(options[:text], options[:remote].merge(:url => options[:url]), options[:html])
99
+ end
100
+
101
+ html
102
+ end
103
+
104
+ # Creates a link for changing to a sepcific page of your data
105
+ #
106
+ # === Example uses
107
+ #
108
+ # page_link(2)
109
+ # page_link(1)
110
+ # page_link(5, :text => "Fifth page", :html => {:class => "fifth_page"})
111
+ #
112
+ # === Options
113
+ # * <tt>:text</tt> -- default: column_name.to_s.humanize, text for the link
114
+ # * <tt>:html</tt> -- html arrtributes for the <a> tag.
115
+ #
116
+ # === Advanced Options
117
+ # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base leve in params such as params[:page], params[:per_page], etc, then set this to nil.
118
+ # * <tt>:search_obj</tt> -- default: @#{params_scope}, this is your search object, everything revolves around this. It will try to infer the name from your params_scope. If your params_scope is :search it will try to get @search, etc. If it can not be inferred by this, you need to pass the object itself.
119
+ def page_link(page, options = {})
120
+ add_page_link_defaults!(page, options)
121
+ html = searchgasm_state_for(:page, options)
122
+
123
+ if !options[:is_remote]
124
+ html += link_to(options[:text], options[:url], options[:html])
125
+ else
126
+ html += link_to_remote(options[:text], options[:remote].merge(:url => options[:url]), options[:html])
127
+ end
128
+
129
+ html
130
+ end
131
+
132
+ private
133
+ def add_order_by_link_defaults!(order_by, options = {})
134
+ add_searchgasm_helper_defaults!(:order_by, options)
135
+ options[:text] ||= determine_order_by_text(order_by)
136
+ options[:asc_indicator] ||= Config.asc_indicator
137
+ options[:desc_indicator] ||= Config.desc_indicator
138
+ options[:text] += options[:search_obj].desc? ? options[:desc_indicator] : options[:asc_indicator] if options[:search_obj].order_by == order_by
139
+ url_hash = searchgasm_url_hash(:order_by, order_by, options)
140
+ url_hash[:order_as] = (options[:search_obj].order_by == order_by && options[:search_obj].asc?) ? "DESC" : "ASC"
141
+ options[:url] = searchgasm_url(url_hash, options)
142
+ options
143
+ end
144
+
145
+ def add_order_as_link_defaults!(order_as, options = {})
146
+ add_searchgasm_helper_defaults!(:order_as, options)
147
+ options[:text] ||= order_as.to_s
148
+ options[:url] = searchgasm_url(searchgasm_url_hash(:order_as, order_as, options), options)
149
+ options
150
+ end
151
+
152
+ def add_per_page_link_defaults!(per_page, options = {})
153
+ add_searchgasm_helper_defaults!(:per_page, options)
154
+ options[:text] ||= per_page.blank? ? "Show all" : "#{per_page} per page"
155
+ options[:url] = searchgasm_url(searchgasm_url_hash(:per_page, per_page, options), options)
156
+ options
157
+ end
158
+
159
+ def add_page_link_defaults!(page, options = {})
160
+ add_searchgasm_helper_defaults!(:page, options)
161
+ options[:text] ||= page.to_s
162
+ options[:url] = searchgasm_url(searchgasm_url_hash(:page, page, options), options)
163
+ options
164
+ end
165
+
166
+ def determine_order_by_text(column_name, relationship_name = nil)
167
+ case column_name
168
+ when String, Symbol
169
+ relationship_name.blank? ? column_name.to_s.titleize : "#{relationship_name.to_s.titleize} #{column_name.to_s.titleize}"
170
+ when Array
171
+ determine_order_by_text(column_name.first)
172
+ when Hash
173
+ k = column_name.keys.first
174
+ v = column_name.values.first
175
+ determine_order_by_text(v, k)
176
+ end
177
+ end
178
+
179
+ def deep_stringify(obj)
180
+ case obj
181
+ when String
182
+ obj
183
+ when Symbol
184
+ obj = obj.to_s
185
+ when Array
186
+ obj = obj.collect { |item| deep_stringify(item) }
187
+ when Hash
188
+ new_obj = {}
189
+ obj.each { |key, value| new_obj[key.to_s] = deep_stringify(value) }
190
+ new_obj
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ ActionController::Base.helper Searchgasm::Helpers::ControlTypes::Link if defined?(ActionController)
@@ -0,0 +1,149 @@
1
+ module Searchgasm
2
+ module Helpers
3
+ module ControlTypes
4
+ module Links
5
+ # Creates a group of links that order the data by a column or columns. All that this does is loop through the :choices option and call order_by_link and then glue it all together.
6
+ #
7
+ # === Examples
8
+ #
9
+ # order_by_links
10
+ # order_by_links(:choices => [:name, {:orders => {:line_items => :total}}, :email])
11
+ #
12
+ # === Options
13
+ #
14
+ # Please look at order_by_link. All options there are applicable here and are passed onto each option.
15
+ #
16
+ # * <tt>:choices</tt> -- default: the models column names, the choices to loop through when calling order_by_link
17
+ def order_by_links(options = {})
18
+ add_order_by_links_defaults!(options)
19
+ link_options = options.dup
20
+ link_options.delete(:choices)
21
+ html = ""
22
+ options[:choices].each { |choice| html += order_by_link(choice, link_options.dup) }
23
+ html
24
+ end
25
+
26
+ # Creates a group of links that ascend or descend the data. All that this does is loop through the :choices option and call order_as_link and then glue it all together.
27
+ #
28
+ # === Examples
29
+ #
30
+ # order_as_links
31
+ # order_as_links(:choices => [:ascending, :descending])
32
+ #
33
+ # === Options
34
+ #
35
+ # Please look at order_as_link. All options there are applicable here and are passed onto each option.
36
+ #
37
+ # * <tt>:choices</tt> -- default: ["asc", "desc"], the choices to loop through when calling order_as_link
38
+ def order_as_links(options = {})
39
+ add_order_as_links_defaults!(options)
40
+ link_options = options.dup
41
+ link_options.delete(:choices)
42
+ html = ""
43
+ options[:choices].each { |choice| html += order_as_link(choice, link_options.dup) }
44
+ html
45
+ end
46
+
47
+ # Creates a group of links that limit how many items are on each page. All that this does is loop through the :choices option and call per_page_link and then glue it all together.
48
+ #
49
+ # === Examples
50
+ #
51
+ # per_page_links
52
+ # per_page_links(:choices => [25, 50, nil])
53
+ #
54
+ # === Options
55
+ #
56
+ # Please look at per_page_link. All options there are applicable here and are passed onto each option.
57
+ #
58
+ # * <tt>:choices</tt> -- default: [10, 25, 50, 100, 150, 200, nil], the choices to loop through when calling per_page_link.
59
+ def per_page_links(options = {})
60
+ add_per_page_links_defaults!(options)
61
+ link_options = options.dup
62
+ link_options.delete(:choices)
63
+ html = ""
64
+ options[:choices].each { |choice| html += per_page_link(choice, link_options.dup) }
65
+ html
66
+ end
67
+
68
+ # Creates a group of links that paginate through the data. Kind of like a flickr page navigation. This one has some nifty options.
69
+ #
70
+ # === Examples
71
+ #
72
+ # page_links
73
+ # page_links(:choices => [25, 50, nil])
74
+ #
75
+ # === Options
76
+ #
77
+ # Please look at per_page_link. All options there are applicable here and are passed onto each option.
78
+ #
79
+ # * <tt>:spread</tt> -- default: 3, how many choices available on each side of the current page
80
+ # * <tt>:prev</tt> -- default: <, set to nil to omit. This is an extra link on the left side of the page links that will go to the previous page
81
+ # * <tt>:next</tt> -- default: >, set to nil to omit. This is an extra link on the right side of the page links that will go to the next page
82
+ # * <tt>:first</tt> -- default: <<, set to nil to omit. This is an extra link on thefar left side of the page links that will go to the first page
83
+ # * <tt>:last</tt> -- default: >>, set to nil to omit. This is an extra link on the far right side of the page links that will go to the last page
84
+ def page_links(options = {})
85
+ add_page_links_defaults!(options)
86
+
87
+ current_page = options[:search_obj].page
88
+ page_start = 0
89
+ page_end = 0
90
+ if !options[:spread].blank?
91
+ page_start = current_page - options[:spread]
92
+ page_start = options[:choices].first unless options[:choices].include?(page_start)
93
+ page_end = current_page + options[:spread]
94
+ page_end = options[:choices].last unless options[:choices].include?(page_end)
95
+ else
96
+ page_start = options[:choices].first
97
+ page_end = options[:choices].last
98
+ end
99
+
100
+
101
+ link_options = options.dup
102
+ [:choices, :spread, :prev, :next, :first, :last].each { |option| link_options.delete(option) }
103
+ html = ""
104
+ (page_start..page_end).each { |choice| html += page_link(choice, link_options.dup) }
105
+ html
106
+ end
107
+
108
+ private
109
+ def add_order_by_links_defaults!(options)
110
+ add_searchgasm_helper_defaults!(:order_by, options)
111
+ options[:choices] ||= options[:search_obj].klass.column_names.map(&:humanize)
112
+ options
113
+ end
114
+
115
+ def add_order_as_links_defaults!(options)
116
+ add_searchgasm_helper_defaults!(:order_as, options)
117
+ options[:choices] = [:asc, :desc]
118
+ options
119
+ end
120
+
121
+ def add_per_page_links_defaults!(options)
122
+ add_searchgasm_helper_defaults!(:per_page, options)
123
+ options[:choices] ||= Config.per_page_choices.dup
124
+ if !options[:search_obj].per_page.blank? && !options[:choices].include?(options[:search_obj].per_page)
125
+ options[:choices] << options[:search_obj].per_page
126
+ has_nil = options[:choices].include?(nil)
127
+ options[:choices].compact!
128
+ options[:choices].sort!
129
+ options[:choices] << nil if has_nil
130
+ end
131
+ options
132
+ end
133
+
134
+ def add_page_links_defaults!(options)
135
+ add_searchgasm_helper_defaults!(:page, options)
136
+ options[:choices] ||= (1..options[:search_obj].page_count)
137
+ options[:spead] ||= 3
138
+ options[:prev] ||= "<"
139
+ options[:next] ||= ">"
140
+ options[:first] ||= "<<"
141
+ options[:last] ||= ">>"
142
+ options
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ ActionController::Base.helper Searchgasm::Helpers::ControlTypes::Links if defined?(ActionController)
@@ -0,0 +1,86 @@
1
+ module Searchgasm
2
+ module Helpers
3
+ module ControlTypes
4
+ # = Remote Link Control Types
5
+ #
6
+ # These helpers use rails built in remote_function as links.
7
+ module RemoteLink
8
+ # The same thing as order_by_link but instead of using rails link_to it uses link_to_remote
9
+ #
10
+ # === Examples
11
+ #
12
+ # remote_order_by_link
13
+ # remote_order_by_link(:remote => {:update => "users"})
14
+ #
15
+ # === Options
16
+ #
17
+ # Please look at order_by_link, this accepts the same options with the following addition:
18
+ #
19
+ # * <tt>:remote</tt> -- default: {}, the options to pass into link_to_remote remote options. Such as :update => {:success => "alert('success')"}
20
+ def remote_order_by_link(order_by, options = {})
21
+ add_remote_defaults!(options)
22
+ order_by_link(order_by, options)
23
+ end
24
+
25
+ # The same thing as order_as_link but instead of using rails link_to it uses link_to_remote
26
+ #
27
+ # === Examples
28
+ #
29
+ # remote_order_as_link
30
+ # remote_order_as_link(:remote => {:update => "users"})
31
+ #
32
+ # === Options
33
+ #
34
+ # Please look at order_as_link, this accepts the same options with the following addition:
35
+ #
36
+ # * <tt>:remote</tt> -- default: {}, the options to pass into link_to_remote remote options. Such as :update => {:success => "alert('success')"}
37
+ def remote_order_as_link(order_as, options = {})
38
+ add_remote_defaults!(options)
39
+ order_as_link(order_as, options)
40
+ end
41
+
42
+ # The same thing as per_page_link but instead of using rails link_to it uses link_to_remote
43
+ #
44
+ # === Examples
45
+ #
46
+ # remote_per_page_link
47
+ # remote_per_page_link(:remote => {:update => "users"})
48
+ #
49
+ # === Options
50
+ #
51
+ # Please look at per_page_link, this accepts the same options with the following addition:
52
+ #
53
+ # * <tt>:remote</tt> -- default: {}, the options to pass into link_to_remote remote options. Such as :update => {:success => "alert('success')"}
54
+ def remote_per_page_link(per_page, options = {})
55
+ add_remote_defaults!(options)
56
+ per_page_link(per_page, options)
57
+ end
58
+
59
+ # The same thing as page_link but instead of using rails link_to it uses link_to_remote
60
+ #
61
+ # === Examples
62
+ #
63
+ # remote_page_link
64
+ # remote_page_link(:remote => {:update => "users"})
65
+ #
66
+ # === Options
67
+ #
68
+ # Please look at page_link, this accepts the same options with the following addition:
69
+ #
70
+ # * <tt>:remote</tt> -- default: {}, the options to pass into link_to_remote remote options. Such as :update => {:success => "alert('success')"}
71
+ def remote_page_link(page, options = {})
72
+ add_remote_defaults!(options)
73
+ page_link(page, options)
74
+ end
75
+
76
+ private
77
+ def add_remote_defaults!(options)
78
+ options[:remote] ||= {}
79
+ options[:is_remote] = true
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ ActionController::Base.helper Searchgasm::Helpers::ControlTypes::RemoteLink if defined?(ActionController)
@@ -0,0 +1,69 @@
1
+ module Searchgasm
2
+ module Helpers
3
+ module ControlTypes
4
+ module RemoteLinks
5
+ # Same as order_by_links, but uses link_to_remote instead of remote.
6
+ #
7
+ # === Examples
8
+ #
9
+ # remote_order_by_links
10
+ # remote_order_by_links(:remote => {:update => "users"})
11
+ #
12
+ # === Options
13
+ #
14
+ # Please look at remote_order_by_link and order_by_links. All options there are applicable here. This is just a wrapper method for those 2 methods.
15
+ def remote_order_by_links(options = {})
16
+ add_remote_defaults!(options)
17
+ order_by_links(options)
18
+ end
19
+
20
+ # Same as order_as_links, but uses link_to_remote instead of remote.
21
+ #
22
+ # === Examples
23
+ #
24
+ # remote_order_as_links
25
+ # remote_order_as_links(:remote => {:update => "users"})
26
+ #
27
+ # === Options
28
+ #
29
+ # Please look at remote_order_as_link and order_as_links. All options there are applicable here. This is just a wrapper method for those 2 methods.
30
+ def remote_order_as_links(options = {})
31
+ add_remote_defaults!(options)
32
+ order_as_link(options)
33
+ end
34
+
35
+ # Same as per_page_links, but uses link_to_remote instead of remote.
36
+ #
37
+ # === Examples
38
+ #
39
+ # remote_per_page_links
40
+ # remote_per_page_links(:remote => {:update => "users"})
41
+ #
42
+ # === Options
43
+ #
44
+ # Please look at remote_per_page_link and per_page_links. All options there are applicable here. This is just a wrapper method for those 2 methods.
45
+ def remote_per_page_links(options = {})
46
+ add_remote_defaults!(options)
47
+ per_page_links(options)
48
+ end
49
+
50
+ # Same as page_links, but uses link_to_remote instead of remote.
51
+ #
52
+ # === Examples
53
+ #
54
+ # remote_page_links
55
+ # remote_page_links(:remote => {:update => "users"})
56
+ #
57
+ # === Options
58
+ #
59
+ # Please look at remote_page_link and page_links. All options there are applicable here. This is just a wrapper method for those 2 methods.
60
+ def remote_page_links(options = {})
61
+ add_remote_defaults!(options)
62
+ page_links(options)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ ActionController::Base.helper Searchgasm::Helpers::ControlTypes::RemoteLinks if defined?(ActionController)