Module: Kwatable::ColumnHelper

Defined in:
lib/kwatable/template/helper/column.rb

Class Method Summary collapse

Class Method Details

.column_attr(column) ⇒ Object Also known as: column_name



14
15
16
# File 'lib/kwatable/template/helper/column.rb', line 14

def column_attr(column)
  return column['attr'] || column['name']
end

.column_control_type(column) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/kwatable/template/helper/column.rb', line 51

def column_control_type(column)
  type = column['type']
  name = column['name']
  if    name == 'id'                                 ;  return nil
  elsif column['ref']                                ;  return 'select'
  elsif column['enum']                               ;  return 'radio'
  elsif %w[created_on created_at].include?(name)     ;  return nil
  elsif %w[modified_on modified_at].include?(name)   ;  return nil
  elsif %w[date timestamp datetime].include?(type)   ;  return 'select'
  elsif %w[boolean bool].include?(type)              ;  return 'checkbox'
  elsif %w[text].include?(type)                      ;  return 'text_area'
  elsif %w[password passwd].include?(name)           ;  return 'password_field'
  else                                               ;  return 'text_field'
  end
end

.column_editable?(column) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/kwatable/template/helper/column.rb', line 43

def column_editable?(column)
  name = column['name']
  return false if name == 'id'
  return false if name =~ /\A(created|updated)_(on|at)\z/
  return true
end

.column_label(column) ⇒ Object



28
29
30
# File 'lib/kwatable/template/helper/column.rb', line 28

def column_label(column)
  return column['label'] || column_refname(column)
end

.column_refname(column) ⇒ Object



21
22
23
24
25
# File 'lib/kwatable/template/helper/column.rb', line 21

def column_refname(column)
  attr = column_attr(column)
  return column['ref-name'] || \
         (column['ref'] ? attr.sub(/_#{column['ref']['name']}\z/, '') : attr)
end

.column_showable?(column) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/kwatable/template/helper/column.rb', line 34

def column_showable?(column)
  #return column_control_type(column) ? true : false
  name = column['name']
  return false if name == 'id'
  return false if name == 'password' || name == 'passwd'
  return true
end