Class: OMF::Web::Tab::Code::CodeService

Inherits:
AbstractService show all
Defined in:
lib/omf-web/UNUSED/tab/code/code_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(tab_id, opts) ⇒ CodeService

Returns a new instance of CodeService.



9
10
11
12
# File 'lib/omf-web/UNUSED/tab/code/code_service.rb', line 9

def initialize(tab_id, opts)
  super
  @widgets = []
end

Instance Method Details

#show(req, opts) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omf-web/UNUSED/tab/code/code_service.rb', line 14

def show(req, opts)
  tid = opts[:card_id] = (req.params['tid'] || 0).to_i
  unless (widget = @widgets[tid])
    if descr = OMF::Web::Widget::Code[tid]
      widget = @widgets[tid] = descr[:widget_class].new(descr) #.create_widget
    else
      if OMF::Web::Widget::Code.count > 0
        opts[:flash] = {:alert => "Unknown script id '#{tid}'"}
      else
        opts[:flash] = {:alert => "No scripts defined"}
      end                    
    end
  end
  if opts[:widget] = widget
    opts[:card_title] = widget.name
  end
  
  OMF::Web::Theme.require 'multi_card_page'
  page = OMF::Web::Theme::MultiCardPage.new(widget, :code, OMF::Web::Widget::Code, opts)
  [page.to_html, 'text/html']
end