Class: ODDB::Html::State::Drugs::Admin::Package

Inherits:
Package show all
Defined in:
lib/oddb/html/state/drugs/admin/package.rb

Direct Known Subclasses

NewPackage

Constant Summary collapse

VIEW =
View::Drugs::Admin::Package

Constants inherited from Package

Package::LIMIT

Constants inherited from Global

Global::GLOBAL_MAP, Global::LIMIT

Instance Attribute Summary

Attributes inherited from Global

#passed_turing_test

Attributes included from LoginMethods

#desired_input

Instance Method Summary collapse

Methods inherited from Package

#_package, #direct_event

Methods inherited from Global

transparent_login

Methods included from Events

#_compare, #_complete, #_explain_ddd_price, #_explain_price, #_fachinfo, #_feedback, #_package, #_package_by_code, #_package_infos, #_patinfo, #_products, #_remote, #_remote_comparables, #_remote_infos, #_remote_package, #_remote_packages, #_search, #_search_append_products, #_search_append_sequences, #_search_by, #_search_local, #_search_remote, #_tax_factor, #compare_remote, #ddd, #limited?, #navigation, #search

Methods inherited from Global

#_download, #compare, #explain_ddd_price, #explain_price, #fachinfo, #feedback, #home, #limit_state, #limited?, #logout, #method_missing, #navigation, #package_infos, #partitioned_keys, #patinfo, #proceed_export, #proceed_poweruser, #product, #products, #remote_infos, #sequence

Methods included from PayPal::Checkout

#ajax_autofill, #checkout, #checkout_keys, #checkout_mandatory, #collect, #create_user

Methods included from LoginMethods

#login_

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ODDB::Html::State::Global

Instance Method Details

#_update(input) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/oddb/html/state/drugs/admin/package.rb', line 75

def _update input
  email = @session.user.email
  input.each { |key, value|
    unless(@errors[key])
      set = case key
            when :name
              @model.name.de = value unless(@model.name.de == value)
            when :price_public, :price_festbetrag, :price_exfactory
              update_price(/price_(.*)/.match(key.to_s)[1].to_sym, value.to_f)
            when :code_cid, :code_festbetragsgruppe, :code_festbetragsstufe
              update_code(/code_(.*)/.match(key.to_s)[1].to_sym, value)
            when :code_zuzahlungsbefreit, :code_prescription
              update_code(/code_(.*)/.match(key.to_s)[1].to_sym, !!value)
            when :size
              update_parts(input)
            end
      unless(set.nil?)
        @model.data_origins.store key, email
      end
    end
  }
  if((uid = input[:sequence]) \
     && (seq = ODDB::Drugs::Sequence.find_by_uid(uid)) \
     && @model.sequence != seq)
    @model.sequence = seq
    @model.parts.each_with_index { |part, idx| 
      part.composition = seq.compositions[idx]
      part.save
    }
  elsif((seq = @model.sequence) && seq.is_a?(Util::UnsavedHelper))
    @model.sequence = seq.delegate
  end
  @model.save
  self
end

#ajax_create_partObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/oddb/html/state/drugs/admin/package.rb', line 19

def ajax_create_part
  check_model
  parts = @model.parts.dup
  if(!error?)
    part = ODDB::Drugs::Part.new
    part.package = Util::UnsavedHelper.new(@model)
    parts.push part
  end
  AjaxParts.new @session, parts
end

#ajax_delete_partObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/oddb/html/state/drugs/admin/package.rb', line 29

def ajax_delete_part
  check_model
  keys = [:code_cid, :part]
  input = user_input(keys, keys)
  agents = []
  if(!error? \
     && (part = @model.parts.at(input[:part].to_i)))
    part.delete
  end
  AjaxParts.new(@session, @model.parts)
end

#check_modelObject



40
41
42
43
44
# File 'lib/oddb/html/state/drugs/admin/package.rb', line 40

def check_model
  if(@model.code(:cid, ODDB.config.country).to_s != @session.user_input(:code_cid))
    @errors.store :code_cid, create_error(:e_state_expired, :code_cid, nil)
  end
end

#deleteObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/oddb/html/state/drugs/admin/package.rb', line 45

def delete
  check_model
  unless error?
    seq = @model.sequence
    if(seq.is_a? Util::UnsavedHelper)
      seq = seq.delegate
    end
    @model.delete
    Sequence.new(@session, seq)
  end
end

#packageObject



110
111
112
113
114
115
116
# File 'lib/oddb/html/state/drugs/admin/package.rb', line 110

def package
  if((code = @session.user_input(:cid)) && @model.code(:cid, ODDB.config.country) == code)
    self
  else
    super
  end
end

#updateObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/oddb/html/state/drugs/admin/package.rb', line 56

def update
  mandatory = [ :name, :code_cid ]
  keys = [ :price_exfactory, :price_public, :price_festbetrag,
           :code_festbetragsstufe, :code_festbetragsgruppe,
           :code_zuzahlungsbefreit, :code_prescription, :unit, :sequence,
           :size, :multi, :composition, :quantity ]
  input = user_input(mandatory + keys, mandatory)
  others = ODDB::Drugs::Package.search_by_code(:type    => 'cid',
                                               :value   => input[:code_cid],
                                               :country => ODDB.config.country)
  others.delete(@model)
  unless others.empty?
    value = sprintf "'%i' (%s)", input[:code_cid], 
                    others.collect { |pac| pac.name.de }.join(', ')
    @errors.store(:code_cid, 
                  create_error(:e_duplicate_cid, :code_cid, value))
  end
  _update input
end