Class: ODDB::View::Drugs::NarcoticComposite

Inherits:
HtmlGrid::Composite show all
Defined in:
src/view/drugs/narcotic.rb

Constant Summary

COMPONENTS =
{
  [0,0] => :narcotic_connection,
  [0,1]  => NarcoticInnerComposite,
  [0,2]  => :reservation_text,
  [0,3] => :packages,
}
CSS_MAP =
{
  [0,0]  => 'th',
  [0,3] => 'list',
}
LEGACY_INTERFACE =
false
CSS_CLASS =
'composite'
DEFAULT_CLASS =
HtmlGrid::Value
@@reservation =
/(SR|RS) (\d{3}\.\d{3}\.\d{2})/u

Instance Method Summary (collapse)

Methods inherited from HtmlGrid::Composite

event_link, #hash_insert_col, #hash_insert_row

Instance Method Details

- (Object) narcotic_connection(model)



86
87
88
# File 'src/view/drugs/narcotic.rb', line 86

def narcotic_connection(model)
  @lookandfeel.lookup(:narcotic_connection, model.substances.sort.first)
end

- (Object) packages(model)



89
90
91
92
93
94
# File 'src/view/drugs/narcotic.rb', line 89

def packages(model)
  pack = model.packages
  unless(pack.empty?)
    PackagesList.new(pack, @session, self)
  end
end

- (Object) reservation_text(model)



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'src/view/drugs/narcotic.rb', line 95

def reservation_text(model)
  if(text = model.reservation_text)
    div = HtmlGrid::Div.new(model, @session, self)
    div.css_class = 'long-text list bg'
    txt = text.send(@session.language)
    div.value = if(match = @@reservation.match(txt))
      url = sprintf('http://www.admin.ch/ch/%s/%s/c%s.html',
        (@session.language.to_s == 'fr') ? 'f' : 'd', 
        match[1].downcase,
        match[2].gsub('.', '_'))
      link = "<a href='#{url}'>#{match.to_s}</a>"
      txt.gsub(match.to_s, link)
    else
      txt
    end
    div
  end
end