Class: ODDB::Html::State::Global

Inherits:
SBSM::State
  • Object
show all
Includes:
PayPal::Checkout
Defined in:
lib/oddb/html/state/global.rb,
lib/oddb/html/state/global_predefine.rb

Constant Summary collapse

LIMIT =
false
GLOBAL_MAP =
{
  :atc_browser => Drugs::AtcBrowser,
  :downloads   => Drugs::Downloads,
  :login       => Drugs::Login,
}

Instance Attribute Summary collapse

Attributes included from LoginMethods

#desired_input

Instance Method Summary collapse

Methods included from PayPal::Checkout

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

Methods included from PayPal::Download

#collect

Methods included from Util::Download

compressed_download, #compressed_download

Methods included from LoginMethods

#login_

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mth, *args) ⇒ Object



196
197
198
199
200
201
202
# File 'lib/oddb/html/state/global.rb', line 196

def method_missing(mth, *args)
  if(mth.to_s[0] == ?_)
    self
  else
    super
  end
end

Instance Attribute Details

#passed_turing_testObject (readonly)

Returns the value of attribute passed_turing_test.



22
23
24
# File 'lib/oddb/html/state/global.rb', line 22

def passed_turing_test
  @passed_turing_test
end

Instance Method Details

#_download(file) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/oddb/html/state/global.rb', line 43

def _download(file)
  path = File.join ODDB.config.export_dir, file
  if File.exist?(path)
    Download.new(@session, path)
  elsif match = /(.+)_(.+).csv/.match(file)
    packages = _search_local match[1].tr('-', ' '), match[2]
    packages.filename = file
    Drugs::DownloadExport.new(@session, packages)
  end
end

#compareObject



29
30
31
32
33
# File 'lib/oddb/html/state/global.rb', line 29

def compare
  if(code = @session.user_input(:pzn))
    _compare(code)
  end
end

#explain_ddd_priceObject



53
54
55
56
57
58
# File 'lib/oddb/html/state/global.rb', line 53

def explain_ddd_price
  if((code = @session.user_input(:pzn)) \
     && (idx = @session.user_input(:offset)))
    _explain_ddd_price(code, idx.to_i)
  end
end

#explain_priceObject



59
60
61
62
63
# File 'lib/oddb/html/state/global.rb', line 59

def explain_price
  if(code = @session.user_input(:pzn))
    _explain_price(code)
  end
end

#fachinfoObject



64
65
66
67
68
# File 'lib/oddb/html/state/global.rb', line 64

def fachinfo
  if(uid = @session.user_input(:uid))
    _fachinfo(uid)
  end
end

#feedbackObject



69
70
71
72
73
# File 'lib/oddb/html/state/global.rb', line 69

def feedback
  if(code = @session.user_input(:pzn) || @session.user_input(:uid))
    (code)
  end
end

#grant_downloadObject



34
35
36
37
38
39
40
41
42
# File 'lib/oddb/html/state/global.rb', line 34

def grant_download
  email = @session.user_input(:email)
  file = @session.user_input(:file)
  if email && file && user = ODDB::Business::GrantDownload.find_by_email(email)
    unless user.expired?(@session.user_input(:file))
      _download(@session.user_input(:file))
    end
  end
end

#homeObject



74
75
76
# File 'lib/oddb/html/state/global.rb', line 74

def home
  State::Drugs::Init.new @session, nil
end

#limit_stateObject



80
81
82
# File 'lib/oddb/html/state/global.rb', line 80

def limit_state
  State::Limit.new(@session, nil)
end

#limited?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/oddb/html/state/global.rb', line 77

def limited?
  self.class.const_get(:LIMIT)
end

#logoutObject



83
84
85
86
# File 'lib/oddb/html/state/global.rb', line 83

def logout
  @session.logout
  home
end


193
194
195
# File 'lib/oddb/html/state/global.rb', line 193

def navigation
  []
end

#packageObject



87
88
89
90
91
# File 'lib/oddb/html/state/global.rb', line 87

def package
  if(code = @session.user_input(:pzn))
    _package(code)
  end
end

#package_infosObject



