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

end



422
423
424
425
426
427
# File 'lib/jinda/helpers.rb', line 422

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



434
435
436
# File 'lib/jinda/helpers.rb', line 434

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

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



437
438
439
# File 'lib/jinda/helpers.rb', line 437

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



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/jinda/helpers.rb', line 441

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



428
429
430
431
432
433
# File 'lib/jinda/helpers.rb', line 428

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