schof-searchlogic 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/CHANGELOG.rdoc +302 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Manifest +157 -0
  4. data/README.rdoc +461 -0
  5. data/Rakefile +13 -0
  6. data/TODO.rdoc +4 -0
  7. data/init.rb +1 -0
  8. data/lib/searchlogic.rb +100 -0
  9. data/lib/searchlogic/active_record/associations.rb +52 -0
  10. data/lib/searchlogic/active_record/base.rb +224 -0
  11. data/lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb +176 -0
  12. data/lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb +172 -0
  13. data/lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb +80 -0
  14. data/lib/searchlogic/condition/base.rb +165 -0
  15. data/lib/searchlogic/condition/begins_with.rb +17 -0
  16. data/lib/searchlogic/condition/blank.rb +21 -0
  17. data/lib/searchlogic/condition/child_of.rb +11 -0
  18. data/lib/searchlogic/condition/descendant_of.rb +11 -0
  19. data/lib/searchlogic/condition/ends_with.rb +17 -0
  20. data/lib/searchlogic/condition/equals.rb +33 -0
  21. data/lib/searchlogic/condition/greater_than.rb +15 -0
  22. data/lib/searchlogic/condition/greater_than_or_equal_to.rb +15 -0
  23. data/lib/searchlogic/condition/inclusive_descendant_of.rb +10 -0
  24. data/lib/searchlogic/condition/keywords.rb +47 -0
  25. data/lib/searchlogic/condition/less_than.rb +15 -0
  26. data/lib/searchlogic/condition/less_than_or_equal_to.rb +15 -0
  27. data/lib/searchlogic/condition/like.rb +15 -0
  28. data/lib/searchlogic/condition/nested_set.rb +17 -0
  29. data/lib/searchlogic/condition/nil.rb +21 -0
  30. data/lib/searchlogic/condition/not_begin_with.rb +20 -0
  31. data/lib/searchlogic/condition/not_blank.rb +19 -0
  32. data/lib/searchlogic/condition/not_end_with.rb +20 -0
  33. data/lib/searchlogic/condition/not_equal.rb +27 -0
  34. data/lib/searchlogic/condition/not_have_keywords.rb +20 -0
  35. data/lib/searchlogic/condition/not_like.rb +20 -0
  36. data/lib/searchlogic/condition/not_nil.rb +19 -0
  37. data/lib/searchlogic/condition/sibling_of.rb +14 -0
  38. data/lib/searchlogic/conditions/any_or_all.rb +42 -0
  39. data/lib/searchlogic/conditions/base.rb +244 -0
  40. data/lib/searchlogic/conditions/groups.rb +74 -0
  41. data/lib/searchlogic/conditions/magic_methods.rb +286 -0
  42. data/lib/searchlogic/conditions/multiparameter_attributes.rb +105 -0
  43. data/lib/searchlogic/conditions/protection.rb +36 -0
  44. data/lib/searchlogic/config.rb +31 -0
  45. data/lib/searchlogic/config/helpers.rb +338 -0
  46. data/lib/searchlogic/config/search.rb +53 -0
  47. data/lib/searchlogic/core_ext/hash.rb +75 -0
  48. data/lib/searchlogic/core_ext/object.rb +19 -0
  49. data/lib/searchlogic/helpers/control_types/link.rb +310 -0
  50. data/lib/searchlogic/helpers/control_types/links.rb +242 -0
  51. data/lib/searchlogic/helpers/control_types/remote_link.rb +87 -0
  52. data/lib/searchlogic/helpers/control_types/remote_links.rb +72 -0
  53. data/lib/searchlogic/helpers/control_types/remote_select.rb +36 -0
  54. data/lib/searchlogic/helpers/control_types/select.rb +82 -0
  55. data/lib/searchlogic/helpers/form.rb +208 -0
  56. data/lib/searchlogic/helpers/utilities.rb +197 -0
  57. data/lib/searchlogic/modifiers/absolute.rb +15 -0
  58. data/lib/searchlogic/modifiers/acos.rb +11 -0
  59. data/lib/searchlogic/modifiers/asin.rb +11 -0
  60. data/lib/searchlogic/modifiers/atan.rb +11 -0
  61. data/lib/searchlogic/modifiers/avg.rb +15 -0
  62. data/lib/searchlogic/modifiers/base.rb +27 -0
  63. data/lib/searchlogic/modifiers/ceil.rb +15 -0
  64. data/lib/searchlogic/modifiers/char_length.rb +15 -0
  65. data/lib/searchlogic/modifiers/cos.rb +15 -0
  66. data/lib/searchlogic/modifiers/cot.rb +15 -0
  67. data/lib/searchlogic/modifiers/count.rb +11 -0
  68. data/lib/searchlogic/modifiers/day_of_month.rb +15 -0
  69. data/lib/searchlogic/modifiers/day_of_week.rb +15 -0
  70. data/lib/searchlogic/modifiers/day_of_year.rb +15 -0
  71. data/lib/searchlogic/modifiers/degrees.rb +11 -0
  72. data/lib/searchlogic/modifiers/exp.rb +15 -0
  73. data/lib/searchlogic/modifiers/floor.rb +15 -0
  74. data/lib/searchlogic/modifiers/hex.rb +11 -0
  75. data/lib/searchlogic/modifiers/hour.rb +11 -0
  76. data/lib/searchlogic/modifiers/log.rb +15 -0
  77. data/lib/searchlogic/modifiers/log10.rb +11 -0
  78. data/lib/searchlogic/modifiers/log2.rb +11 -0
  79. data/lib/searchlogic/modifiers/lower.rb +15 -0
  80. data/lib/searchlogic/modifiers/ltrim.rb +15 -0
  81. data/lib/searchlogic/modifiers/md5.rb +11 -0
  82. data/lib/searchlogic/modifiers/microseconds.rb +11 -0
  83. data/lib/searchlogic/modifiers/milliseconds.rb +11 -0
  84. data/lib/searchlogic/modifiers/minute.rb +15 -0
  85. data/lib/searchlogic/modifiers/month.rb +15 -0
  86. data/lib/searchlogic/modifiers/octal.rb +15 -0
  87. data/lib/searchlogic/modifiers/radians.rb +11 -0
  88. data/lib/searchlogic/modifiers/round.rb +11 -0
  89. data/lib/searchlogic/modifiers/rtrim.rb +15 -0
  90. data/lib/searchlogic/modifiers/second.rb +15 -0
  91. data/lib/searchlogic/modifiers/sign.rb +11 -0
  92. data/lib/searchlogic/modifiers/sin.rb +11 -0
  93. data/lib/searchlogic/modifiers/square_root.rb +15 -0
  94. data/lib/searchlogic/modifiers/sum.rb +11 -0
  95. data/lib/searchlogic/modifiers/tan.rb +15 -0
  96. data/lib/searchlogic/modifiers/trim.rb +15 -0
  97. data/lib/searchlogic/modifiers/upper.rb +15 -0
  98. data/lib/searchlogic/modifiers/week.rb +11 -0
  99. data/lib/searchlogic/modifiers/year.rb +11 -0
  100. data/lib/searchlogic/search/base.rb +148 -0
  101. data/lib/searchlogic/search/conditions.rb +53 -0
  102. data/lib/searchlogic/search/ordering.rb +244 -0
  103. data/lib/searchlogic/search/pagination.rb +121 -0
  104. data/lib/searchlogic/search/protection.rb +89 -0
  105. data/lib/searchlogic/search/searching.rb +32 -0
  106. data/lib/searchlogic/shared/utilities.rb +56 -0
  107. data/lib/searchlogic/shared/virtual_classes.rb +39 -0
  108. data/lib/searchlogic/version.rb +79 -0
  109. data/searchlogic.gemspec +41 -0
  110. data/test/active_record_tests/associations_test.rb +94 -0
  111. data/test/active_record_tests/base_test.rb +115 -0
  112. data/test/condition_tests/base_test.rb +54 -0
  113. data/test/condition_tests/begins_with_test.rb +11 -0
  114. data/test/condition_tests/blank_test.rb +31 -0
  115. data/test/condition_tests/child_of_test.rb +17 -0
  116. data/test/condition_tests/descendant_of_test.rb +12 -0
  117. data/test/condition_tests/ends_with_test.rb +11 -0
  118. data/test/condition_tests/equals_test.rb +28 -0
  119. data/test/condition_tests/greater_than_or_equal_to_test.rb +11 -0
  120. data/test/condition_tests/greater_than_test.rb +11 -0
  121. data/test/condition_tests/inclusive_descendant_of_test.rb +12 -0
  122. data/test/condition_tests/keywords_test.rb +23 -0
  123. data/test/condition_tests/less_than_or_equal_to_test.rb +11 -0
  124. data/test/condition_tests/less_than_test.rb +11 -0
  125. data/test/condition_tests/like_test.rb +11 -0
  126. data/test/condition_tests/nil_test.rb +31 -0
  127. data/test/condition_tests/not_begin_with_test.rb +8 -0
  128. data/test/condition_tests/not_blank_test.rb +8 -0
  129. data/test/condition_tests/not_end_with_test.rb +8 -0
  130. data/test/condition_tests/not_equal_test.rb +19 -0
  131. data/test/condition_tests/not_have_keywords_test.rb +8 -0
  132. data/test/condition_tests/not_like_test.rb +8 -0
  133. data/test/condition_tests/not_nil_test.rb +13 -0
  134. data/test/condition_tests/sibling_of_test.rb +15 -0
  135. data/test/conditions_tests/any_or_all_test.rb +23 -0
  136. data/test/conditions_tests/base_test.rb +185 -0
  137. data/test/conditions_tests/groups_test.rb +68 -0
  138. data/test/conditions_tests/magic_methods_test.rb +36 -0
  139. data/test/conditions_tests/multiparameter_attributes_test.rb +15 -0
  140. data/test/conditions_tests/protection_test.rb +18 -0
  141. data/test/config_test.rb +23 -0
  142. data/test/fixtures/accounts.yml +12 -0
  143. data/test/fixtures/animals.yml +7 -0
  144. data/test/fixtures/orders.yml +12 -0
  145. data/test/fixtures/user_groups.yml +5 -0
  146. data/test/fixtures/users.yml +45 -0
  147. data/test/libs/awesome_nested_set.rb +545 -0
  148. data/test/libs/awesome_nested_set/compatability.rb +29 -0
  149. data/test/libs/awesome_nested_set/helper.rb +40 -0
  150. data/test/libs/awesome_nested_set/named_scope.rb +140 -0
  151. data/test/libs/rexml_fix.rb +14 -0
  152. data/test/modifier_tests/day_of_month_test.rb +16 -0
  153. data/test/search_tests/base_test.rb +241 -0
  154. data/test/search_tests/conditions_test.rb +21 -0
  155. data/test/search_tests/ordering_test.rb +167 -0
  156. data/test/search_tests/pagination_test.rb +74 -0
  157. data/test/search_tests/protection_test.rb +26 -0
  158. data/test/test_helper.rb +116 -0
  159. metadata +385 -0
