Class: Netzke::AccordionPanel
- Inherits:
-
Base
- Object
- Base
- Netzke::AccordionPanel
- Defined in:
- lib/netzke/accordion_panel.rb
Overview
AccordionPanel
Features:
-
Dynamically loads widgets for the panels that get expanded for the first time
-
Is loaded along with the active widget - saves a request to the server
Future features:
-
Stores the last active panel in persistent_config
Class Method Summary collapse
-
.js_extend_properties ⇒ Object
JavaScript part.
Instance Method Summary collapse
-
#fit_panels ⇒ Object
“Fit-panels” - panels of layout ‘fit’ (effectively the accordion panels) that will contain the widgets (“items”).
-
#initial_aggregatees ⇒ Object
All items become late aggregatees, besides the ones that are marked “active”.
-
#initialize(*args) ⇒ AccordionPanel
constructor
Some normalization of config.
-
#items ⇒ Object
Returns items configs.
-
#js_config ⇒ Object
Provides configs for fit panels (which will effectively be accordion panels).
Constructor Details
#initialize(*args) ⇒ AccordionPanel
Some normalization of config
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/netzke/accordion_panel.rb', line 57 def initialize(*args) super seen_active = false config[:items].each_with_index do |item, i| # if some items are provided without names, give them generated names item[:name] ||= "item#{i}" # remove duplucated :active configuration if item[:active] item[:active] = nil if seen_active seen_active ||= true end end end |
Class Method Details
.js_extend_properties ⇒ Object
JavaScript part
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 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/netzke/accordion_panel.rb', line 13 def self.js_extend_properties { :layout => 'accordion', :defaults => {:layout => 'fit'}, :init_component => <<-END_OF_JAVASCRIPT.l, function(){ Ext.netzke.cache.#{}.superclass.initComponent.call(this); // Set events this.items.each(function(i){ // Set the expand event i.on('expand', this.loadItemWidget, this); // If not collapsed, add the active aggregatee (item) into it if (!i.collapsed) { var preloadedItemConfig = this[i.widget.camelize(true) + "Config"]; i.add(new Ext.netzke.cache[preloadedItemConfig.widgetClassName](preloadedItemConfig)); i.doLayout(); // always needed after adding a component } }, this); } END_OF_JAVASCRIPT # Loads widget into the panel if it wasn't loaded yet :load_item_widget => <<-END_OF_JAVASCRIPT.l, function(panel) { // if (!panel.getWidget()) panel.loadWidget(this.id + "__" + panel.widget + "__get_widget"); var preloadedItemConfig = this[panel.widget.camelize(true) + "Config"]; if (preloadedItemConfig){ // preloaded widget only needs to be instantiated, as its class and configuration have already been loaded panel.add(new Ext.netzke.cache[preloadedItemConfig.widgetClassName](preloadedItemConfig)); panel.doLayout(); // always needed after adding a component } else { // load the widget from the server this.loadAggregatee({id:panel.widget, container:panel.id}); } } END_OF_JAVASCRIPT } end |
Instance Method Details
#fit_panels ⇒ Object
“Fit-panels” - panels of layout ‘fit’ (effectively the accordion panels) that will contain the widgets (“items”)
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/netzke/accordion_panel.rb', line 88 def fit_panels res = [] config[:items].each_with_index do |item, i| res << { # :id => item[:active] && id_name + '_active', # to mark the fit-panel which will contain the active widget :title => item[:title] || (item[:name] && item[:name].to_s.humanize), :widget => item[:name], # to know which fit panel will load which widget :collapsed => !(item[:active] || false) } end res end |
#initial_aggregatees ⇒ Object
All items become late aggregatees, besides the ones that are marked “active”
102 103 104 105 106 107 108 109 |
# File 'lib/netzke/accordion_panel.rb', line 102 def initial_aggregatees res = {} config[:items].each_with_index do |item, i| item[:late_aggregation] = !item[:active] res.merge!(item[:name].to_sym => item) end res end |
#items ⇒ Object
Returns items configs
75 76 77 |
# File 'lib/netzke/accordion_panel.rb', line 75 def items @items ||= config[:items] end |
#js_config ⇒ Object
Provides configs for fit panels (which will effectively be accordion panels)
80 81 82 83 84 85 |
# File 'lib/netzke/accordion_panel.rb', line 80 def js_config super.merge({ # these "items" are not related to the "items" of the config, rather these are the items required by the the accordion panel :items => fit_panels }) end |