Permalink
Browse files

toggle changes

  • Loading branch information...
1 parent f274db4 commit 9e38d6bbc951e56e16b2d213b241d07df4c57976 Noel Rappin committed May 2, 2008
Showing with 58 additions and 0 deletions.
  1. +1 −0 init.rb
  2. +31 −0 lib/form_builder_extensions.rb
  3. +26 −0 lib/iui_helper.rb
View
@@ -1,3 +1,4 @@
require File.dirname(__FILE__) + '/lib/iui_helper.rb'
require File.dirname(__FILE__) + '/lib/iphone_controller'
+require File.dirname(__FILE__) + '/lib/form_builder_extensions'
Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,31 @@
+module ActionView
+ module Helpers
+ module FormHelper
+ def toggle(object_name, method, options = {})
+ obj = instance_variable_get("@#{object_name}")
+ value = if obj.send(method) then "ON" else "OFF" end
+ hidden = hidden_field_tag("#{object_name}[#{method}]", value,
+ :id => "#{object_name}_#{method}")
+ thumb = content_tag(:span, "", :class => "thumb")
+ on = content_tag(:span, "ON", :class => "toggleOn")
+ off = content_tag(:span, "OFF", :class => "toggleOff")
+ toggle = content_tag(:div, thumb + on + off,
+ :toggled => value,
+ :class => "toggle",
+ :id => "#{object_name}_#{method}_toggle",
+ :onclick => "$('#{object_name}_#{method}').value = ($('#{object_name}_#{method}').value == 'OFF') ? 'ON' : 'OFF';")
+ row = content_tag(:div, toggle, :class => "row")
+ hidden + row
+ end
+ end
+
+ class FormBuilder
+
+ def toggle(method, options = {})
+ @template.toggle(@object_name, method, objectify_options(options))
+ end
+
+ end
+
+ end
+end
View
@@ -82,6 +82,32 @@ def iui_grouped_list(items, options = {}, &group_by_block)
content_tag(:ul, group_elements.flatten.join("\n"), :selected => "true")
end
+ def fieldset(&block)
+ concat(content_tag(:fieldset, capture(&block)), block.binding)
+ end
+
+ def row(label_text="", &block)
+ label = if label_text.blank? then "" else content_tag(:label, label_text) end
+ block = if block_given? then capture(&block) else "" end
+ div = content_tag(:div, label + block, :class => "row")
+ if block_given?
+ concat(div, block.binding)
+ else
+ div
+ end
+ end
+
+ def row_label(&block)
+ label = content_tag(:label, capture(&block))
+ div = content_tag(:div, label, :class => "row")
+ concat(div, block.binding)
+ end
+
+ def panel(&block)
+ div = content_tag(:div, capture(&block), :class => "panel")
+ concat(div, block.binding)
+ end
+
end
ActionView::Base.send(:include, IuiHelper)

0 comments on commit 9e38d6b

Please sign in to comment.