<commit_before># Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  def current_url_with_format_of( format )
    url_for( params.merge( 'format' => format, 'escape' => false ) )
  end

  # TODO Remove duplication in ApplicationController
  def current_user_name
    return session.user_name unless session.nil? or session.user_name.nil?
  end

  def session
    Session.get_from_cookies(cookies)
  end

  def is_admin?
    return session.admin? if session
  end

  def submit_button(name = 'Save')
      submit_tag(name, :class => 'btn_submit')
  end

  def cancel_button(path)
      link_to 'Cancel', path, :confirm => 'Are you sure you want to cancel?', :class => "link_cancel"
  end

  def discard_button(path)
      link_to 'Discard', path, :confirm => 'Clicking OK Will Discard Any Unsaved Changes. Click Cancel To Return To The Child Record Instead.', :class => 'link_discard'
  end

  def show_sidebar_links
    sidebar_links = {"View All Children" => children_path,
                     "Search" => search_children_path,
                     "Advanced Search" => new_advanced_search_path}
    sidebar_links.select do |_, link|
      !current_page?(link)
    end
  end

  def link_with_confirm(link_to, anchor, link_options = {})
    link_options.merge!(link_confirm_options(controller))
    link_to link_to, anchor, link_options
  end

  def link_confirm_options(controller)
    confirm_options = { }
    confirm_message = 'Clicking OK Will Discard Any Unsaved Changes. Click Cancel To Return To The %s Instead.'
    if /children/.match(controller.controller_name) and /edit|new/.match(controller.action_name)
      confirm_options[:confirm] = confirm_message % 'Child Record'
    elsif /user/.match(controller.controller_name) and /edit|new/.match(controller.action_name)
      confirm_options[:confirm] = confirm_message % 'Users Page'
    elsif /form_section/.match(controller.controller_name) and /index/.match(controller.action_name)
       confirm_options[:confirm] = confirm_message % 'Manage Form Sections'
    end
    confirm_options
  end

end
<commit_msg>#1348 - Akash/Ashok - oops fixing login<commit_after># Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  def current_url_with_format_of( format )
    url_for( params.merge( 'format' => format, 'escape' => false ) )
  end

  # TODO Remove duplication in ApplicationController
  def current_user_name
    return session.user_name unless session.nil? or session.user_name.nil?
  end

  def session
    Session.get_from_cookies(cookies)
  end

  def is_admin?
    return session.user.has_permission?(Permission::ADMIN[:admin]) if session
  end

  def submit_button(name = 'Save')
      submit_tag(name, :class => 'btn_submit')
  end

  def cancel_button(path)
      link_to 'Cancel', path, :confirm => 'Are you sure you want to cancel?', :class => "link_cancel"
  end

  def discard_button(path)
      link_to 'Discard', path, :confirm => 'Clicking OK Will Discard Any Unsaved Changes. Click Cancel To Return To The Child Record Instead.', :class => 'link_discard'
  end

  def show_sidebar_links
    sidebar_links = {"View All Children" => children_path,
                     "Search" => search_children_path,
                     "Advanced Search" => new_advanced_search_path}
    sidebar_links.select do |_, link|
      !current_page?(link)
    end
  end

  def link_with_confirm(link_to, anchor, link_options = {})
    link_options.merge!(link_confirm_options(controller))
    link_to link_to, anchor, link_options
  end

  def link_confirm_options(controller)
    confirm_options = { }
    confirm_message = 'Clicking OK Will Discard Any Unsaved Changes. Click Cancel To Return To The %s Instead.'
    if /children/.match(controller.controller_name) and /edit|new/.match(controller.action_name)
      confirm_options[:confirm] = confirm_message % 'Child Record'
    elsif /user/.match(controller.controller_name) and /edit|new/.match(controller.action_name)
      confirm_options[:confirm] = confirm_message % 'Users Page'
    elsif /form_section/.match(controller.controller_name) and /index/.match(controller.action_name)
       confirm_options[:confirm] = confirm_message % 'Manage Form Sections'
    end
    confirm_options
  end

end

{'fraction_non_alphanumeric': 0.0922722029988466, 'fraction_numerical': 0.000922722029988466, 'mean_word_length': 3.8231368186874306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4532751', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1265, 'n_words': 356}