-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require a description when creating Snapshot #12637
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -558,6 +558,20 @@ def snap | |
end | ||
alias_method :vm_snapshot_add, :snap | ||
|
||
def render_missing_field(session, missing_field_name) | ||
add_flash(_("%{missing_field_name} is required") % | ||
{:missing_field_name => missing_field_name}, :error) | ||
@in_a_form = true | ||
drop_breadcrumb(:name => _("Snapshot VM '%{name}'") % {:name => @record.name}, | ||
:url => "/vm_common/snap") | ||
if session[:edit] && session[:edit][:explorer] | ||
@edit = session[:edit] # saving it to use in next transaction | ||
javascript_flash(:spinner_off => true) | ||
else | ||
render :action => "snap" | ||
end | ||
end | ||
|
||
def snap_vm | ||
@vm = @record = identify_record(params[:id], VmOrTemplate) | ||
if params["cancel"] || params[:button] == "cancel" | ||
|
@@ -573,15 +587,9 @@ def snap_vm | |
@name = params[:name] | ||
@description = params[:description] | ||
if params[:name].blank? && [email protected](:snapshot_name_optional?) | ||
add_flash(_("Name is required"), :error) | ||
@in_a_form = true | ||
drop_breadcrumb(:name => _("Snapshot VM '%{name}'") % {:name => @record.name}, :url => "/vm_common/snap") | ||
if session[:edit] && session[:edit][:explorer] | ||
@edit = session[:edit] # saving it to use in next transaction | ||
javascript_flash(:spinner_off => true) | ||
else | ||
render :action => "snap" | ||
end | ||
render_missing_field(session, "Name") | ||
elsif params[:description].blank? && @record.try(:snapshot_description_required?) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor, but I always prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to be the opposite of what i want here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, you are absolutely right! so scratch that. It was just a reflex 😄 |
||
render_missing_field(session, "Description") | ||
else | ||
flash_error = false | ||
# audit = {:event=>"vm_genealogy_change", :target_id=>@record.id, :target_class=>@record.class.base_class.name, :userid => session[:userid]} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for refactoring into a method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tnx. I just discovered I have a Vim plugin to extract methods ))
Although it did put the method inside a non related if block at first, but it was still nice :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, I use IntelliJ with vim bindings and like the refactoring tools there as well