92
93
94
95
96
# File 'lib/oddb/html/state/global.rb', line 92

def package_infos
  if(code = @session.user_input(:pzn))
    _package_infos(code)
  end
end

#partitioned_keys(keys) ⇒ Object



97
98
99
100
101
# File 'lib/oddb/html/state/global.rb', line 97

def partitioned_keys(keys)
  keys.partition { |key|
    /^[a-z]$/.match(key)
  }
end

#patinfoObject



102
103
104
105
106
# File 'lib/oddb/html/state/global.rb', line 102

def patinfo
  if(uid = @session.user_input(:uid))
    _patinfo(uid)
  end
end

#proceed_downloadObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/oddb/html/state/global.rb', line 107

def proceed_download
  keys = [:downloads, :months, :compression]
  input = user_input keys, keys
  compression = input[:compression][/[^_]+$/]
  unless error?
    invoice = ODDB::Business::Invoice.new
    input[:downloads].each do |filename, status|
      if status == '1'
        months = input[:months][filename]
        prices = ODDB.config.prices["org.oddb.de.download.#{months}"] || {}
        price = prices[filename].to_f / months.to_i
        item = invoice.add :download, filename, months, '', price,
                           :compression => compression
        unless price > 0
          @errors.store "months[#{filename}]",
                        create_error(:e_empty_result, :months, '0')
        end
      end
    end
  end
  if error?
    self
  else
    State::RegisterDownload.new(@session, invoice)
  end
end

#proceed_exportObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/oddb/html/state/global.rb', line 133

def proceed_export
  query = @session.persistent_user_input(:query)
  dstype = @session.persistent_user_input(:dstype) || ODDB.config.default_dstype
  result = _search_local(query, dstype)
  filename = sprintf('%s_%s.csv', query.tr(' ', '-'), dstype)
  if @session.allowed?('download', "#{ODDB.config.auth_domain}.#{filename}")
    result.filename = filename
    Drugs::DownloadExport.new @session, result
  else
    lines = result.size
    price = ODDB.config.prices["org.oddb.de.export.csv"].to_f
    unless(lines > 0 && price > 0)
      @errors.store :days, create_error(:e_empty_result, :query, query)
      self
    else
      invoice = ODDB::Business::Invoice.new
      item = invoice.add(:export, filename, lines, '', price)
      State::RegisterExport.new(@session, invoice)
    end
  end
end

#proceed_poweruserObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/oddb/html/state/global.rb', line 154

def proceed_poweruser
  days = @session.user_input(:days).to_i
  total = ODDB.config.prices["org.oddb.de.view.#{days}"].to_f 
  unless(days > 0 && total > 0)
    @errors.store :days, create_error(:e_missing_days, :days, 0)
    self
  else
    invoice = ODDB::Business::Invoice.new
    item = invoice.add(:poweruser, "unlimited access", days, 
                       @session.lookandfeel.lookup(:days), total / days)
    State::RegisterPowerUser.new(@session, invoice)
  end
=begin
    if(usr = @session.user_input(:pointer))
      State::User::RenewPowerUser.new(@session, invoice)
    else
      State::User::RegisterPowerUser.new(@session, invoice)
    end
  end
=end
end

#productObject

if(usr = @session.user_input(:pointer))

    State::User::RenewPowerUser.new(@session, invoice)
  else
    State::User::RegisterPowerUser.new(@session, invoice)
  end
end


175
176
177
178
179
# File 'lib/oddb/html/state/global.rb', line 175

def product
  if(uid = @session.user_input(:uid))
    _product(uid)
  end
end

#productsObject



180
181
182
# File 'lib/oddb/html/state/global.rb', line 180

def products
  _products(@session.persistent_user_input(:range))
end

#remote_infosObject



183
184
185
186
187
# File 'lib/oddb/html/state/global.rb', line 183

def remote_infos
  if(id = @session.user_input(:uid))
    _remote_infos(id)
  end
end

#sequenceObject



188
189
190
191
192
# File 'lib/oddb/html/state/global.rb', line 188

def sequence
  if(uid = @session.user_input(:uid))
    _sequence(uid)
  end
end