<commit_before># Setting Accordion methods included in PxeController.rb
module PxeController::PxeCustomizationTemplates
  extend ActiveSupport::Concern

  # AJAX driven routine to check for changes in ANY field on the form
  def template_form_field_changed
    return unless load_edit("ct_edit__#{params[:id]}", "replace_cell__explorer")
    @prev_typ = @edit[:new][:typ]
    template_get_form_vars
    render :update do |page|                    # Use JS to update the display
      changed = (@edit[:new] != @edit[:current])
      if params[:typ] && @prev_typ != @edit[:new][:typ]
        @edit[:new][:script] = ""
        page.replace_html("script_div", :partial => "template_script_data")
      end
      page << javascript_for_miq_button_visibility(changed)
    end
  end

  def customization_template_delete
    assert_privileges("customization_template_delete")
    template_button_operation('destroy', 'Delete')
  end

  def template_list
    @lastaction = "template_list"
    @force_no_grid_xml   = true
    @gtl_type            = "list"
    @ajax_paging_buttons = true
    if params[:ppsetting]                                             # User selected new per page value
      @items_per_page = params[:ppsetting].to_i                       # Set the new per page value
      @settings[:perpage][@gtl_type.to_sym] = @items_per_page         # Set the per page setting for this gtl type
    end
    @sortcol = session[:ct_sortcol].nil? ? 0 : session[:ct_sortcol].to_i
    @sortdir = session[:ct_sortdir].nil? ? "ASC" : session[:ct_sortdir]
    pxe_img_id = x_node.split('-').last == "system" ? nil : x_node.split('-').last
    if pxe_img_id
      @view, @pages = get_view(CustomizationTemplate, :conditions => ["pxe_image_type_id=?", from_cid(pxe_img_id)]) # Get the records (into a view) and the paginator
    else
      @view, @pages = get_view(CustomizationTemplate, :conditions => ["system=?", true])  # Get the records (into a view) and the paginator
    end

    @current_page = @pages[:current] unless @pages.nil? # save the current page number
    session[:ct_sortcol] = @sortcol
    session[:ct_sortdir] = @sortdir

    if params[:action] != "button" && (params[:ppsetting] || params[:searchtag] || params[:entry] || params[:sort_choice] || params[:page])
      render :update do |page|                    # Use RJS to update the display
        page.replace("gtl_div", :partial => "layouts/x_gtl", :locals => {:action_url => "template_list"})
        page.replace_html("paging_div", :partial => "layouts/x_pagingcontrols")
        page << "miqSparkle(false);"  # Need to turn off sparkle in case original ajax element gets replaced
      end
    end
  end

  def customization_template_new
    assert_privileges("customization_template_new")
    @ct = CustomizationTemplate.new
    template_set_form_vars
    @in_a_form = true
    replace_right_cell("ct-")
  end

  def customization_template_copy
    assert_privileges("customization_template_copy")
    @_params[:typ] = "copy"
    customization_template_edit
  end

  def customization_template_edit
    assert_privileges("customization_template_edit")
    unless params[:id]
      obj = find_checked_items
      @_params[:id] = obj[0] unless obj.empty?
    end
    @ct = @record = identify_record(params[:id], CustomizationTemplate) if params[:id]
    if params[:typ] && params[:typ] == "copy"
      options = {}
      options[:name] = "Copy of #{@record.name}"
      options[:description] = @record.description
      options[:script] = @record.script
      options[:type] = @record.type
      options[:pxe_image_type_id] = @record.pxe_image_type_id.to_s if @record.pxe_image_type_id
      @ct = CustomizationTemplate.new(options)
    end
    template_set_form_vars
    @in_a_form = true
    session[:changed] = false
    replace_right_cell("ct-#{params[:id]}")
  end<commit_msg>PxeCustomizationTemplates: make options construction more declarative<commit_after># Setting Accordion methods included in PxeController.rb
