mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-15 21:32:35 +00:00
63 lines
1.9 KiB
Ruby
63 lines
1.9 KiB
Ruby
module TAC
|
|
class Dialog
|
|
class ActionDialog < Dialog
|
|
def build
|
|
background Gosu::Color::GRAY
|
|
|
|
label "Name", width: 1.0, text_align: :center
|
|
@name_error = label "Error", color: TAC::Palette::TACNET_CONNECTION_ERROR
|
|
@name_error.hide
|
|
@name = edit_line @options[:action] ? @options[:action].name : "", filter: method(:name_filter), width: 1.0
|
|
|
|
label "Comment", width: 1.0, text_align: :center
|
|
@comment = edit_line @options[:action] ? @options[:action].comment : "", width: 1.0
|
|
|
|
flow width: 1.0, margin_top: THEME_DIALOG_BUTTON_PADDING do
|
|
button "Cancel", width: 0.475 do
|
|
close
|
|
end
|
|
|
|
button @options[:action] ? @options[:accept_label] ? @options[:accept_label] : "Update" : "Add", width: 0.475 do |b|
|
|
if valid?
|
|
if @options[:action]
|
|
@options[:callback_method].call(@options[:action], @name.value.strip, @comment.value.strip)
|
|
else
|
|
@options[:callback_method].call(@name.value.strip, @comment.value.strip)
|
|
end
|
|
|
|
close
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def valid?
|
|
valid = true
|
|
name = @name.value.strip
|
|
|
|
if name.empty?
|
|
@name_error.value = "Error: Name cannot be blank\n or only whitespace."
|
|
@name_error.show
|
|
valid = false
|
|
|
|
### TODO: Handle case when renaming a cloned Action
|
|
# elsif @options[:action] && @options[:action].name == name
|
|
# @name_error.value = ""
|
|
# @name_error.hide
|
|
|
|
elsif @options[:list].find { |action| action.name == name}
|
|
@name_error.value = "Error: Name is not unique!"
|
|
@name_error.show
|
|
valid = false
|
|
|
|
else
|
|
@name_error.value = ""
|
|
@name_error.hide
|
|
end
|
|
|
|
return valid
|
|
end
|
|
end
|
|
end
|
|
end
|