diff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rb
index af686d8..e0ac783 100644
--- a/app/helpers/forms_helper.rb
+++ b/app/helpers/forms_helper.rb
@@ -18,6 +18,18 @@ module FormsHelper
content_tag( 'label', human_name, :for => options[:id] )
end
+ def labelled_text_field( human_name, name, value=nil, options={} )
+ options[:id] ||= 'text-field-' + FormsHelper.next_id_number
+ content_tag('label', human_name, :for => options[:id]) +
+ text_field_tag( name, value, options )
+ end
+
+ def labelled_select( human_name, name, value_method, text_method, selected, collection, options )
+ options[:id] ||= 'select-' + FormsHelper.next_id_number
+ content_tag('label', human_name, :for => options[:id]) +
+ select_tag( name, options_from_collection_for_select(collection, value_method, text_method, selected), options)
+ end
+
protected
def self.next_id_number
if defined? @@id_num
@@ -27,3 +39,4 @@ protected
end
end
end
+
diff --git a/app/models/product_search_block.rb b/app/models/product_search_block.rb
deleted file mode 100644
index a5d9875..0000000
--- a/app/models/product_search_block.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-class ProductSearchBlock < Block
-
- def self.description
- _('A block to search products.')
- end
-
- def self.title
- _('Product search')
- end
-
- def content
- block_title(title)
- end
-
-end
diff --git a/app/views/search/_search_form.rhtml b/app/views/search/_search_form.rhtml
index f92f194..6dc97e8 100644
--- a/app/views/search/_search_form.rhtml
+++ b/app/views/search/_search_form.rhtml
@@ -22,7 +22,7 @@
<%= _('Search within:') %>
-
<%= text_field_tag 'radius', '',:id => 'search-radius' %>
+
<%= text_field_tag 'radius', '',:id => 'search-radius' %>
<%= text_field :region, :name, :id => 'search_region' %>
<%= auto_complete_field('search_region', :url => {:action => 'complete_region'}) %>
diff --git a/app/views/search/_sellers_form.rhtml b/app/views/search/_sellers_form.rhtml
index 7c7da6d..fb2d2a2 100644
--- a/app/views/search/_sellers_form.rhtml
+++ b/app/views/search/_sellers_form.rhtml
@@ -1,7 +1,10 @@
-<% form_tag({:controller => 'search', :action => 'index'}, {:method => 'get'}) do %>
- <%= _('Category: ') %> <%= select_tag 'query', options_from_collection_for_select(@categories, :name, :name, @product_category), :width => 15 %>
- <%= _('Distance: ') %> <%= text_field_tag 'radius' %>
- <%= _('From: ') %> <%= text_field :region, :name, :id => 'search_region_block' %>
+
<%= _('Search for sellers') %>
+<% form_tag({:controller => 'search', :action => 'assets'}, {:method => 'get'}) do %>
+
<%= _('Search in:') %>
+ <%= labelled_radio_button _('Products'), 'asset', 'products', true %>
+ <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', false %>
+
<%= labelled_text_field 'Distance (km): ', 'radius' %>
+
<%= labelled_text_field 'From: ', 'region[name]', nil, :id => 'search_region_block' %>
<%= auto_complete_field('search_region_block', :url => {:controller => 'search', :action => 'complete_region'}) %>
diff --git a/app/views/search/products.rhtml b/app/views/search/products.rhtml
new file mode 100644
index 0000000..3c2949b
--- /dev/null
+++ b/app/views/search/products.rhtml
@@ -0,0 +1,34 @@
+
+ <% if !@query.blank? %>
+ <%=h @category ? (_('Products results for "%{query}" of enterprises in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Products results for "%s"') % @query) %>
+ <% else %>
+ <%=h @category ? (_('Products of enterprises in "%s"') % @category.name) : _('Products') %>
+ <% end %>
+
+
+<% if @radius && @region %>
+
<%=h (_('Within %s from %s') % [@radius, @region.name]) %>
+<% end %>
+
+<%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %>
+
+<% if @found_product_categories %>
+
+<% end %>
+
+
+
+
+
<%= render :partial => 'product', :collection => @results[:products] %>
+
+
+
+
+
+
diff --git a/config/environment.rb b/config/environment.rb
index 91aa09a..8fd60b0 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -98,6 +98,7 @@ require 'acts_as_having_boxes'
require 'acts_as_having_settings'
require 'acts_as_having_image'
require 'hacked_after_create'
+require 'sqlite_extension'
# load a local configuration if present, but not under test environment.
if ENV['RAILS_ENV'] != 'test'
diff --git a/lib/sqlite_extension.rb b/lib/sqlite_extension.rb
new file mode 100644
index 0000000..e4dd9df
--- /dev/null
+++ b/lib/sqlite_extension.rb
@@ -0,0 +1,28 @@
+if ActiveRecord::Base.connection.adapter_name =~ /^sqlite$/i
+
+ database = ActiveRecord::Base.connection.raw_connection
+
+ database.create_function('pow', 2, :numeric) do |func, base, exponent|
+ func.set_result(base.to_f ** exponent.to_f)
+ end
+
+ database.create_function('sqrt', 1, :numeric) do |func, value|
+ func.set_result(Math.sqrt(value))
+ end
+
+ database.create_function('radians', 1, :numeric) do |func, value|
+ func.set_result(value.to_f * Math::PI / 180.0)
+ end
+
+ database.create_function('spheric_distance', 5, :real) do |func, lat1, long1, lat2, long2, radius|
+ func.set_result(
+ radius.to_f * Math.acos(
+ [1,
+ Math.cos(lat1.to_f) * Math.cos(long1.to_f) * Math.cos(lat2.to_f) * Math.cos(long2.to_f) +
+ Math.cos(lat1.to_f) * Math.sin(long1.to_f) * Math.cos(lat2.to_f) * Math.sin(long2.to_f) +
+ Math.sin(lat1.to_f) * Math.sin(lat2.to_f)
+ ].min
+ )
+ )
+ end
+end
diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css
index 9c4be1a..8f2838e 100644
--- a/public/stylesheets/common.css
+++ b/public/stylesheets/common.css
@@ -231,19 +231,21 @@ table.cms-articles th, table.cms-articles td {
/* for fields with auto-completion */
div.auto-complete {
display: block;
- float: none;
background: #729FCF;
border: 2px solid #204A87;
+ z-index: 100;
}
div.auto-complete ul {
margin: 0px;
padding: 0px;
}
-div.auto-complete li {
+#content div.auto-complete li, div.auto-complete li {
list-style: none;
margin: 0px;
padding: 0px;
color: #204A87;
+ float: none;
+ width: auto;
}
div.auto-complete li.selected {
background: #B8CFE7;
diff --git a/test/unit/product_search_block_test.rb b/test/unit/product_search_block_test.rb
deleted file mode 100644
index 9cb6ff7..0000000
--- a/test/unit/product_search_block_test.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
-class ProductSearchBlockTest < Test::Unit::TestCase
-
- should 'describe itself' do
- assert_not_equal Block.description, ProductSearchBlock.description
- end
-
- should 'titleize itself' do
- assert_not_nil ProductSearchBlock.title
- end
-
- should 'take block content'
-
-end
--
libgit2 0.21.2