button_helper.rb 1.63 KB
Newer Older
1
module ButtonHelper
2 3 4 5 6 7 8 9 10 11 12
  # Output a "Copy to Clipboard" button
  #
  # data - Data attributes passed to `content_tag`
  #
  # Examples:
  #
  #   # Define the clipboard's text
  #   clipboard_button(clipboard_text: "Foo")
  #   # => "<button class='...' data-clipboard-text='Foo'>...</button>"
  #
  #   # Define the target element
13 14
  #   clipboard_button(clipboard_target: "div#foo")
  #   # => "<button class='...' data-clipboard-target='div#foo'>...</button>"
15 16 17
  #
  # See http://clipboardjs.com/#usage
  def clipboard_button(data = {})
18 19
    content_tag :button,
      icon('clipboard'),
20 21
      class: 'btn btn-xs btn-clipboard',
      data: data,
22 23 24
      type: :button
  end

25
  def http_clone_button(project)
26
    klass = 'btn js-protocol-switch'
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    klass << ' active'      if default_clone_protocol == 'http'
    klass << ' has_tooltip' if current_user.try(:require_password?)

    protocol = gitlab_config.protocol.upcase

    content_tag :button, protocol,
      class: klass,
      data: {
        clone: project.http_url_to_repo,
        container: 'body',
        html: 'true',
        title: "Set a password on your account<br>to pull or push via #{protocol}"
      },
      type: :button
  end

  def ssh_clone_button(project)
44
    klass = 'btn js-protocol-switch'
45 46 47 48 49 50 51 52 53 54 55 56 57 58
    klass << ' active'      if default_clone_protocol == 'ssh'
    klass << ' has_tooltip' if current_user.try(:require_ssh_key?)

    content_tag :button, 'SSH',
      class: klass,
      data: {
        clone: project.ssh_url_to_repo,
        container: 'body',
        html: 'true',
        title: 'Add an SSH key to your profile<br>to pull or push via SSH.'
      },
      type: :button
  end
end