Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/jinda_engine/helpers.rb,
app/helpers/jinda_engine/jinda_helper.rb

Instance Method Summary collapse

Instance Method Details

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



910
911
912
913
914
915
# File 'lib/jinda_engine/helpers.rb', line 910

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



907
908
909
# File 'lib/jinda_engine/helpers.rb', line 907

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



925
926
927
# File 'lib/jinda_engine/helpers.rb', line 925

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



929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
# File 'lib/jinda_engine/helpers.rb', line 929

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 = <<-EOT
  <script type='text/javascript'>
  //<![CDATA[
    var latLng;
    var map_#{self.object_name};
    var marker_#{self.object_name};

    function init_map() {
var lat =  #{o[:lat]};
var lng =  #{o[:lng]};
//var lat =  position.coords.latitude"; // HTML5 pass position in function initialize(position)
// google.loader.ClientLocation.latitude;
//var lng =  position.coords.longitude;
// google.loader.ClientLocation.longitude;
latLng = new google.maps.LatLng(lat, lng);
map_#{self.object_name} = new google.maps.Map(document.getElementById("map_#{self.object_name}"), {
  zoom: #{o[:zoom]},
  center: latLng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
});
marker_#{self.object_name} = new google.maps.Marker({
  position: latLng,
  map: map_#{self.object_name},
  draggable: true,
});
google.maps.event.addListener(marker_#{self.object_name}, 'dragend', function(event) {
  $('##{self.object_name}_lat').val(event.latLng.lat());
  $('##{self.object_name}_lng').val(event.latLng.lng());
});
google.maps.event.addListener(map_#{self.object_name}, 'click', function(event) {
  $('##{self.object_name}_lat').val(event.latLng.lat());
  $('##{self.object_name}_lng').val(event.latLng.lng());
  move();
});
$('##{self.object_name}_lat').val(lat);
$('##{self.object_name}_lng').val(lng);
    };

    function move() {
latLng = new google.maps.LatLng($('##{self.object_name}_lat').val(), $('##{self.object_name}_lng').val());
map_#{self.object_name}.panTo(latLng);
marker_#{self.object_name}.setPosition(latLng);
    }

    //google.maps.event.addDomListener(window, 'load', init_map);

  //]]>
  </script>
  <div class="field" data-role="fieldcontain">
    Latitude: #{self.text_field :lat, :style=>"width:300px;" }
    Longitude: #{self.text_field :lng, :style=>"width:300px;" }
  </div>
  <p/>
  <div id='map_#{self.object_name}' style='max-width: none !important; width:#{o[:width]}; height:#{o[:height]};' class='map'></div>
  <script>
    $('##{self.object_name}_lat').change(function() {move()});
    $('##{self.object_name}_lng').change(function() {move()});
    //var w= $("input[id*=lat]").parent().width();
    //$("input[id*=lat]").css('width','300px');
    //$("input[id*=lng]").css('width','300px');
    $( document ).one( "pagechange", function(){
init_map();
    });
  </script>
  EOT
  out.html_safe
end

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



916
917
918
919
920
921
# File 'lib/jinda_engine/helpers.rb', line 916

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