@@ -0,0 +1,242 @@
1
+ module Searchlogic
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
+ links_options = options.deep_dup
20
+ links_options.delete(:choices)
21
+ html = ""
22
+ options[:choices].each do |choice|
23
+ link_options = links_option.deep_dup
24
+ text, value = option_text_and_value(choice)
25
+ link_options[:text] ||= text
26
+ html += order_by_link(value, link_options)
27
+ end
28
+ html
29
+ end
30
+
31
+ # 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.
32
+ #
33
+ # === Examples
34
+ #
35
+ # order_as_links
36
+ # order_as_links(:choices => [:ascending, :descending])
37
+ #
38
+ # === Options
39
+ #
40
+ # Please look at order_as_link. All options there are applicable here and are passed onto each option.
41
+ #
42
+ # * <tt>:choices</tt> -- default: ["asc", "desc"], the choices to loop through when calling order_as_link
43
+ def order_as_links(options = {})
44
+ add_order_as_links_defaults!(options)
45
+ links_options = options.deep_dup
46
+ links_options.delete(:choices)
47
+ html = ""
48
+ options[:choices].each do |choice|
49
+ link_options = links_option.deep_dup
50
+ text, value = option_text_and_value(choice)
51
+ link_options[:text] ||= text
52
+ html += order_as_link(value, link_options)
53
+ end
54
+ html
55
+ end
56
+
57
+ # 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.
58
+ #
59
+ # === Examples
60
+ #
61
+ # per_page_links
62
+ # per_page_links(:choices => [25, 50, nil])
63
+ #
64
+ # === Options
65
+ #
66
+ # Please look at per_page_link. All options there are applicable here and are passed onto each option.
67
+ #
68
+ # * <tt>:choices</tt> -- default: [["10 per page", 10], ["25 per page", 25], ["50 per page", 50], ["100 per page", 100], ["150 per page", 150], ["200 per page", 200], ["Show all", nil]]
69
+ def per_page_links(options = {})
70
+ add_per_page_links_defaults!(options)
71
+ links_options = options.deep_dup
72
+ links_options.delete(:choices)
73
+ html = ""
74
+ options[:choices].each do |choice|
75
+ link_options = links_options.deep_dup
76
+ text, value = option_text_and_value(choice)
77
+ link_options[:text] ||= text
78
+ searchlogic_add_class!(link_options[:html], Config.helpers.order_by_links_ordering_by_class_name) if link_options[:search_obj].per_page == value
79
+ html += per_page_link(value, link_options)
80
+ end
81
+ html
82
+ end
83
+
84
+ # Creates a group of links that paginate through the data. Kind of like a flickr page navigation. This one has some nifty options.
85
+ #
86
+ # === Examples
87
+ #
88
+ # page_links
89
+ # page_links(:first => "<< First", :last => "Last >>")
90
+ #
91
+ # === Classes and tags
92
+ #
93
+ # If the user is on the current page they will get a <span> tag, not an <a> tag. If they are on the first page the "first" and "prev" options will be a <span> also. The same goes
94
+ # for "next" and "last" if the user is on the last page. Other than that each element will come with a CSS class so you can style it to your liking. Somtimes the easiest way to understand this
95
+ # Is to either look at the example (linked in the README) or try it out and view the HTML source. It's pretty simple, but here are the explanations:
96
+ #
97
+ # * <tt>page</tt> - This is in *every* element, span or a.
98
+ # * <tt>first_page</tt> - This is for the "first page" element only.
99
+ # * <tt>prev_page</tt> - This is for the "prev page" element only.
100
+ # * <tt>current_page</tt> - This is for the current page element
101
+ # * <tt>next_page</tt> - This is for the "next page" element only.
102
+ # * <tt>last_page</tt> - This is for the "last page" element only.
103
+ # * <tt>disabled_page</tt> - Any element that is a span instead of an a tag.
104
+ #
105
+ # === Options
106
+ #
107
+ # Please look at per_page_link. All options there are applicable here and are passed onto each option.
108
+ #
109
+ # * <tt>:inner_spread</tt> -- default: 3, set to nil to show all pages, set 0 to show no page links. This represents how many choices available on each side of the current page
110
+ # * <tt>:outer_spread</tt> -- default: 1, set to nil to disable, set to 0 show no outer spread but the separator will still be present. This represents how many choices are in the "outer" spread.
111
+ # * <tt>:prev</tt> -- default: "< Prev", 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
112
+ # * <tt>:next</tt> -- default: "Next >", 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
113
+ # * <tt>:first</tt> -- default: nil, 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
114
+ # * <tt>:last</tt> -- default: nil, 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
115
+ def page_links(options = {})
116
+ add_page_links_defaults!(options)
117
+ return if options[:last_page] <= 1
118
+
119
+ inner_spread_start = inner_spread_end = lower_gap = lower_outer_spread_start = lower_outer_spread_end = upper_gap = upper_outer_spread_start = upper_outer_spread_end = 0
120
+ if !options[:inner_spread].blank?
121
+ inner_spread_start = options[:current_page] - options[:inner_spread]
122
+ inner_spread_start = options[:first_page] if inner_spread_start < options[:first_page]
123
+ inner_spread_end = options[:current_page] + options[:inner_spread]
124
+ inner_spread_end = options[:last_page] if inner_spread_end > options[:last_page]
125
+
126
+ if !options[:outer_spread].blank?
127
+ lower_gap = inner_spread_start - options[:first_page]
128
+ if lower_gap > 0
129
+ lower_outer_spread_start = options[:first_page]
130
+ lower_outer_spread_end = options[:outer_spread] > lower_gap ? lower_gap : options[:outer_spread]
131
+ end
132
+
133
+ upper_gap = options[:last_page] - inner_spread_end
134
+ if upper_gap > 0
135
+ upper_outer_spread_start = options[:last_page] - (options[:outer_spread] > upper_gap ? upper_gap : options[:outer_spread]) + 1
136
+ upper_outer_spread_end = options[:last_page]
137
+ end
138
+ end
139
+ else
140
+ inner_spread_start = options[:first_page]
141
+ inner_spread_end = options[:last_page]
142
+ end
143
+
144
+ html = ""
145
+ html += span_or_page_link(:first, options.deep_dup, options[:current_page] == options[:first_page]) if options[:first]
146
+ html += span_or_page_link(:prev, options.deep_dup, options[:current_page] == options[:first_page]) if options[:prev]
147
+
148
+ if lower_gap > 0
149
+ (lower_outer_spread_start..lower_outer_spread_end).each { |page| html += span_or_page_link(page, options.deep_dup, false) }
150
+ html += content_tag(:span, "&hellip;", options[:html]) if (inner_spread_start - lower_outer_spread_end) > 1
151
+ end
152
+
153
+ (inner_spread_start..inner_spread_end).each { |page| html += span_or_page_link(page, options.deep_dup, page == options[:current_page]) }
154
+
155
+ if upper_gap > 0
156
+ html += content_tag(:span, "&hellip;", options[:html]) if (upper_outer_spread_start - inner_spread_end) > 1
157
+ (upper_outer_spread_start..upper_outer_spread_end).each { |page| html += span_or_page_link(page, options.deep_dup, false) }
158
+ end
159
+
160
+ html += span_or_page_link(:next, options.deep_dup, options[:current_page] == options[:last_page]) if options[:next]
161
+ html += span_or_page_link(:last, options.deep_dup, options[:current_page] == options[:last_page]) if options[:last]
162
+ html = content_tag(:div, html, :class => Config.helpers.page_links_div_wrapper_class_name) if Config.helpers.page_links_div_wrapper
163
+ html
164
+ end
165
+
166
+ private
167
+ def add_order_by_links_defaults!(options)
168
+ add_searchlogic_control_defaults!(options)
169
+ options[:choices] ||= options[:search_obj].klass.column_names.map(&:humanize)
170
+ options
171
+ end
172
+
173
+ def add_order_as_links_defaults!(options)
174
+ add_searchlogic_control_defaults!(options)
175
+ options[:choices] = [:asc, :desc]
176
+ options
177
+ end
178
+
179
+ def add_per_page_links_defaults!(options)
180
+ add_searchlogic_control_defaults!(options)
181
+ options[:choices] ||= Config.helpers.per_page_links_choices.dup
182
+ if !options[:search_obj].per_page.blank? && !choices_include?(options[:choices], options[:search_obj].per_page)
183
+ options[:choices] << ["#{options[:search_obj].per_page} per page", options[:search_obj].per_page]
184
+ options[:choices].sort! do |a, b|
185
+ a_value = (a.is_a?(Array) ? a.last : a).to_i
186
+ return -1 if a_value == 0
187
+ b_value = (b.is_a?(Array) ? b.last : b).to_i
188
+ a_value <=> b_value
189
+ end
190
+ end
191
+ options
192
+ end
193
+
194
+ def choices_include?(choices, includes)
195
+ choices.each do |choice|
196
+ value = choice.is_a?(Array) ? choice.last : choice
197
+ return true if value == includes
198
+ end
199
+ false
200
+ end
201
+
202
+ def add_page_links_defaults!(options)
203
+ add_searchlogic_control_defaults!(options)
204
+ options[:first_page] ||= 1
205
+ options[:last_page] ||= options[:search_obj].page_count
206
+ options[:current_page] ||= options[:search_obj].page
207
+ options[:inner_spread] = Config.helpers.page_links_inner_spread unless options.has_key?(:inner_spread)
208
+ options[:outer_spread] = Config.helpers.page_links_outer_spread unless options.has_key?(:outer_spread)
209
+ options[:prev] = Config.helpers.page_links_prev unless options.has_key?(:prev)
210
+ options[:next] = Config.helpers.page_links_next unless options.has_key?(:next)
211
+ options[:first] = Config.helpers.page_links_first unless options.has_key?(:first)
212
+ options[:last] = Config.helpers.page_links_last unless options.has_key?(:last)
213
+ options
214
+ end
215
+
216
+ def span_or_page_link(name, options, span)
217
+ text = ""
218
+ page = 0
219
+ case name
220
+ when Fixnum
221
+ text = name
222
+ page = name
223
+ searchlogic_add_class!(options[:html], Config.helpers.page_links_current_page_class_name) if span
224
+ else
225
+ text = options[name]
226
+ page = options[:search_obj].send("#{name}_page")
227
+ searchlogic_add_class!(options[:html], Config.helpers.send("page_links_#{name}_page_class_name"))
228
+ end
229
+
230
+ if span
231
+ searchlogic_add_class!(options[:html], Config.helpers.page_links_disabled_class_name)
232
+ searchlogic_add_class!(options[:html], Config.helpers.page_link_class_name)
233
+ end
234
+ options[:text] = text
235
+ span ? content_tag(:span, text, options[:html]) : page_link(page, options)
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
241
+
242
+ ActionController::Base.helper Searchlogic::Helpers::ControlTypes::Links if defined?(ActionController)
@@ -0,0 +1,87 @@
1
+ module Searchlogic
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[:remote][:method] ||= :get
80
+ options[:is_remote] = true
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ ActionController::Base.helper Searchlogic::Helpers::ControlTypes::RemoteLink if defined?(ActionController)
@@ -0,0 +1,72 @@
1
+ module Searchlogic
2
+ module Helpers
3
+ module ControlTypes
4
+ # = Remote Links Control Types
5
+ #
6
+ # These helpers use rails built in remote_function as links. They are the same thing as the Links control type, but just use rails built in remote helpers.
7
+ module RemoteLinks
8
+ # Same as order_by_links, but uses link_to_remote instead of remote.
9
+ #
10
+ # === Examples
11
+ #
12
+ # remote_order_by_links
13
+ # remote_order_by_links(:remote => {:update => "users"})
14
+ #
15
+ # === Options
16
+ #
17
+ # 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.
18
+ def remote_order_by_links(options = {})
19
+ add_remote_defaults!(options)
20
+ order_by_links(options)
21
+ end
22
+
23
+ # Same as order_as_links, but uses link_to_remote instead of remote.
24
+ #
25
+ # === Examples
26
+ #
27
+ # remote_order_as_links
28
+ # remote_order_as_links(:remote => {:update => "users"})
29
+ #
30
+ # === Options
31
+ #
32
+ # 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.
33
+ def remote_order_as_links(options = {})
34
+ add_remote_defaults!(options)
35
+ order_as_link(options)
36
+ end
37
+
38
+ # Same as per_page_links, but uses link_to_remote instead of remote.
39
+ #
40
+ # === Examples
41
+ #
42
+ # remote_per_page_links
43
+ # remote_per_page_links(:remote => {:update => "users"})
44
+ #
45
+ # === Options
46
+ #
47
+ # 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.
48
+ def remote_per_page_links(options = {})
49
+ add_remote_defaults!(options)
50
+ per_page_links(options)
51
+ end
52
+
53
+ # Same as page_links, but uses link_to_remote instead of remote.
54
+ #
55
+ # === Examples
56
+ #
57
+ # remote_page_links
58
+ # remote_page_links(:remote => {:update => "users"})
59
+ #
60
+ # === Options
61
+ #
62
+ # 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.
63
+ def remote_page_links(options = {})
64
+ add_remote_defaults!(options)
65
+ page_links(options)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ ActionController::Base.helper Searchlogic::Helpers::ControlTypes::RemoteLinks if defined?(ActionController)
@@ -0,0 +1,36 @@
1
+ module Searchlogic
2
+ module Helpers
3
+ module ControlTypes
4
+ # = Remote Select Control Types
5
+ #
6
+ # These helpers use rails built in remote_function as links. They are the same thing as the Select control type, but just use rails built in remote helpers.
7
+ module RemoteSelect
8
+ # Please see order_by_links. All options are the same and applicable here. The only difference is that instead of a group of links, this gets returned as a select form element that will perform the same function when the value is changed.
9
+ def remote_order_by_select(options = {})
10
+ add_remote_defaults!(options)
11
+ order_by_select(options)
12
+ end
13
+
14
+ # Please see order_as_links. All options are the same and applicable here. The only difference is that instead of a group of links, this gets returned as a select form element that will perform the same function when the value is changed.
15
+ def remote_order_as_select(options = {})
16
+ add_remote_defaults!(options)
17
+ order_as_select(options)
18
+ end
19
+
20
+ # Please see per_page_links. All options are the same and applicable here. The only difference is that instead of a group of links, this gets returned as a select form element that will perform the same function when the value is changed.
21
+ def remote_per_page_select(options = {})
22
+ add_remote_defaults!(options)
23
+ per_page_select(options)
24
+ end
25
+
26
+ # Please see page_links. All options are the same and applicable here, except the :prev, :next, :first, and :last options. The only difference is that instead of a group of links, this gets returned as a select form element that will perform the same function when the value is changed.
27
+ def remote_page_select(options = {})
28
+ add_remote_defaults!(options)
29
+ page_select(options)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ ActionController::Base.helper Searchlogic::Helpers::ControlTypes::RemoteSelect if defined?(ActionController)
@@ -0,0 +1,82 @@
1
+ module Searchlogic
2
+ module Helpers
3
+ module ControlTypes
4
+ # = Select Control Types
5
+ #
6
+ # These create <select> tags to help navigate through search data. This is here as an alternative to the Links control types.
7
+ module Select
8
+ # Please see order_by_links. All options are the same and applicable here. The only difference is that instead of a group of links, this gets returned as a select form element that will perform the same function when the value is changed.
9
+ def order_by_select(options = {})
10
+ add_order_by_select_defaults!(options)
11
+ searchlogic_state(options) + select(options[:params_scope], :order_by, options[:choices], options[:tag], options[:html] || {})
12
+ end
13
+
14
+ # Please see order_as_links. All options are the same and applicable here. The only difference is that instead of a group of links, this gets returned as a select form element that will perform the same function when the value is changed.
15
+ def order_as_select(options = {})
16
+ add_order_as_select_defaults!(options)
17
+ searchlogic_state(options) + select(options[:params_scope], :order_as, options[:choices], options[:tag], options[:html])
18
+ end
19
+
20
+ # Please see per_page_links. All options are the same and applicable here. The only difference is that instead of a group of links, this gets returned as a select form element that will perform the same function when the value is changed.
21
+ def per_page_select(options = {})
22
+ add_per_page_select_defaults!(options)
23
+ searchlogic_state(options) + select(options[:params_scope], :per_page, options[:choices], options[:tag], options[:html])
24
+ end
25
+
26
+ # Please see page_links. All options are the same and applicable here, excep the :prev, :next, :first, and :last options. The only difference is that instead of a group of links, this gets returned as a select form element that will perform the same function when the value is changed.
27
+ def page_select(options = {})
28
+ add_page_select_defaults!(options)
29
+ searchlogic_state(options) + select(options[:params_scope], :page, (options[:first_page]..options[:last_page]), options[:tag], options[:html])
30
+ end
31
+
32
+ private
33
+ def add_order_by_select_defaults!(options)
34
+ add_order_by_links_defaults!(options)
35
+ searchlogic_add_class!(options[:html], Config.helpers.order_by_select_class_name)
36
+ add_searchlogic_select_defaults!(:order_by, options)
37
+ options
38
+ end
39
+
40
+ def add_order_as_select_defaults!(options)
41
+ add_order_as_links_defaults!(options)
42
+ searchlogic_add_class!(options[:html], Config.helpers.order_as_select_class_name)
43
+ add_searchlogic_select_defaults!(:order_as, options)
44
+ options
45
+ end
46
+
47
+ def add_per_page_select_defaults!(options)
48
+ add_per_page_links_defaults!(options)
49
+ searchlogic_add_class!(options[:html], Config.helpers.per_page_select_class_name)
50
+ add_searchlogic_select_defaults!(:per_page, options)
51
+ options
52
+ end
53
+
54
+ def add_page_select_defaults!(options)
55
+ add_page_links_defaults!(options)
56
+ searchlogic_add_class!(options[:html], Config.helpers.page_select_class_name)
57
+ add_searchlogic_select_defaults!(:page, options)
58
+ options
59
+ end
60
+
61
+ def add_searchlogic_select_defaults!(option, options)
62
+ options[:tag] ||= {}
63
+ options[:tag][:object] = options[:search_obj]
64
+
65
+ url = searchlogic_url(options.merge(:literal_search_params => {option => "'+this.value+'"}))
66
+
67
+ options[:html][:onchange] ||= ""
68
+ options[:html][:onchange] += ";"
69
+ if !options[:remote]
70
+ options[:html][:onchange] += "window.location='#{url}';"
71
+ else
72
+ options[:html][:onchange] += remote_function(:url => url, :method => :get).gsub(/\\'\+this.value\+\\'/, "'+this.value+'")
73
+ end
74
+ options[:html][:id] ||= "#{option}_select"
75
+ options
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ ActionController::Base.helper Searchlogic::Helpers::ControlTypes::Select if defined?(ActionController)