Class: Glimmer::SWT::DialogProxy

Inherits:
CompositeProxy show all
Defined in:
lib/glimmer/swt/dialog_proxy.rb

Constant Summary collapse

STYLE =
".ui-dialog .ui-dialog-content {\n  background: rgb(235, 235, 235);\n}\n.ui-dialog-titlebar {\n  background: rgb(80, 116, 211);\n  color: white;\n}\n.ui-dialog .dialog .ui-widget-overlay {\n  z-index: 10 !important;\n  background-color: rgba(0, 0, 0, 0.4);\n  opacity: 1;\n}\n.ui-dialog * {\n  z-index: 200 !important;\n}\n"

Constants inherited from WidgetProxy

WidgetProxy::DEFAULT_INITIALIZERS

Instance Attribute Summary collapse

Attributes inherited from WidgetProxy

#args, #background, #children, #disposed?, #enabled, #focus, #font, #foreground, #menu, #menu_requested, #parent, #rendered

Instance Method Summary collapse

Methods inherited from CompositeProxy

#default_layout, #get_layout, #layout=, #layout​, #pack

Methods inherited from WidgetProxy

#add_content_on_render, #add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content_on_render_blocks, #css_classes, #default_observation_request_to_event_mapping, #dialog_ancestor, #dispose, #dom_element, #effective_observation_request_to_event_mapping, #element, #event_handling_suspended?, #event_listener_proxies, for, #get_data, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, max_id_number_for, max_id_numbers, #method_missing, #name, next_id_number_for, #observation_request_to_event_mapping, #observation_requests, #parent_dom_element, #parent_path, #parents, #post_add_content, #post_dispose_child, #post_initialize_child, #property_type_converters, #remove_all_listeners, #remove_css_class, #remove_css_classes, #remove_event_listener_proxies, #render, reset_max_id_numbers!, #selector, #set_attribute, #set_data, #set_focus, #shell, #skip_content_on_render_blocks?, #style_element, #swt_widget, underscored_widget_name, widget_class, widget_exists?, widget_handling_listener, #widget_property_listener_installers

Methods included from PropertyOwner

#attribute_getter, #attribute_setter, #get_attribute, #set_attribute

Constructor Details

#initialize(parent, args, block) ⇒ DialogProxy

Returns a new instance of DialogProxy.



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/glimmer/swt/dialog_proxy.rb', line 62

def initialize(parent, args, block)
  i = 0
  @parent = parent
  @parent = nil if parent.is_a?(LatestShellProxy)
  @parent ||= DisplayProxy.instance.shells.detect(&:open?) || ShellProxy.new([])
  @args = args
  @block = block
  @children = Set.new
  @enabled = true
  DisplayProxy.instance.opened_dialogs.last&.suspend_event_handling
  DisplayProxy.instance.dialogs << self
  @parent.post_initialize_child(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::WidgetProxy

Instance Attribute Details

#textObject

.close {

  color: #aaaaaa;
  float: right;
  font-weight: bold;
  margin: 5px;
}
.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}


60
61
62
# File 'lib/glimmer/swt/dialog_proxy.rb', line 60

def text
  @text
end

Instance Method Details

#closeObject



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/glimmer/swt/dialog_proxy.rb', line 127

def close
  dom_element.dialog('destroy')
  dom_element.remove
  @open = false
  @init = false
  Element['.dialog-overlay'].add_class('hide') unless DisplayProxy.instance.dialogs.any?(&:open?)
  parent.children.delete(self)
  shell.close if shell.children.empty?
  DisplayProxy.instance.dialogs.delete(self)
  DisplayProxy.instance.opened_dialogs.last&.resume_event_handling
end

#content(&block) ⇒ Object



140
141
142
# File 'lib/glimmer/swt/dialog_proxy.rb', line 140

def content(&block)
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Opal::DialogExpression.new, &block)
end

#domObject

def selector

  super + ' .close'
end

def listener_path
  widget_path + ' .close'
end

def observation_request_to_event_mapping
  {
    'on_widget_selected' => {
      event: 'click'
    },
  }
end


178
179
180
181
182
183
# File 'lib/glimmer/swt/dialog_proxy.rb', line 178

def dom
  @dom ||= html {
    div(id: id, class: "#{name} modal hide", title: text) {
    }
  }.to_s
end

#hideObject



120
121
122
123
124
125
# File 'lib/glimmer/swt/dialog_proxy.rb', line 120

def hide
  @hiding = true
  dom_element.dialog('close')
  @open = false
  Element['.dialog-overlay'].add_class('hide') unless DisplayProxy.instance.dialogs.any?(&:open?)
end

#openObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/glimmer/swt/dialog_proxy.rb', line 89

def open
  owned_proc = Glimmer::Util::ProcTracker.new(owner: self, invoked_from: :open) {
    shell.open(async: false) unless shell.open?
    unless @init
      dom_element.remove_class('hide')
      dom_element.dialog('auto_open' => false)
      @init = true
      dom_element.dialog('option', 'appendTo', parent.path)
      dom_element.dialog('option', 'modal', true) # NOTE: Not Working! Doing manually below by relying on overlay in ShellProxy.
      unless DisplayProxy.instance.dialogs.any?(&:open?) # only add for first dialog open
        Element['.dialog-overlay'].remove_class('hide')
      end
      dom_element.dialog('option', 'closeOnEscape', true)
      dom_element.dialog('option', 'draggable', true)
      dom_element.dialog('option', 'width', 'auto')
      dom_element.dialog('option', 'minHeight', 'none')
      dom_element.on('dialogclose') do
        unless @hiding
          close
        else
          @hiding = false
        end
      end
    else
      dom_element.dialog('open')
    end
    @open = true
  }
  DisplayProxy.instance.async_exec(owned_proc)
end

#open?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/glimmer/swt/dialog_proxy.rb', line 85

def open?
  @open
end

#pathObject



144
145
146
147
148
149
150
# File 'lib/glimmer/swt/dialog_proxy.rb', line 144

def path
  if @init # it gets moved once initialized by jQuery UI, so only ID is reliable then
    "##{id}"
  else
    super
  end
end

#resume_event_handlingObject



157
158
159
160
# File 'lib/glimmer/swt/dialog_proxy.rb', line 157

def resume_event_handling
  super
  Element["[aria-describedby=#{id}]"].css('z-index', 100)
end

#suspend_event_handlingObject



152
153
154
155
# File 'lib/glimmer/swt/dialog_proxy.rb', line 152

def suspend_event_handling
  super
  Element["[aria-describedby=#{id}]"].css('z-index', 9)
end