Permalink
Browse files

selectors

  • Loading branch information...
1 parent ba9dc87 commit 5d8716ed562e13de85c0add991250ca2052b8aee @kristianmandrup committed Sep 11, 2012
View
@@ -81,7 +81,7 @@ PATH
PATH
remote: /Users/kmandrup/private/repos/jquery-ui-rails-helpers
specs:
- jquery_ui_rails_helpers (0.1.4)
+ jquery_ui_rails_helpers (0.1.6)
haml
PATH
@@ -1 +1,17 @@
# Define your coffeescript code for the TopBar::Form widget
+namespace "Widget.topBar"
+ Form:
+ class Form
+ constructor : (@widget_id = widget_id) ->
+
+ search: (@search = search) ->
+ # add custom widget function here
+ # pass in the id of the property
+ show: (options) ->
+ $('select#rooms_from, select#rooms_to').selectToUISlider labels :5, scaleAndTics: false, hideSlider: true
+ $('select#size_from, select#size_to').selectToUISlider labels:3, scaleAndTics: false, hideSlider: true
+ $('select#cost_from, select#cost_to').selectToUISlider labels:3, scaleAndTics: false, hideSlider: true
+
+$ ->
+ Widgets.topBar.form = new Widget.topBar.Form()
+
@@ -9,6 +9,6 @@ Sass will respect your existing definition rather than overwriting it with the B
@import 'bootstrap/overrides';
/* Fonts */
-@import 'my-font-awesome';
+@import 'font-awesome-sass';
// @import 'ui-bootstrap/jquery-ui-bootstrap.latest';
Oops, something went wrong.
@@ -0,0 +1,15 @@
+class Search
+ module Form
+ class ButtonsetSelector < MultipleSelector
+ def selector id, checkbox_hash = {}
+ content_tag :div, id: id do
+ create_checkboxes checkbox_hash
+ end
+ end
+
+ def js_enable
+ "$('.checkboxes' ).buttonset();"
+ end
+ end
+ end
+end
@@ -0,0 +1,13 @@
+class Search
+ module Form
+ class CheckboxSelector < MultipleSelector
+ protected
+
+ def create_checkboxes hash
+ hash.inject('') do |res,(key, label)|
+ res << s check_box_tag(key), label_tag(key, label)
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,13 @@
+class Search
+ module Form
+ class CheckboxesSelector < MultipleSelector
+ def selector checkbox_hash = {}
+ s create_checkboxes checkbox_hash
+ end
+
+ def js_enable
+ "$('form input').filter(:checkbox, :radio).checkbox();"
+ end
+ end
+ end
+end
@@ -0,0 +1,87 @@
+class Search
+ module Form
+ class DateRangeSelector < Selector
+ def label
+ "#{from} - #{to}"
+ end
+
+ def selector
+ ui_daterange html: html_options, ui: ui_options
+ end
+
+ protected
+
+ def labels
+ I18n.t("search.form.selector.#{name}.labels")
+ end
+
+ # rangeStartTitle: 'Start date',
+ # rangeEndTitle: 'End date',
+ # nextLinkText: 'Next',
+ # prevLinkText: 'Prev',
+ # doneButtonText: 'Done',
+ # earliestDate: Date.parse('-15years'), //earliest date allowed
+ # latestDate: Date.parse('+15years'), //latest date allowed
+ # rangeSplitter: '-', //string to use between dates in single input
+ # dateFormat: 'm/d/yy', // date formatting. Available formats: http://docs.jquery.com/UI/Datepicker/%24.datepicker.formatDate
+ # closeOnSelect: true, //if a complete selection is made, close the menu
+ # arrows: false,
+ def ui_options
+ {
+ rangeStartTitle: range_start_title, rangeEndTitle: range_end_title, nextLinkText: next_link_text, prevLinkText: prev_link_text, doneButtonText: done_button_text,
+ earliestDate: earliest_date, latestDate: latest_date, dateFormat: date_format
+ }
+ end
+
+ def range_start_title
+ i18n :start_date
+ end
+
+ def range_end_title
+ i18n :end_date
+ end
+
+ def next_link_text
+ i18n :next
+ end
+
+ def prev_link_text
+ i18n :previous
+ end
+
+ def done_button_text
+ i18n :done_button
+ end
+
+ def latest_date
+ Date.parse("-#{period_forward}")
+ end
+
+ def earliest_date
+ Date.parse("-#{period_back}")
+ end
+
+ # fx '14 days'
+ def period_back
+ i18n :period_back
+ end
+
+ # fx '1year'
+ def period_forward
+ i18n :period_forward
+ end
+
+ def latest_date
+ Date.parse('+1year')
+ end
+
+ def date_format
+ i18n :date_format
+ end
+
+ def html_options
+ {id: name, class: "daterange hidden"}
+ end
+ end
+ end
+end
@@ -0,0 +1,25 @@
+class Search
+ module Form
+ class MultipleSelector < Selector
+ def label
+ selected.humanize_join(splitter)
+ end
+
+ protected
+
+ def selected
+ raise NotImplementedError, "must be implemented by sublclass"
+ end
+
+ def labels
+ i18n :labels
+ end
+
+ def splitter
+ I18n.t(:or) || 'or'
+ rescue
+ 'or'
+ end
+ end
+ end
+end
@@ -0,0 +1,9 @@
+class Search
+ module Form
+ class PeriodSelector < DateRangeSelector
+ def name
+ :period
+ end
+ end
+ end
+end
@@ -0,0 +1,10 @@
+class Search
+ module Form
+ class ResidenceTypeSelector < CheckboxesSelector
+
+ def selected
+ search.type.selected
+ end
+ end
+ end
+end
@@ -0,0 +1,9 @@
+class Search
+ module Form
+ class RoomsSelector < Selector
+ def name
+ :rooms
+ end
+ end
+ end
+end
@@ -0,0 +1,36 @@
+class Search
+ module Form
+ class Selector
+ def initialize search, settings
+ @search = search
+ @settings = settings
+ end
+
+ def label
+ "#{from} - #{to} #{unit}"
+ end
+
+ def selector
+ raise NotImplementedError, "Must be implemented by subclass"
+ end
+
+ def checkbox_any
+ form.input name, as: :checkboxes, collection: i18n(:any)
+ end
+
+ protected
+
+ def unit
+ i18n :unit
+ end
+
+ def labels
+ i18n :labels
+ end
+
+ def i18n
+ I18n.t("search.form.selector.#{path}"
+ end
+ end
+ end
+end
@@ -0,0 +1,11 @@
+class Search
+ module Form
+ class SizeSelector < Selector
+ protected
+
+ def name
+ :size
+ end
+ end
+ end
+end
@@ -0,0 +1,52 @@
+class Search
+ module Form
+ class SliderSelector < Selector
+ def initialize search, settings
+ @search = search
+ @settings = settings
+ end
+
+ def label
+ "#{from} - #{to} #{unit}"
+ end
+
+ def selector
+ ui_select_slider html: html_options, ui: ui_options,
+ end
+
+ protected
+
+ def from
+ search.send(name).from
+ end
+
+ def to
+ search.send(name).to
+ end
+
+ def range
+ [from, to]
+ end
+
+ def options
+ {labels: labels, range: range}
+ end
+
+ def labels
+ I18n.t("search.form.selector.#{name}.labels")
+ end
+
+ def ui_options
+ {hideSelect: true}
+ end
+
+ def html_options
+ {id: name, class: "slider hidden"}
+ end
+
+ def unit
+ I18n.t("search.form.selector.#{name}.unit")
+ end
+ end
+ end
+end
@@ -18,23 +18,15 @@ def search_button form
form.action :submit, :as => :button, label: t('search.form.button')
end
- def slider_rooms
- ui_select_slider html: {id: 'rooms', class: 'slider rooms'}, ui: {labels: 5}, labels: (1..5).to_a, range: [1,3]
- end
-
- def slider_size
- ui_select_slider html: {id: 'size', class: 'slider size'}, ui: {labels: 3}, labels: (1..10).to_a.map{|v| v*10}, range: [30,60]
- end
-
protected
safe_content :show_results do
badge(search.results) + link_to('show results', '/properties')
end
- safe_content :show_results do
+ safe_content :create_agent do
awesome_icon(:group) do
- link_to('show results', '/properties')
+ link_to('crate agent', '/create_agent')
end
end
@@ -8,5 +8,5 @@
/ Placed at the end of the document so the pages load faster
= gmaps_libs_now map_options: {provider: :google, :provider_key => 'AIzaSyAldHWZicBdBhSrd4xC2uh3cVIwEdWFfiY'}
= yield :scripts
- = yield :jquery_ui_helpers
+ / = yield :jquery_ui_helpers
= javascript_include_tag "application"
@@ -1,6 +1,12 @@
class TopBar::FormWidget < Apotomo::Widget
def show
- @search_decorator = Decorators.decorate(:search)
- render
+ @search = session[:search] = Search.new
+ @search_decorator = Decorators.decorator(:search).decorate(@search)
+ render view: 'show'
+ end
+
+ def search
+ @search = session[:search]
+ render text: "Widgets.topBar.form.search(#{@search.to_json});"
end
end
@@ -2,12 +2,10 @@
= semantic_form_for @search, :url => url_for_event(:submit), :remote => true do |form|
= form.inputs do
= @search_decorator.form(form).location_input
- = form.inputs do
- = @search_decorator.form(form).inputs_line 1
- = @search_decorator.form(form).inputs_line 2
-
= form.inputs do
- = @search_decorator.form(form).slider_rooms
- = @search_decorator.form(form).slider_size
+ = @search_decorator.form(form).slider_rooms
+ = @search_decorator.form(form).slider_size
/ = @search_decorator.form(form).inputs_line 2
-
+ = @search_decorator.create_agent
+ = @search_decorator.show_results
+= render view: 'search'
Oops, something went wrong.

0 comments on commit 5d8716e

Please sign in to comment.