module PxeController::PxeCustomizationTemplates
  extend ActiveSupport::Concern

  # AJAX driven routine to check for changes in ANY field on the form
  def template_form_field_changed
    return unless load_edit("ct_edit__#{params[:id]}", "replace_cell__explorer")
    @prev_typ = @edit[:new][:typ]
    template_get_form_vars
    render :update do |page|                    # Use JS to update the display
      changed = (@edit[:new] != @edit[:current])
      if params[:typ] && @prev_typ != @edit[:new][:typ]
        @edit[:new][:script] = ""
        page.replace_html("script_div", :partial => "template_script_data")
      end
      page << javascript_for_miq_button_visibility(changed)
    end
  end

  def customization_template_delete
    assert_privileges("customization_template_delete")
    template_button_operation('destroy', 'Delete')
  end

  def template_list
    @lastaction = "template_list"
    @force_no_grid_xml   = true
    @gtl_type            = "list"
    @ajax_paging_buttons = true
    if params[:ppsetting]                                             # User selected new per page value
      @items_per_page = params[:ppsetting].to_i                       # Set the new per page value
      @settings[:perpage][@gtl_type.to_sym] = @items_per_page         # Set the per page setting for this gtl type
    end
    @sortcol = session[:ct_sortcol].nil? ? 0 : session[:ct_sortcol].to_i
    @sortdir = session[:ct_sortdir].nil? ? "ASC" : session[:ct_sortdir]
    pxe_img_id = x_node.split('-').last == "system" ? nil : x_node.split('-').last
    if pxe_img_id
      @view, @pages = get_view(CustomizationTemplate, :conditions => ["pxe_image_type_id=?", from_cid(pxe_img_id)]) # Get the records (into a view) and the paginator
    else
      @view, @pages = get_view(CustomizationTemplate, :conditions => ["system=?", true])  # Get the records (into a view) and the paginator
    end

    @current_page = @pages[:current] unless @pages.nil? # save the current page number
    session[:ct_sortcol] = @sortcol
    session[:ct_sortdir] = @sortdir

    if params[:action] != "button" && (params[:ppsetting] || params[:searchtag] || params[:entry] || params[:sort_choice] || params[:page])
      render :update do |page|                    # Use RJS to update the display
        page.replace("gtl_div", :partial => "layouts/x_gtl", :locals => {:action_url => "template_list"})
        page.replace_html("paging_div", :partial => "layouts/x_pagingcontrols")
        page << "miqSparkle(false);"  # Need to turn off sparkle in case original ajax element gets replaced
      end
    end
  end

  def customization_template_new
    assert_privileges("customization_template_new")
    @ct = CustomizationTemplate.new
    template_set_form_vars
    @in_a_form = true
    replace_right_cell("ct-")
  end

  def customization_template_copy
    assert_privileges("customization_template_copy")
    @_params[:typ] = "copy"
    customization_template_edit
  end

  def customization_template_edit
    assert_privileges("customization_template_edit")
    unless params[:id]
      obj = find_checked_items
      @_params[:id] = obj[0] unless obj.empty?
    end
    @ct = @record = identify_record(params[:id], CustomizationTemplate) if params[:id]
    if params[:typ] && params[:typ] == "copy"
      options = {
        :name        => "Copy of #{@record.name}",
        :description => @record.description,
        :script      => @record.script,
        :type        => @record.type
      }
      options[:pxe_image_type_id] = @record.pxe_image_type_id.to_s if @record.pxe_image_type_id
      @ct = CustomizationTemplate.new(options)
    end
    template_set_form_vars
    @in_a_form = true
    session[:changed] = false
    replace_right_cell("ct-#{params[:id]}")
  end
{'fraction_non_alphanumeric': 0.11716235354705806, 'fraction_numerical': 0.0005149993562508047, 'mean_word_length': 3.428734321550741, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4891258', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2386, 'n_words': 546}