-
Notifications
You must be signed in to change notification settings - Fork 15
/
add_pool.rb
98 lines (78 loc) · 2.22 KB
/
add_pool.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require "yast"
require "cwm/popup"
Yast.import "Label"
Yast.import "NtpClient"
Yast.import "Stage"
Yast.import "Popup"
# Work around YARD inability to link across repos/gems:
# @!macro [new] seeAbstractWidget
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/AbstractWidget:${0}
# @!macro [new] seeCustomWidget
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/CustomWidget:${0}
# @!macro [new] seeItemsSelection
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/ItemsSelection:${0}
# @!macro [new] seeDialog
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/Dialog:${0}
# @!macro [new] seePopup
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/Popup:${0}
module Y2NtpClient
module Dialog
# Dialog to add/edit ntp pool server
class AddPool < ::CWM::Popup
# Constructor
#
# @param address_widget [CWM::InputField]
# @param pool_type [Symbol]
def initialize(address_widget, pool_type)
super()
textdomain "ntp-client"
@address_widget = address_widget
@address = @address_widget.value
@pool_chooser = pool_for(pool_type)
end
# @macro seeDialog
def title
# TRANSLATORS: title for choosing a ntp server dialog
_("Available NTP servers")
end
# @macro seeDialog
def contents
VBox(
@pool_chooser
)
end
def next_handler
return :cancel if @pool_chooser.value.to_s.empty?
@address = @pool_chooser.value
:next
end
# @macro seeDialog
def next_button
ok_button_label
end
# @macro seeDialog
def run
result = super
@address_widget.value = @address if result == :next
result
end
private
# @macro seeDialog
def ok_button
PushButton(Id(:next), Opt(:default), ok_button_label)
end
def available_pools
{ local: Widgets::LocalList, public: Widgets::PublicList }
end
def pool_for(type)
available_pools.fetch(type, Widgets::LocalList).new(@address_widget.value)
end
def min_height
8
end
def buttons
[ok_button, cancel_button]
end
end
end
end