Class: DynamicGridColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/erp_forms/dynamic_grid_column.rb

Class Method Summary collapse

Class Method Details

.build_action_column(header, icon, action) ⇒ Object


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/erp_forms/dynamic_grid_column.rb', line 48

def self.build_action_column(header, icon, action)    
  col = '{
      "menuDisabled":true,
      "resizable":false,
      "xtype":"actioncolumn",
      "header":"'+header+'",
      "align":"center",
      "width":50,
      "items":[{
          "icon":"'+icon+'",
          "tooltip":"'+header+'",
          "handler" :function(grid, rowIndex, colIndex){
              var rec = grid.getStore().getAt(rowIndex);
              '+action+'
          }
      }]
  }'
  
  col
end

.build_column(field_hash, options = {}) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/erp_forms/dynamic_grid_column.rb', line 3

def self.build_column(field_hash, options={})
  field_hash.symbolize_keys!
  header = (field_hash[:header] ? field_hash[:header] : field_hash[:fieldLabel])
  type = (field_hash[:type] ? field_hash[:type] : DynamicGridColumn.convert_xtype_to_column_type(field_hash[:xtype]))
  data_index = (field_hash[:dataIndex] ? field_hash[:dataIndex] : field_hash[:name])
  sortable = (field_hash[:sortable].nil? ? true : field_hash[:sortable])
  renderer = (type == 'date' ? "Ext.util.Format.dateRenderer('m/d/Y')" : '')
  
  col = {
    :header => header,
    :type => type,
    :dataIndex => data_index,
    :sortable => sortable
  }

  col[:width] = field_hash[:width] unless field_hash[:width].nil?
  col[:renderer] = renderer unless renderer.blank?

  if field_hash[:editor]
    selections = (field_hash[:editor][:store] ? field_hash[:editor][:store] : [])
    col[:editor] = DynamicFormField.basic_field(field_hash[:editor][:xtype], field_hash[:editor], selections)
  end    
  
  col.to_json
end

.build_delete_column(action = '') ⇒ Object


29
30
31
32
33
34
35
36
37
38
# File 'lib/erp_forms/dynamic_grid_column.rb', line 29

def self.build_delete_column(action='')
  action = "var messageBox = Ext.MessageBox.confirm(
    'Confirm', 'Are you sure?', 
    function(btn){
      if (btn == 'yes'){ 
        #{action}               
      }
    });"    
  DynamicGridColumn.build_action_column("Delete", "/images/icons/delete/delete_16x16.png", action)
end

.build_edit_column(action = '') ⇒ Object


44
45
46
# File 'lib/erp_forms/dynamic_grid_column.rb', line 44

def self.build_edit_column(action='')    
  DynamicGridColumn.build_action_column("Edit", "/images/icons/document_edit/document_edit_16x16.png", action)
end

.build_view_column(action = '') ⇒ Object


40
41
42
# File 'lib/erp_forms/dynamic_grid_column.rb', line 40

def self.build_view_column(action='')    
  DynamicGridColumn.build_action_column("View", "/images/icons/document_view/document_view_16x16.png", action)
end

.convert_xtype_to_column_type(xtype) ⇒ Object


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/erp_forms/dynamic_grid_column.rb', line 69

def self.convert_xtype_to_column_type(xtype)
  case xtype
  when 'textfield'
    return 'string'
  when 'datefield'
    return 'date'
  when 'textarea'
    return 'string'
  when 'numberfield'
    return 'number'
  when 'actioncolumn'
    return 'actioncolumn'
  else
    return 'string'
  end
end