diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 704676ba..62da7536 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -81,8 +81,17 @@ } #navbar-search { - float: right; + position: absolute; + right: 13%; + top: 15px; + color: $navbar-link-color; + background-color: white; padding: 0px 20px; + z-index: 2; + width: 15%; + height: 30px; + border-radius: 3px; + display: block; } #login_links a { diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index fe6888cd..7a175e0a 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -21,4 +21,17 @@ def opensearch format.xml { render :content_type => 'application/opensearchdescription+xml' } end end + + def search + event = Event.find_event(params[:search]) + venue = Venue.find_venue(params[:search]) + if event != [] + redirect_to '/events/'+event.first.id.to_s + elsif venue != [] + redirect_to '/venues/'+venue.first.id.to_s + else + redirect_to '/' + end + end + end diff --git a/app/models/event.rb b/app/models/event.rb index 7d5e4b31..9915cd8f 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -196,6 +196,12 @@ def self.time_for(value) end end + def self.find_event(search) + if search + Event.find(:all, :conditions => ['title LIKE ?', "%#{search}%"]) + end + end + #---[ Queries ]--------------------------------------------------------- # Returns groups of records for the site overview screen in the following format: diff --git a/app/models/venue.rb b/app/models/venue.rb index 73e9752b..95a0a761 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -153,6 +153,12 @@ def self.find_duplicates_by_type(type='na') end end + def self.find_venue(search) + if search + Venue.find(:all, :conditions => ['title LIKE ?', "%#{search}%"]) + end + end + #===[ Address helpers ]================================================= # Does this venue have any address information? diff --git a/app/views/site/_navbar.html.haml b/app/views/site/_navbar.html.haml index 866926aa..1af2f6ee 100644 --- a/app/views/site/_navbar.html.haml +++ b/app/views/site/_navbar.html.haml @@ -20,6 +20,5 @@ %li{:class => link_class[:venues]}= link_to t('.menu.venues'), venues_path %li= link_to t('.menu.new_event'), new_event_path -#navbar-search = form_tag search_events_path, :method => :get do - = text_field_tag 'query', @query, :placeholder => t('.search.placeholder') + = text_field_tag :search, nil, id: "navbar-search", :placeholder => "Search" diff --git a/config/routes.rb b/config/routes.rb index 6f961678..23019399 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,7 +15,7 @@ resources :events do collection do post :squash_many_duplicates - get :search + get :search, to: 'site#search', as: 'search' get :duplicates get :widget, :action => 'index', :widget => true get 'widget/builder', :action => 'widget_builder'