Skip to content

Commit

Permalink
more widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Mar 20, 2019
1 parent a284cbc commit e218d57
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
52 changes: 52 additions & 0 deletions src/lib/y2network/widgets/destination.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Yast.import "IP"

require "cwm/common_widgets"

module Y2Network
module Widgets
class Destination < CWM::InputField
# @param route route object to get and store netmask value
# TODO: I expect it will be useful on multiple places, so we need find way how to store it
def initialize(route)
textdomain "network"
end

def label
_("&Destination")
end

def help
# TODO: original also does not have help
""
end

def opt
[:hstretch]
end

def init
Yast::UI.ChangeWidget(Id(widget_id), :ValidChars, Yast::IP.ValidChars +"-/")
# TODO: init from route object
end

def validate
return true if valid_destination?

Yast::Popup.Error(_("Destination is invalid."))
focus
false
end

private

# Validates user's input obtained from destination field
def valid_destination?
destination = value
return true if destination == "default"

ip = destination[/^[^/]+/]
Yast::IP.Check(ip)
end
end
end
end
2 changes: 0 additions & 2 deletions src/lib/y2network/widgets/netmask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def validate
# It currently allows to use netmask for IPv4 (e.g. 255.0.0.0) or
# prefix length. If prefix length is used it has to start with '/'.
# For IPv6 network, only prefix length is allowed.
#
# @param [String] netmask or /<prefix length>
def valid_netmask?
netmask = value
return false if netmask.nil? || netmask.empty?
Expand Down
33 changes: 33 additions & 0 deletions src/lib/y2network/widgets/route_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Yast.import "Netmask"
Yast.import "Label"

require "cwm/common_widgets"

module Y2Network
module Widgets
class RouteOptions < CWM::InputField
# @param route route object to get and store netmask value
# TODO: I expect it will be useful on multiple places, so we need find way how to store it
def initialize(route)
textdomain "network"
end

def label
Yast::LAbel.Options
end

def help
# TODO: original also does not have help
""
end

def opt
[:hstretch]
end

def init
# TODO: init from route object
end
end
end
end

0 comments on commit e218d57

Please sign in to comment.