Sha256: 2914653f340073b63f0b959ba65939662c8ce02a48000715778a0507d8e5092c

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

require 'omf-web/theme/bright/widget_chrome'

module OMF::Web::Theme
  
  class TabbedRenderer < Erector::Widget
    
    def initialize(layout_widget, widgets, opts)
      super opts
      @layout_widget = layout_widget
      @widgets = widgets || []
      @opts = opts
    end
    
    def content
      selected = get_selected_widget()
      div :class => 'tabbed_layout' do
        div :id => 'card_nav', :class => 'navigation' do
          render_card_nav(selected)
        end
        if selected
          div :id => :card_content, :class => 'content' do 
            render_widget selected
          end
        else
          div :class => 'flash_alert flash' do
            text "Nothing to display"
          end
        end
      end     
    end
    
    # Return an array of widgets to collect data sources from
    #
    # def data_source_widgets
      # puts "TABREN>>>>>>> #{get_selected_widget()}"
      # [get_selected_widget()]
    # end

    def render_card_nav(selected)
      cname = @opts[:component_name]
      path = @opts[:path]

      ol do
        @widgets.each_with_index do |w, i| 
          klass = (w == selected) ? 'selected' : nil
          li :class => klass do
            a w.name || 'unknown', :href => "#{path}?tid=#{i}&sid=#{Thread.current["sessionID"]}"
          end
        end
      end            
    end # render_card_nav

    def render_widget(w)
      r = w.content
      unless w.layout?
        r = WidgetChrome.new(w, r, @opts)
      end
      rawtext r.to_html      
    end    
    
    def get_selected_widget()
      # TODO: THIS NEEDS FIXING - WE NEED TO GET REQ OBJECT THROUGH THREAD
      req = Thread.current["top_renderer"].opts[:request]
      # opts[:tab] = tab_id = tab[:id]
      # opts[:request] = req      
      tid = (req.params['tid'] || 0).to_i
      return @widgets[tid]
    end
    
  end # TabbedRenderer
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
omf_web-0.9.6 lib/omf-web/theme/bright/tabbed_renderer.rb
omf_web-0.9.5 lib/omf-web/theme/bright/tabbed_renderer.rb
omf_web-0.9.4 lib/omf-web/theme/bright/tabbed_renderer.rb
omf_web-0.9.3 lib/omf-web/theme/bright/tabbed_renderer.rb