Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/jinda/helpers.rb

Instance Method Summary collapse

Instance Method Details

#date_field(method, options = {}) ⇒ Object



758
759
760
761
762
763
# File 'lib/jinda/helpers.rb', line 758

def date_field(method, options = {})
  default= options[:default]  || self.object.send(method) || Date.today
  data_options= ({"mode"=>"calbox"}).merge(options)
  out= %Q(<input name='#{self.object_name}[#{method}]' id='#{self.object_name}_#{method}' value='#{default.strftime("%F")}' type='date' data-role='datebox' data-options='#{data_options.to_json}'>)
  out.html_safe
end

#date_select_thai(method, default = Time.now, disabled = false) ⇒ Object



755
756
757
# File 'lib/jinda/helpers.rb', line 755

def date_select_thai(method)
  self.date_select method, :use_month_names=>THAI_MONTHS, :order=>[:day, :month, :year]
end

#datetime_select_thai(method, default = Time.now, disabled = false) ⇒ Object



773
774
775
# File 'lib/jinda/helpers.rb', line 773

def datetime_select_thai(method, default= Time.now, disabled=false)
  datetime_select method, :default => default, :use_month_names=>THAI_MONTHS, :order=>[:day, :month, :year], :disabled=>disabled
end

#point(o = {}) ⇒ Object



777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
# File 'lib/jinda/helpers.rb', line 777

def point(o={})
  o[:zoom]= 11 unless o[:zoom]
  o[:width]= '100%' unless o[:width]
  o[:height]= '300px' unless o[:height]
  o[:lat] = 13.91819 unless o[:lat]
  o[:lng] = 100.48889 unless o[:lng]

  out = "  <script type='text/javascript'>\n  //<![CDATA[\n    var latLng;\n    var map_\#{self.object_name};\n    var marker_\#{self.object_name};\n\n    function init_map() {\nvar lat =  \#{o[:lat]};\nvar lng =  \#{o[:lng]};\n//var lat =  position.coords.latitude\"; // HTML5 pass position in function initialize(position)\n// google.loader.ClientLocation.latitude;\n//var lng =  position.coords.longitude;\n// google.loader.ClientLocation.longitude;\nlatLng = new google.maps.LatLng(lat, lng);\nmap_\#{self.object_name} = new google.maps.Map(document.getElementById(\"map_\#{self.object_name}\"), {\n  zoom: \#{o[:zoom]},\n  center: latLng,\n  mapTypeId: google.maps.MapTypeId.ROADMAP\n});\nmarker_\#{self.object_name} = new google.maps.Marker({\n  position: latLng,\n  map: map_\#{self.object_name},\n  draggable: true,\n});\ngoogle.maps.event.addListener(marker_\#{self.object_name}, 'dragend', function(event) {\n  $('#\#{self.object_name}_lat').val(event.latLng.lat());\n  $('#\#{self.object_name}_lng').val(event.latLng.lng());\n});\ngoogle.maps.event.addListener(map_\#{self.object_name}, 'click', function(event) {\n  $('#\#{self.object_name}_lat').val(event.latLng.lat());\n  $('#\#{self.object_name}_lng').val(event.latLng.lng());\n  move();\n});\n$('#\#{self.object_name}_lat').val(lat);\n$('#\#{self.object_name}_lng').val(lng);\n    };\n\n    function move() {\nlatLng = new google.maps.LatLng($('#\#{self.object_name}_lat').val(), $('#\#{self.object_name}_lng').val());\nmap_\#{self.object_name}.panTo(latLng);\nmarker_\#{self.object_name}.setPosition(latLng);\n    }\n\n    //google.maps.event.addDomListener(window, 'load', init_map);\n\n  //]]>\n  </script>\n  <div class=\"field\" data-role=\"fieldcontain\">\n    Latitude: \#{self.text_field :lat, :style=>\"width:300px;\" }\n    Longitude: \#{self.text_field :lng, :style=>\"width:300px;\" }\n  </div>\n  <p/>\n  <div id='map_\#{self.object_name}' style='max-width: none !important; width:\#{o[:width]}; height:\#{o[:height]};' class='map'></div>\n  <script>\n    $('#\#{self.object_name}_lat').change(function() {move()});\n    $('#\#{self.object_name}_lng').change(function() {move()});\n    //var w= $(\"input[id*=lat]\").parent().width();\n    //$(\"input[id*=lat]\").css('width','300px');\n    //$(\"input[id*=lng]\").css('width','300px');\n    $( document ).one( \"pagechange\", function(){\ninit_map();\n    });\n  </script>\n"
  out.html_safe
end

#time_field(method, options = {}) ⇒ Object



764
765
766
767
768
769
# File 'lib/jinda/helpers.rb', line 764

def time_field(method, options = {})
  default= self.object.send(method) || Time.now
  data_options= ({"mode"=>"timebox"}).merge(options)
  out=%Q(<input name='#{self.object_name}[#{method}]' id='#{self.object_name}_#{method}' value='#{default}' type='date' data-role='datebox' data-options='#{data_options.to_json}'>)
  out.html_safe
end