Class: ODDB::State::Admin::Sponsor

Inherits:
Global show all
Defined in:
src/state/admin/root.rb,
src/state/admin/sponsor.rb

Constant Summary

DIRECT_EVENT =
:sponsor
VIEW =
View::Admin::
PATH =
File.expand_path('../../../doc/resources/sponsor', 
File.dirname(__FILE__))

Constants inherited from Global

HOME_STATE, ZONE

Constants inherited from Global

DIRECT_EVENT, GLOBAL_MAP, HOME_STATE, LIMITED, PRINT_STATES, READONLY_STATES, RESOLVE_STATES, REVERSE_MAP, VIEW, ZONE_NAVIGATION

Constants included from UmlautSort

FILTER_PAIRS

Instance Method Summary (collapse)

Methods inherited from Global

#zone_navigation

Methods inherited from Global

#_search_drugs, #_search_drugs_state, #_trigger, #add_to_interaction_basket, #allowed?, #atc_chooser, #checkout, #clear_interaction_basket, #creditable?, #direct_request_path, #doctorlist, #download, #export_csv, #extend, #fachinfo, #feedbacks, #help_navigation, #home_navigation, #home_state, #hospitallist, #interaction_basket, #limit_state, #limited?, #logout, #navigation, #notify, #password_reset, #paypal_return, #powerlink, #print, #proceed_download, #proceed_poweruser, #resolve, #resolve_state, #rss, #search, #show, #snapback_event, #sort, #sponsorlink, #suggest_address, #switch, #unique_email, #user_input, #user_navigation, #ywesee_contact, #zone_navigation, #zones

Methods included from LoginMethods

#autologin, #login

Methods included from UmlautSort

#sort_model, #umlaut_filter

Instance Method Details

- (Object) keyname(io, key)



68
69
70
# File 'src/state/admin/sponsor.rb', line 68

def keyname(io, key)
  [@session.flavor, key, io.original_filename].join('_')
end

- (Object) store_logo(io, key, oldname)



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'src/state/admin/sponsor.rb', line 53

def (io, key, oldname)
  if(oldname)
    old = File.expand_path(oldname, PATH)
    if(File.exist?(old))
      File.delete(old)
    end
  end
  filename = keyname(io, key)
  path = File.expand_path(filename, PATH)
  FileUtils.mkdir_p(PATH)
  File.open(path, 'wb') { |fh|
    fh << io.read
  }
  filename
end

- (Object) update



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'src/state/admin/sponsor.rb', line 16

def update
  keys = [:sponsor_until, :emails, :company_name, :logo_file, :logo_fr, :urls ]
  input = user_input(keys)
  name = input[:company_name]
  values = {
    :sponsor_until =>  input[:sponsor_until],
    :urls            =>  input[:urls],
    :emails         =>  input[:emails],
  }
  if(name.empty?)
    values.store(:company, nil)
  elsif(company = @session.app.company_by_name(name))
    values.store(:company, company.pointer)
  else
    err = create_error(:e_unknown_company, :company_name, name)
    @errors.store(:company_name, err)
  end
  unless error?
    begin
      @model = @session.app.update(@model.pointer, values, unique_email)
      if(logo_default = input[:logo_file])
        name = (logo_default, :default, 
          @model.logo_filenames[:default])
        @model.logo_filenames.store(:default, name)
      end
      if(logo_fr = input[:logo_fr])
        name = (logo_fr, :fr, @model.logo_filenames[:fr])
        @model.logo_filenames.store(:fr, name)
      end
      @model.odba_store
    rescue StandardError => e
      err = create_error(:e_exception, :logo_file, e.message) 
      @errors.store(:logo_file, err)
    end
  end
  self
end