Class: ExtPivotgrid

Inherits:
ExtNode show all
Includes:
Magic::Store, Magic::Title
Defined in:
lib/extclasses/pivotgrid.rb

Constant Summary collapse

@@ALIAS_CONFIG =
{
  :text => :title
}

Instance Attribute Summary

Attributes inherited from ExtNode

#childs, #config, #deep_lvl, #default_config, #parent, #xtype

Instance Method Summary collapse

Methods included from Magic::Title

included

Methods included from Magic::Store

included

Methods inherited from ExtNode

#add_child, #apply_config, before_to_extjs, #build_abstract_function, #child_of?, #child_of_form?, #collect_events, #collect_ref, #conv_id_to_label, #conv_id_to_name, #conv_id_to_ref, #do_alias_config, #do_layout, #find, #find_field_elements, #find_parent, #get_all_siblings, get_before_filters, #get_deep, get_events, get_refs, #has_child?, #is_field_element?, #override_config, #prepare_config, #remove_childs, #remove_config, reset_generator_config, #root?, set_generator_config, #set_parent

Constructor Details

#initialize(config, parent) ⇒ ExtPivotgrid

Returns a new instance of ExtPivotgrid.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/extclasses/pivotgrid.rb', line 9

def initialize(config, parent)
   @default_config = {
     title: "My Grid",
     # enableHdMenu: false,
     columnLines: true,
     sm: "",
     selector: "row",
     # enableColumnmove: false,
     viewConfig: { 
       forceFit: true,
       emptyText: "No record"
       # for expanding row to show any infomation
       # enableRowBody: true
     },
     frame: true,
     width: "auto",
     loadMask: true,
     # TODO dummy store
     store: [],
     height: 200
     # columns: [
     #   { id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
     #   { header: 'Price', dataIndex: 'price'},
     #   { header: 'Change', dataIndex: 'change'},
     #   { header: '% Change', dataIndex: 'pctChange'},
     #   {
     #     header: 'Last Updated', width: 135, dataIndex: 'lastChange',
     #     xtype: 'datecolumn', format: 'M d, Y'
     #   }
     # ]
   }
   
	super('pivotgrid',config, parent)
end

Instance Method Details

#to_extjs(at_deep = 0) ⇒ Object

TODO refactor



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/extclasses/pivotgrid.rb', line 45

def to_extjs(at_deep = 0)
  # columns
  cols = []
  self.childs.each do |c|
    cols << c.to_extjs(at_deep) unless c.xtype.match(/column$/).nil?
  end
  @config.merge! :columns => cols unless cols.nil?
  
  # rowselection type : row | rows, cell | cells, checkbox | checkboxs
  unless @config[:selector].nil?
    # generate random js variable name
    require "securerandom"
    var = SecureRandom.urlsafe_base64.gsub(/\d|\W/,'')
    case @config[:selector]
    when "row"
      @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.RowSelectionModel({ singleSelect: true }))</js>)"
    when "rows"
      @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.RowSelectionModel({ singleSelect: false }))</js>)"
    # TODO
    # when "cell"
    #   @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CellSelectionModel())</js>)" 
    when "checkbox"
      @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CheckboxSelectionModel({ singleSelect: true, header: '' }))</js>)"
      @config[:columns].unshift("<js>this._#{var}</js>")
    when "checkboxs"
      @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CheckboxSelectionModel())</js>)"
      @config[:columns].unshift("<js>this._#{var}</js>")
    end
    @config.delete :selector 
  end

  toolbar = self.find("toolbar", {recursive: 1})
  @config.merge! :tbar => toolbar.to_extjs(at_deep + 1) if toolbar

  paging = self.find("paging")
  if paging
    unless @config[:store] =~ /<js>/
      paging.override_config :store => @config[:store]
    end
    @config.merge! :bbar => paging.to_extjs(at_deep + 1)
  end

  # grid not allow to have items
  self.childs = []
  super(at_deep)
end