Class: Netzke::BorderLayoutPanel

Inherits:
Base
  • Object
show all
Defined in:
lib/netzke/border_layout_panel.rb

Overview

Represents the Ext.Panel with layout ‘border’. May serve as parent class for compound widgets.

Features:

  • Responds to region resizing, storing the sizes in persistent config

Future features:

  • Stores expand/collapse state in the persistent config

Non-functional features:

  • (JavaScript) Creates convinient methods to access aggregatees inside the regions, like

getCenterWidget(), getWestWidget(), etc

Configuration:

:regions - a hash in form:

{:center => {<netzke widget config>}, :east => {<another netzke widget config>}, ...}

:regions => :center/:west/:etc => :region_config - configuration options for Ext.layout.BorderLayout.SplitRegion.

Example configuration:

:regions => {
  :center => {:widget_class_name => "Panel", :ext_config => {:html => "A panel"}}, 
  :west => {
    :widget_class_name => "GridPanel", 
    :data_class_name => "User", 
    :region_config => {
      :width => 100,
      :split => true
    }
  }
}

Direct Known Subclasses

TableEditor

Constant Summary collapse

REGIONS =
%w(center west east south north).map(&:to_sym)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.js_extend_propertiesObject

JavaScript part



39
40
41
42
43
44
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
91
92
93
94
95
96
97
98
99
# File 'lib/netzke/border_layout_panel.rb', line 39

def self.js_extend_properties
  {
    :layout => 'border',
    
    :init_component => <<-END_OF_JAVASCRIPT.l,
    
    :get_region_widget => <<-END_OF_JAVASCRIPT.l,
    
    :set_resize_events => <<-END_OF_JAVASCRIPT.l,
    function(){
      this.items.each(function(item, index, length){
        if (!item.oldSize) item.oldSize = item.getSize();
        if (item.region == 'east' || item.region == 'west') item.on('resize', function(panel, w, h){
          if (panel.oldSize.width != w) {
            this.resizeRegion({region_name: panel.region, new_width:w});
            panel.oldSize.width = w;
          }
          return true;
        }, this);
        else if (item.region == 'south' || item.region == 'north') item.on('resize', function(panel, w, h){
          if (panel.oldSize.height != h) {
            this.resizeRegion({region_name: panel.region, new_height:h});
            panel.oldSize.height = h;
          }
          return true;
        }, this);
      }, this);
    }
  END_OF_JAVASCRIPT
}
end

Instance Method Details

#initial_aggregateesObject



101
102
103
# File 'lib/netzke/border_layout_panel.rb', line 101

def initial_aggregatees
  config[:regions] || {}
end

#js_configObject



109
110
111
112
113
114
115
116
117
# File 'lib/netzke/border_layout_panel.rb', line 109

def js_config
  regions = {}
  REGIONS.each do |r|
    if region_aggr = aggregatees[r]
      regions.merge!(r => region_aggr[:region_config] || {})
    end
  end
  super.merge(:regions => regions)
end

#region_aggregateesObject



105
106
107
# File 'lib/netzke/border_layout_panel.rb', line 105

def region_aggregatees
  aggregatees.reject{ |k,v| !REGIONS.include?(k) }
end

#resize_region(params) ⇒ Object



121
122
123
124
125
# File 'lib/netzke/border_layout_panel.rb', line 121

def resize_region(params)
  persistent_config["regions__#{params["region_name"]}__region_config__width"] = params["new_width"].to_i if params["new_width"]
  persistent_config["regions__#{params["region_name"]}__region_config__height"] = params["new_height"].to_i if params["new_height"]
  {}
end