Commit a062f1485e9f7532e982b5b22045ea21f5905817
1 parent
d0d973be
Exists in
master
and in
29 other branches
ActionItem129: fixed css for autocomplete and fixed sqlite
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1922 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
88 additions
and
37 deletions
Show diff stats
app/helpers/forms_helper.rb
@@ -18,6 +18,18 @@ module FormsHelper | @@ -18,6 +18,18 @@ module FormsHelper | ||
18 | content_tag( 'label', human_name, :for => options[:id] ) | 18 | content_tag( 'label', human_name, :for => options[:id] ) |
19 | end | 19 | end |
20 | 20 | ||
21 | + def labelled_text_field( human_name, name, value=nil, options={} ) | ||
22 | + options[:id] ||= 'text-field-' + FormsHelper.next_id_number | ||
23 | + content_tag('label', human_name, :for => options[:id]) + | ||
24 | + text_field_tag( name, value, options ) | ||
25 | + end | ||
26 | + | ||
27 | + def labelled_select( human_name, name, value_method, text_method, selected, collection, options ) | ||
28 | + options[:id] ||= 'select-' + FormsHelper.next_id_number | ||
29 | + content_tag('label', human_name, :for => options[:id]) + | ||
30 | + select_tag( name, options_from_collection_for_select(collection, value_method, text_method, selected), options) | ||
31 | + end | ||
32 | + | ||
21 | protected | 33 | protected |
22 | def self.next_id_number | 34 | def self.next_id_number |
23 | if defined? @@id_num | 35 | if defined? @@id_num |
@@ -27,3 +39,4 @@ protected | @@ -27,3 +39,4 @@ protected | ||
27 | end | 39 | end |
28 | end | 40 | end |
29 | end | 41 | end |
42 | + |
app/models/product_search_block.rb
app/views/search/_search_form.rhtml
@@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
22 | <h4><%= _('Search within:') %></h4> | 22 | <h4><%= _('Search within:') %></h4> |
23 | <br style='clear:left'/> | 23 | <br style='clear:left'/> |
24 | <div> | 24 | <div> |
25 | - <label for="search-radius"><%= _('Distance: ') %></label><%= text_field_tag 'radius', '',:id => 'search-radius' %> | 25 | + <label for="search-radius"><%= _('Distance (km): ') %></label><%= text_field_tag 'radius', '',:id => 'search-radius' %> |
26 | <label for="search_region"><%= _('From: ') %></label><%= text_field :region, :name, :id => 'search_region' %> | 26 | <label for="search_region"><%= _('From: ') %></label><%= text_field :region, :name, :id => 'search_region' %> |
27 | <div id='search_region_auto_complete' class='auto-complete'></div> | 27 | <div id='search_region_auto_complete' class='auto-complete'></div> |
28 | <%= auto_complete_field('search_region', :url => {:action => 'complete_region'}) %> | 28 | <%= auto_complete_field('search_region', :url => {:action => 'complete_region'}) %> |
app/views/search/_sellers_form.rhtml
1 | -<% form_tag({:controller => 'search', :action => 'index'}, {:method => 'get'}) do %> | ||
2 | - <%= _('Category: ') %> <%= select_tag 'query', options_from_collection_for_select(@categories, :name, :name, @product_category), :width => 15 %><br/> | ||
3 | - <%= _('Distance: ') %> <%= text_field_tag 'radius' %><br/> | ||
4 | - <%= _('From: ') %> <%= text_field :region, :name, :id => 'search_region_block' %> | 1 | +<h3><%= _('Search for sellers') %></h3> |
2 | +<% form_tag({:controller => 'search', :action => 'assets'}, {:method => 'get'}) do %> | ||
3 | + <p class="search-in-opt"><%= _('Search in:') %><dir> | ||
4 | + <%= labelled_radio_button _('Products'), 'asset', 'products', true %><br /> | ||
5 | + <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', false %></dir></p> | ||
6 | + <p class="search-distance-opt"><%= labelled_text_field 'Distance (km): ', 'radius' %></p> | ||
7 | + <p class="search-from-opt"><%= labelled_text_field 'From: ', 'region[name]', nil, :id => 'search_region_block' %></p> | ||
5 | <div id='search_region_block_auto_complete' class='auto-complete'></div> | 8 | <div id='search_region_block_auto_complete' class='auto-complete'></div> |
6 | <%= auto_complete_field('search_region_block', :url => {:controller => 'search', :action => 'complete_region'}) %> | 9 | <%= auto_complete_field('search_region_block', :url => {:controller => 'search', :action => 'complete_region'}) %> |
7 | <br/> | 10 | <br/> |
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +<h1> | ||
2 | + <% if !@query.blank? %> | ||
3 | + <%=h @category ? (_('Products results for "%{query}" of enterprises in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Products results for "%s"') % @query) %> | ||
4 | + <% else %> | ||
5 | + <%=h @category ? (_('Products of enterprises in "%s"') % @category.name) : _('Products') %> | ||
6 | + <% end %> | ||
7 | +</h1> | ||
8 | + | ||
9 | +<% if @radius && @region %> | ||
10 | + <h2><%=h (_('Within %s from %s') % [@radius, @region.name]) %><h2> | ||
11 | +<% end %> | ||
12 | + | ||
13 | +<%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> | ||
14 | + | ||
15 | +<% if @found_product_categories %> | ||
16 | + <div id="product-categories-menu"> | ||
17 | + <ul> | ||
18 | + <% @found_product_categories.each do |cat, hits| %> | ||
19 | + <li><%= link_to (cat.name + "(#{hits})"), params.merge({:product_category => cat.id}) %> </li> | ||
20 | + <% end %> | ||
21 | + </ul> | ||
22 | + </div> | ||
23 | +<% end %> | ||
24 | + | ||
25 | +<div id="search-results" class="only-one-result-box"> | ||
26 | + <div class="search-results-products search-results-box"> | ||
27 | + <div class="search-results-innerbox search-results-type-product"> | ||
28 | + <ul><%= render :partial => 'product', :collection => @results[:products] %></ul> | ||
29 | + </div> | ||
30 | + <hr /> | ||
31 | + </div> | ||
32 | +</div> | ||
33 | + | ||
34 | +<br style="clear:both" /> |
config/environment.rb
@@ -98,6 +98,7 @@ require 'acts_as_having_boxes' | @@ -98,6 +98,7 @@ require 'acts_as_having_boxes' | ||
98 | require 'acts_as_having_settings' | 98 | require 'acts_as_having_settings' |
99 | require 'acts_as_having_image' | 99 | require 'acts_as_having_image' |
100 | require 'hacked_after_create' | 100 | require 'hacked_after_create' |
101 | +require 'sqlite_extension' | ||
101 | 102 | ||
102 | # load a local configuration if present, but not under test environment. | 103 | # load a local configuration if present, but not under test environment. |
103 | if ENV['RAILS_ENV'] != 'test' | 104 | if ENV['RAILS_ENV'] != 'test' |
@@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
1 | +if ActiveRecord::Base.connection.adapter_name =~ /^sqlite$/i | ||
2 | + | ||
3 | + database = ActiveRecord::Base.connection.raw_connection | ||
4 | + | ||
5 | + database.create_function('pow', 2, :numeric) do |func, base, exponent| | ||
6 | + func.set_result(base.to_f ** exponent.to_f) | ||
7 | + end | ||
8 | + | ||
9 | + database.create_function('sqrt', 1, :numeric) do |func, value| | ||
10 | + func.set_result(Math.sqrt(value)) | ||
11 | + end | ||
12 | + | ||
13 | + database.create_function('radians', 1, :numeric) do |func, value| | ||
14 | + func.set_result(value.to_f * Math::PI / 180.0) | ||
15 | + end | ||
16 | + | ||
17 | + database.create_function('spheric_distance', 5, :real) do |func, lat1, long1, lat2, long2, radius| | ||
18 | + func.set_result( | ||
19 | + radius.to_f * Math.acos( | ||
20 | + [1, | ||
21 | + Math.cos(lat1.to_f) * Math.cos(long1.to_f) * Math.cos(lat2.to_f) * Math.cos(long2.to_f) + | ||
22 | + Math.cos(lat1.to_f) * Math.sin(long1.to_f) * Math.cos(lat2.to_f) * Math.sin(long2.to_f) + | ||
23 | + Math.sin(lat1.to_f) * Math.sin(lat2.to_f) | ||
24 | + ].min | ||
25 | + ) | ||
26 | + ) | ||
27 | + end | ||
28 | +end |
public/stylesheets/common.css
@@ -231,19 +231,21 @@ table.cms-articles th, table.cms-articles td { | @@ -231,19 +231,21 @@ table.cms-articles th, table.cms-articles td { | ||
231 | /* for fields with auto-completion */ | 231 | /* for fields with auto-completion */ |
232 | div.auto-complete { | 232 | div.auto-complete { |
233 | display: block; | 233 | display: block; |
234 | - float: none; | ||
235 | background: #729FCF; | 234 | background: #729FCF; |
236 | border: 2px solid #204A87; | 235 | border: 2px solid #204A87; |
236 | + z-index: 100; | ||
237 | } | 237 | } |
238 | div.auto-complete ul { | 238 | div.auto-complete ul { |
239 | margin: 0px; | 239 | margin: 0px; |
240 | padding: 0px; | 240 | padding: 0px; |
241 | } | 241 | } |
242 | -div.auto-complete li { | 242 | +#content div.auto-complete li, div.auto-complete li { |
243 | list-style: none; | 243 | list-style: none; |
244 | margin: 0px; | 244 | margin: 0px; |
245 | padding: 0px; | 245 | padding: 0px; |
246 | color: #204A87; | 246 | color: #204A87; |
247 | + float: none; | ||
248 | + width: auto; | ||
247 | } | 249 | } |
248 | div.auto-complete li.selected { | 250 | div.auto-complete li.selected { |
249 | background: #B8CFE7; | 251 | background: #B8CFE7; |
test/unit/product_search_block_test.rb
@@ -1,15 +0,0 @@ | @@ -1,15 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../test_helper' | ||
2 | - | ||
3 | -class ProductSearchBlockTest < Test::Unit::TestCase | ||
4 | - | ||
5 | - should 'describe itself' do | ||
6 | - assert_not_equal Block.description, ProductSearchBlock.description | ||
7 | - end | ||
8 | - | ||
9 | - should 'titleize itself' do | ||
10 | - assert_not_nil ProductSearchBlock.title | ||
11 | - end | ||
12 | - | ||
13 | - should 'take block content' | ||
14 | - | ||
15 | -end |