Class: Glimmer::SWT::DialogProxy

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

Constant Summary collapse

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

Constants inherited from ShellProxy

ShellProxy::HEIGHT_MIN, ShellProxy::WIDTH_MIN

Constants inherited from WidgetProxy

WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::JS_KEY_CODE_TO_SWT_KEY_CODE_MAP, WidgetProxy::JS_LOCATION_TO_SWT_KEY_LOCATION_MAP, WidgetProxy::SWT_CURSOR_TO_CSS_CURSOR_MAP

Instance Attribute Summary collapse

Attributes inherited from ShellProxy

#menu_bar, #minimum_size

Attributes inherited from WidgetProxy

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

Instance Method Summary collapse

Methods inherited from ShellProxy

#element, #favicon_dom_element, #handle_observation_request, #image, #image=, #parent_path, #post_add_content, #style_dom_css, #visible, #visible=

Methods inherited from CompositeProxy

#background_image, #background_image=, #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, #attach, #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_javascript_observation_request, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, #listeners, #listeners_for, 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, #print, #property_type_converters, #reattach, #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_data, #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.



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

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;
}


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

def text
  @text
end

Instance Method Details

#closeObject



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/glimmer/swt/dialog_proxy.rb', line 133

def close
  dom_element.dialog('destroy')
  dom_element.remove
  @open = false
  @init = false
  listeners_for('swt_close').each {|listener| listener.call(Event.new(widget: self))}
  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



147
148
149
# File 'lib/glimmer/swt/dialog_proxy.rb', line 147

def content(&block)
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Opal::DialogExpression.new, 'dialog', &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


185
186
187
188
189
190
# File 'lib/glimmer/swt/dialog_proxy.rb', line 185

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

#hideObject



126
127
128
129
130
131
# File 'lib/glimmer/swt/dialog_proxy.rb', line 126

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

#open(async: true) ⇒ Object



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
119
120
121
122
123
124
# File 'lib/glimmer/swt/dialog_proxy.rb', line 90

def open(async: true)
  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
    listeners_for('swt_show').each {|listener| listener.call(Event.new(widget: self))}
  }
  if async
    DisplayProxy.instance.async_exec(owned_proc)
  else
    owned_proc.call
  end
end

#open?Boolean

Returns:

  • (Boolean)


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

def open?
  @open
end

#pathObject



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

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



164
165
166
167
# File 'lib/glimmer/swt/dialog_proxy.rb', line 164

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

#suspend_event_handlingObject



159
160
161
162
# File 'lib/glimmer/swt/dialog_proxy.rb', line 159

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