Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion app/controllers/miq_request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def prov_copy
)

if req.kind_of?(ServiceTemplateProvisionRequest)
@dialog_replace_data = req.options[:dialog].map { |key, val| {:name => key.split('dialog_').last, :value => val } }.to_json
@dialog_replace_data = req.options[:dialog].map { |key, val| {:name => key.split('dialog_').last, :value => parse_val(key, val)} }.to_json
@new_dialog = true
template = find_record_with_rbac(ServiceTemplate, req.source_id)
resource_action = template.resource_actions.find { |r| r.action.downcase == 'provision' && r.dialog_id }
Expand Down Expand Up @@ -338,6 +338,35 @@ def menu_section_id(parms = {})

private

def parse_val(key, val)
if val.kind_of?(Integer) # Handle integer values
if key.include?("Array::") # Handle multi select with integers
val = [val]
else # Handle single select with integers
return val
end
end

# TODO: Tag Control Field currently does not handle default values
if val.include?("Classification::") # Handle tag control default values
if val.include?("\u001F") # Array of tags
val = val.split("\u001F").map do |tag|
Classification.find_by(:id => tag.split('::').second).id
end
else # Single tag
val = Classification.find_by(:id => val.split('::').second).id
end
elsif key.include?("Array::") # Handle drop down with multi select default values
if val.kind_of?(String) && val.include?("\u001F") # Check if string is an array of values
val = val.split("\u001F") # Split the string into an array
else
val = [val] # Handle single string value
end
end

val # Handles all other conditions such as non-multi-select drop downs, text fields, etc.
end

def replace_gtl
render :update do |page|
page << javascript_prologue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefr
_.forEach(tab.dialog_groups, function(group) {
_.forEach(group.dialog_fields, function(field) {
const replaceField = dialogReplaceData ? JSON.parse(dialogReplaceData).find(function (replace) { return replace.name === field.name }) : false;

// Handles multi-select dropdowns with integer values
if (field.type === 'DialogFieldDropDownList' && field.data_type === 'integer' && replaceField.value && Array.isArray(replaceField.value)) {
replaceField.value = replaceField.value.map(function (value) {
return parseInt(value, 10);
});
}

if (replaceField) {
field.default_value = replaceField.value;
}
Expand Down