Class: ExtFieldset

Inherits:
ExtNode show all
Includes:
Magic::Title
Defined in:
lib/extclasses/fieldset.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 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) ⇒ ExtFieldset

Returns a new instance of ExtFieldset.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/extclasses/fieldset.rb', line 8

def initialize(config, parent)
  @default_config = {
    layout: 'anchor',
    animCollapse: true,
    labelAlign: "right",
    # collapsed: true,
    # checkboxToggle: true,
    autoHeight: true
    # columnWidth: 0.5
  }
  super("fieldset", config, parent) 
end

Instance Method Details

#to_extjs(at_deep = 0) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/extclasses/fieldset.rb', line 21

def to_extjs(at_deep = 0)
  col_label_width = []
  x = self.find_field_elements.map do |c|
    [c.config[:fieldLabel], c.parent.config[:col_index], c.parent.config[:labelWidth] ]
  end
  self.find_field_elements.each do |c|
    i = c.parent.config[:col_index] || 0
    next unless i
    unless col_label_width[i] 
      col_label_width[i] = []
    end
    col_label_width[i] << c.parent.config[:labelWidth]
  end
  max_label_width = []
  col_label_width.each_with_index do |c, i|
    max_label_width[i] = c.compact.max
  end

  # update max label within every fields container
  self.find_field_elements.each do |c|
    i = c.parent.config[:col_index] || 0
    c.parent.config[:labelWidth] = max_label_width[i]
  end

  if @config[:labelWidth]
    @config.merge!({ :defaults => { :labelWidth => @config[:labelWidth] } } )
    # if set a button at the last child
    if @childs.last.xtype == "button"
      btn_style = @childs.last.config[:style]
      new_btn_style = btn_style.dup if btn_style
      new_btn_style ||= "{}"
      fix_style = "margin-left: #{@config[:labelWidth]+5}px; margin-bottom: 0.5em; }"
      new_btn_style.gsub!("}", fix_style)
      @childs.last.config[:style] = new_btn_style
    end
    @config.delete :labelWidth
  end

  super(at_deep)
end