Class: Ezframe::DateType
Instance Attribute Summary
Attributes inherited from TypeBase
#attribute, #error, #parent
Instance Method Summary
collapse
Methods inherited from TextType
#normalize
Methods inherited from TypeBase
#db_value, #form_html, get_class, #initialize, #key, #label, #multi_inputs?, #no_edit?, #no_view?, #normalize, type_name, #validate
Instance Method Details
280
281
282
|
# File 'lib/ezframe/column_type.rb', line 280
def db_type
"date"
end
|
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'lib/ezframe/column_type.rb', line 267
def form(opts = {})
return nil if no_edit? && !opts[:force]
h = super
if h
h[:type] = "text"
h[:value] = @value || ""
h[:class] = [ "datepicker" ]
h[:class].push@attribute[:class] if @attribute[:class]
end
return h
end
|
284
285
286
287
288
289
|
# File 'lib/ezframe/column_type.rb', line 284
def value
if @value.is_a?(Date) || @value.is_a?(Time)
return "%d-%02d-%02d" % [@value.year, @value.mon, @value.mday]
end
return @value
end
|
#value=(v) ⇒ Object
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/ezframe/column_type.rb', line 291
def value=(v)
if v.nil?
default = @attribute[:default]
if default
@value = default
else
@value = nil
end
return
end
if v.is_a?(String)
if v.strip.empty?
@value = nil
return
end
y, m, d = v.split(/[\-\/]/)
@value = Date.new(y.to_i, m.to_i, d.to_i)
return
end
if v.is_a?(Date) || v.is_a?(Time)
@value = v
else
mylog "[WARN] illegal value for date type: #{v.inspect}"
end
end
|
#view(opts = {}) ⇒ Object
317
318
319
320
321
322
323
324
|
# File 'lib/ezframe/column_type.rb', line 317
def view(opts = {})
return nil if no_view? && !opts[:force]
if @value.is_a?(Time) || @value.is_a?(Date)
return "#{@value.year}/#{@value.mon}/#{@value.mday}"
else
return @value
end
end
|