Skip to content

Commit

Permalink
Fix multiselectbox dialog when more dialogs on page
Browse files Browse the repository at this point in the history
More diloag refreshing were causing errors.
  • Loading branch information
Ladas committed Sep 1, 2016
1 parent 6d6512c commit 8c88baa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
20 changes: 11 additions & 9 deletions app/models/dialog_field_drop_down_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def show_refresh_button?
end

def multi_value?
return true if options[:force_multi_value].present? && options[:force_multi_value] != "null"
return true if options[:force_multi_value].present? && options[:force_multi_value] != "null" && options[:force_multi_value]
end

def force_multi_value=(setting)
Expand All @@ -29,27 +29,29 @@ def refresh_json_value(checked_value)

refreshed_values = values

if refreshed_values.collect { |value_pair| value_pair[0].to_s }.include?(checked_value)
if checked_value.is_a?(Array) && (refreshed_values.collect { |value_pair| value_pair[0].to_s } & checked_value).present?
@value = refreshed_values.collect { |value_pair| value_pair[0].to_s } & checked_value
elsif refreshed_values.collect { |value_pair| value_pair[0].to_s }.include?(checked_value)
@value = checked_value
else
@value = @default_value
end

{:refreshed_values => refreshed_values, :checked_value => @value, :read_only => read_only?, :visible => visible?}
end

def automate_output_value
return super unless multi_value?
a = @value.chomp.split(',')
if @value.is_a?(Integer)
a = [@value]
elsif @value.is_a?(Array)
a = @value
else
a = @value.blank? ? [] : @value.chomp.split(',')
end
automate_values = a.first.kind_of?(Integer) ? a.map(&:to_i) : a
MiqAeEngine.create_automation_attribute_array_value(automate_values)
end

def automate_key_name
return super unless multi_value?
MiqAeEngine.create_automation_attribute_array_key(super)
end

private

def load_values_on_init?
Expand Down
10 changes: 7 additions & 3 deletions app/views/shared/dialogs/_dialog_field_drop_down_list.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
- if edit
- select_values = field.values.collect
- select_values = field.values.collect(&:reverse)
- selected ||= wf.value(field.name)

- if field.multi_value?
= select_tag(field.name,
options_for_select(select_values, wf.value(field.name)),
Expand All @@ -19,7 +18,12 @@
- if field.auto_refresh
:javascript
dialogFieldRefresh.listenForAutoRefreshMessages("#{field.id}", function() {
var selectedValue = $('select[name="#{field.name}"]').val();
var field = $('select[name="#{field.name}"]').length;
if (field) {
var selectedValue = $('select[name="#{field.name}"]').val();
} else {
var selectedValue = $('select[name="#{field.name}[]"]').val();
}
dialogFieldRefresh.refreshDropDownList("#{field.name}", "#{field.id}", selectedValue);
});

Expand Down

0 comments on commit 8c88baa

Please sign in to comment.