glimmer-dsl-opal 0.0.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +56 -0
- data/README.md +815 -76
- data/VERSION +1 -1
- data/lib/glimmer-dsl-opal.rb +45 -8
- data/lib/glimmer-dsl-opal/ext/date.rb +13 -0
- data/lib/glimmer-dsl-opal/ext/exception.rb +5 -0
- data/lib/glimmer-dsl-opal/missing/net/http.rb +17 -0
- data/lib/glimmer-dsl-opal/missing/uri.rb +64 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager.rb +2 -3
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_manager_presenter.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_repository.rb +24 -99
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/login.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/board.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/cell.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_browser.rb +0 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +63 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_computed.rb +19 -19
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_computed/contact.rb +0 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +155 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +86 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_list_multi_selection.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_list_single_selection.rb +0 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_tab.rb +50 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_world.rb +29 -0
- data/lib/glimmer-dsl-opal/vendor/jquery.js +2 -0
- data/lib/glimmer/data_binding/element_binding.rb +1 -1
- data/lib/glimmer/data_binding/ext/observable_model.rb +6 -6
- data/lib/glimmer/data_binding/list_selection_binding.rb +1 -1
- data/lib/glimmer/data_binding/table_items_binding.rb +70 -0
- data/lib/glimmer/dsl/opal/async_exec_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/color_expression.rb +38 -0
- data/lib/glimmer/dsl/opal/column_properties_expression.rb +22 -0
- data/lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/custom_widget_expression.rb +77 -0
- data/lib/glimmer/dsl/opal/dsl.rb +15 -14
- data/lib/glimmer/dsl/opal/font_expression.rb +47 -0
- data/lib/glimmer/dsl/opal/layout_data_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/layout_expression.rb +22 -0
- data/lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb +2 -3
- data/lib/glimmer/dsl/opal/message_box_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/property_expression.rb +5 -2
- data/lib/glimmer/dsl/opal/rgb_expression.rb +32 -0
- data/lib/glimmer/dsl/opal/rgba_expression.rb +32 -0
- data/lib/glimmer/dsl/opal/shell_expression.rb +18 -2
- data/lib/glimmer/dsl/opal/swt_expression.rb +46 -0
- data/lib/glimmer/dsl/opal/{composite_expression.rb → table_column_expression.rb} +3 -3
- data/lib/glimmer/dsl/opal/{list_expression.rb → table_expression.rb} +3 -3
- data/lib/glimmer/dsl/opal/table_items_data_binding_expression.rb +29 -0
- data/lib/glimmer/dsl/opal/widget_expression.rb +24 -0
- data/lib/glimmer/dsl/opal/widget_listener_expression.rb +16 -3
- data/lib/glimmer/swt.rb +499 -0
- data/lib/glimmer/swt/browser_proxy.rb +27 -0
- data/lib/glimmer/swt/button_proxy.rb +40 -0
- data/lib/glimmer/swt/color_proxy.rb +119 -0
- data/lib/glimmer/{opal/select_proxy.rb → swt/combo_proxy.rb} +24 -19
- data/lib/glimmer/swt/composite_proxy.rb +31 -0
- data/lib/glimmer/{opal → swt}/display_proxy.rb +6 -4
- data/lib/glimmer/{opal → swt}/event_listener_proxy.rb +1 -1
- data/lib/glimmer/swt/fill_layout_proxy.rb +84 -0
- data/lib/glimmer/swt/font_proxy.rb +79 -0
- data/lib/glimmer/swt/grid_layout_proxy.rb +71 -0
- data/lib/glimmer/swt/label_proxy.rb +34 -0
- data/lib/glimmer/swt/layout_data_proxy.rb +87 -0
- data/lib/glimmer/swt/layout_proxy.rb +63 -0
- data/lib/glimmer/{opal → swt}/list_proxy.rb +31 -23
- data/lib/glimmer/swt/message_box_proxy.rb +143 -0
- data/lib/glimmer/{opal → swt}/point.rb +1 -1
- data/lib/glimmer/{opal → swt}/property_owner.rb +1 -1
- data/lib/glimmer/swt/row_layout_proxy.rb +105 -0
- data/lib/glimmer/swt/shell_proxy.rb +246 -0
- data/lib/glimmer/swt/style_constantizable.rb +154 -0
- data/lib/glimmer/swt/swt_proxy.rb +53 -0
- data/lib/glimmer/{opal/tab_folder.rb → swt/tab_folder_proxy.rb} +21 -15
- data/lib/glimmer/swt/tab_item_proxy.rb +84 -0
- data/lib/glimmer/swt/table_column_proxy.rb +56 -0
- data/lib/glimmer/swt/table_item_proxy.rb +147 -0
- data/lib/glimmer/swt/table_proxy.rb +159 -0
- data/lib/glimmer/swt/text_proxy.rb +46 -0
- data/lib/glimmer/swt/widget_proxy.rb +490 -0
- data/lib/glimmer/ui/custom_shell.rb +91 -0
- data/lib/glimmer/ui/custom_widget.rb +291 -0
- data/lib/glimmer/util/proc_tracker.rb +39 -0
- metadata +131 -76
- data/lib/glimmer/config.rb +0 -22
- data/lib/glimmer/dsl/engine.rb +0 -193
- data/lib/glimmer/dsl/expression.rb +0 -42
- data/lib/glimmer/dsl/expression_handler.rb +0 -48
- data/lib/glimmer/dsl/opal/browser_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/button_expression.rb +0 -18
- data/lib/glimmer/dsl/opal/combo_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/grid_layout_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/label_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/tab_folder_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/tab_item_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/text_expression.rb +0 -22
- data/lib/glimmer/dsl/parent_expression.rb +0 -12
- data/lib/glimmer/dsl/static_expression.rb +0 -36
- data/lib/glimmer/dsl/top_level_expression.rb +0 -7
- data/lib/glimmer/error.rb +0 -6
- data/lib/glimmer/invalid_keyword_error.rb +0 -6
- data/lib/glimmer/opal/div_proxy.rb +0 -22
- data/lib/glimmer/opal/document_proxy.rb +0 -178
- data/lib/glimmer/opal/element_proxy.rb +0 -287
- data/lib/glimmer/opal/grid_layout_proxy.rb +0 -54
- data/lib/glimmer/opal/iframe_proxy.rb +0 -23
- data/lib/glimmer/opal/input_proxy.rb +0 -45
- data/lib/glimmer/opal/label_proxy.rb +0 -25
- data/lib/glimmer/opal/layout_data_proxy.rb +0 -31
- data/lib/glimmer/opal/modal.rb +0 -94
- data/lib/glimmer/opal/tab_item.rb +0 -98
- data/lib/samples/elaborate/launch +0 -6
- data/lib/samples/hello/hello_combo.rb +0 -34
- data/lib/samples/hello/hello_tab.rb +0 -24
- data/lib/samples/hello/hello_world.rb +0 -8
- data/lib/samples/hello/launch +0 -10
- data/lib/samples/launch +0 -4
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'glimmer/swt/layout_proxy'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
class GridLayoutProxy < LayoutProxy
|
6
|
+
attr_reader :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing, :margin_width, :margin_height
|
7
|
+
|
8
|
+
def initialize(parent, args)
|
9
|
+
super(parent, args)
|
10
|
+
self.horizontal_spacing = 10
|
11
|
+
self.vertical_spacing = 10
|
12
|
+
self.num_columns = @args.first || 1
|
13
|
+
reapply
|
14
|
+
end
|
15
|
+
|
16
|
+
def num_columns=(columns)
|
17
|
+
@num_columns = columns
|
18
|
+
# TODO do the following instead of reapply
|
19
|
+
# @parent.add_css_class("num-columns-#{@num_columns}")
|
20
|
+
reapply
|
21
|
+
end
|
22
|
+
|
23
|
+
def make_columns_equal_width=(equal_width)
|
24
|
+
@make_columns_equal_width = equal_width
|
25
|
+
# @parent.add_css_class('make_columns_equal_width') if @make_columns_equal_width
|
26
|
+
reapply
|
27
|
+
end
|
28
|
+
|
29
|
+
def horizontal_spacing=(spacing)
|
30
|
+
@horizontal_spacing = spacing
|
31
|
+
# @parent.add_css_class("horizontal-spacing-#{@horizontal_spacing}")
|
32
|
+
reapply
|
33
|
+
end
|
34
|
+
|
35
|
+
def vertical_spacing=(spacing)
|
36
|
+
@vertical_spacing = spacing
|
37
|
+
# @parent.add_css_class("vertical-spacing-#{@vertical_spacing}")
|
38
|
+
reapply
|
39
|
+
end
|
40
|
+
|
41
|
+
def margin_width=(pixels)
|
42
|
+
@margin_width = pixels
|
43
|
+
# Using padding for width since margin-right isn't getting respected with width 100%
|
44
|
+
@parent.dom_element.css('padding-left', @margin_width)
|
45
|
+
@parent.dom_element.css('padding-right', @margin_width)
|
46
|
+
end
|
47
|
+
|
48
|
+
def margin_height=(pixels)
|
49
|
+
@margin_height = pixels
|
50
|
+
@parent.dom_element.css('margin-top', @margin_height)
|
51
|
+
@parent.dom_element.css('margin-bottom', @margin_height)
|
52
|
+
end
|
53
|
+
|
54
|
+
def reapply
|
55
|
+
layout_css = <<~CSS
|
56
|
+
display: grid;
|
57
|
+
grid-template-columns: #{'auto ' * @num_columns.to_i};
|
58
|
+
grid-template-rows: min-content;
|
59
|
+
grid-row-gap: #{@vertical_spacing}px;
|
60
|
+
grid-column-gap: #{@horizontal_spacing}px;
|
61
|
+
justify-content: start;
|
62
|
+
align-items: start;
|
63
|
+
align-content: start;
|
64
|
+
CSS
|
65
|
+
layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
|
66
|
+
@parent.dom_element.css(key, value) unless key.nil?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'glimmer/swt/widget_proxy'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
class LabelProxy < WidgetProxy
|
6
|
+
attr_reader :text
|
7
|
+
|
8
|
+
def text=(value)
|
9
|
+
@text = value
|
10
|
+
dom_element.html(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
def element
|
14
|
+
'label'
|
15
|
+
end
|
16
|
+
|
17
|
+
def alignment
|
18
|
+
[:left, :center, :right].detect {|value| args.detect { |arg| SWTProxy[value] == arg } }
|
19
|
+
end
|
20
|
+
|
21
|
+
def dom
|
22
|
+
label_text = @text
|
23
|
+
label_id = id
|
24
|
+
label_style = "text-align: #{alignment};"
|
25
|
+
label_class = name
|
26
|
+
@dom ||= html {
|
27
|
+
label(id: label_id, style: label_style, class: label_class) {
|
28
|
+
label_text
|
29
|
+
}
|
30
|
+
}.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'glimmer/swt/property_owner'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
class LayoutDataProxy
|
6
|
+
include Glimmer::SWT::PropertyOwner
|
7
|
+
attr_reader :parent,
|
8
|
+
:args,
|
9
|
+
:horizontal_alignment,
|
10
|
+
:vertical_alignment,
|
11
|
+
:horizontal_span,
|
12
|
+
:vertical_span,
|
13
|
+
:horizontal_indent,
|
14
|
+
:vertical_indent,
|
15
|
+
:grab_excess_horizontal_space,
|
16
|
+
:grab_excess_vertical_space,
|
17
|
+
:height_hint
|
18
|
+
|
19
|
+
def initialize(parent, args)
|
20
|
+
@parent = parent
|
21
|
+
@args = args
|
22
|
+
# TODO spread args correctly
|
23
|
+
# TODO avoid using reapply
|
24
|
+
reapply
|
25
|
+
end
|
26
|
+
|
27
|
+
def height_hint=(height_hint)
|
28
|
+
@height_hint = height_hint
|
29
|
+
# TODO
|
30
|
+
reapply
|
31
|
+
end
|
32
|
+
|
33
|
+
def horizontal_alignment=(horizontal_alignment)
|
34
|
+
@horizontal_alignment = horizontal_alignment
|
35
|
+
# TODO
|
36
|
+
reapply
|
37
|
+
end
|
38
|
+
|
39
|
+
def vertical_alignment=(vertical_alignment)
|
40
|
+
@vertical_alignment = vertical_alignment
|
41
|
+
# TODO
|
42
|
+
reapply
|
43
|
+
end
|
44
|
+
|
45
|
+
def horizontal_span=(value)
|
46
|
+
@horizontal_span = value
|
47
|
+
@parent.dom_element.css('grid-column-start', "span #{@horizontal_span}")
|
48
|
+
reapply
|
49
|
+
end
|
50
|
+
|
51
|
+
def vertical_span=(value)
|
52
|
+
@vertical_span = value
|
53
|
+
@parent.dom_element.css('grid-row-start', "span #{@horizontal_span}")
|
54
|
+
reapply
|
55
|
+
end
|
56
|
+
|
57
|
+
def horizontal_indent=(value)
|
58
|
+
@horizontal_indent = value
|
59
|
+
@parent.dom_element.css('padding-left', @horizontal_indent)
|
60
|
+
reapply
|
61
|
+
end
|
62
|
+
|
63
|
+
def vertical_indent=(value)
|
64
|
+
@vertical_indent = value
|
65
|
+
@parent.dom_element.css('padding-top', @vertical_indent)
|
66
|
+
reapply
|
67
|
+
end
|
68
|
+
|
69
|
+
def grab_excess_horizontal_space=(grab_excess_horizontal_space)
|
70
|
+
@grab_excess_horizontal_space = grab_excess_horizontal_space
|
71
|
+
# TODO
|
72
|
+
reapply
|
73
|
+
end
|
74
|
+
|
75
|
+
def grab_excess_vertical_space=(grab_excess_vertical_space)
|
76
|
+
@grab_excess_vertical_space = grab_excess_vertical_space
|
77
|
+
# TODO
|
78
|
+
reapply
|
79
|
+
end
|
80
|
+
|
81
|
+
def reapply
|
82
|
+
# @parent.css = <<~CSS
|
83
|
+
# CSS
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'glimmer/swt/property_owner'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
class LayoutProxy
|
6
|
+
include Glimmer::SWT::PropertyOwner
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Factory Method that translates a Glimmer DSL keyword into a WidgetProxy object
|
10
|
+
def for(keyword, parent, args)
|
11
|
+
the_layout_class = layout_class(keyword) || Glimmer::SWT::GridLayoutProxy
|
12
|
+
the_layout_class.new(parent, args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def layout_class(keyword)
|
16
|
+
class_name_alternative = keyword.camelcase(:upper)
|
17
|
+
class_name_main = "#{class_name_alternative}Proxy"
|
18
|
+
a_layout_class = Glimmer::SWT.const_get(class_name_main.to_sym) rescue Glimmer::SWT.const_get(class_name_alternative.to_sym)
|
19
|
+
a_layout_class if a_layout_class.ancestors.include?(Glimmer::SWT::LayoutProxy)
|
20
|
+
rescue => e
|
21
|
+
puts "Layout #{keyword} was not found!"
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def layout_exists?(keyword)
|
26
|
+
!!layout_class(keyword)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :parent, :args
|
31
|
+
|
32
|
+
def initialize(parent, args)
|
33
|
+
@parent = parent
|
34
|
+
@parent = parent.body_root if @parent.is_a?(Glimmer::UI::CustomWidget)
|
35
|
+
@parent.css_classes.each do |css_class|
|
36
|
+
@parent.remove_css_class(css_class) if css_class.include?('layout')
|
37
|
+
end
|
38
|
+
@args = args
|
39
|
+
@parent.add_css_class(css_class)
|
40
|
+
@parent.layout = self
|
41
|
+
self.margin_width = 15 if respond_to?(:margin_width=)
|
42
|
+
self.margin_height = 15 if respond_to?(:margin_height=)
|
43
|
+
end
|
44
|
+
|
45
|
+
def css_class
|
46
|
+
self.class.name.split('::').last.underscore.sub(/_proxy$/, '').gsub('_', '-')
|
47
|
+
end
|
48
|
+
|
49
|
+
def reapply
|
50
|
+
# subclasses can override this
|
51
|
+
end
|
52
|
+
|
53
|
+
# Decorates widget dom. Subclasses may override. Returns widget dom by default.
|
54
|
+
def dom(widget_dom)
|
55
|
+
widget_dom
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
require 'glimmer/swt/grid_layout_proxy'
|
62
|
+
require 'glimmer/swt/fill_layout_proxy'
|
63
|
+
require 'glimmer/swt/row_layout_proxy'
|
@@ -1,19 +1,30 @@
|
|
1
|
-
require 'glimmer/
|
1
|
+
require 'glimmer/swt/widget_proxy'
|
2
2
|
|
3
3
|
module Glimmer
|
4
|
-
module
|
5
|
-
class ListProxy <
|
4
|
+
module SWT
|
5
|
+
class ListProxy < WidgetProxy
|
6
6
|
ITEM_EMPTY = '_____'
|
7
7
|
attr_reader :items, :selection
|
8
8
|
|
9
|
-
def initialize(parent, args)
|
9
|
+
def initialize(parent, args)
|
10
10
|
super(parent, args)
|
11
11
|
@selection = []
|
12
12
|
end
|
13
13
|
|
14
14
|
def items=(items)
|
15
15
|
@items = items.map {|item| item.strip == '' ? ITEM_EMPTY : item}
|
16
|
-
|
16
|
+
list_selection = selection
|
17
|
+
items_dom = @items.to_a.each_with_index.map do |item, index|
|
18
|
+
li_class = ''
|
19
|
+
li_class += ' selected' if list_selection.include?(item)
|
20
|
+
li_class += ' empty-list-item' if item == ITEM_EMPTY
|
21
|
+
html {
|
22
|
+
li(class: li_class) {
|
23
|
+
item
|
24
|
+
}
|
25
|
+
}.to_s
|
26
|
+
end
|
27
|
+
dom_element.html(items_dom)
|
17
28
|
end
|
18
29
|
|
19
30
|
def index_of(item)
|
@@ -23,7 +34,11 @@ module Glimmer
|
|
23
34
|
# used for multi-selection taking an array
|
24
35
|
def selection=(selection)
|
25
36
|
@selection = selection
|
26
|
-
|
37
|
+
dom_element.find('li').remove_class('selected')
|
38
|
+
@selection.each do |item|
|
39
|
+
index = @items.index(item)
|
40
|
+
dom_element.find("li:nth-child(#{index + 1})").add_class('selected')
|
41
|
+
end
|
27
42
|
end
|
28
43
|
|
29
44
|
# used for single selection taking an index
|
@@ -43,37 +58,30 @@ module Glimmer
|
|
43
58
|
'on_widget_selected' => {
|
44
59
|
event: 'click',
|
45
60
|
event_handler: -> (event_listener) {
|
46
|
-
-> (event) {
|
47
|
-
|
48
|
-
|
49
|
-
|
61
|
+
-> (event) {
|
62
|
+
if event.target.prop('nodeName') == 'LI'
|
63
|
+
selected_item = event.target.text
|
64
|
+
select(index_of(selected_item), event.meta_key)
|
65
|
+
event_listener.call(event)
|
66
|
+
end
|
50
67
|
}
|
51
68
|
}
|
52
69
|
}
|
53
70
|
}
|
54
71
|
end
|
55
72
|
|
56
|
-
def
|
73
|
+
def element
|
57
74
|
'ul'
|
58
75
|
end
|
59
76
|
|
60
77
|
def dom
|
61
|
-
list_items = @items
|
62
78
|
list_id = id
|
63
79
|
list_style = css
|
64
80
|
list_selection = selection
|
65
|
-
@dom ||=
|
66
|
-
ul(id: list_id, style: list_style) {
|
67
|
-
list_items.to_a.each_with_index do |item, index|
|
68
|
-
li_class = ''
|
69
|
-
li_class += ' selected-list-item' if list_selection.include?(item)
|
70
|
-
li_class += ' empty-list-item' if item == ITEM_EMPTY
|
71
|
-
li(class: li_class) {
|
72
|
-
item
|
73
|
-
}
|
74
|
-
end
|
81
|
+
@dom ||= html {
|
82
|
+
ul(id: list_id, class: name, style: list_style) {
|
75
83
|
}
|
76
|
-
}
|
84
|
+
}.to_s
|
77
85
|
end
|
78
86
|
end
|
79
87
|
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'glimmer/swt/widget_proxy'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
class MessageBoxProxy < WidgetProxy
|
6
|
+
attr_reader :text, :message
|
7
|
+
|
8
|
+
def initialize(parent, args)
|
9
|
+
i = 0
|
10
|
+
@parent = parent
|
11
|
+
@args = args
|
12
|
+
@children = Set.new
|
13
|
+
@enabled = true
|
14
|
+
content do
|
15
|
+
on_widget_selected {
|
16
|
+
hide
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def text=(txt)
|
22
|
+
@text = txt
|
23
|
+
dom_element.find('.modal-content .text').html(@text)
|
24
|
+
end
|
25
|
+
|
26
|
+
def message=(msg)
|
27
|
+
@message = msg
|
28
|
+
dom_element.find('.modal-content .message').html(@text)
|
29
|
+
end
|
30
|
+
|
31
|
+
def document
|
32
|
+
element = self
|
33
|
+
begin
|
34
|
+
element = element.parent
|
35
|
+
end while(element.parent)
|
36
|
+
element
|
37
|
+
end
|
38
|
+
|
39
|
+
def open
|
40
|
+
document.add_child(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
def hide
|
44
|
+
dom_element.remove
|
45
|
+
end
|
46
|
+
|
47
|
+
def content(&block)
|
48
|
+
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Opal::MessageBoxExpression.new, &block)
|
49
|
+
end
|
50
|
+
|
51
|
+
def name
|
52
|
+
'div'
|
53
|
+
end
|
54
|
+
|
55
|
+
def selector
|
56
|
+
super + ' .close'
|
57
|
+
end
|
58
|
+
|
59
|
+
def listener_path
|
60
|
+
path + ' .close'
|
61
|
+
end
|
62
|
+
|
63
|
+
def observation_request_to_event_mapping
|
64
|
+
{
|
65
|
+
'on_widget_selected' => {
|
66
|
+
event: 'click'
|
67
|
+
},
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def style_dom_modal_css
|
72
|
+
<<~CSS
|
73
|
+
.modal {
|
74
|
+
position: fixed;
|
75
|
+
z-index: 1;
|
76
|
+
padding-top: 100px;
|
77
|
+
left: 0;
|
78
|
+
top: 0;
|
79
|
+
width: 100%;
|
80
|
+
height: 100%;
|
81
|
+
overflow: auto;
|
82
|
+
background-color: rgb(0,0,0);
|
83
|
+
background-color: rgba(0,0,0,0.4);
|
84
|
+
text-align: center;
|
85
|
+
}
|
86
|
+
.modal-content .text {
|
87
|
+
background: rgb(80, 116, 211);
|
88
|
+
color: white;
|
89
|
+
padding: 5px;
|
90
|
+
}
|
91
|
+
.modal-content .message {
|
92
|
+
padding: 20px;
|
93
|
+
}
|
94
|
+
.modal-content {
|
95
|
+
background-color: #fefefe;
|
96
|
+
padding-bottom: 15px;
|
97
|
+
border: 1px solid #888;
|
98
|
+
display: inline-block;
|
99
|
+
min-width: 200px;
|
100
|
+
}
|
101
|
+
CSS
|
102
|
+
# .close {
|
103
|
+
# color: #aaaaaa;
|
104
|
+
# float: right;
|
105
|
+
# font-weight: bold;
|
106
|
+
# margin: 5px;
|
107
|
+
# }
|
108
|
+
# .close:hover,
|
109
|
+
# .close:focus {
|
110
|
+
# color: #000;
|
111
|
+
# text-decoration: none;
|
112
|
+
# cursor: pointer;
|
113
|
+
# }
|
114
|
+
end
|
115
|
+
|
116
|
+
def dom
|
117
|
+
modal_id = id
|
118
|
+
modal_style = css
|
119
|
+
modal_text = text
|
120
|
+
modal_message = message
|
121
|
+
modal_class = ['modal', name].join(' ')
|
122
|
+
@dom ||= html {
|
123
|
+
div(id: modal_id, style: modal_style, class: modal_class) {
|
124
|
+
style(class: 'modal-style') {
|
125
|
+
style_dom_modal_css #.split("\n").map(&:strip).join(' ')
|
126
|
+
}
|
127
|
+
div(class: 'modal-content') {
|
128
|
+
header(class: 'text') {
|
129
|
+
modal_text
|
130
|
+
}
|
131
|
+
tag(_name: 'p', id: 'message', class: 'message') {
|
132
|
+
modal_message
|
133
|
+
}
|
134
|
+
input(type: 'button', class: 'close', autofocus: 'autofocus', value: 'OK')
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}.to_s
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
require 'glimmer/dsl/opal/message_box_expression'
|