Class: ODDB::Html::View::Drugs::Admin::Parts

Inherits:
List
  • Object
show all
Defined in:
lib/oddb/html/view/drugs/admin/package.rb

Constant Summary collapse

COMPONENTS =
{
  [0,0] => :delete,
  [1,0] => :multi,
  [2,0] => "x",
  [3,0] => :size,
  [4,0] => :unit,
  [5,0] => "à",
  [6,0] => :quantity,
  [7,0] => :composition,
}
COMPONENT_CSS_MAP =
{ 
  [1,0,3] => "short right",
  [6,0]   => "short right",
}
CSS_ID =
'parts'
DEFAULT_CLASS =
HtmlGrid::InputText
EMPTY_LIST =
true
OMIT_HEADER =
true

Constants inherited from List

List::BACKGROUND_ROW, List::BACKGROUND_SUFFIX, List::LEGACY_INTERFACE, List::SORT_DEFAULT

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from List

#query_args, #query_key, #sort_link

Class Method Details

.input_text(*keys) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/oddb/html/view/drugs/admin/package.rb', line 58

def input_text(*keys)
  keys.each { |key|
    define_method(key) { |model| 
      input = HtmlGrid::Input.new(name(key), model, @session, self)
      input.value = model.send(key) if model
      input
    }
  }
end

Instance Method Details

#add(model) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/oddb/html/view/drugs/admin/package.rb', line 87

def add(model)
  if(@model.empty? || @model.last.saved?)
    link = HtmlGrid::Link.new(:plus, model, @session, self)
    link.set_attribute('title', @lookandfeel.lookup(:create_part))
    link.css_class = 'create square'
    args = [ :code_cid, @session.state.model.code(:cid) ]
    url = @session.lookandfeel.event_url(:ajax_create_part, args)
    link.onclick = "replace_element('#{css_id}', '#{url}');"
    link
  end
end


98
99
100
101
102
# File 'lib/oddb/html/view/drugs/admin/package.rb', line 98

def compose_footer(offset)
  if(@model.empty? || @model.last.saved?)
    @grid.add add(@model), *offset
  end
end

#composition(model) ⇒ Object



103
104
105
# File 'lib/oddb/html/view/drugs/admin/package.rb', line 103

def composition(model)
  CompositionSelect.new(name("composition"), model, @session, self)
end

#delete(model) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/oddb/html/view/drugs/admin/package.rb', line 106

def delete(model)
  if(@model.size > 1)
    link = HtmlGrid::Link.new(:minus, model, @session, self)
    link.set_attribute('title', @lookandfeel.lookup(:delete))
    link.css_class = 'delete square'
    args = [ :code_cid, @session.state.model.code(:cid), :part, @list_index ]
    url = @session.lookandfeel.event_url(:ajax_delete_part, args)
    link.onclick = "replace_element('#{css_id}', '#{url}');"
    link
  end
end

#name(part) ⇒ Object



117
118
119
# File 'lib/oddb/html/view/drugs/admin/package.rb', line 117

def name(part)
  "#{part}[#@list_index]"
end

#unsaved(model) ⇒ Object



120
121
122
# File 'lib/oddb/html/view/drugs/admin/package.rb', line 120

def unsaved(model)
  @lookandfeel.lookup(:unsaved) unless model.saved?
end