Class: AlTimestamp

Inherits:
AlWidget show all
Defined in:
lib/al_form.rb

Overview

Note:

年月日と時分秒を扱う

タイムスタンプウィジェット

内部的にはTimeオブジェクトで保存する。

Direct Known Subclasses

AlDate, AlTime

Constant Summary collapse

STRFTIME_FORMAT =
"%Y-%m-%d %H:%M:%S"

Instance Attribute Summary collapse

Attributes inherited from AlWidget

#filter, #foreign, #hidden, #label, #message, #name, #required, #tag_attr, #tag_type, #value

Instance Method Summary collapse

Methods inherited from AlWidget

#set_attr, #set_value

Constructor Details

#initialize(name, arg = {}) ⇒ AlTimestamp

(AlTimestamp) constructor

Parameters:

  • name (String)

    ウィジェット識別名 英文字を推奨

  • arg (Hash) (defaults to: {})

    引数ハッシュ

Options Hash (arg):

  • :max (Integer)

    最大値

  • :min (Integer)

    最小値

See Also:



1500
1501
1502
1503
1504
1505
# File 'lib/al_form.rb', line 1500

def initialize( name, arg = {} )
  super( name, arg )
  @filter = arg[:filter] || AlForm::FILTER_STRIP
  @max = normalize( arg[:max] )
  @min = normalize( arg[:min] )
end

Instance Attribute Details

#maxInteger

Returns 最大値.

Returns:

  • (Integer)

    最大値



1485
1486
1487
# File 'lib/al_form.rb', line 1485

def max
  @max
end

#minInteger

Returns 最小値.

Returns:

  • (Integer)

    最小値



1488
1489
1490
# File 'lib/al_form.rb', line 1488

def min
  @min
end

Instance Method Details

#make_tag(appendix_tag = {}) ⇒ String

(AlTimestamp) HTMLタグの生成

Parameters:

  • appendix_tag (Hash) (defaults to: {})

    htmlタグへ追加するアトリビュートを指定

Returns:

  • (String)

    htmlタグ



1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
# File 'lib/al_form.rb', line 1551

def make_tag( appendix_tag = {} )
  if @hidden
    return %Q(<input type="hidden" name="#{@name}" id="#{@name}" value="#{make_value()}">\n)
  end

  r = %Q(<input type="#{@tag_type || "text"}" name="#{@name}" id="#{@name}" value="#{make_value()}")
  make_tag_attr(r, appendix_tag)
  r << ">"
  return r
end

#make_value(*arg) ⇒ String

(AlTimestamp) HTML値の生成

Parameters:

  • arg (String, Time)

    表示値。指定なければ内部値を使う。

Returns:

  • (String)

    html文字列



1569
1570
1571
1572
1573
1574
1575
1576
# File 'lib/al_form.rb', line 1569

def make_value( *arg )
  v = arg.empty? ? @value : arg[0]
  if v.class == Time
    return v.strftime('%Y-%m-%d %H:%M:%S')
  else
    return Alone::escape_html( v )
  end
end

#validateBoolean

(AlTimestamp) バリデート

Returns:

  • (Boolean)

    成否



1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
# File 'lib/al_form.rb', line 1513

def validate()
  @message = ""

  if @value == "" || @value == nil
    if @required
      @message = "#{@label}を入力してください。"
      return false
    end
    @value = nil
    return true
  end

  begin
    @value = normalize( @value.to_s )
  rescue
    @message = "#{@label}を正しく入力してください。"
    return false
  end

  if @max && @value > @max
    @message = "#{@label}は、最大#{@max.strftime(self.class::STRFTIME_FORMAT)}までで入力してください。"
    return false
  end
  if @min && @value < @min
    @message = "#{@label}は、最小#{@min.strftime(self.class::STRFTIME_FORMAT)}までで入力してください。"
    return false
  end

  return true
end