ManageIQ/manageiq-ui-classic

View on GitHub
app/views/miq_ae_customization/_dialog_sample.html.haml

Summary

Maintainability
Test Coverage
-# if dialogs is selected
.row
  .col-md-12.col-lg-12
    #dialog_tabs
      %ul.nav.nav-tabs{'role' => 'tablist'}
        - @record.ordered_dialog_resources.each do |dt|
          = miq_tab_header("#{dt.resource.id}_tab") do
            = dt.resource.label
      .tab-content
        - @record.ordered_dialog_resources.each do |dt|
          -# dialog tabs
          = miq_tab_content("#{dt.resource.id}_tab") do
            - dt.resource.ordered_dialog_resources.each do |tg|
              -# dialog groups/fields
              - group = tg.resource
              %h3{:title => group.description}
                = group.label
              .form-horizontal
                - group.ordered_dialog_resources.select(&:visible).each do |g|
                  - field = g.resource
                  .form-group
                    %label.col-md-2.control-label{:title => field.description}
                      = field.label
                    .col-md-8{:title => field.description}
                      - field_id = "field_#{field.id}"
                      - case field.type
                      - when "DialogFieldTextBox"
                        - if field.protected?
                          = password_field_tag(field_id, '********', :maxlength => 20, :disabled => true)
                        - else
                          = text_field_tag(field_id, field.sample_text, :maxlength => 20, :disabled => true)

                      - when "DialogFieldCheckBox"
                        = check_box_tag(field_id, "1", field.default_value == 't', :disabled => true)
                      - when "DialogFieldDateControl", "DialogFieldDateTimeControl"
                        - time = field.default_value.present? ? Time.zone.parse(field.default_value) : Time.zone.now
                        - if field.show_past_dates
                          :javascript
                            ManageIQ.calendar.calDateFrom = undefined;
                        - else
                          :javascript
                            ManageIQ.calendar.calDateFrom = new Date("#{Time.zone.now.strftime("%Y, %m, %d")}");
                        - date_val = ["#{time.month}/#{time.day}/#{time.year}"]
                        = datepicker_input_tag("miq_date_1", h(date_val[0]),
                          :class    => "css1",
                          :readonly => "true",
                          :data_date_start => field.show_past_dates ? "" : Time.zone.now.strftime("%Y, %m, %d"))
                        - if field.type == "DialogFieldDateTimeControl"
                           
                          = _('at')
                           
                          = select_tag("start_hour", options_for_select(Array.new(24) { |i| i }, time.hour))
                          \:
                          = select_tag("start_min", options_for_select(Array.new(60) { |i| i }, time.min))

                      - when "DialogFieldTextAreaBox"
                        = text_area_tag(field.id, field.sample_text, :size => "50x6", :disabled => true)
                      - when "DialogFieldDropDownList", "DialogFieldRadioButton"
                        - if field.dynamic
                          - if field.type == "DialogFieldRadioButton"
                            %input#dialog_field_radio_sample_1{:type => "radio", :name => "dialog_field_radio"}
                            %label{:for => "dialog_field_radio_sample_1"} Option 1
                            %input#dialog_field_radio_sample_2{:type => "radio", :name => "dialog_field_radio"}
                            %label{:for => "dialog_field_radio_sample_2"} Option 2

                          - if field.type == "DialogFieldDropDownList"
                            - select_attrs = {:class => 'selectpicker'}
                            - select_attrs[:multiple] = '' if field.multiselect?
                            = select_tag("#{field.id}", options_for_select([_("Option 1"), _("Option 2")]), select_attrs)

                          - if field.show_refresh_button?
                            = button_tag(_('Refresh'), :disabled => true)

                        - else
                          - if field.values.length > 1
                            - val = copy_array(field.values.map {|x, y| x.nil? ? [x,_(y)] : [x, y]})

                            - if field.options.key?(:sort_by)
                              - if field.data_type == 'integer'
                                - val = val.map { |item| item[0].nil? ? item : [item[0].to_i, item[1]] }
                              - val = val.sort { |a, b| a[0].nil? ? -1 : field.options[:sort_by] == 'value' ? a[0] <=> b[0] : a[1] <=> b[1] }
                              - if field.options.key?(:sort_order) && field.options[:sort_order] == 'descending'
                                - val.reverse!
                            - if field.type == "DialogFieldDropDownList"
                              - select_attrs = {:class => 'selectpicker'}
                              - select_attrs[:multiple] = '' if field.multiselect?
                              = select_tag(field.id, options_for_select(val.collect(&:reverse), field.default_value), select_attrs)
                            - else
                              - val.each_with_index do |rb, i|
                                %input{:type     => "radio",
                                       :disabled => true,
                                       :checked  => (field.default_value == rb[0]),
                                       :value    => rb[0]}
                                &nbsp;
                                = rb[1]
                                &nbsp;
                          - else
                            = h(field.values[0].last) unless field.values.empty?

                      - when "DialogFieldTagControl"
                        - select_attrs = {:class => 'selectpicker'}
                        - select_attrs[:multiple] = '' if field.multiselect?
                        = select_tag(field_id, options_for_select(dialog_dropdown_select_values(field)), select_attrs)

:javascript
  miq_tabs_init("#dialog_tabs");
  miqInitSelectPicker();