Module: ODDB::State::Admin::SelectSubstanceMethods

Included in:
SelectSubstance, User::SelectSubstance
Defined in:
src/state/admin/selectsubstance.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) update



11
12
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
# File 'src/state/admin/selectsubstance.rb', line 11

def update
  pointer = @session.user_input(:pointer)
  substance = nil
  if(pointer.is_a?(SBSM::InvalidDataError))
    pointer = Persistence::Pointer.new(:substance).creator
    update = {
      'lt'  => @model.user_input[:substance],
    }
    substance = @session.app.update(pointer, update, unique_email)
  else
    substance = pointer.resolve(@session.app)
  end
  active_agent = @model.active_agent
  aptr = active_agent.pointer
  hash = {
    :dose        =>  @model.user_input[:dose],
    :substance =>  substance.pointer,
  }
  if(active_agent.is_a?(Persistence::CreateItem))
    active_agent.append(substance.name)
    aptr = active_agent.inner_pointer
  end
  if(!error? && (klass = resolve_state(aptr)))
    model = @session.app.update(@model.pointer, hash, unique_email)
    klass.new(@session, model)
  end
end