Class: Reactive::View::Wx::Base

Inherits:
View::Base
  • Object
show all
Defined in:
lib/base.rb

Constant Summary collapse

@@template_class =
Template

Class Method Summary collapse

Class Method Details

.do_request(hash, wx_event = nil) ⇒ Object



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 'lib/base.rb', line 17

def do_request(hash, wx_event = nil)
  # params may be of two forms, a simple params hash or a complex hash with embedded hashes. To distinguish: if the hash contains a :link key it is a complex one.
  params, options = hash.has_key?(:link) ? [hash[:link], hash] : [hash, {}]
  new_params = params.dup
  
  # handle forms params
  forms = options[:forms]
  forms = [forms] unless forms.is_a?(Array)
  forms.compact.each do |form|
    form_name, window = case form
      when :self
        [:self, self]
      when ::Wx::Window
        raise InvalidForm, "Window #{form} has no name!" unless name = form.get_name
        [name, form]
      when String
        raise InvalidForm, "No window named #{form}" unless win = ::Wx::Window.find_window_by_name(form, self)
        [form, win]
      else
        raise InvalidForm, "Unhandled param, passed form: #{form.inspect}"
    end
    form_param = {}
    window.get_children.each {|child| next unless child.get_name =~ /^[\da-z_]+$/ ;form_param[child.get_name] = child.value}       #TODO: Handle sub-children recursively
    new_params[form_name] = form_param
  end
  
  # handle late update of params
  continue = (late_proc = options[:late]) ? late_proc.call(new_params, wx_event) : true
  
  # set up the request
  request = Request.new(new_params)
  request.local_assigns = options[:locals]
  
  # let the request run
  Base.handle_request(request) if continue
end