ManageIQ/manageiq-ui-classic

View on GitHub
app/views/miq_request/_prov_field.html.haml

Summary

Maintainability
Test Coverage
- url = url_for_only_path(:action => 'prov_field_changed', :id => (@edit[:req_id] || 'new')) if @edit
-# wf          The workflow object currently in use
-# dialog      Dialog name (symbol)
-# field       Field name (symbol)
- options = @options ? @options : @edit[:new]
- field_hash = wf.get_field(field, dialog)
- return if field_hash.blank?
- field_id = dialog.to_s + "__" + field.to_s
- disabled ||= false
- unless [:hide, :ignore].include?(field_hash[:display])
  :javascript
    // Create from/to date JS vars to limit calendar starting from
    ManageIQ.calendar.calDateFrom = miqCalendarDateConversion("#{@timezone_offset}");
  - if [:cluster_filter, :ds_filter, :host_filter, :rp_filter, :vm_filter, :placement_storage_profile].include?(field)
    -# Filter Pull Down fields, show them only if there are any values
    - unless field_hash[:values].blank?
      .form-group
        %label.col-md-2.control-label
          = field_hash[:description]
          - if @edit && field_hash[:required] && field_hash[:display] == :edit
            *
        .col-md-8
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of this pulldown field
            - opts = [["<#{_('ALL')}>", 0]]
            - if field_hash[:data_type] == :integer
              - opts += Array(field_hash[:values].invert).sort_by(&:last)
            - else
              - opts += Array(field_hash[:values].invert).sort_by(&:first)
            = select_tag(field_id,
                         options_for_select(opts, options[field].kind_of?(Array) ? options[field].first : options[field]),
                         :style                 => "width: auto;",
                         "data-miq_sparkle_on"  => true,
                         "data-miq_sparkle_off" => true,
                         :class                 => "selectpicker")
            :javascript
              miqInitSelectPicker();
              miqSelectPickerEvent("#{field_id}", "#{url}")
          - else
            -# Just show the field value
            -# Description is in the second, last, array element
            = options[field].last
          -# Display notes if available
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            = field_hash[:notes]
  - else
    .form-group
      %label.col-md-2.control-label{:valign => "top"}
        = field_hash[:description]
        - len =  field_hash[:max_length] ? field_hash[:max_length] : ViewHelper::MAX_NAME_LEN
        - if field_hash[:help]
          %a{:id               => "popover-#{field_hash.object_id}",
             :tabindex         => 0,
             :role             => "button",
             :"data-toggle"    => "popover",
             :"data-trigger"   => "focus",
             :"data-html"      => "true",
             :title            => "",
             :"data-content"   => "#{field_hash[:help]}",
             :"data-placement" => "top"}
            %span.fa.fa-info-circle
          :javascript
            $('#popover-#{field_hash.object_id}').popovers();
        - if field_hash[:description] == "Provision on"
          (#{get_timezone_abbr(current_user)})
        - if @edit && @edit[:new] && [:vm_description].include?(field)
          %br
          (
          %span#description_count
            = @edit[:new][:vm_description] ? @edit[:new][:vm_description].length : 0
          \/ #{len} )
        - if @edit && field_hash[:required] && field_hash[:display] == :edit
          *
      -# Text fields
      - if [:allocated_disk_storage, :cpu_limit, :cpu_reserve, :entitled_processors, :dns_servers, :dns_suffixes, :gateway,
            :hostname, :ip_addr, :linux_host_name, :linux_domain_name,
            :mac_address, :owner_address, :owner_city, :owner_company,
            :owner_country, :owner_department, :owner_email,
            :owner_first_name, :owner_last_name, :owner_load_ldap,
            :owner_office, :owner_manager, :owner_manager_mail,
            :owner_manager_phone, :owner_phone, :owner_phone_mobile,
            :owner_state, :owner_title, :owner_zip, :request_notes,
            :subnet_mask, :memory_limit, :memory_reserve,
            :root_username, :root_password, :ssh_public_key, :sysprep_password, :sysprep_domain_admin,
            :sysprep_domain_password, :sysprep_workgroup_name,
            :sysprep_full_name, :sysprep_organization,
            :sysprep_product_id, :sysprep_computer_name,
            :sysprep_per_server_max_connections, :vm_description,
            :vm_name, :wins_servers, :sysprep_domain,
            :sysprep_admin_password, :sysprep_product_key, :sysprep_locale_ui,
            :sysprep_locale_input, :sysprep_locale_system, :sysprep_locale_user,
            :sysprep_machine_object_ou].include?(field)
        .col-md-8
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of the text field
            - if [:root_password, :sysprep_password, :sysprep_domain_password, :sysprep_admin_password].include?(field)
              = password_field_tag(field_id, options[field],
                                   :maxlength         => ViewHelper::MAX_NAME_LEN,
                                   :class             => "form-control",
                                   :disabled          => disabled,
                                   "data-miq_observe" => {:interval => '.5', :url => url}.to_json)
            - elsif [:request_notes, :vm_description].include?(field)
              = text_area_tag(field_id, options[field],
                              :maxlength                  => len,
                              :class                      => "form-control",
                              :size                       => "25x4",
                              :counter                    => "description_count",
                              "data-miq_check_max_length" => true,
                              "data-miq_observe"          => {:interval => '.5', :url => url}.to_json)
            - else
              = text_field_tag(field_id, options[field],
                               :maxlength         => len,
                               :class             => "form-control",
                               :disabled          => disabled,
                               "data-miq_observe" => {:interval => '.5', :url => url}.to_json)
          - else
            -# Just show the field value
            - if [:root_password, :sysprep_password, :sysprep_domain_password, :sysprep_admin_password].include?(field)
              - unless options[field].nil?
                - options[field].length.times do
                  *
            - else
              = options[field]
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            -# Display notes if available
            = field_hash[:notes]
        .col-md-2
          - if field == :owner_email
            - fh = wf.get_field(:owner_load_ldap, dialog)
            - if @edit && field_hash[:display] == :edit && fh[:display] == :show && !@edit[:stamp_typ]
              #lookup_button_off{:style => "#{options[field].blank? ? '' : 'display:none'}"}
                = button_tag(_("Lookup"), :class => "btn btn-default disabled")
              #lookup_button_on{:style => "#{options[field].blank? ? 'display:none' : ''}"}
                = button_tag(_('Lookup'),
                             :class   => "btn btn-primary",
                             :alt     => t = _("LDAP Group Lookup"),
                             :title   => t,
                             :onclick => "miqAjaxButton('#{url_for_only_path(:controller => 'miq_request',
                                                                   :action     => 'retrieve_email',
                                                                   :field      => fh[:pressed][:method],
                                                                   :button     => 'submit')}');")
      - elsif [:vm_prefix].include?(field)
        -# text field for vm prefix/suffix
        .col-md-8
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of the text field
            = text_field_tag(field_id, options[field],
              :maxlength         => ViewHelper::MAX_NAME_LEN,
              "data-miq_observe" => {:interval => '.5', :url => url}.to_json)
            = "_(%s)_" % _("VM Number")
            -# = h(i)
            = text_field_tag("#{dialog}__vm_suffix", options[:vm_suffix],
              :maxlength         => ViewHelper::MAX_NAME_LEN,
              "data-miq_observe" => {:interval => '.5', :url => url}.to_json)
          - else
            -# Just show the field value
            = "#{options[field]}_(%s)_#{options[:vm_suffix]}" % _("VM Number")
          -# Display notes if available
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            = field_hash[:notes]
      - elsif [:vm_memory].include?(field)
        -# text field or a Pull down for vm memory, depending upon existence of :values hash
        .col-md-8
          - if @edit && field_hash[:display] == :edit && !field_hash[:values] && !@edit[:stamp_typ]
            -# Allow editing of the text field
            = text_field_tag(field_id, options[field].kind_of?(Array) ? options[field].last : options[field],
              :maxlength         => ViewHelper::MAX_NAME_LEN,
              "data-miq_observe" => {:interval => '.5', :url => url}.to_json)
          - elsif @edit && field_hash[:display] == :edit && field_hash[:values] && !@edit[:stamp_typ]
            -# Allow editing of the text field
            - if field_hash[:values].blank?
              - opts = [["<#{_('No Choices Available')}>", nil]]
            - else
              - if field_hash[:default]
                - opts = []
              - else
                - opts = [["<#{_('Choose')}>", nil]]
              - opts += (Array(field_hash[:values].invert).sort_by { |a| a.first.to_i })
            = select_tag(field_id,
                          options_for_select(opts, options[field].kind_of?(Array) ? options[field].first : options[field]),
                          :disabled              => disabled,
                          "data-miq_sparkle_on"  => true,
                          "data-miq_sparkle_off" => true,
                          :class    => "selectpicker")
            :javascript
              miqInitSelectPicker();
              miqSelectPickerEvent("#{field_id}", "#{url}")
          - else
            -# Just show the field value
            = options[field].kind_of?(Array) ? options[field].last : options[field]
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            -# Display notes if available
            = field_hash[:notes]
      - elsif [:customization_template_script, :sysprep_upload_text, :user_script_text].include?(field)
        -# text Area field to display uploaded file contents
        .col-md-8
          = text_area_tag(field_id, options[field],
            :readonly => "readonly",
            :style    => "width: 600px; height: 250px;")
      - elsif [:placement_folder_name].include?(field)
        -# wider Pull Down field that fits into 1280 wide screens
        .col-md-8
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of this pulldown field
            - if field_hash[:values].blank?
              - opts = [["<#{_('No Choices Available')}>", nil]]
            - else
              - if field_hash[:required]
                - if field_hash[:default]
                  - opts = []
                - else
                  - opts = [["<#{_('Choose')}>", nil]]
              - else
                - opts = [["<#{_('None')}>", nil]]
              - if field_hash[:data_type] == :integer
                - opts += Array(field_hash[:values].invert).sort_by(&:first)
              - else
                - opts += Array(field_hash[:values].invert).sort_by { |a| a.first.downcase }
            = select_tag(field_id,
                         options_for_select(opts, options[field].kind_of?(Array) ? options[field].first : options[field]),
                         :disabled              => disabled,
                         :style                 => "width:auto;",
                         "data-miq_sparkle_on"  => true,
                         "data-miq_sparkle_off" => true,
                         :class                 => "selectpicker")
            :javascript
              miqInitSelectPicker();
              miqSelectPickerEvent("#{field_id}", "#{url}")
          - else
            -# Just show the field value
            = options[field].last
            -# Description is in the second, last, array element
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            -# Display notes if available
            = field_hash[:notes]
      - elsif [:instance_type, :sys_type, :storage_type, :cloud_volumes, :pin_policy, :guest_access_key_pair, :security_groups, :monitoring, :vm_tag_1,
               :vm_tag_2, :vm_tag_3, :vm_tag_4, :vm_tag_5, :vm_tag_6, :vm_tag_7, :vm_tag_8,
               :vm_tag_9, :vm_tag_10, :provision_type, :network_adapters, :retirement,
               :retirement_warn, :cloud_network, :network_port, :cloud_subnet,
               :floating_ip_address, :resource_group, :load_balancer,
               :sysprep_auto_logon_count, :sysprep_domain_name, :sysprep_server_license_mode,
               :vlan, :cloud_tenant, :src_configuration_profile_id, :vm_minimum_memory,
               :vm_maximum_memory, :boot_disk_size, :subnet, :placement_group, :shared_processor_pool].include?(field)
        -# Pull Down fields
        -# Multiple select Pull Down fields
        - multiple = %i[security_groups cloud_volumes].include?(field)
        - td_class = field == :security_groups ? "wider" : "wide"
        .col-md-8{:class => td_class}
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of this pulldown field
            - if field_hash[:values].blank?
              - opts = [["<#{_('No Choices Available')}>", nil]]
            - else
              - if field_hash[:required]
                - if field_hash[:default]
                  - opts = []
                - else
                  - opts = [["<#{_('Choose')}>", nil]]
              - else
                - opts = multiple ? [] : [["<#{_('None')}>", nil]]
              - if field_hash[:sort_by] == :none
                - opts += Array(field_hash[:values].invert)
              - elsif field_hash[:data_type] == :integer
                - opts += Array(field_hash[:values].invert).sort_by(&:last)
              - else
                - opts += Array(field_hash[:values].invert).sort_by { |a| a.first.downcase }
            = select_tag(field_id,
                         options_for_select(opts, (options[field].kind_of?(Array) && !multiple) ? options[field].first : options[field]),
                         :multiple              => multiple,
                         :disabled              => disabled,
                         "data-miq_sparkle_on"  => true,
                         "data-miq_sparkle_off" => true,
                         :class                 => "selectpicker")
            :javascript
              miqInitSelectPicker();
              miqSelectPickerEvent("#{field_id}", "#{url}")
          - else
            -# Just show the field value
            - if multiple
              - options[field].each_with_index do |val, i|
                = field_hash[:values][val]
                - if i < options[field].length - 1
                  %br
            - else
              -# Description is in the second, last, array element
              = options[field].last
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            -# Display notes if available
            = field_hash[:notes]
      - elsif [:tag_ids, :vm_tags].include?(field)
        -# tree control for tags fields
        .col-md-10.tagging-container
          = react('TaggingWrapperConnected',
            :tags    => @tags,
            :options => { :type => 'provision', :hideHeaders => false, :hideButtons => true,
                          :url => url, :isDisabled => @tags[:isDisabled]})
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            -# Display notes if available
            = field_hash[:notes]
      - elsif [:attached_ds, :iso_image_id, :placement_availability_zone,
               :placement_cluster_name, :placement_dc_name, :placement_ds_name,
               :placement_ems_name, :placement_host_name, :placement_rp_name,
               :pxe_image_id, :windows_image_id, :src_configured_system_ids,
               :src_host_ids, :src_vm_id, :sysprep_custom_spec,
               :customization_template_id].include?(field)
        -# Pull Down fields that need to be sorted on description
        .col-md-8
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of this pulldown field
            - if display_prov_grid(field)
              = render :partial => "miq_request/prov_grid_item", :locals => {:field => field, :field_id => field_id, :spec => field_hash[:required]}
            - else
              - if field_hash[:values].blank?
                - opts = [["<#{_('No Choices Available')}>", nil]]
              - else
                - if field_hash[:required]
                  - if field_hash[:default]
                    - opts = []
                  - else
                    - opts = [["<#{_('Choose')}>", nil]]
                - else
                  - opts = [["<#{_('None')}>", nil]]
                - opts += Array(field_hash[:values].invert).sort_by { |a| a.first.downcase }
              = select_tag(field_id,
                           options_for_select(opts, options[field].kind_of?(Array) ? options[field].first : options[field]),
                           :style                 => "width: auto;",
                           "data-miq_sparkle_on"  => true,
                           "data-miq_sparkle_off" => true,
                           :class                 => "selectpicker")
              :javascript
                miqInitSelectPicker();
                miqSelectPickerEvent("#{field_id}", "#{url}")
          - else
            -# Just show the field value
            - if field == :src_host_ids
              -# read only grid for src_host_id
              = render :partial => "miq_request/prov_host_grid", :locals => {:field_id => field_id}
            - elsif field == :src_configured_system_ids
              -# read only grid for src_configured_system_ids
              = render :partial => "miq_request/prov_configured_system_grid", :locals => {:field_id => field_id}
            - elsif field == :attached_ds
              -# Description is in the second, last, array element
              = Array.wrap(options[:attached_ds_names]).join(",")
            - elsif options[field]
              -# Description is in the second, last, array element
              = options[field].last
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            -# Display notes if available
            = field_hash[:notes]
      - elsif [:pxe_server_id, :number_of_vms, :number_of_cpus, :number_of_sockets, :cores_per_socket, :snapshot, :sysprep_enabled, :sysprep_timezone].include?(field)
        -# ### Pull Down for fields that dont need <None> in the list
        .col-md-8
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of this pulldown field
            - if field_hash[:values].blank?
              - opts = [["<#{_('No Choices Available')}>", nil]]
            - else
              - if field_hash[:default]
                - opts = []
              - else
                - opts = [["<#{_('Choose')}>", nil]]
              - if field == :sysprep_timezone
                - opts += Array(field_hash[:values].invert)
              - elsif field_hash[:data_type] == :integer
                - opts += Array(field_hash[:values].invert).sort_by(&:last)
              - else
                - opts += Array(field_hash[:values].invert).sort_by(&:first)
            = select_tag(field_id,
                         options_for_select(opts, options[field].kind_of?(Array) ? options[field].first : options[field]),
                         :disabled              => disabled,
                         "data-miq_sparkle_on"  => true,
                         "data-miq_sparkle_off" => true,
                         :class                 => "selectpicker")
            :javascript
              miqInitSelectPicker();
              miqSelectPickerEvent("#{field_id}", "#{url}")
          - else
            -# Just show the field value
            -# Description is in the second, last, if it is an array element, or possible single value from the API
            - if options[field].kind_of?(Array)
              = options[field].last
            - else
              = options[field]
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            -# Display notes if available
            = field_hash[:notes]
      - elsif [:linked_clone, :migratable, :placement_auto, :stateless, :sysprep_auto_logon, :sysprep_change_sid, :seal_template,
               :sysprep_delete_accounts, :sysprep_spec_override, :vm_auto_start, :vm_dynamic_memory, :is_preemptible, :public_network,
               :cpu_hot_add, :cpu_hot_remove, :memory_hot_add].include?(field)
        -# ### Checkbox fields
        .col-md-8{:style => "vertical-align: top;"}
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of the text field
            - checked = options[field] && options[field][0].to_s == "true"
            = check_box_tag(field_id, true, checked,
                            :disabled                   => disabled,
                            "data-miq_sparkle_on"       => true,
                            "data-miq_sparkle_off"      => true,
                            "data-miq_observe_checkbox" => {:url => url}.to_json)
          - else
            -# Just show the field value
            - checked = options[field] && options[field][0].to_s == "true"
            = check_box_tag(field_id, true, checked,
                            :id       => field_id,
                            :disabled => true)
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            -# Display notes if available
            = field_hash[:notes]
      - elsif [:addr_mode, :disk_format, :sysprep_identification, :schedule_type, :cloud_network_selection_method, :disk_sparsity].include?(field)
        -# Radio Button fields
        .col-md-8
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of the text field
            -# need to specify Checked/Disabled to check or disable a checkbox, so need separate lines for each depending upon radio button state
            - field_hash[:values].each do |f|
              - checked = options[field] && options[field][0] == f[0]
              - current_div = "#{@edit[:new][:current_tab_key]}"
              - onclick = remote_function(:with => "miqSerializeField('#{current_div}', '#{field_id}')", :url => url, :loading => "miqSparkle(true);", :complete => "miqSparkle(false);")
              .radio
                %label
                  %input{:type => "radio", :id => field_id, :value => f[0], :name => field_id, :checked => checked, :onclick => disabled ? "" : onclick}
                  = f[1]
          - else
            = options[field][1]
          - unless field_hash[:notes_display] == :hide || field_hash[:notes].blank?
            -# Display notes if available
            = field_hash[:notes]
      - elsif [:schedule_time].include?(field)
        .col-md-10
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of the text field
            = datepicker_input_tag("miq_date_1", options[:start_date],
                                   :class                  => "css1",
                                   "data-width"           => "auto",
                                   :readonly               => "true",
                                   "data-miq_observe_date" => {:url => url}.to_json)
          - else
            = options[:start_date]
          - if @edit && field_hash[:display] == :edit && !@edit[:stamp_typ]
            -# Allow editing of the text field
            = select_tag("start_hour",
                         options_for_select((0..23).to_a, options[:start_hour].to_i),
                         :class => "selectpicker selectWidth")
            %span h
            :javascript
              miqInitSelectPicker();
              miqSelectPickerEvent("start_hour", "#{url}")
            = select_tag("start_min",
                         options_for_select((0..55).step(5).to_a, options[:start_min].to_i),
                         :class    => "selectpicker selectWidth")
            %span m
            :javascript
              miqInitSelectPicker();
              miqSelectPickerEvent("start_min", "#{url}")
          - else
            #{options[:start_hour]}h
            &nbsp;
            #{options[:start_min]}m
      - elsif [:sysprep_upload_file].include?(field)
        .col-md-8
          - path = Rails.application.routes.recognize_path request.referer
          - if path[:controller] == "miq_request"
            = form_tag({:action    => "prov_edit",
                        :req_id    => @edit[:req_id].to_s},
                       :multipart => true,
                       :method    => :post) do
              .form-group
                .col-md-4
                  = render :partial => "shared/file_chooser", :locals => {:object_name => "upload", :method => "file"}
                .col-md-6
                  = submit_tag(_("Upload"), :class => "upload btn btn-default")
          - else
            = form_tag({:controller => path[:controller],
                        :action     => "explorer"},
                       :multipart  => true,
                       :method     => :post) do
              .form-group
                .col-md-4
                  = render :partial => "shared/file_chooser", :locals => {:object_name => "upload", :method => "file"}
                .col-md-6
                  = submit_tag(_("Upload"), :class => "upload btn btn-default")
      - elsif field == :user_script
        .col-md-8
          - path = Rails.application.routes.recognize_path request.referer
          - if path[:controller] == "miq_request"
            = form_tag({:action    => "prov_edit",
                         :req_id    => @edit[:req_id]&.to_s}.compact,
                         :multipart => true,
                         :method    => :post) do
              .form-group
                .col-md-4
                  = render :partial => "shared/file_chooser", :locals => {:object_name => "upload", :method => "file"}
                .col-md-6
                  = submit_tag(_("Upload Script"), :class => "upload btn btn-default")
                  = submit_tag(_("Clear Script"),  :class => "upload btn btn-default")
          - else
            = form_tag({:controller => path[:controller],
                        :action     => "explorer"},
                        :multipart  => true,
                        :method     => :post) do
              .form-group
                .col-md-4
                  = render :partial => "shared/file_chooser", :locals => {:object_name => "upload", :method => "file"}
                .col-md-6
                  = submit_tag(_("Upload Script"), :class => "upload btn btn-default")
                  = submit_tag(_("Clear Script"),  :class => "upload btn btn-default")