app/views/report/_form_styling.html.haml
- url = url_for_only_path(:action => 'form_field_changed', :id => (@edit[:rpt_id] || 'new'))
-# JSON hash to hold text fields and types for miqValueStylePrefill
= javascript_tag("ManageIQ.reportEditor.valueStyles = {};")
#styling_div
%h3
= _('Specify Column Styles')
%table.table.table-striped.table-bordered
%thead
%tr
%th
= _('Column Name')
%th
= _('Style')
%th
= _('If')
-# only draw th up to maximum styles defined in any of the columns
- @edit[:new][:field_order].each_with_index do |f, _|
- col_name = MiqExpression.parse_field_or_tag(f.last).report_column
- style = @edit.fetch_path(:new, :col_options, col_name, :style)
- styles_length = style.length if style
- @max_styles_length ||= 0
- @max_styles_length = styles_length if styles_length && @max_styles_length < styles_length
- @max_styles_length.times do |_|
%th
%tbody
- @edit[:new][:field_order].each_with_index do |f, f_idx|
- field_type = MiqExpression.get_col_info(f.last.split("__").first)[:format_sub_type]
- col_name = MiqExpression.parse_field_or_tag(f.last).report_column
- styles = @edit.fetch_path(:new, :col_options, col_name, :style) || []
%tr
%td
= h(f.first)
%td
- 3.times do |s_idx|
- break if s_idx > 0 && (styles[s_idx - 1].blank? || styles[s_idx - 1][:operator] == "DEFAULT")
- if s_idx > 0
%br
- opts = [[styles[s_idx] ? "<#{_('Remove')}>" : "<#{_('Normal')}>", nil]] + ReportHelper::STYLE_CLASSES.invert.map { |x| [_(x[0]), x[1]] }.sort_by { |a| a.first.downcase }
= select_tag("style_#{f_idx}_#{s_idx}",
options_for_select(opts, styles[s_idx] ? styles[s_idx][:class] : nil),
"data-miq_sparkle_on" => true,
"data-miq_observe" => {:url => url}.to_json)
%td
- 3.times do |s_idx|
- break if s_idx > 0 && (styles[s_idx - 1].blank? || styles[s_idx - 1][:operator] == "DEFAULT")
- if s_idx > 0
%br
- if styles[s_idx] && styles[s_idx][:class]
- opts = [["#{_('Default')}", "DEFAULT"]] + MiqExpression.get_col_style_operators(f.last)
= select_tag("styleop_#{f_idx}_#{s_idx}",
options_for_select(opts, styles[s_idx].nil? ? nil : styles[s_idx][:operator]),
:multiple => false,
"data-miq_sparkle_on" => true,
"data-miq_observe" => {:url => url}.to_json)
- unless styles[s_idx][:operator].nil? || styles[s_idx][:operator] == "DEFAULT" || styles[s_idx][:operator].include?("NULL") || styles[s_idx][:operator].include?("EMPTY")
- if field_type == :boolean
- values = [["#{_('true')}", "true"], ["#{_('false')}", "false"]]
= select_tag("styleval_#{f_idx}_#{s_idx}",
options_for_select(values, styles[s_idx][:value]),
:multiple => false,
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-miq_observe" => {:url => url}.to_json)
- elsif [:datetime, :date].include?(field_type)
- opts = h((field_type == :datetime ? ViewHelper::FROM_HOURS : []) + |
ViewHelper::FROM_DAYS + ViewHelper::FROM_WEEKS + ViewHelper::FROM_MONTHS + |
ViewHelper::FROM_QUARTERS + ViewHelper::FROM_YEARS) |
= select_tag("styleval_#{f_idx}_#{s_idx}",
options_for_select(Hash[opts.map {|x| [_(x), x]}], styles[s_idx][:value]),
:multiple => false,
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-miq_observe" => {:url => url}.to_json)
- else
-# Add the text field id and type into the JSON valueStyles hash for miqValueStylePrefill
= javascript_tag("ManageIQ.reportEditor.valueStyles['#styleval_#{f_idx}_#{s_idx}'] = '#{field_type}';")
= text_field_tag("styleval_#{f_idx}_#{s_idx}", styles[s_idx][:value],
:maxlength => 50,
"data-miq_observe" => {:interval => '.5', :url => url}.to_json)
- if field_type == :percent
\%
- elsif MiqExpression::FORMAT_SUB_TYPES.fetch_path(field_type, :units)
= select_tag("stylesuffix_#{f_idx}_#{s_idx}",
options_for_select(MiqExpression::FORMAT_SUB_TYPES[field_type][:units], styles[s_idx][:value_suffix]),
:multiple => false,
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-miq_observe" => {:url => url}.to_json)
- elsif !styles[s_idx]
= _('Default')
- @max_styles_length.times do |s_idx|
- if styles[s_idx] && styles[s_idx][:class]
%td{:class => styles[s_idx][:class].to_s}
= _('Sample')
- else
%td
%br
= _('* Style "If" conditions are evaluated top to bottom for each column')
-# Initiate the prefill function to show text field background images when empty
= javascript_tag("miqValueStylePrefill();")